browser_test_focus_dialog.js (2613B)
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/states.js */ 8 /* import-globals-from ../../mochitest/role.js */ 9 loadScripts( 10 { name: "states.js", dir: MOCHITESTS_DIR }, 11 { name: "role.js", dir: MOCHITESTS_DIR } 12 ); 13 14 async function runTests(browser) { 15 let onFocus = waitForEvent(EVENT_FOCUS, "button"); 16 await SpecialPowers.spawn(browser, [], () => { 17 content.document.getElementById("button").focus(); 18 }); 19 let button = (await onFocus).accessible; 20 testStates(button, STATE_FOCUSED); 21 22 // Bug 1377942 - The target of the focus event changes under different 23 // circumstances. 24 // In e10s the focus event is the new window, in non-e10s it's the doc. 25 onFocus = waitForEvent(EVENT_FOCUS, () => true); 26 let newWin = await BrowserTestUtils.openNewBrowserWindow(); 27 // button should be blurred 28 await onFocus; 29 testStates(button, 0, 0, STATE_FOCUSED); 30 31 onFocus = waitForEvent(EVENT_FOCUS, "button"); 32 await BrowserTestUtils.closeWindow(newWin); 33 testStates((await onFocus).accessible, STATE_FOCUSED); 34 35 onFocus = waitForEvent(EVENT_FOCUS, "body2"); 36 await SpecialPowers.spawn(browser, [], () => { 37 content.document 38 .getElementById("editabledoc") 39 .contentWindow.document.body.focus(); 40 }); 41 testStates((await onFocus).accessible, STATE_FOCUSED); 42 43 onFocus = waitForEvent(EVENT_FOCUS, "body2"); 44 newWin = await BrowserTestUtils.openNewBrowserWindow(); 45 await BrowserTestUtils.closeWindow(newWin); 46 testStates((await onFocus).accessible, STATE_FOCUSED); 47 48 let onShow = waitForEvent(EVENT_SHOW, "alertdialog"); 49 onFocus = waitForEvent(EVENT_FOCUS, "alertdialog"); 50 await SpecialPowers.spawn(browser, [], () => { 51 let alertDialog = content.document.getElementById("alertdialog"); 52 alertDialog.style.display = "block"; 53 alertDialog.focus(); 54 }); 55 await onShow; 56 testStates((await onFocus).accessible, STATE_FOCUSED); 57 } 58 59 /** 60 * Accessible dialog focus testing 61 */ 62 addAccessibleTask( 63 ` 64 <button id="button">button</button> 65 <iframe id="editabledoc" 66 src="${snippetToURL("", { 67 contentDocBodyAttrs: { id: "body2", contentEditable: "true" }, 68 })}"> 69 </iframe> 70 <div id="alertdialog" style="display: none" tabindex="-1" role="alertdialog" aria-labelledby="title2" aria-describedby="desc2"> 71 <div id="title2">Blah blah</div> 72 <div id="desc2">Woof woof woof.</div> 73 <button>Close</button> 74 </div>`, 75 runTests 76 );