summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/e10s/browser_caching_attributes.js
blob: 7b20cff49f8e0f46b584ab9f7d2f41cb25f2709b (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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/* import-globals-from ../../mochitest/attributes.js */
loadScripts({ name: "attributes.js", dir: MOCHITESTS_DIR });

/**
 * Default textbox accessible attributes.
 */
const defaultAttributes = {
  "margin-top": "0px",
  "margin-right": "0px",
  "margin-bottom": "0px",
  "margin-left": "0px",
  "text-align": "start",
  "text-indent": "0px",
  id: "textbox",
  tag: "input",
  display: "inline-block",
};

/**
 * Test data has the format of:
 * {
 *   desc        {String}         description for better logging
 *   expected    {Object}         expected attributes for given accessibles
 *   unexpected  {Object}         unexpected attributes for given accessibles
 *
 *   action      {?AsyncFunction} an optional action that awaits a change in
 *                                attributes
 *   attrs       {?Array}         an optional list of attributes to update
 *   waitFor     {?Number}        an optional event to wait for
 * }
 */
const attributesTests = [
  {
    desc: "Initiall accessible attributes",
    expected: defaultAttributes,
    unexpected: {
      "line-number": "1",
      "explicit-name": "true",
      "container-live": "polite",
      live: "polite",
    },
  },
  {
    desc: "@line-number attribute is present when textbox is focused",
    async action(browser) {
      await invokeFocus(browser, "textbox");
    },
    waitFor: EVENT_FOCUS,
    expected: Object.assign({}, defaultAttributes, { "line-number": "1" }),
    unexpected: {
      "explicit-name": "true",
      "container-live": "polite",
      live: "polite",
    },
  },
  {
    desc: "@aria-live sets container-live and live attributes",
    attrs: [
      {
        attr: "aria-live",
        value: "polite",
      },
    ],
    expected: Object.assign({}, defaultAttributes, {
      "line-number": "1",
      "container-live": "polite",
      live: "polite",
    }),
    unexpected: {
      "explicit-name": "true",
    },
  },
  {
    desc: "@title attribute sets explicit-name attribute to true",
    attrs: [
      {
        attr: "title",
        value: "textbox",
      },
    ],
    expected: Object.assign({}, defaultAttributes, {
      "line-number": "1",
      "explicit-name": "true",
      "container-live": "polite",
      live: "polite",
    }),
    unexpected: {},
  },
];

/**
 * Test caching of accessible object attributes
 */
addAccessibleTask(
  `
  <input id="textbox" value="hello">`,
  async function (browser, accDoc) {
    let textbox = findAccessibleChildByID(accDoc, "textbox");
    for (let {
      desc,
      action,
      attrs,
      expected,
      waitFor,
      unexpected,
    } of attributesTests) {
      info(desc);
      let onUpdate;

      if (waitFor) {
        onUpdate = waitForEvent(waitFor, "textbox");
      }

      if (action) {
        await action(browser);
      } else if (attrs) {
        for (let { attr, value } of attrs) {
          await invokeSetAttribute(browser, "textbox", attr, value);
        }
      }

      await onUpdate;
      testAttrs(textbox, expected);
      testAbsentAttrs(textbox, unexpected);
    }
  },
  {
    // These tests don't work yet with the parent process cache.
    topLevel: false,
    iframe: false,
    remoteIframe: false,
  }
);

/**
 * Test caching of the tag attribute.
 */
addAccessibleTask(
  `
<p id="p">text</p>
<textarea id="textarea"></textarea>
  `,
  async function (browser, docAcc) {
    testAttrs(docAcc, { tag: "body" }, true);
    const p = findAccessibleChildByID(docAcc, "p");
    testAttrs(p, { tag: "p" }, true);
    const textLeaf = p.firstChild;
    testAbsentAttrs(textLeaf, { tag: "" });
    const textarea = findAccessibleChildByID(docAcc, "textarea");
    testAttrs(textarea, { tag: "textarea" }, true);
  },
  { chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);

/**
 * Test caching of the text-input-type attribute.
 */
addAccessibleTask(
  `
  <input id="default">
  <input id="email" type="email">
  <input id="password" type="password">
  <input id="text" type="text">
  <input id="date" type="date">
  <input id="time" type="time">
  <input id="checkbox" type="checkbox">
  <input id="radio" type="radio">
  `,
  async function (browser, docAcc) {
    function testInputType(id, inputType) {
      if (inputType == undefined) {
        testAbsentAttrs(findAccessibleChildByID(docAcc, id), {
          "text-input-type": "",
        });
      } else {
        testAttrs(
          findAccessibleChildByID(docAcc, id),
          { "text-input-type": inputType },
          true
        );
      }
    }

    testInputType("default");
    testInputType("email", "email");
    testInputType("password", "password");
    testInputType("text", "text");
    testInputType("date", "date");
    testInputType("time", "time");
    testInputType("checkbox");
    testInputType("radio");
  },
  { chrome: true, topLevel: true, iframe: false, remoteIframe: false }
);

/**
 * Test caching of the display attribute.
 */
addAccessibleTask(
  `
<div id="div">
  <ins id="ins">a</ins>
  <button id="button">b</button>
</div>
  `,
  async function (browser, docAcc) {
    const div = findAccessibleChildByID(docAcc, "div");
    testAttrs(div, { display: "block" }, true);
    const ins = findAccessibleChildByID(docAcc, "ins");
    testAttrs(ins, { display: "inline" }, true);
    const textLeaf = ins.firstChild;
    testAbsentAttrs(textLeaf, { display: "" });
    const button = findAccessibleChildByID(docAcc, "button");
    testAttrs(button, { display: "inline-block" }, true);

    await invokeContentTask(browser, [], () => {
      content.document.getElementById("ins").style.display = "block";
      content.document.body.offsetTop; // Flush layout.
    });
    await untilCacheIs(
      () => ins.attributes.getStringProperty("display"),
      "block",
      "ins display attribute changed to block"
    );
  },
  { chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);

/**
 * Test that there is no display attribute on image map areas.
 */
addAccessibleTask(
  `
<map name="normalMap">
  <area id="normalArea" shape="default">
</map>
<img src="http://example.com/a11y/accessible/tests/mochitest/moz.png" usemap="#normalMap">
<audio>
  <map name="unslottedMap">
    <area id="unslottedArea" shape="default">
  </map>
</audio>
<img src="http://example.com/a11y/accessible/tests/mochitest/moz.png" usemap="#unslottedMap">
  `,
  async function (browser, docAcc) {
    const normalArea = findAccessibleChildByID(docAcc, "normalArea");
    testAbsentAttrs(normalArea, { display: "" });
    const unslottedArea = findAccessibleChildByID(docAcc, "unslottedArea");
    testAbsentAttrs(unslottedArea, { display: "" });
  },
  { topLevel: true }
);

/**
 * Test caching of the explicit-name attribute.
 */
addAccessibleTask(
  `
<h1 id="h1">content</h1>
<button id="buttonContent">content</button>
<button id="buttonLabel" aria-label="label">content</button>
<button id="buttonEmpty"></button>
<button id="buttonSummary"><details><summary>test</summary></details></button>
<div id="div"></div>
  `,
  async function (browser, docAcc) {
    const h1 = findAccessibleChildByID(docAcc, "h1");
    testAbsentAttrs(h1, { "explicit-name": "" });
    const buttonContent = findAccessibleChildByID(docAcc, "buttonContent");
    testAbsentAttrs(buttonContent, { "explicit-name": "" });
    const buttonLabel = findAccessibleChildByID(docAcc, "buttonLabel");
    testAttrs(buttonLabel, { "explicit-name": "true" }, true);
    const buttonEmpty = findAccessibleChildByID(docAcc, "buttonEmpty");
    testAbsentAttrs(buttonEmpty, { "explicit-name": "" });
    const buttonSummary = findAccessibleChildByID(docAcc, "buttonSummary");
    testAbsentAttrs(buttonSummary, { "explicit-name": "" });
    const div = findAccessibleChildByID(docAcc, "div");
    testAbsentAttrs(div, { "explicit-name": "" });

    info("Setting aria-label on h1");
    let nameChanged = waitForEvent(EVENT_NAME_CHANGE, h1);
    await invokeContentTask(browser, [], () => {
      content.document.getElementById("h1").setAttribute("aria-label", "label");
    });
    await nameChanged;
    testAttrs(h1, { "explicit-name": "true" }, true);
  },
  { chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);

/**
 * Test caching of ARIA attributes that are exposed via object attributes.
 */
addAccessibleTask(
  `
<div id="currentTrue" aria-current="true">currentTrue</div>
<div id="currentFalse" aria-current="false">currentFalse</div>
<div id="currentPage" aria-current="page">currentPage</div>
<div id="currentBlah" aria-current="blah">currentBlah</div>
<div id="haspopupMenu" aria-haspopup="menu">haspopup</div>
<div id="rowColCountPositive" role="table" aria-rowcount="1000" aria-colcount="1000">
  <div role="row">
    <div id="rowColIndexPositive" role="cell" aria-rowindex="100" aria-colindex="100">positive</div>
  </div>
</div>
<div id="rowColCountNegative" role="table" aria-rowcount="-1" aria-colcount="-1">
  <div role="row">
    <div id="rowColIndexNegative" role="cell" aria-rowindex="-1" aria-colindex="-1">negative</div>
  </div>
</div>
<div id="rowColCountInvalid" role="table" aria-rowcount="z" aria-colcount="z">
  <div role="row">
    <div id="rowColIndexInvalid" role="cell" aria-rowindex="z" aria-colindex="z">invalid</div>
  </div>
</div>
<div id="foo" aria-foo="bar">foo</div>
<div id="mutate" aria-current="true">mutate</div>
  `,
  async function (browser, docAcc) {
    const currentTrue = findAccessibleChildByID(docAcc, "currentTrue");
    testAttrs(currentTrue, { current: "true" }, true);
    const currentFalse = findAccessibleChildByID(docAcc, "currentFalse");
    testAbsentAttrs(currentFalse, { current: "" });
    const currentPage = findAccessibleChildByID(docAcc, "currentPage");
    testAttrs(currentPage, { current: "page" }, true);
    // Test that token normalization works.
    const currentBlah = findAccessibleChildByID(docAcc, "currentBlah");
    testAttrs(currentBlah, { current: "true" }, true);
    const haspopupMenu = findAccessibleChildByID(docAcc, "haspopupMenu");
    testAttrs(haspopupMenu, { haspopup: "menu" }, true);

    // Test normalization of integer values.
    const rowColCountPositive = findAccessibleChildByID(
      docAcc,
      "rowColCountPositive"
    );
    testAttrs(
      rowColCountPositive,
      { rowcount: "1000", colcount: "1000" },
      true
    );
    const rowColIndexPositive = findAccessibleChildByID(
      docAcc,
      "rowColIndexPositive"
    );
    testAttrs(rowColIndexPositive, { rowindex: "100", colindex: "100" }, true);
    const rowColCountNegative = findAccessibleChildByID(
      docAcc,
      "rowColCountNegative"
    );
    testAttrs(rowColCountNegative, { rowcount: "-1", colcount: "-1" }, true);
    const rowColIndexNegative = findAccessibleChildByID(
      docAcc,
      "rowColIndexNegative"
    );
    testAbsentAttrs(rowColIndexNegative, { rowindex: "", colindex: "" });
    const rowColCountInvalid = findAccessibleChildByID(
      docAcc,
      "rowColCountInvalid"
    );
    testAbsentAttrs(rowColCountInvalid, { rowcount: "", colcount: "" });
    const rowColIndexInvalid = findAccessibleChildByID(
      docAcc,
      "rowColIndexInvalid"
    );
    testAbsentAttrs(rowColIndexInvalid, { rowindex: "", colindex: "" });

    // Test that unknown aria- attributes get exposed.
    const foo = findAccessibleChildByID(docAcc, "foo");
    testAttrs(foo, { foo: "bar" }, true);

    const mutate = findAccessibleChildByID(docAcc, "mutate");
    testAttrs(mutate, { current: "true" }, true);
    info("mutate: Removing aria-current");
    let changed = waitForEvent(EVENT_OBJECT_ATTRIBUTE_CHANGED, mutate);
    await invokeContentTask(browser, [], () => {
      content.document.getElementById("mutate").removeAttribute("aria-current");
    });
    await changed;
    testAbsentAttrs(mutate, { current: "" });
    info("mutate: Adding aria-current");
    changed = waitForEvent(EVENT_OBJECT_ATTRIBUTE_CHANGED, mutate);
    await invokeContentTask(browser, [], () => {
      content.document
        .getElementById("mutate")
        .setAttribute("aria-current", "page");
    });
    await changed;
    testAttrs(mutate, { current: "page" }, true);
  },
  { chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);

/**
 * Test support for the xml-roles attribute.
 */
addAccessibleTask(
  `
<div id="knownRole" role="main">knownRole</div>
<div id="emptyRole" role="">emptyRole</div>
<div id="unknownRole" role="foo">unknownRole</div>
<div id="multiRole" role="foo main">multiRole</div>
<main id="landmarkMarkup">landmarkMarkup</main>
<main id="landmarkMarkupWithRole" role="banner">landmarkMarkupWithRole</main>
<main id="landmarkMarkupWithEmptyRole" role="">landmarkMarkupWithEmptyRole</main>
<article id="markup">markup</article>
<article id="markupWithRole" role="banner">markupWithRole</article>
<article id="markupWithEmptyRole" role="">markupWithEmptyRole</article>
  `,
  async function (browser, docAcc) {
    const knownRole = findAccessibleChildByID(docAcc, "knownRole");
    testAttrs(knownRole, { "xml-roles": "main" }, true);
    const emptyRole = findAccessibleChildByID(docAcc, "emptyRole");
    testAbsentAttrs(emptyRole, { "xml-roles": "" });
    const unknownRole = findAccessibleChildByID(docAcc, "unknownRole");
    testAttrs(unknownRole, { "xml-roles": "foo" }, true);
    const multiRole = findAccessibleChildByID(docAcc, "multiRole");
    testAttrs(multiRole, { "xml-roles": "foo main" }, true);
    const landmarkMarkup = findAccessibleChildByID(docAcc, "landmarkMarkup");
    testAttrs(landmarkMarkup, { "xml-roles": "main" }, true);
    const landmarkMarkupWithRole = findAccessibleChildByID(
      docAcc,
      "landmarkMarkupWithRole"
    );
    testAttrs(landmarkMarkupWithRole, { "xml-roles": "banner" }, true);
    const landmarkMarkupWithEmptyRole = findAccessibleChildByID(
      docAcc,
      "landmarkMarkupWithEmptyRole"
    );
    testAttrs(landmarkMarkupWithEmptyRole, { "xml-roles": "main" }, true);
    const markup = findAccessibleChildByID(docAcc, "markup");
    testAttrs(markup, { "xml-roles": "article" }, true);
    const markupWithRole = findAccessibleChildByID(docAcc, "markupWithRole");
    testAttrs(markupWithRole, { "xml-roles": "banner" }, true);
    const markupWithEmptyRole = findAccessibleChildByID(
      docAcc,
      "markupWithEmptyRole"
    );
    testAttrs(markupWithEmptyRole, { "xml-roles": "article" }, true);
  },
  { chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);

/**
 * Test lie region attributes.
 */
addAccessibleTask(
  `
<div id="noLive"><p>noLive</p></div>
<output id="liveMarkup"><p>liveMarkup</p></output>
<div id="ariaLive" aria-live="polite"><p>ariaLive</p></div>
<div id="liveRole" role="log"><p>liveRole</p></div>
<div id="nonLiveRole" role="group"><p>nonLiveRole</p></div>
<div id="other" aria-atomic="true" aria-busy="true" aria-relevant="additions"><p>other</p></div>
  `,
  async function (browser, docAcc) {
    const noLive = findAccessibleChildByID(docAcc, "noLive");
    for (const acc of [noLive, noLive.firstChild]) {
      testAbsentAttrs(acc, {
        live: "",
        "container-live": "",
        "container-live-role": "",
        atomic: "",
        "container-atomic": "",
        busy: "",
        "container-busy": "",
        relevant: "",
        "container-relevant": "",
      });
    }
    const liveMarkup = findAccessibleChildByID(docAcc, "liveMarkup");
    testAttrs(liveMarkup, { live: "polite" }, true);
    testAttrs(liveMarkup.firstChild, { "container-live": "polite" }, true);
    const ariaLive = findAccessibleChildByID(docAcc, "ariaLive");
    testAttrs(ariaLive, { live: "polite" }, true);
    testAttrs(ariaLive.firstChild, { "container-live": "polite" }, true);
    const liveRole = findAccessibleChildByID(docAcc, "liveRole");
    testAttrs(liveRole, { live: "polite" }, true);
    testAttrs(
      liveRole.firstChild,
      { "container-live": "polite", "container-live-role": "log" },
      true
    );
    const nonLiveRole = findAccessibleChildByID(docAcc, "nonLiveRole");
    testAbsentAttrs(nonLiveRole, { live: "" });
    testAbsentAttrs(nonLiveRole.firstChild, {
      "container-live": "",
      "container-live-role": "",
    });
    const other = findAccessibleChildByID(docAcc, "other");
    testAttrs(
      other,
      { atomic: "true", busy: "true", relevant: "additions" },
      true
    );
    testAttrs(
      other.firstChild,
      {
        "container-atomic": "true",
        "container-busy": "true",
        "container-relevant": "additions",
      },
      true
    );
  },
  { chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);

/**
 * Test the id attribute.
 */
addAccessibleTask(
  `
<p id="withId">withId</p>
<div id="noIdParent"><p>noId</p></div>
  `,
  async function (browser, docAcc) {
    const withId = findAccessibleChildByID(docAcc, "withId");
    testAttrs(withId, { id: "withId" }, true);
    const noId = findAccessibleChildByID(docAcc, "noIdParent").firstChild;
    testAbsentAttrs(noId, { id: "" });
  },
  { chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);

/**
 * Test the valuetext attribute.
 */
addAccessibleTask(
  `
<div id="valuenow" role="slider" aria-valuenow="1"></div>
<div id="valuetext" role="slider" aria-valuetext="text"></div>
<div id="noValue" role="button"></div>
  `,
  async function (browser, docAcc) {
    const valuenow = findAccessibleChildByID(docAcc, "valuenow");
    testAttrs(valuenow, { valuetext: "1" }, true);
    const valuetext = findAccessibleChildByID(docAcc, "valuetext");
    testAttrs(valuetext, { valuetext: "text" }, true);
    const noValue = findAccessibleChildByID(docAcc, "noValue");
    testAbsentAttrs(noValue, { valuetext: "valuetext" });
  },
  { chrome: true, topLevel: true, iframe: true, remoteIframe: true }
);

function untilCacheAttrIs(acc, attr, val, msg) {
  return untilCacheOk(() => {
    try {
      return acc.attributes.getStringProperty(attr) == val;
    } catch (e) {
      return false;
    }
  }, msg);
}

function untilCacheAttrAbsent(acc, attr, msg) {
  return untilCacheOk(() => {
    try {
      acc.attributes.getStringProperty(attr);
    } catch (e) {
      return true;
    }
    return false;
  }, msg);
}

/**
 * Test the class attribute.
 */
addAccessibleTask(
  `
<div id="oneClass" class="c1">oneClass</div>
<div id="multiClass" class="c1 c2">multiClass</div>
<div id="noClass">noClass</div>
<div id="mutate">mutate</div>
  `,
  async function (browser, docAcc) {
    const oneClass = findAccessibleChildByID(docAcc, "oneClass");
    testAttrs(oneClass, { class: "c1" }, true);
    const multiClass = findAccessibleChildByID(docAcc, "multiClass");
    testAttrs(multiClass, { class: "c1 c2" }, true);
    const noClass = findAccessibleChildByID(docAcc, "noClass");
    testAbsentAttrs(noClass, { class: "" });

    const mutate = findAccessibleChildByID(docAcc, "mutate");
    testAbsentAttrs(mutate, { class: "" });
    info("Adding class to mutate");
    await invokeContentTask(browser, [], () => {
      content.document.getElementById("mutate").className = "c1 c2";
    });
    await untilCacheAttrIs(mutate, "class", "c1 c2", "mutate class correct");
    info("Removing class from mutate");
    await invokeContentTask(browser, [], () => {
      content.document.getElementById("mutate").removeAttribute("class");
    });
    await untilCacheAttrAbsent(mutate, "class", "mutate class not present");
  },
  { chrome: true, topLevel: true }
);

/**
 * Test the src attribute.
 */
const kImgUrl = "https://example.com/a11y/accessible/tests/mochitest/moz.png";
addAccessibleTask(
  `
<img id="noAlt" src="${kImgUrl}">
<img id="alt" alt="alt" src="${kImgUrl}">
<img id="mutate">
  `,
  async function (browser, docAcc) {
    const noAlt = findAccessibleChildByID(docAcc, "noAlt");
    testAttrs(noAlt, { src: kImgUrl }, true);
    if (browser.isRemoteBrowser) {
      // To avoid wasting memory, we don't cache src if there's a name.
      const alt = findAccessibleChildByID(docAcc, "alt");
      testAbsentAttrs(alt, { src: "" });
    }

    const mutate = findAccessibleChildByID(docAcc, "mutate");
    testAbsentAttrs(mutate, { src: "" });
    info("Adding src to mutate");
    await invokeContentTask(browser, [kImgUrl], url => {
      content.document.getElementById("mutate").src = url;
    });
    await untilCacheAttrIs(mutate, "src", kImgUrl, "mutate src correct");
    info("Removing src from mutate");
    await invokeContentTask(browser, [], () => {
      content.document.getElementById("mutate").removeAttribute("src");
    });
    await untilCacheAttrAbsent(mutate, "src", "mutate src not present");
  },
  { chrome: true, topLevel: true }
);

/**
 * Test the placeholder attribute.
 */
addAccessibleTask(
  `
<input id="htmlWithLabel" aria-label="label" placeholder="HTML">
<input id="htmlNoLabel" placeholder="HTML">
<input id="ariaWithLabel" aria-label="label" aria-placeholder="ARIA">
<input id="ariaNoLabel" aria-placeholder="ARIA">
<input id="both" aria-label="label" placeholder="HTML" aria-placeholder="ARIA">
<input id="mutate" placeholder="HTML">
  `,
  async function (browser, docAcc) {
    const htmlWithLabel = findAccessibleChildByID(docAcc, "htmlWithLabel");
    testAttrs(htmlWithLabel, { placeholder: "HTML" }, true);
    const htmlNoLabel = findAccessibleChildByID(docAcc, "htmlNoLabel");
    // placeholder is used as name, so not exposed as attribute.
    testAbsentAttrs(htmlNoLabel, { placeholder: "" });
    const ariaWithLabel = findAccessibleChildByID(docAcc, "ariaWithLabel");
    testAttrs(ariaWithLabel, { placeholder: "ARIA" }, true);
    const ariaNoLabel = findAccessibleChildByID(docAcc, "ariaNoLabel");
    // No label doesn't impact aria-placeholder.
    testAttrs(ariaNoLabel, { placeholder: "ARIA" }, true);
    const both = findAccessibleChildByID(docAcc, "both");
    testAttrs(both, { placeholder: "HTML" }, true);

    const mutate = findAccessibleChildByID(docAcc, "mutate");
    testAbsentAttrs(mutate, { placeholder: "" });
    info("Adding label to mutate");
    await invokeContentTask(browser, [], () => {
      content.document
        .getElementById("mutate")
        .setAttribute("aria-label", "label");
    });
    await untilCacheAttrIs(
      mutate,
      "placeholder",
      "HTML",
      "mutate placeholder correct"
    );
    info("Removing mutate placeholder");
    await invokeContentTask(browser, [], () => {
      content.document.getElementById("mutate").removeAttribute("placeholder");
    });
    await untilCacheAttrAbsent(
      mutate,
      "placeholder",
      "mutate placeholder not present"
    );
    info("Setting mutate aria-placeholder");
    await invokeContentTask(browser, [], () => {
      content.document
        .getElementById("mutate")
        .setAttribute("aria-placeholder", "ARIA");
    });
    await untilCacheAttrIs(
      mutate,
      "placeholder",
      "ARIA",
      "mutate placeholder correct"
    );
    info("Setting mutate placeholder");
    await invokeContentTask(browser, [], () => {
      content.document
        .getElementById("mutate")
        .setAttribute("placeholder", "HTML");
    });
    await untilCacheAttrIs(
      mutate,
      "placeholder",
      "HTML",
      "mutate placeholder correct"
    );
  },
  { chrome: true, topLevel: true }
);