summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/editing/editing-0/writing-suggestions/writingsuggestions.html
blob: 49e75000d3eb9cb828fb5e702010a6bd555c73b7 (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
<!DOCTYPE html>
<title>Tests for the writingsuggestions attribute</title>
<link rel='author' title='Sanket Joshi' href='mailto:sajos@microsoft.com'>
<link rel="help" href="https://html.spec.whatwg.org/multipage/interaction.html#writingsuggestions">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
'use strict';

customElements.define('test-custom-element', class extends HTMLElement {});

test(function() {
    assert_true('writingSuggestions' in document.createElement('input'));
}, 'Test that the writingsuggestions attribute is available on HTMLInputElement.');

test(function() {
    assert_true('writingSuggestions' in document.createElement('textarea'));
}, 'Test that the writingsuggestions attribute is available on HTMLTextAreaElement.');

test(function() {
    assert_true('writingSuggestions' in document.createElement('div'));
}, 'Test that the writingsuggestions attribute is available on HTMLDivElement.');

test(function() {
    assert_true('writingSuggestions' in document.createElement('span'));
}, 'Test that the writingsuggestions attribute is available on HTMLSpanElement.');

test(function() {
    assert_true('writingSuggestions' in document.createElement('test-custom-element'));
}, 'Test that the writingsuggestions attribute is available on custom elements.');

function testSetAttributeDirectly(IDLValue, contentValue, expectedIDLValue, expectedContentValue, testDescription) {
  test(function() {
      const elements = [document.createElement('input'),
                        document.createElement('textarea'),
                        document.createElement('div'),
                        document.createElement('span'),
                        document.createElement('test-custom-element') ];

      elements.forEach(function(element) {
        if (IDLValue != undefined) {
          element.writingSuggestions = IDLValue;
        }
        if (contentValue != undefined) {
          element.setAttribute('writingsuggestions', contentValue);
        }
        assert_equals(element.writingSuggestions, expectedIDLValue);
        assert_equals(element.getAttribute('writingsuggestions'), expectedContentValue);
      });
  }, testDescription);
}

// Test setting either the `writingsuggestions` IDL or content attribute to some variation of 'true' directly on the target element.
testSetAttributeDirectly('true', undefined, 'true', 'true', 'Test setting the `writingsuggestions` IDL attribute to `true` directly on the target element.');
testSetAttributeDirectly(undefined, 'true', 'true', 'true', 'Test setting the `writingsuggestions` content attribute to `true` directly on the target element.');
testSetAttributeDirectly(true, undefined, 'true', 'true', 'Test setting the `writingsuggestions` IDL attribute to boolean `true` directly on the target element.');
testSetAttributeDirectly(undefined, true, 'true', 'true', 'Test setting the `writingsuggestions` content attribute to boolean `true` directly on the target element.');
testSetAttributeDirectly('TrUe', undefined, 'true', 'true', 'Test setting the `writingsuggestions` IDL attribute to `TrUe` directly on the target element.');
testSetAttributeDirectly(undefined, 'TrUe', 'true', 'TrUe', 'Test setting the `writingsuggestions` content attribute to `TrUe` directly on the target element.');

// Test setting either the `writingsuggestions` IDL or content attribute to some variation of 'false' directly on the target element.
testSetAttributeDirectly('false', undefined, 'false', 'false', 'Test setting the `writingsuggestions` IDL attribute to `false` directly on the target element.');
testSetAttributeDirectly(undefined, 'false', 'false', 'false', 'Test setting the `writingsuggestions` content attribute to `false` directly on the target element.');
testSetAttributeDirectly(false, undefined, 'false', 'false', 'Test setting the `writingsuggestions` IDL attribute to boolean `false` directly on the target element.');
testSetAttributeDirectly(undefined, false, 'false', 'false', 'Test setting the `writingsuggestions` content attribute to boolean `false` directly on the target element.');
testSetAttributeDirectly('FaLsE', undefined, 'false', 'false', 'Test setting the `writingsuggestions` IDL attribute to `FaLsE` directly on the target element.');
testSetAttributeDirectly(undefined, 'FaLsE', 'false', 'FaLsE', 'Test setting the `writingsuggestions` content attribute to `FaLsE` directly on the target element.');

// Test setting either the `writingsuggestions` IDL or content attribute to the empty string directly on the target element.
testSetAttributeDirectly('', undefined, 'true', 'true', 'Test setting the `writingsuggestions` IDL attribute to the empty string directly on the target element.');
testSetAttributeDirectly(undefined, '', 'true', '', 'Test setting the `writingsuggestions` content attribute to the empty string directly on the target element.');

// Test setting either the `writingsuggestions` IDL or content attribute to an invalid value directly on the target element.
testSetAttributeDirectly('foo', undefined, 'true', 'true', 'Test setting the `writingsuggestions` IDL attribute to an invalid value directly on the target element.');
testSetAttributeDirectly(undefined, 'foo', 'true', 'foo', 'Test setting the `writingsuggestions` content attribute to an invalid value directly on the target element.');

// Test setting neither the `writingsuggestions` IDL nor content attribute directly on the target element.
testSetAttributeDirectly(undefined, undefined, 'true', null, 'Test the writing suggestions state when the `writingsuggestions` attribute is missing.');

// Test setting the content attribute after the IDL attribute and making sure the IDL and content attributes are properly reflected.
testSetAttributeDirectly('true', 'false', 'false', 'false', 'Test setting the `writingsuggestions` content attribute to `false` after the IDL attribute was set to `true`.');
testSetAttributeDirectly('true', '', 'true', '', 'Test setting the `writingsuggestions` content attribute to the empty string after the IDL attribute was set to `true`.');
testSetAttributeDirectly('true', 'foo', 'true', 'foo', 'Test setting the `writingsuggestions` content attribute to an invalid value after the IDL attribute was set to `true`.');
testSetAttributeDirectly('true', 'TrUe', 'true', 'TrUe', 'Test setting the `writingsuggestions` content attribute to `TrUe` after the IDL attribute was set to `true`.');
testSetAttributeDirectly('true', 'FaLsE', 'false', 'FaLsE', 'Test setting the `writingsuggestions` content attribute to `FaLsE` after the IDL attribute was set to `true`.');
testSetAttributeDirectly('true', true, 'true', 'true', 'Test setting the `writingsuggestions` content attribute to boolean `true` after the IDL attribute was set to `true`.');
testSetAttributeDirectly('true', false, 'false', 'false', 'Test setting the `writingsuggestions` content attribute to boolean `false` after the IDL attribute was set to `true`.');

testSetAttributeDirectly('false', 'true', 'true', 'true', 'Test setting the `writingsuggestions` content attribute to `true` after the IDL attribute was set to `false`.');
testSetAttributeDirectly('false', '', 'true', '', 'Test setting the `writingsuggestions` content attribute to the empty string after the IDL attribute was set to `false`.');
testSetAttributeDirectly('false', 'foo', 'true', 'foo', 'Test setting the `writingsuggestions` content attribute to an invalid value after the IDL attribute was set to `false`.');
testSetAttributeDirectly('false', 'TrUe', 'true', 'TrUe', 'Test setting the `writingsuggestions` content attribute to `TrUe` after the IDL attribute was set to `false`.');
testSetAttributeDirectly('false', 'FaLsE', 'false', 'FaLsE', 'Test setting the `writingsuggestions` content attribute to `FaLsE` after the IDL attribute was set to `false`.');
testSetAttributeDirectly('false', true, 'true', 'true', 'Test setting the `writingsuggestions` content attribute to boolean `true` after the IDL attribute was set to `false`.');
testSetAttributeDirectly('false', false, 'false', 'false', 'Test setting the `writingsuggestions` content attribute to boolean `false` after the IDL attribute was set to `false`.');

test(function() {
  const elements = [ new DOMParser().parseFromString('<input writingsuggestions />', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<textarea writingsuggestions></textarea>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<div writingsuggestions></div>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<span writingsuggestions></span>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.writingSuggestions, 'true');
    assert_equals(element.getAttribute('writingsuggestions'), '');
  });
}, 'Test setting the `writingsuggestions` attribute with a missing value directly on the target element.');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions="true"><input /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="true"><textarea></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="true"><div></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="true"><span></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'true');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), 'true');
    assert_equals(element.writingSuggestions, 'true');
    assert_equals(element.getAttribute('writingsuggestions'), null);
  });
}, 'Test setting the `writingsuggestions` attribute to "true" on a parent element.');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions=""><input /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions=""><textarea></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions=""><div></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions=""><span></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'true');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), '');
    assert_equals(element.writingSuggestions, 'true');
    assert_equals(element.getAttribute('writingsuggestions'), null);
  });
}, 'Test setting the `writingsuggestions` attribute to an empty string on a parent element.');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions="false"><input /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><textarea></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><div></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><span></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'false');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), 'false');
    assert_equals(element.writingSuggestions, 'false');
    assert_equals(element.getAttribute('writingsuggestions'), null);
  });
}, 'Test setting the `writingsuggestions` attribute to "false" on a parent element.');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions="foo"><input /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="foo"><textarea></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="foo"><div></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="foo"><span></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'true');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), 'foo');
    assert_equals(element.writingSuggestions, 'true');
    assert_equals(element.getAttribute('writingsuggestions'), null);
  });
}, 'Test setting the `writingsuggestions` attribute to an invalid value on a parent element.');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions="true"><input writingsuggestions="false" /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="true"><textarea writingsuggestions="false"></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="true"><div writingsuggestions="false"></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="true"><span writingsuggestions="false"></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'true');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), 'true');
    assert_equals(element.writingSuggestions, 'false');
    assert_equals(element.getAttribute('writingsuggestions'), 'false');
  });
}, 'Test overriding the parent element\'s `writingsuggestions` attribute from "true" to "false".');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions=""><input writingsuggestions="false" /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions=""><textarea writingsuggestions="false"></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions=""><div writingsuggestions="false"></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions=""><span writingsuggestions="false"></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'true');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), '');
    assert_equals(element.writingSuggestions, 'false');
    assert_equals(element.getAttribute('writingsuggestions'), 'false');
  });
}, 'Test overriding the parent element\'s `writingsuggestions` attribute from the empty string to "false".');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions="false"><input writingsuggestions="true" /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><textarea writingsuggestions="true"></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><div writingsuggestions="true"></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><span writingsuggestions="true"></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'false');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), 'false');
    assert_equals(element.writingSuggestions, 'true');
    assert_equals(element.getAttribute('writingsuggestions'), 'true');
  });
}, 'Test overriding the parent element\'s `writingsuggestions` attribute from "false" to "true".');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions="false"><input writingsuggestions="foo" /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><textarea writingsuggestions="foo"></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><div writingsuggestions="foo"></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><span writingsuggestions="foo"></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'false');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), 'false');
    assert_equals(element.writingSuggestions, 'true');
    assert_equals(element.getAttribute('writingsuggestions'), 'foo');
  });
}, 'Test overriding the parent element\'s `writingsuggestions` attribute from "false" to an invalid value.');

test(function() {
  const elements = [ new DOMParser().parseFromString('<html><body writingsuggestions="false"><input writingsuggestions="" /></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><textarea writingsuggestions=""></textarea></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><div writingsuggestions=""></div></body></html>', 'text/html').body.firstElementChild,
                     new DOMParser().parseFromString('<html><body writingsuggestions="false"><span writingsuggestions=""></span></body></html>', 'text/html').body.firstElementChild ];

  elements.forEach(function(element) {
    assert_equals(element.parentElement.writingSuggestions, 'false');
    assert_equals(element.parentElement.getAttribute('writingsuggestions'), 'false');
    assert_equals(element.writingSuggestions, 'true');
    assert_equals(element.getAttribute('writingsuggestions'), '');
  });
}, 'Test overriding the parent element\'s `writingsuggestions` attribute from "false" to the empty string.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input /><textarea></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test turning off writing suggestions for an entire document.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input writingsuggestions="true" /><textarea></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on an input element from "false" to "true".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input /><textarea writingsuggestions="true"></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a textarea element from "false" to "true".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input /><textarea></textarea><div writingsuggestions="true"></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a div element from "false" to "true".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input /><textarea></textarea><div></div><span writingsuggestions="true"></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a span element from "false" to "true".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input writingsuggestions=""><textarea></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on an input element from "false" to the empty string.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input><textarea writingsuggestions=""></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a textarea element from "false" to the empty string.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input><textarea></textarea><div writingsuggestions=""></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a div element from "false" to the empty string.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input><textarea></textarea><div></div><span writingsuggestions=""></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a span element from "false" to the empty string.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input writingsuggestions="foo"><textarea></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on an input element from "false" to an invalid value.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input><textarea writingsuggestions="foo"></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a textarea element from "false" to an invalid value.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input><textarea></textarea><div writingsuggestions="foo"></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a div element from "false" to an invalid value.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="false"><body><input><textarea></textarea><div></div><span writingsuggestions="foo"></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'false');
  assert_equals(doc.body.writingSuggestions, 'false');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a span element from "false" to an invalid value.');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="true"><body><input writingsuggestions="false"><textarea></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'true');
  assert_equals(doc.body.writingSuggestions, 'true');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on an input element from "true" to "false".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="true"><body><input><textarea writingsuggestions="false"></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'true');
  assert_equals(doc.body.writingSuggestions, 'true');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a textarea element from "true" to "false".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="true"><body><input><textarea></textarea><div writingsuggestions="false"></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'true');
  assert_equals(doc.body.writingSuggestions, 'true');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a div element from "true" to "false".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="true"><body><input><textarea></textarea><div></div><span writingsuggestions="false"></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'true');
  assert_equals(doc.body.writingSuggestions, 'true');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a span element from "true" to "false".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions=""><body><input writingsuggestions="false"><textarea></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'true');
  assert_equals(doc.body.writingSuggestions, 'true');
  assert_equals(doc.querySelector('input').writingSuggestions, 'false');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on an input element from the empty string to "false".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions=""><body><input><textarea writingsuggestions="false"></textarea><div></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'true');
  assert_equals(doc.body.writingSuggestions, 'true');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'false');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a textarea element from the empty string to "false".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions=""><body><input><textarea></textarea><div writingsuggestions="false"></div><span></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'true');
  assert_equals(doc.body.writingSuggestions, 'true');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'false');
  assert_equals(doc.querySelector('span').writingSuggestions, 'true');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a div element from the empty string to "false".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions=""><body><input><textarea></textarea><div></div><span writingsuggestions="false"></span></body></html>', 'text/html');
  assert_equals(doc.documentElement.writingSuggestions, 'true');
  assert_equals(doc.body.writingSuggestions, 'true');
  assert_equals(doc.querySelector('input').writingSuggestions, 'true');
  assert_equals(doc.querySelector('textarea').writingSuggestions, 'true');
  assert_equals(doc.querySelector('div').writingSuggestions, 'true');
  assert_equals(doc.querySelector('span').writingSuggestions, 'false');
}, 'Test overriding a non-parent ancestor element\'s `writingsuggestions` attribute on a span element from the empty string to "false".');

test(function() {
  const doc = new DOMParser().parseFromString('<html writingsuggestions="true"><body><div contenteditable="true"><span>Writing suggestions allowed.</span> <span writingsuggestions="false">Writing suggestions not allowed.</span></div></body></html>', 'text/html');
  const div = doc.querySelector('div');
  const span1 = doc.querySelector('span');
  const span2 = doc.querySelector('span:last-child');
  assert_equals(div.writingSuggestions, 'true');
  assert_equals(span1.writingSuggestions, 'true');
  assert_equals(span2.writingSuggestions, 'false');
}, 'Test that for continuous text on the screen, writing suggestions may be allowed in one part but not another.');

</script>
</body>
</html>