From 748a42f056841c64c6063f65d11ed5557660a5ea Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Tue, 22 Mar 2016 14:32:32 +0000 Subject: [PATCH] Bug 1258344 - fix customizemode re-entering issues when switching tabs, r=jaws MozReview-Commit-ID: 3KONzSxf8g9 --HG-- extra : rebase_source : 31cee7d85b80d2c136722558c9589132574b6455 --- .../customizableui/CustomizeMode.jsm | 4 +++ .../customizableui/test/browser.ini | 1 + .../test/browser_switch_to_customize_mode.js | 34 +++++++++++++++++++ .../components/customizableui/test/head.js | 22 +----------- 4 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 browser/components/customizableui/test/browser_switch_to_customize_mode.js diff --git a/browser/components/customizableui/CustomizeMode.jsm b/browser/components/customizableui/CustomizeMode.jsm index 0f142100c963..644da3621306 100644 --- a/browser/components/customizableui/CustomizeMode.jsm +++ b/browser/components/customizableui/CustomizeMode.jsm @@ -65,6 +65,7 @@ function closeGlobalTab() { win.BrowserOpenTab(); } win.gBrowser.removeTab(gTab); + gTab = null; } function unregisterGlobalTab() { @@ -210,7 +211,10 @@ CustomizeMode.prototype = { return; } if (!gTab.selected) { + // This will force another .enter() to be called via the + // onlocationchange handler of the tabbrowser, so we return early. gTab.ownerGlobal.gBrowser.selectedTab = gTab; + return; } gTab.ownerGlobal.focus(); if (gTab.ownerDocument != this.document) { diff --git a/browser/components/customizableui/test/browser.ini b/browser/components/customizableui/test/browser.ini index 03d0cf5803c8..3bea51ae8dc2 100644 --- a/browser/components/customizableui/test/browser.ini +++ b/browser/components/customizableui/test/browser.ini @@ -147,3 +147,4 @@ skip-if = os == "mac" [browser_bootstrapped_custom_toolbar.js] [browser_customizemode_contextmenu_menubuttonstate.js] [browser_panel_toggle.js] +[browser_switch_to_customize_mode.js] diff --git a/browser/components/customizableui/test/browser_switch_to_customize_mode.js b/browser/components/customizableui/test/browser_switch_to_customize_mode.js new file mode 100644 index 000000000000..459ea7a1c4f5 --- /dev/null +++ b/browser/components/customizableui/test/browser_switch_to_customize_mode.js @@ -0,0 +1,34 @@ +"use strict"; + +add_task(function*() { + yield startCustomizing(); + is(gBrowser.tabs.length, 2, "Should have 2 tabs"); + + let paletteKidCount = document.getElementById("customization-palette").childElementCount; + let nonCustomizingTab = gBrowser.tabContainer.querySelector("tab:not([customizemode=true])"); + let finishedCustomizing = BrowserTestUtils.waitForEvent(gNavToolbox, "aftercustomization"); + yield BrowserTestUtils.switchTab(gBrowser, nonCustomizingTab); + yield finishedCustomizing; + + let startedCount = 0; + let handler = e => startedCount++; + gNavToolbox.addEventListener("customizationstarting", handler); + yield startCustomizing(); + CustomizableUI.removeWidgetFromArea("home-button"); + yield gCustomizeMode.reset().catch(e => { + ok(false, "Threw an exception trying to reset after making modifications in customize mode: " + e); + }); + + let newKidCount = document.getElementById("customization-palette").childElementCount; + is(newKidCount, paletteKidCount, "Should have just as many items in the palette as before."); + yield endCustomizing(); + is(startedCount, 1, "Should have only started once"); + gNavToolbox.removeEventListener("customizationstarting", handler); + let customizableToolbars = document.querySelectorAll("toolbar[customizable=true]:not([autohide=true])"); + for (let toolbar of customizableToolbars) { + ok(!toolbar.hasAttribute("customizing"), "Toolbar " + toolbar.id + " is no longer customizing"); + } + let menuitem = document.getElementById("PanelUI-customize"); + isnot(menuitem.getAttribute("label"), menuitem.getAttribute("exitLabel"), "Should have exited successfully"); +}); + diff --git a/browser/components/customizableui/test/head.js b/browser/components/customizableui/test/head.js index b4d09f864ada..7d9fea44b92e 100644 --- a/browser/components/customizableui/test/head.js +++ b/browser/components/customizableui/test/head.js @@ -191,27 +191,7 @@ function endCustomizing(aWindow=window) { aWindow.gNavToolbox.addEventListener("aftercustomization", onCustomizationEnds); aWindow.gCustomizeMode.exit(); - return deferredEndCustomizing.promise.then(function() { - let deferredLoadNewTab = Promise.defer(); - - //XXXgijs so some tests depend on this tab being about:blank. Make it so. - let newTabBrowser = aWindow.gBrowser.selectedBrowser; - newTabBrowser.stop(); - - // If we stop early enough, this might actually be about:blank. - if (newTabBrowser.currentURI.spec == "about:blank") { - return null; - } - - // Otherwise, make it be about:blank, and wait for that to be done. - function onNewTabLoaded(e) { - newTabBrowser.removeEventListener("load", onNewTabLoaded, true); - deferredLoadNewTab.resolve(); - } - newTabBrowser.addEventListener("load", onNewTabLoaded, true); - newTabBrowser.loadURI("about:blank"); - return deferredLoadNewTab.promise; - }); + return deferredEndCustomizing.promise; } function startCustomizing(aWindow=window) {