From 8a705801f06e8cc6919ce779fc5f3583f63ec867 Mon Sep 17 00:00:00 2001 From: Gijs Kruitbosch Date: Tue, 3 Dec 2013 11:20:11 +0100 Subject: [PATCH] Bug 944887 - Australis' destroyWidget functionality should also remove the node if it's in the palette, r=jaws --- .../customizableui/src/CustomizableUI.jsm | 40 +++++++++---------- .../customizableui/test/browser.ini | 1 + ...destroyWidget_should_destroy_in_palette.js | 25 ++++++++++++ 3 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 browser/components/customizableui/test/browser_944887_destroyWidget_should_destroy_in_palette.js diff --git a/browser/components/customizableui/src/CustomizableUI.jsm b/browser/components/customizableui/src/CustomizableUI.jsm index e34bf0aeab0..1bfcdc99b2b 100644 --- a/browser/components/customizableui/src/CustomizableUI.jsm +++ b/browser/components/customizableui/src/CustomizableUI.jsm @@ -636,7 +636,7 @@ let CustomizableUIInternal = { } LOG("No node for " + aWidgetId + " found."); - return []; + return [null, null]; }, registerMenuPanel: function(aPanel) { @@ -1877,27 +1877,23 @@ let CustomizableUIInternal = { // This will not remove the widget from gPlacements - we want to keep the // setting so the widget gets put back in it's old position if/when it // returns. - - let area = widget.currentArea; - let buildAreaNodes = area && gBuildAreas.get(area); - if (buildAreaNodes) { - for (let buildNode of buildAreaNodes) { - let widgetNode = buildNode.ownerDocument.getElementById(aWidgetId); - let windowCache = gSingleWrapperCache.get(buildNode.ownerDocument.defaultView); - if (windowCache) { - windowCache.delete(aWidgetId); - } - if (widgetNode) { - widgetNode.parentNode.removeChild(widgetNode); - } - if (widget.type == "view") { - let viewNode = buildNode.ownerDocument.getElementById(widget.viewId); - if (viewNode) { - for (let eventName of kSubviewEvents) { - let handler = "on" + eventName; - if (typeof widget[handler] == "function") { - viewNode.removeEventListener(eventName, widget[handler], false); - } + for (let [window, ] of gBuildWindows) { + let windowCache = gSingleWrapperCache.get(window); + if (windowCache) { + windowCache.delete(aWidgetId); + } + let widgetNode = window.document.getElementById(aWidgetId) || + window.gNavToolbox.palette.querySelector(idToSelector(aWidgetId)); + if (widgetNode) { + widgetNode.remove(); + } + if (widget.type == "view") { + let viewNode = window.document.getElementById(widget.viewId); + if (viewNode) { + for (let eventName of kSubviewEvents) { + let handler = "on" + eventName; + if (typeof widget[handler] == "function") { + viewNode.removeEventListener(eventName, widget[handler], false); } } } diff --git a/browser/components/customizableui/test/browser.ini b/browser/components/customizableui/test/browser.ini index 2eab4b6dba3..b40fab71790 100644 --- a/browser/components/customizableui/test/browser.ini +++ b/browser/components/customizableui/test/browser.ini @@ -43,4 +43,5 @@ skip-if = os == "mac" [browser_941083_invalidate_wrapper_cache_createWidget.js] [browser_942581_unregisterArea_keeps_placements.js] [browser_943683_migration_test.js] +[browser_944887_destroyWidget_should_destroy_in_palette.js] [browser_panel_toggle.js] diff --git a/browser/components/customizableui/test/browser_944887_destroyWidget_should_destroy_in_palette.js b/browser/components/customizableui/test/browser_944887_destroyWidget_should_destroy_in_palette.js new file mode 100644 index 00000000000..7ab7fad9067 --- /dev/null +++ b/browser/components/customizableui/test/browser_944887_destroyWidget_should_destroy_in_palette.js @@ -0,0 +1,25 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const kWidgetId = "test-destroy-in-palette"; + +let gTests = [ + { + desc: "Check destroyWidget destroys the node if it's in the palette", + run: function() { + CustomizableUI.createWidget({id: kWidgetId, label: "Test destroying widgets in palette."}); + yield startCustomizing(); + yield endCustomizing(); + ok(gNavToolbox.palette.querySelector("#" + kWidgetId), "Widget still exists in palette."); + CustomizableUI.destroyWidget(kWidgetId); + ok(!gNavToolbox.palette.querySelector("#" + kWidgetId), "Widget no longer exists in palette."); + }, + }, +]; + +function test() { + waitForExplicitFinish(); + runTests(gTests); +} +