summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-font-loading/fontface-override-descriptor-getter-setter.sub.html
blob: a3d8ccec3681d9124458106da9ff85be03fccdb0 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE html>
<title>Tests getters and setters of the font metrics override descriptors of FontFace</title>
<link rel="author" href="mailto:xiaochengh@chromium.org">
<link rel="help" href="https://drafts.csswg.org/css-font-loading/#fontface-interface">
<link rel="help" href="https://drafts.csswg.org/css-fonts-4/#font-metrics-override-desc">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function rejection(promise) {
  return new Promise((resolve, reject) => promise.then(reject, resolve));
}

// ascentOverride

test(() => {
  const face = new FontFace(
      'ascent-override-initial',
      'url(https://{{host}}/font.woff)');
  assert_equals(face.ascentOverride, 'normal');
}, "Initial value of ascentOverride should be 'normal'");

test(() => {
  const face = new FontFace(
    'ascent-override-initialize-with-normal',
    'url(https://{{host}}/font.woff)',
    {ascentOverride: 'normal'});
  assert_equals(face.ascentOverride, 'normal');
}, "Initialize ascentOverride with 'normal' should succeed");

test(() => {
  const face = new FontFace(
    'ascent-override-initialize-with-percentage',
    'url(https://{{host}}/font.woff)',
    {ascentOverride: '50%'});
  assert_equals(face.ascentOverride, '50%');
}, "Initialize ascentOverride with a percentage should succeed");

promise_test(async () => {
  const face = new FontFace(
      'ascent-override-initialize-with-negative-percentage',
      'url(https://{{host}}/font.woff)',
      {ascentOverride: '-50%'});
  const error = await rejection(face.load());
  assert_equals('error', face.status);
  assert_throws_dom('SyntaxError', () => {throw error});
}, "Initialize ascentOverride with a negative percentage should fail");

promise_test(async () => {
  const face = new FontFace(
      'ascent-override-initialize-with-non-percentage',
      'url(https://{{host}}/font.woff)',
      {ascentOverride: '10px'});
  const error = await rejection(face.load());
  assert_equals('error', face.status);
  assert_throws_dom('SyntaxError', () => {throw error});
}, "Initialize ascentOverride with a non-percentage should fail");

test(() => {
  const face = new FontFace(
    'ascent-override-normal-to-percentage',
    'url(https://{{host}}/font.woff)',
    {ascentOverride: 'normal'});
  face.ascentOverride = '50%';
  assert_equals(face.ascentOverride, '50%');
}, "Changing ascentOverride from 'normal' to percentage should succeed");

test(() => {
  const face = new FontFace(
    'ascent-override-percentage-to-normal',
    'url(https://{{host}}/font.woff)',
    {ascentOverride: '50%'});
  face.ascentOverride = 'normal';
  assert_equals(face.ascentOverride, 'normal');
}, "Changing ascentOverride from percentage to 'normal' should succeed");

test(() => {
  const face = new FontFace(
    'ascent-override-set-to-invalid',
    'url(https://{{host}}/font.woff)');
  assert_throws_dom('SyntaxError', () => {face.ascentOverride = '10px'});
}, "Changing ascentOverride to invalid value should fail");

// descentOverride

test(() => {
  const face = new FontFace(
      'descent-override-initial',
      'url(https://{{host}}/font.woff)');
  assert_equals(face.descentOverride, 'normal');
}, "Initial value of descentOverride should be 'normal'");

test(() => {
  const face = new FontFace(
    'descent-override-initialize-with-normal',
    'url(https://{{host}}/font.woff)',
    {descentOverride: 'normal'});
  assert_equals(face.descentOverride, 'normal');
}, "Initialize descentOverride with 'normal' should succeed");

test(() => {
  const face = new FontFace(
    'descent-override-initialize-with-percentage',
    'url(https://{{host}}/font.woff)',
    {descentOverride: '50%'});
  assert_equals(face.descentOverride, '50%');
}, "Initialize descentOverride with a percentage should succeed");

promise_test(async () => {
  const face = new FontFace(
      'descent-override-initialize-with-negative-percentage',
      'url(https://{{host}}/font.woff)',
      {descentOverride: '-50%'});
  const error = await rejection(face.load());
  assert_equals('error', face.status);
  assert_throws_dom('SyntaxError', () => {throw error});
}, "Initialize descentOverride with a negative percentage should fail");

promise_test(async () => {
  const face = new FontFace(
      'descent-override-initialize-with-non-percentage',
      'url(https://{{host}}/font.woff)',
      {descentOverride: '10px'});
  const error = await rejection(face.load());
  assert_equals('error', face.status);
  assert_throws_dom('SyntaxError', () => {throw error});
}, "Initialize descentOverride with a non-percentage should fail");

test(() => {
  const face = new FontFace(
    'descent-override-normal-to-percentage',
    'url(https://{{host}}/font.woff)',
    {descentOverride: 'normal'});
  face.descentOverride = '50%';
  assert_equals(face.descentOverride, '50%');
}, "Changing descentOverride from 'normal' to percentage should succeed");

test(() => {
  const face = new FontFace(
    'descent-override-percentage-to-normal',
    'url(https://{{host}}/font.woff)',
    {descentOverride: '50%'});
  face.descentOverride = 'normal';
  assert_equals(face.descentOverride, 'normal');
}, "Changing descentOverride from percentage to 'normal' should succeed");

test(() => {
  const face = new FontFace(
    'descent-override-set-to-invalid',
    'url(https://{{host}}/font.woff)');
  assert_throws_dom('SyntaxError', () => {face.descentOverride = '10px'});
}, "Changing descentOverride to invalid value should fail");

// lineGapOverride

test(() => {
  const face = new FontFace(
      'lineGap-override-initial',
      'url(https://{{host}}/font.woff)');
  assert_equals(face.lineGapOverride, 'normal');
}, "Initial value of lineGapOverride should be 'normal'");

test(() => {
  const face = new FontFace(
    'lineGap-override-initialize-with-normal',
    'url(https://{{host}}/font.woff)',
    {lineGapOverride: 'normal'});
  assert_equals(face.lineGapOverride, 'normal');
}, "Initialize lineGapOverride with 'normal' should succeed");

test(() => {
  const face = new FontFace(
    'lineGap-override-initialize-with-percentage',
    'url(https://{{host}}/font.woff)',
    {lineGapOverride: '50%'});
  assert_equals(face.lineGapOverride, '50%');
}, "Initialize lineGapOverride with a percentage should succeed");

promise_test(async () => {
  const face = new FontFace(
      'lineGap-override-initialize-with-negative-percentage',
      'url(https://{{host}}/font.woff)',
      {lineGapOverride: '-50%'});
  const error = await rejection(face.load());
  assert_equals('error', face.status);
  assert_throws_dom('SyntaxError', () => {throw error});
}, "Initialize lineGapOverride with a negative percentage should fail");

promise_test(async () => {
  const face = new FontFace(
      'lineGap-override-initialize-with-non-percentage',
      'url(https://{{host}}/font.woff)',
      {lineGapOverride: '10px'});
  const error = await rejection(face.load());
  assert_equals('error', face.status);
  assert_throws_dom('SyntaxError', () => {throw error});
}, "Initialize lineGapOverride with a non-percentage should fail");

test(() => {
  const face = new FontFace(
    'lineGap-override-normal-to-percentage',
    'url(https://{{host}}/font.woff)',
    {lineGapOverride: 'normal'});
  face.lineGapOverride = '50%';
  assert_equals(face.lineGapOverride, '50%');
}, "Changing lineGapOverride from 'normal' to percentage should succeed");

test(() => {
  const face = new FontFace(
    'lineGap-override-percentage-to-normal',
    'url(https://{{host}}/font.woff)',
    {lineGapOverride: '50%'});
  face.lineGapOverride = 'normal';
  assert_equals(face.lineGapOverride, 'normal');
}, "Changing lineGapOverride from percentage to 'normal' should succeed");

test(() => {
  const face = new FontFace(
    'lineGap-override-set-to-invalid',
    'url(https://{{host}}/font.woff)');
  assert_throws_dom('SyntaxError', () => {face.lineGapOverride = '10px'});
}, "Changing lineGapOverride to invalid value should fail");
</script>