font_access_query_select.tentative.https.window.js (3332B)
1 // META: script=/resources/testdriver.js 2 // META: script=/resources/testdriver-vendor.js 3 // META: script=resources/font-asserts.js 4 // META: script=resources/font-data.js 5 // META: script=resources/font-test-utils.js 6 // META: timeout=long 7 8 font_access_test(async t => { 9 const testData = getTestData(); 10 assert_greater_than_equal( 11 testData.size, 1, 'Need a least one test font data.'); 12 const testFont = testData.values().next().value; 13 14 const queryInput = {postscriptNames: [testFont.postscriptName]}; 15 const fonts = await self.queryLocalFonts(queryInput); 16 17 assert_equals( 18 fonts.length, 1, 'The result length should match the test length.'); 19 assert_font_equals(fonts[0], testFont); 20 }, 'queryLocalFonts(): valid postscript name in QueryOptions'); 21 22 font_access_test(async t => { 23 const queryInput = {postscriptNames: ['invalid_postscript_name']}; 24 const fonts = await self.queryLocalFonts(queryInput); 25 26 assert_equals( 27 fonts.length, 0, 28 'Fonts should not be selected for an invalid postscript name.'); 29 }, 'queryLocalFonts(): invalid postscript name in QueryOptions'); 30 31 font_access_test(async t => { 32 const fonts = await self.queryLocalFonts({}); 33 34 assert_greater_than_equal( 35 fonts.length, 1, 36 'All available fonts should be returned when an empty object is passed.'); 37 }, 'queryLocalFonts(): empty object for QueryOptions.postscriptNames'); 38 39 font_access_test(async t => { 40 const queryInput = {invalidFieldName: []}; 41 const fonts = await self.queryLocalFonts(queryInput); 42 43 assert_greater_than_equal( 44 fonts.length, 1, 45 'All available fonts should be returned when an invalid field name for ' + 46 'QueryOptions is passed.'); 47 }, 'queryLocalFonts(): invalid QueryOptions field'); 48 49 font_access_test(async t => { 50 const queryInput = {postscriptNames: []}; 51 const fonts = await self.queryLocalFonts(queryInput); 52 53 assert_equals( 54 fonts.length, 0, 55 'Fonts should not be selected when an empty list for ' + 56 'QueryOptions.postscriptNames is passed.'); 57 }, 'queryLocalFonts(): empty QueryOptions.postscriptNames list'); 58 59 font_access_test(async t => { 60 const fonts = await self.queryLocalFonts(undefined); 61 62 assert_greater_than_equal( 63 fonts.length, 1, 64 'All available fonts should be returned when undefined is passed for ' + 65 'input.'); 66 }, 'queryLocalFonts(): undefined QueryOptions'); 67 68 const non_ascii_input = [ 69 {postscriptNames: ['¥']}, 70 {postscriptNames: ['ß']}, 71 {postscriptNames: ['🎵']}, 72 // UTF-16LE, encodes to the same first four bytes as "Ahem" in ASCII. 73 {postscriptNames: ['\u6841\u6d65']}, 74 // U+6C34 CJK UNIFIED IDEOGRAPH (water) 75 {postscriptNames: ['\u6C34']}, 76 // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair) 77 {postscriptNames: ['\uD834\uDD1E']}, 78 // U+FFFD REPLACEMENT CHARACTER 79 {postscriptNames: ['\uFFFD']}, 80 // UTF-16 surrogate lead 81 {postscriptNames: ['\uD800']}, 82 // UTF-16 surrogate trail 83 {postscriptNames: ['\uDC00']}, 84 ]; 85 86 for (const test of non_ascii_input) { 87 font_access_test(async t => { 88 const fonts = await self.queryLocalFonts(test); 89 assert_equals( 90 fonts.length, 0, 91 'Fonts should not be selected for non-ASCII character input: ' + 92 JSON.stringify(fonts)); 93 }, `queryLocalFonts(): non-ASCII character input: ${JSON.stringify(test)}`); 94 }