browser_webarea.js (3560B)
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 // Test web area role and AXLoadComplete event 11 addAccessibleTask(``, async browser => { 12 let evt = waitForMacEvent("AXLoadComplete", iface => { 13 return iface.getAttributeValue("AXDescription") == "webarea test"; 14 }); 15 await SpecialPowers.spawn(browser, [], () => { 16 content.location = "data:text/html,<title>webarea test</title>"; 17 }); 18 let doc = await evt; 19 20 is( 21 doc.getAttributeValue("AXRole"), 22 "AXWebArea", 23 "document has AXWebArea role" 24 ); 25 is(doc.getAttributeValue("AXValue"), "", "document has no AXValue"); 26 is(doc.getAttributeValue("AXTitle"), "", "document has no AXTitle"); 27 28 is(doc.getAttributeValue("AXLoaded"), 1, "document has finished loading"); 29 }); 30 31 // Test iframe web area role and AXLayoutComplete event 32 addAccessibleTask(`<title>webarea test</title>`, async browser => { 33 // If the iframe loads before the top level document finishes loading, we'll 34 // get both an AXLayoutComplete event for the iframe and an AXLoadComplete 35 // event for the document. Otherwise, if the iframe loads after the 36 // document, we'll get one AXLoadComplete event. 37 let eventPromise = Promise.race([ 38 waitForMacEvent("AXLayoutComplete", iface => { 39 return iface.getAttributeValue("AXDescription") == "iframe document"; 40 }), 41 waitForMacEvent("AXLoadComplete", iface => { 42 return iface.getAttributeValue("AXDescription") == "webarea test"; 43 }), 44 ]); 45 await SpecialPowers.spawn(browser, [], () => { 46 const iframe = content.document.createElement("iframe"); 47 iframe.src = "data:text/html,<title>iframe document</title>hello world"; 48 content.document.body.appendChild(iframe); 49 }); 50 let doc = await eventPromise; 51 52 if (doc.getAttributeValue("AXTitle")) { 53 // iframe should have no title, so if we get a title here 54 // we've got the main document and need to get the iframe from 55 // the main doc 56 doc = doc.getAttributeValue("AXChildren")[0]; 57 } 58 59 is( 60 doc.getAttributeValue("AXRole"), 61 "AXWebArea", 62 "iframe document has AXWebArea role" 63 ); 64 is(doc.getAttributeValue("AXValue"), "", "iframe document has no AXValue"); 65 is(doc.getAttributeValue("AXTitle"), "", "iframe document has no AXTitle"); 66 is( 67 doc.getAttributeValue("AXDescription"), 68 "iframe document", 69 "test has correct label" 70 ); 71 72 is( 73 doc.getAttributeValue("AXLoaded"), 74 1, 75 "iframe document has finished loading" 76 ); 77 }); 78 79 // Test AXContents in outer doc (AXScrollArea) 80 addAccessibleTask( 81 `<p id="p">Hello</p>`, 82 async (browser, accDoc) => { 83 const doc = accDoc.nativeInterface.QueryInterface( 84 Ci.nsIAccessibleMacInterface 85 ); 86 87 const outerDoc = doc.getAttributeValue("AXParent"); 88 const p = getNativeInterface(accDoc, "p"); 89 90 let contents = outerDoc.getAttributeValue("AXContents"); 91 is(contents.length, 1, "outer doc has single AXContents member"); 92 is( 93 contents[0].getAttributeValue("AXRole"), 94 "AXWebArea", 95 "AXContents member is a web area" 96 ); 97 98 ok( 99 !doc.attributeNames.includes("AXContents"), 100 "Web area does not have XContents" 101 ); 102 ok( 103 !p.attributeNames.includes("AXContents"), 104 "Web content does not hace XContents" 105 ); 106 }, 107 { iframe: true, remoteIframe: true } 108 );