Bug 993322 - fix widgets not showing up in toolbox, r=mconley, a=sylvestre
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 09 Apr 2014 01:00:31 +0100
changeset 183739 c1bbbe2e1309bc8d67b4896bb3ab1a676aba6db7
parent 183738 5eb91b9f89ec6518f59d33f3f688ba4820487ba6
child 183740 d20804c31f61e4e50630ae97d68b6158e728b5b9
push id3465
push usergijskruitbosch@gmail.com
push dateMon, 14 Apr 2014 12:21:48 +0000
treeherdermozilla-beta@d20804c31f61 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley, sylvestre
bugs993322
milestone29.0
Bug 993322 - fix widgets not showing up in toolbox, r=mconley, a=sylvestre
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_993322_widget_notoolbar.js
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -1853,51 +1853,60 @@ let CustomizableUIInternal = {
         area.get("defaultPlacements").push(widget.id);
       } else {
         area.set("defaultPlacements", [widget.id]);
       }
     }
 
     // Look through previously saved state to see if we're restoring a widget.
     let seenAreas = new Set();
+    let widgetMightNeedAutoAdding = true;
     for (let [area, placements] of gPlacements) {
       seenAreas.add(area);
+      let areaIsRegistered = gAreas.has(area);
       let index = gPlacements.get(area).indexOf(widget.id);
       if (index != -1) {
-        widget.currentArea = area;
-        widget.currentPosition = index;
+        widgetMightNeedAutoAdding = false;
+        if (areaIsRegistered) {
+          widget.currentArea = area;
+          widget.currentPosition = index;
+        }
         break;
       }
     }
 
     // Also look at saved state data directly in areas that haven't yet been
     // restored. Can't rely on this for restored areas, as they may have
     // changed.
-    if (!widget.currentArea && gSavedState) {
+    if (widgetMightNeedAutoAdding && gSavedState) {
       for (let area of Object.keys(gSavedState.placements)) {
         if (seenAreas.has(area)) {
           continue;
         }
 
+        let areaIsRegistered = gAreas.has(area);
         let index = gSavedState.placements[area].indexOf(widget.id);
         if (index != -1) {
-          widget.currentArea = area;
-          widget.currentPosition = index;
+          widgetMightNeedAutoAdding = false;
+          if (areaIsRegistered) {
+            widget.currentArea = area;
+            widget.currentPosition = index;
+          }
           break;
         }
       }
     }
 
     // If we're restoring the widget to it's old placement, fire off the
     // onWidgetAdded event - our own handler will take care of adding it to
     // any build areas.
     if (widget.currentArea) {
       this.notifyListeners("onWidgetAdded", widget.id, widget.currentArea,
                            widget.currentPosition);
-    } else {
+    } else if (widgetMightNeedAutoAdding) {
       let autoAdd = true;
       try {
         autoAdd = Services.prefs.getBoolPref(kPrefCustomizationAutoAdd);
       } catch (e) {}
 
       // If the widget doesn't have an existing placement, and it hasn't been
       // seen before, then add it to its default area so it can be used.
       // If the widget is not removable, we *have* to add it to its default
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -87,9 +87,10 @@ skip-if = os == "linux"
 
 [browser_985815_propagate_setToolbarVisibility.js]
 [browser_981305_separator_insertion.js]
 [browser_989609_bootstrapped_custom_toolbar.js]
 [browser_987177_destroyWidget_xul.js]
 [browser_987177_xul_wrapper_updating.js]
 [browser_987492_window_api.js]
 [browser_992747_toggle_noncustomizable_toolbar.js]
+[browser_993322_widget_notoolbar.js]
 [browser_panel_toggle.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_993322_widget_notoolbar.js
@@ -0,0 +1,34 @@
+/* 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-API-created-widget-toolbar-gone";
+const TOOLBARID = "test-API-created-extra-toolbar";
+
+add_task(function*() {
+  let toolbar = createToolbarWithPlacements(TOOLBARID, []);
+  CustomizableUI.addWidgetToArea(BUTTONID, TOOLBARID);
+  is(CustomizableUI.getPlacementOfWidget(BUTTONID).area, TOOLBARID, "Should be on toolbar");
+  is(toolbar.children.length, 0, "Toolbar has no kid");
+
+  CustomizableUI.unregisterArea(TOOLBARID);
+  CustomizableUI.createWidget({id: BUTTONID, label: "Test widget toolbar gone"});
+
+  let currentWidget = CustomizableUI.getWidget(BUTTONID);
+
+  yield startCustomizing();
+  let buttonNode = document.getElementById(BUTTONID);
+  ok(buttonNode, "Should find button in window");
+  if (buttonNode) {
+    is(buttonNode.parentNode.localName, "toolbarpaletteitem", "Node should be wrapped");
+    is(buttonNode.parentNode.getAttribute("place"), "palette", "Node should be in palette");
+    is(buttonNode, gNavToolbox.palette.querySelector("#" + BUTTONID), "Node should really be in palette.");
+  }
+  is(currentWidget.forWindow(window).node, buttonNode, "Should have the same node for customize mode");
+  yield endCustomizing();
+
+  CustomizableUI.destroyWidget(BUTTONID);
+  CustomizableUI.unregisterArea(TOOLBARID, true);
+});