browser_treeupdate_whitespace.js (3802B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 /* import-globals-from ../../mochitest/role.js */ 8 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR }); 9 10 addAccessibleTask( 11 "e10s/doc_treeupdate_whitespace.html", 12 async function (browser, accDoc) { 13 let container1 = findAccessibleChildByID(accDoc, "container1"); 14 let container2Parent = findAccessibleChildByID(accDoc, "container2-parent"); 15 16 let tree = { 17 SECTION: [ 18 { GRAPHIC: [] }, 19 { TEXT_LEAF: [] }, 20 { GRAPHIC: [] }, 21 { TEXT_LEAF: [] }, 22 { GRAPHIC: [] }, 23 ], 24 }; 25 testAccessibleTree(container1, tree); 26 27 let onReorder = waitForEvent(EVENT_REORDER, "container1"); 28 // Remove img1 from container1 29 await invokeContentTask(browser, [], () => { 30 let doc = content.document; 31 doc.getElementById("container1").removeChild(doc.getElementById("img1")); 32 }); 33 await onReorder; 34 35 tree = { 36 SECTION: [{ GRAPHIC: [] }, { TEXT_LEAF: [] }, { GRAPHIC: [] }], 37 }; 38 testAccessibleTree(container1, tree); 39 40 tree = { 41 SECTION: [{ LINK: [] }, { LINK: [{ GRAPHIC: [] }] }], 42 }; 43 testAccessibleTree(container2Parent, tree); 44 45 onReorder = waitForEvent(EVENT_REORDER, "container2-parent"); 46 // Append an img with valid src to container2 47 await invokeContentTask(browser, [], () => { 48 let doc = content.document; 49 let img = doc.createElement("img"); 50 img.setAttribute( 51 "src", 52 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 53 "http://example.com/a11y/accessible/tests/mochitest/moz.png" 54 ); 55 doc.getElementById("container2").appendChild(img); 56 }); 57 await onReorder; 58 59 tree = { 60 SECTION: [ 61 { LINK: [{ GRAPHIC: [] }] }, 62 { TEXT_LEAF: [] }, 63 { LINK: [{ GRAPHIC: [] }] }, 64 ], 65 }; 66 testAccessibleTree(container2Parent, tree); 67 }, 68 { iframe: true, remoteIframe: true } 69 ); 70 71 /** 72 * Test whitespace before hard and soft line breaks. 73 */ 74 addAccessibleTask( 75 ` 76 <div id="hardContainer"><span>a</span> <span id="b" hidden>b</span></div> 77 <div id="softContainer" style="width: 1ch; font-family: monospace;"> 78 <span>c</span> <span>d</span> 79 </div> 80 `, 81 async function testBeforeLineBreaks(browser, docAcc) { 82 const hardContainer = findAccessibleChildByID(docAcc, "hardContainer"); 83 testAccessibleTree(hardContainer, { 84 role: ROLE_SECTION, 85 children: [{ role: ROLE_TEXT_LEAF, name: "a" }], 86 }); 87 88 info("Showing b"); 89 let reordered = waitForEvent(EVENT_REORDER, hardContainer); 90 await invokeContentTask(browser, [], () => { 91 content.document.getElementById("b").hidden = false; 92 }); 93 await reordered; 94 testAccessibleTree(hardContainer, { 95 role: ROLE_SECTION, 96 children: [ 97 { role: ROLE_TEXT_LEAF, name: "a" }, 98 { role: ROLE_TEXT_LEAF, name: " " }, 99 { role: ROLE_TEXT_LEAF, name: "b" }, 100 ], 101 }); 102 103 info("Hiding b"); 104 reordered = waitForEvent(EVENT_REORDER, hardContainer); 105 await invokeContentTask(browser, [], () => { 106 content.document.getElementById("b").hidden = true; 107 }); 108 await reordered; 109 testAccessibleTree(hardContainer, { 110 role: ROLE_SECTION, 111 children: [{ role: ROLE_TEXT_LEAF, name: "a" }], 112 }); 113 114 const softContainer = findAccessibleChildByID(docAcc, "softContainer"); 115 testAccessibleTree(softContainer, { 116 role: ROLE_SECTION, 117 children: [ 118 { role: ROLE_TEXT_LEAF, name: "c" }, 119 { role: ROLE_TEXT_LEAF, name: " " }, 120 { role: ROLE_TEXT_LEAF, name: "d" }, 121 ], 122 }); 123 }, 124 { chrome: true, topLevel: true } 125 );