|
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/. */ |
|
4 |
|
5 let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager); |
|
6 |
|
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); |
|
14 } |
|
15 |
|
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; |
|
20 |
|
21 let numTabs = gBrowser.tabs.length; |
|
22 |
|
23 waitForFocus(function() { |
|
24 // Sanity check |
|
25 is(fm.activeWindow, consoleWin, |
|
26 "the console window is focused"); |
|
27 |
|
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); |
|
35 |
|
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"); |
|
42 |
|
43 // Cleanup. |
|
44 executeSoon(function() { |
|
45 consoleWin.close(); |
|
46 gBrowser.removeTab(gBrowser.selectedTab); |
|
47 gBrowser.removeTab(newTab); |
|
48 finish(); |
|
49 }); |
|
50 }, true); |
|
51 }, true); |
|
52 |
|
53 // Open the addons manager, uses switchToTabHavingURI. |
|
54 consoleWin.BrowserOpenAddonsMgr(); |
|
55 }, consoleWin); |
|
56 } |
|
57 |
|
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. |