[Australis] Bug 987177 - make destroyWidget clear caches for XUL wrappers, r=jaws, a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 26 Mar 2014 00:38:14 +0000
changeset 191349 230efbf7f58d8f728797a95e1dd74be5a814b70e
parent 191348 573846297dbae08634b89e7596cea0eb3b683681
child 191350 253020a7ffe46e035207f7f350fb135e973c29a4
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, sylvestre
bugs987177
milestone30.0a2
[Australis] Bug 987177 - make destroyWidget clear caches for XUL wrappers, r=jaws, a=sylvestre
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
@@ -78,10 +78,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.");
+});
+