bug 841350 - register pageshow handler earlier in browser.js r=ttaubert
[gecko.git] / browser / base / content / test / browser_bug427559.js
blob50993f9b9811c4d2a8d0674e64f2f8120ca4f3cd
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/. */
5 /*
6  * Test bug 427559 to make sure focused elements that are no longer on the page
7  * will have focus transferred to the window when changing tabs back to that
8  * tab with the now-gone element.
9  */
11 // Default focus on a button and have it kill itself on blur
12 let testPage = 'data:text/html,<body><button onblur="this.parentNode.removeChild(this);"><script>document.body.firstChild.focus();</script></body>';
14 function test() {
15   waitForExplicitFinish();
17   gBrowser.selectedTab = gBrowser.addTab();
19   gBrowser.selectedBrowser.addEventListener("load", function () {
20     gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true);
21     setTimeout(function () {
22       var testPageWin = content;
24       // The test page loaded, so open an empty tab, select it, then restore
25       // the test tab. This causes the test page's focused element to be removed
26       // from its document.
27       gBrowser.selectedTab = gBrowser.addTab();
28       gBrowser.removeCurrentTab();
30       // Make sure focus is given to the window because the element is now gone
31       is(document.commandDispatcher.focusedWindow, testPageWin,
32          "content window is focused");
34       gBrowser.removeCurrentTab();
35       finish();
36     }, 0);
37   }, true);
39   content.location = testPage;