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