summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/font-access/font_access_query_select.tentative.https.window.js
blob: df89ea7938bc571d0501a79ce660b784aa2cdab9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// META: script=/resources/testdriver.js
// META: script=/resources/testdriver-vendor.js
// META: script=resources/font-asserts.js
// META: script=resources/font-data.js
// META: script=resources/font-test-utils.js
// META: timeout=long

font_access_test(async t => {
  const testData = getTestData();
  assert_greater_than_equal(
      testData.size, 1, 'Need a least one test font data.');
  const testFont = testData.values().next().value;

  const queryInput = {postscriptNames: [testFont.postscriptName]};
  const fonts = await self.queryLocalFonts(queryInput);

  assert_equals(
      fonts.length, 1, 'The result length should match the test length.');
  assert_font_equals(fonts[0], testFont);
}, 'queryLocalFonts(): valid postscript name in QueryOptions');

font_access_test(async t => {
  const queryInput = {postscriptNames: ['invalid_postscript_name']};
  const fonts = await self.queryLocalFonts(queryInput);

  assert_equals(
      fonts.length, 0,
      'Fonts should not be selected for an invalid postscript name.');
}, 'queryLocalFonts(): invalid postscript name in QueryOptions');

font_access_test(async t => {
  const fonts = await self.queryLocalFonts({});

  assert_greater_than_equal(
      fonts.length, 1,
      'All available fonts should be returned when an empty object is passed.');
}, 'queryLocalFonts(): empty object for QueryOptions.postscriptNames');

font_access_test(async t => {
  const queryInput = {invalidFieldName: []};
  const fonts = await self.queryLocalFonts(queryInput);

  assert_greater_than_equal(
      fonts.length, 1,
      'All available fonts should be returned when an invalid field name for ' +
          'QueryOptions is passed.');
}, 'queryLocalFonts(): invalid QueryOptions field');

font_access_test(async t => {
  const queryInput = {postscriptNames: []};
  const fonts = await self.queryLocalFonts(queryInput);

  assert_equals(
      fonts.length, 0,
      'Fonts should not be selected when an empty list for ' +
          'QueryOptions.postscriptNames is passed.');
}, 'queryLocalFonts(): empty QueryOptions.postscriptNames list');

font_access_test(async t => {
  const fonts = await self.queryLocalFonts(undefined);

  assert_greater_than_equal(
      fonts.length, 1,
      'All available fonts should be returned when undefined is passed for ' +
          'input.');
}, 'queryLocalFonts(): undefined QueryOptions');

const non_ascii_input = [
  {postscriptNames: ['¥']},
  {postscriptNames: ['ß']},
  {postscriptNames: ['🎵']},
  // UTF-16LE, encodes to the same first four bytes as "Ahem" in ASCII.
  {postscriptNames: ['\u6841\u6d65']},
  // U+6C34 CJK UNIFIED IDEOGRAPH (water)
  {postscriptNames: ['\u6C34']},
  // U+1D11E MUSICAL SYMBOL G-CLEF (UTF-16 surrogate pair)
  {postscriptNames: ['\uD834\uDD1E']},
  // U+FFFD REPLACEMENT CHARACTER
  {postscriptNames: ['\uFFFD']},
  // UTF-16 surrogate lead
  {postscriptNames: ['\uD800']},
  // UTF-16 surrogate trail
  {postscriptNames: ['\uDC00']},
];

for (const test of non_ascii_input) {
  font_access_test(async t => {
    const fonts = await self.queryLocalFonts(test);
    assert_equals(
        fonts.length, 0,
        'Fonts should not be selected for non-ASCII character input: ' +
            JSON.stringify(fonts));
  }, `queryLocalFonts(): non-ASCII character input: ${JSON.stringify(test)}`);
}