michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: // Open the javascript console. It has the mac menu overlay, so browser.js is michael@0: // loaded in it. michael@0: let consoleWin = window.open("chrome://global/content/console.xul", "_blank", michael@0: "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar"); michael@0: testWithOpenWindow(consoleWin); michael@0: } michael@0: michael@0: function testWithOpenWindow(consoleWin) { michael@0: // Add a tab so we don't open the url into the current tab michael@0: let newTab = gBrowser.addTab("http://example.com"); michael@0: gBrowser.selectedTab = newTab; michael@0: michael@0: let numTabs = gBrowser.tabs.length; michael@0: michael@0: waitForFocus(function() { michael@0: // Sanity check michael@0: is(fm.activeWindow, consoleWin, michael@0: "the console window is focused"); michael@0: michael@0: gBrowser.tabContainer.addEventListener("TabOpen", function(aEvent) { michael@0: gBrowser.tabContainer.removeEventListener("TabOpen", arguments.callee, true); michael@0: let browser = aEvent.originalTarget.linkedBrowser; michael@0: browser.addEventListener("pageshow", function(event) { michael@0: if (event.target.location.href != "about:addons") michael@0: return; michael@0: browser.removeEventListener("pageshow", arguments.callee, true); michael@0: michael@0: is(fm.activeWindow, window, michael@0: "the browser window was focused"); michael@0: is(browser.currentURI.spec, "about:addons", michael@0: "about:addons was loaded in the window"); michael@0: is(gBrowser.tabs.length, numTabs + 1, michael@0: "a new tab was added"); michael@0: michael@0: // Cleanup. michael@0: executeSoon(function() { michael@0: consoleWin.close(); michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: gBrowser.removeTab(newTab); michael@0: finish(); michael@0: }); michael@0: }, true); michael@0: }, true); michael@0: michael@0: // Open the addons manager, uses switchToTabHavingURI. michael@0: consoleWin.BrowserOpenAddonsMgr(); michael@0: }, consoleWin); michael@0: } michael@0: michael@0: // Ideally we'd also check that the case for no open windows works, but we can't michael@0: // due to limitations with the testing framework.