bug 841350 - register pageshow handler earlier in browser.js r=ttaubert
[gecko.git] / browser / base / content / test / browser_bug565667.js
blob6fac026c8481d7acc138ce629ce8ed34d1dc83e9
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 let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
7 function test() {
8   waitForExplicitFinish();
9   // Open the javascript console. It has the mac menu overlay, so browser.js is
10   // loaded in it.
11   let consoleWin = window.open("chrome://global/content/console.xul", "_blank",
12                                "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
13   testWithOpenWindow(consoleWin);
16 function testWithOpenWindow(consoleWin) {
17   // Add a tab so we don't open the url into the current tab
18   let newTab = gBrowser.addTab("http://example.com");
19   gBrowser.selectedTab = newTab;
21   let numTabs = gBrowser.tabs.length;
23   waitForFocus(function() {
24     // Sanity check
25     is(fm.activeWindow, consoleWin,
26        "the console window is focused");
28     gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) {
29       gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, true);
30       let browser = aEvent.originalTarget.linkedBrowser;
31       browser.addEventListener("pageshow", function(event) {
32         if (event.target.location.href != "about:addons")
33           return;
34         browser.removeEventListener("pageshow", arguments.callee, true);
36         is(fm.activeWindow, window,
37            "the browser window was focused");
38         is(browser.currentURI.spec, "about:addons",
39            "about:addons was loaded in the window");
40         is(gBrowser.tabs.length, numTabs + 1,
41            "a new tab was added");
43         // Cleanup.
44         executeSoon(function() {
45           consoleWin.close();
46           gBrowser.removeTab(gBrowser.selectedTab);
47           gBrowser.removeTab(newTab);
48           finish();
49         });
50       }, true);
51     }, true);
53     // Open the addons manager, uses switchToTabHavingURI.
54     consoleWin.BrowserOpenAddonsMgr();
55   }, consoleWin);
58 // Ideally we'd also check that the case for no open windows works, but we can't
59 // due to limitations with the testing framework.