browser_bug427559.js (1206B)
1 "use strict"; 2 3 /* 4 * Test bug 427559 to make sure focused elements that are no longer on the page 5 * will have focus transferred to the window when changing tabs back to that 6 * tab with the now-gone element. 7 */ 8 9 // Default focus on a button and have it kill itself on blur. 10 const URL = 11 "data:text/html;charset=utf-8," + 12 '<body><button onblur="this.remove()">' + 13 "<script>document.body.firstElementChild.focus()</script></body>"; 14 15 function getFocusedLocalName(browser) { 16 return SpecialPowers.spawn(browser, [], async function () { 17 return content.document.activeElement.localName; 18 }); 19 } 20 21 add_task(async function () { 22 let testTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL); 23 24 let browser = testTab.linkedBrowser; 25 26 is(await getFocusedLocalName(browser), "button", "button is focused"); 27 28 let blankTab = await BrowserTestUtils.openNewForegroundTab( 29 gBrowser, 30 "about:blank" 31 ); 32 33 await BrowserTestUtils.switchTab(gBrowser, testTab); 34 35 // Make sure focus is given to the window because the element is now gone. 36 is(await getFocusedLocalName(browser), "body", "body is focused"); 37 38 // Cleanup. 39 gBrowser.removeTab(blankTab); 40 gBrowser.removeCurrentTab(); 41 });