browser/base/content/test/general/browser_bug565667.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug565667.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
     1.9 +
    1.10 +function test() {
    1.11 +  waitForExplicitFinish();
    1.12 +  // Open the javascript console. It has the mac menu overlay, so browser.js is
    1.13 +  // loaded in it.
    1.14 +  let consoleWin = window.open("chrome://global/content/console.xul", "_blank",
    1.15 +                               "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
    1.16 +  testWithOpenWindow(consoleWin);
    1.17 +}
    1.18 +
    1.19 +function testWithOpenWindow(consoleWin) {
    1.20 +  // Add a tab so we don't open the url into the current tab
    1.21 +  let newTab = gBrowser.addTab("http://example.com");
    1.22 +  gBrowser.selectedTab = newTab;
    1.23 +
    1.24 +  let numTabs = gBrowser.tabs.length;
    1.25 +
    1.26 +  waitForFocus(function() {
    1.27 +    // Sanity check
    1.28 +    is(fm.activeWindow, consoleWin,
    1.29 +       "the console window is focused");
    1.30 +
    1.31 +    gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) {
    1.32 +      gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, true);
    1.33 +      let browser = aEvent.originalTarget.linkedBrowser;
    1.34 +      browser.addEventListener("pageshow", function(event) {
    1.35 +        if (event.target.location.href != "about:addons")
    1.36 +          return;
    1.37 +        browser.removeEventListener("pageshow", arguments.callee, true);
    1.38 +
    1.39 +        is(fm.activeWindow, window,
    1.40 +           "the browser window was focused");
    1.41 +        is(browser.currentURI.spec, "about:addons",
    1.42 +           "about:addons was loaded in the window");
    1.43 +        is(gBrowser.tabs.length, numTabs + 1,
    1.44 +           "a new tab was added");
    1.45 +
    1.46 +        // Cleanup.
    1.47 +        executeSoon(function() {
    1.48 +          consoleWin.close();
    1.49 +          gBrowser.removeTab(gBrowser.selectedTab);
    1.50 +          gBrowser.removeTab(newTab);
    1.51 +          finish();
    1.52 +        });
    1.53 +      }, true);
    1.54 +    }, true);
    1.55 +
    1.56 +    // Open the addons manager, uses switchToTabHavingURI.
    1.57 +    consoleWin.BrowserOpenAddonsMgr();
    1.58 +  }, consoleWin);
    1.59 +}
    1.60 +
    1.61 +// Ideally we'd also check that the case for no open windows works, but we can't
    1.62 +// due to limitations with the testing framework.

mercurial