|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Detaching a tab to a new window shouldn't break the menu panel. |
|
6 */ |
|
7 |
|
8 "use strict"; |
|
9 |
|
10 let gTestTab; |
|
11 let gContentAPI; |
|
12 let gContentWindow; |
|
13 let gContentDoc; |
|
14 let highlight = document.getElementById("UITourHighlight"); |
|
15 let tooltip = document.getElementById("UITourTooltip"); |
|
16 |
|
17 Components.utils.import("resource:///modules/UITour.jsm"); |
|
18 |
|
19 function test() { |
|
20 registerCleanupFunction(function() { |
|
21 gContentDoc = null; |
|
22 }); |
|
23 UITourTest(); |
|
24 } |
|
25 |
|
26 let tests = [ |
|
27 function test_move_tab_to_new_window(done) { |
|
28 let gOpenedWindow; |
|
29 let onVisibilityChange = (aEvent) => { |
|
30 if (!document.hidden && window != UITour.getChromeWindow(aEvent.target)) { |
|
31 gContentAPI.showHighlight("appMenu"); |
|
32 } |
|
33 }; |
|
34 let onDOMWindowDestroyed = (aWindow, aTopic, aData) => { |
|
35 if (gOpenedWindow && aWindow == gOpenedWindow) { |
|
36 Services.obs.removeObserver(onDOMWindowDestroyed, "dom-window-destroyed", false); |
|
37 done(); |
|
38 } |
|
39 }; |
|
40 let onBrowserDelayedStartup = (aWindow, aTopic, aData) => { |
|
41 gOpenedWindow = aWindow; |
|
42 Services.obs.removeObserver(onBrowserDelayedStartup, "browser-delayed-startup-finished"); |
|
43 try { |
|
44 let newWindowHighlight = gOpenedWindow.document.getElementById("UITourHighlight"); |
|
45 let selectedTab = aWindow.gBrowser.selectedTab; |
|
46 is(selectedTab.linkedBrowser && selectedTab.linkedBrowser.contentDocument, gContentDoc, "Document should be selected in new window"); |
|
47 ok(UITour.originTabs && UITour.originTabs.has(aWindow), "Window should be known"); |
|
48 ok(UITour.originTabs.get(aWindow).has(selectedTab), "Tab should be known"); |
|
49 waitForElementToBeVisible(newWindowHighlight, function checkHighlightIsThere() { |
|
50 let shownPromise = promisePanelShown(aWindow); |
|
51 gContentAPI.showMenu("appMenu"); |
|
52 shownPromise.then(() => { |
|
53 isnot(aWindow.PanelUI.panel.state, "closed", "Panel should be open"); |
|
54 ok(aWindow.PanelUI.contents.children.length > 0, "Panel contents should have children"); |
|
55 gContentAPI.hideHighlight(); |
|
56 gContentAPI.hideMenu("appMenu"); |
|
57 gTestTab = null; |
|
58 aWindow.close(); |
|
59 }).then(null, Components.utils.reportError); |
|
60 }, "Highlight should be shown in new window."); |
|
61 } catch (ex) { |
|
62 Cu.reportError(ex); |
|
63 ok(false, "An error occurred running UITour tab detach test."); |
|
64 } finally { |
|
65 gContentDoc.removeEventListener("visibilitychange", onVisibilityChange, false); |
|
66 Services.obs.addObserver(onDOMWindowDestroyed, "dom-window-destroyed", false); |
|
67 } |
|
68 }; |
|
69 |
|
70 Services.obs.addObserver(onBrowserDelayedStartup, "browser-delayed-startup-finished", false); |
|
71 // NB: we're using this rather than gContentWindow.document because the latter wouldn't |
|
72 // have an XRayWrapper, and we need to compare this to the doc we get using this method |
|
73 // later on... |
|
74 gContentDoc = gBrowser.selectedTab.linkedBrowser.contentDocument; |
|
75 gContentDoc.addEventListener("visibilitychange", onVisibilityChange, false); |
|
76 gContentAPI.showHighlight("appMenu"); |
|
77 waitForElementToBeVisible(highlight, function checkForInitialHighlight() { |
|
78 gBrowser.replaceTabWithWindow(gBrowser.selectedTab); |
|
79 }); |
|
80 |
|
81 }, |
|
82 ]; |
|
83 |