Bug 987177 - make destroyWidget clear caches for XUL wrappers, r=jaws
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 26 Mar 2014 00:38:14 +0000
changeset 175608 37b77d7a64c84224e4a9f497444cdf92afe42bca
parent 175607 d1ff84188da27c630bf26c07539e9eee4fc65157
child 175609 0c4f13342090abf95fb2801334d4ec78239f9a40
push id26495
push usercbook@mozilla.com
push dateThu, 27 Mar 2014 13:14:49 +0000
treeherdermozilla-central@bb4dd9872236 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws
bugs987177
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 987177 - make destroyWidget clear caches for XUL wrappers, r=jaws
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_987177_destroyWidget_xul.js
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -2036,16 +2036,23 @@ let CustomizableUIInternal = {
         Cu.reportError(e);
       }
     };
   },
 
   destroyWidget: function(aWidgetId) {
     let widget = gPalette.get(aWidgetId);
     if (!widget) {
+      gGroupWrapperCache.delete(aWidgetId);
+      for (let [window, ] of gBuildWindows) {
+        let windowCache = gSingleWrapperCache.get(window);
+        if (windowCache) {
+          windowCache.delete(aWidgetId);
+        }
+      }
       return;
     }
 
     // Remove it from the default placements of an area if it was added there:
     if (widget.defaultArea) {
       let area = gAreas.get(widget.defaultArea);
       if (area) {
         let defaultPlacements = area.get("defaultPlacements");
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -85,10 +85,11 @@ skip-if = os == "linux"
 [browser_976792_insertNodeInWindow.js]
 skip-if = os == "linux"
 
 [browser_978084_dragEnd_after_move.js]
 [browser_980155_add_overflow_toolbar.js]
 [browser_981418-widget-onbeforecreated-handler.js]
 [browser_985815_propagate_setToolbarVisibility.js]
 [browser_981305_separator_insertion.js]
+[browser_987177_destroyWidget_xul.js]
 [browser_987177_xul_wrapper_updating.js]
 [browser_panel_toggle.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_987177_destroyWidget_xul.js
@@ -0,0 +1,33 @@
+/* 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/. */
+
+"use strict";
+
+const BUTTONID = "test-XUL-wrapper-destroyWidget";
+
+
+add_task(function() {
+  let btn = createDummyXULButton(BUTTONID, "XUL btn");
+  gNavToolbox.palette.appendChild(btn);
+  let firstWrapper = CustomizableUI.getWidget(BUTTONID).forWindow(window);
+  ok(firstWrapper, "Should get a wrapper");
+  ok(firstWrapper.node, "Node should be there on first wrapper.");
+
+  btn.remove();
+  CustomizableUI.destroyWidget(BUTTONID);
+  let secondWrapper = CustomizableUI.getWidget(BUTTONID).forWindow(window);
+  isnot(firstWrapper, secondWrapper, "Wrappers should be different after destroyWidget call.");
+  ok(!firstWrapper.node, "No node should be there on old wrapper.");
+  ok(!secondWrapper.node, "No node should be there on new wrapper.");
+
+  btn = createDummyXULButton(BUTTONID, "XUL btn");
+  gNavToolbox.palette.appendChild(btn);
+  let thirdWrapper = CustomizableUI.getWidget(BUTTONID).forWindow(window);
+  ok(thirdWrapper, "Should get a wrapper");
+  is(secondWrapper, thirdWrapper, "Should get the second wrapper again.");
+  ok(firstWrapper.node, "Node should be there on old wrapper.");
+  ok(secondWrapper.node, "Node should be there on second wrapper.");
+  ok(thirdWrapper.node, "Node should be there on third wrapper.");
+});
+