browser_test_aria_hidden_svg.js (5965B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* import-globals-from ../../mochitest/role.js */ 7 loadScripts({ name: "role.js", dir: MOCHITESTS_DIR }); 8 9 const SVG_DOCUMENT_ID = "rootSVG"; 10 const HIDDEN_SVG_URI = 11 "data:image/svg+xml,%3Csvg%20id%3D%22rootSVG%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20aria-hidden%3D%22true%22%3E%3Ctext%20x%3D%2210%22%20y%3D%2250%22%20font-size%3D%2230%22%20id%3D%22textSVG%22%3EMy%20SVG%3C%2Ftext%3E%3C%2Fsvg%3E"; 12 const SVG_URI = 13 "data:image/svg+xml,%3Csvg%20id%3D%22rootSVG%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Ctext%20x%3D%2210%22%20y%3D%2250%22%20font-size%3D%2230%22%20id%3D%22textSVG%22%3EMy%20SVG%3C%2Ftext%3E%3C%2Fsvg%3E"; 14 15 /** 16 * Verify loading an SVG document with aria-hidden=true renders the 17 * entire document subtree. 18 * Non-root svg elements, like those in embedded iframes, should 19 * continue to respect aria-hidden when applied. 20 */ 21 addAccessibleTask( 22 `hello world`, 23 async function testSVGDocument(browser) { 24 let loaded = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, SVG_DOCUMENT_ID); 25 info("Loading SVG"); 26 browser.loadURI(Services.io.newURI(HIDDEN_SVG_URI), { 27 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), 28 }); 29 await loaded; 30 31 const tree = { 32 DOCUMENT: [ 33 { 34 TEXT_CONTAINER: [ 35 { 36 TEXT_LEAF: [], 37 }, 38 ], 39 }, 40 ], 41 }; 42 const root = getRootAccessible(document); 43 const svgRoot = findAccessibleChildByID(root, SVG_DOCUMENT_ID); 44 testAccessibleTree(svgRoot, tree); 45 }, 46 { chrome: true, topLevel: true, iframe: false, remoteIframe: false } 47 ); 48 49 /** 50 * Verify loading an SVG document with aria-hidden=true 51 * in an iframe does not render the document subtree. 52 */ 53 addAccessibleTask( 54 `hello world`, 55 async function testSVGIframeDocument(browser) { 56 info("Loading SVG"); 57 const loaded = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, SVG_DOCUMENT_ID); 58 await SpecialPowers.spawn( 59 browser, 60 [DEFAULT_IFRAME_ID, HIDDEN_SVG_URI], 61 (_id, _uri) => { 62 content.document.getElementById(_id).src = _uri; 63 } 64 ); 65 await loaded; 66 67 const tree = { 68 DOCUMENT: [], 69 }; 70 71 const root = getRootAccessible(document); 72 const svgRoot = findAccessibleChildByID(root, SVG_DOCUMENT_ID); 73 testAccessibleTree(svgRoot, tree); 74 }, 75 { chrome: false, topLevel: false, iframe: true, remoteIframe: true } 76 ); 77 78 /** 79 * Verify adding aria-hidden to root svg elements has no effect. 80 * Non-root svg elements, like those in embedded iframes, should 81 * continue to respect aria-hidden when applied. 82 */ 83 addAccessibleTask( 84 `hello world`, 85 async function testSVGDocumentMutation(browser) { 86 let loaded = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, SVG_DOCUMENT_ID); 87 info("Loading SVG"); 88 browser.loadURI(Services.io.newURI(SVG_URI), { 89 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), 90 }); 91 await loaded; 92 93 const originalTree = { 94 DOCUMENT: [ 95 { 96 TEXT_CONTAINER: [ 97 { 98 TEXT_LEAF: [], 99 }, 100 ], 101 }, 102 ], 103 }; 104 const root = getRootAccessible(document); 105 const svgRoot = findAccessibleChildByID(root, SVG_DOCUMENT_ID); 106 testAccessibleTree(svgRoot, originalTree); 107 info("Adding aria-hidden=true to svg"); 108 // XXX Bug 1959547: We incorrectly get a reorder 109 // here. The tree should be unaffected by this attribute, 110 // but it seems like it isn't! Below we'll verify that 111 // the tree isn't removed, despite this reorder. 112 const unexpectedEvents = { expected: [[EVENT_REORDER, SVG_DOCUMENT_ID]] }; 113 info("Adding aria-hidden"); 114 await contentSpawnMutation( 115 browser, 116 unexpectedEvents, 117 function (_id) { 118 const d = content.document.getElementById(_id); 119 d.setAttribute("aria-hidden", "true"); 120 }, 121 [SVG_DOCUMENT_ID] 122 ); 123 // XXX Bug 1959547: We end up with an extra node in the 124 // tree after adding aria-hidden. It seems like SVG root 125 // element is splitting off / no longer behaves as the 126 // document...? 127 const newTree = { 128 DOCUMENT: [ 129 { 130 DIAGRAM: [ 131 { 132 TEXT_CONTAINER: [ 133 { 134 TEXT_LEAF: [], 135 }, 136 ], 137 }, 138 ], 139 }, 140 ], 141 }; 142 testAccessibleTree(svgRoot, newTree); 143 }, 144 { chrome: true, topLevel: true, iframe: false, remoteIframe: false } 145 ); 146 147 /** 148 * Verify adding aria-hidden to root svg elements in iframes removes 149 * the svg subtree. 150 */ 151 addAccessibleTask( 152 `hello world`, 153 async function testSVGIframeDocumentMutation(browser) { 154 info("Loading SVG"); 155 const loaded = waitForEvent(EVENT_DOCUMENT_LOAD_COMPLETE, SVG_DOCUMENT_ID); 156 await SpecialPowers.spawn( 157 browser, 158 [DEFAULT_IFRAME_ID, SVG_URI], 159 (contentId, _uri) => { 160 content.document.getElementById(contentId).src = _uri; 161 } 162 ); 163 await loaded; 164 const originalTree = { 165 DOCUMENT: [ 166 { 167 TEXT_CONTAINER: [ 168 { 169 TEXT_LEAF: [], 170 }, 171 ], 172 }, 173 ], 174 }; 175 const svgRoot = findAccessibleChildByID( 176 getRootAccessible(document), 177 SVG_DOCUMENT_ID 178 ); 179 testAccessibleTree(svgRoot, originalTree); 180 181 info("Adding aria-hidden=true to svg"); 182 const events = { expected: [[EVENT_REORDER, SVG_DOCUMENT_ID]] }; 183 await contentSpawnMutation( 184 browser, 185 events, 186 function (_id) { 187 const d = content.document.getElementById(_id); 188 d.setAttribute("aria-hidden", "true"); 189 }, 190 [SVG_DOCUMENT_ID] 191 ); 192 193 const newTree = { DOCUMENT: [] }; 194 testAccessibleTree(svgRoot, newTree); 195 }, 196 { chrome: false, topLevel: false, iframe: true, remoteIframe: true } 197 );