Bug 995161 - Customize mode can still break after bootstrapped add-on with custom legacy:true toolbar restarts. r=Gijs, a=sylvestre.
authorMike Conley <mconley@mozilla.com>
Sun, 13 Apr 2014 19:49:07 -0400
changeset 183748 27221179c8b0ad197e907558e6d2a9ef0f46ff5c
parent 183747 8855f67b592c67391c42b83af82fe6bc50217d4e
child 183749 bf8adf5a7040b942b3139c6cf9a250241ed575c2
push id3468
push usermdeboer@mozilla.com
push dateMon, 14 Apr 2014 15:16:59 +0000
treeherdermozilla-beta@a7433dd3312a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, sylvestre
bugs995161
milestone29.0
Bug 995161 - Customize mode can still break after bootstrapped add-on with custom legacy:true toolbar restarts. r=Gijs, a=sylvestre.
browser/components/customizableui/src/CustomizableUI.jsm
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_989609_bootstrapped_custom_toolbar.js
browser/components/customizableui/test/browser_bootstrapped_custom_toolbar.js
--- a/browser/components/customizableui/src/CustomizableUI.jsm
+++ b/browser/components/customizableui/src/CustomizableUI.jsm
@@ -333,17 +333,17 @@ let CustomizableUIInternal = {
     // Sanity check default placements array:
     if (!Array.isArray(props.get("defaultPlacements"))) {
       throw new Error("Should provide an array of default placements");
     }
 
     if (!areaIsKnown) {
       gAreas.set(aName, props);
 
-      if (props.get("legacy")) {
+      if (props.get("legacy") && !gPlacements.has(aName)) {
         // Guarantee this area exists in gFuturePlacements, to avoid checking it in
         // various places elsewhere.
         gFuturePlacements.set(aName, new Set());
       } else {
         this.restoreStateForArea(aName);
       }
 
       // If we have pending build area nodes, register all of them
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -82,15 +82,15 @@ skip-if = os == "linux"
 [browser_980155_add_overflow_toolbar.js]
 [browser_981418-widget-onbeforecreated-handler.js]
 
 [browser_984455_bookmarks_items_reparenting.js]
 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_bootstrapped_custom_toolbar.js]
 [browser_panel_toggle.js]
rename from browser/components/customizableui/test/browser_989609_bootstrapped_custom_toolbar.js
rename to browser/components/customizableui/test/browser_bootstrapped_custom_toolbar.js
--- a/browser/components/customizableui/test/browser_989609_bootstrapped_custom_toolbar.js
+++ b/browser/components/customizableui/test/browser_bootstrapped_custom_toolbar.js
@@ -2,74 +2,78 @@
  * 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 kTestBarID = "testBar";
 const kWidgetID = "characterencoding-button";
 
-function createTestBar() {
+function createTestBar(aLegacy) {
   let testBar = document.createElement("toolbar");
   testBar.id = kTestBarID;
   testBar.setAttribute("customizable", "true");
-  CustomizableUI.registerArea(kTestBarID,
-    { type: CustomizableUI.TYPE_TOOLBAR, legacy: false }
-  );
+  CustomizableUI.registerArea(kTestBarID, {
+    type: CustomizableUI.TYPE_TOOLBAR,
+    legacy: aLegacy,
+  });
   gNavToolbox.appendChild(testBar);
   return testBar;
 }
 
 /**
  * Helper function that does the following:
  *
  * 1) Creates a custom toolbar and registers it
- *    with CustomizableUI.
+ *    with CustomizableUI. Sets the legacy attribute
+ *    of the object passed to registerArea to aLegacy.
  * 2) Adds the widget with ID aWidgetID to that new
  *    toolbar.
  * 3) Enters customize mode and makes sure that the
  *    widget is still in the right toolbar.
  * 4) Exits customize mode, then removes and deregisters
  *    the custom toolbar.
  * 5) Checks that the widget has no placement.
  * 6) Re-adds and re-registers a custom toolbar with the same
- *    ID as the first one.
+ *    ID and options as the first one.
  * 7) Enters customize mode and checks that the widget is
  *    properly back in the toolbar.
  * 8) Exits customize mode, removes and de-registers the
  *    toolbar, and resets the toolbars to default.
  */
-function checkRestoredPresence(aWidgetID) {
+function checkRestoredPresence(aWidgetID, aLegacy) {
   return Task.spawn(function* () {
-    let testBar = createTestBar();
+    let testBar = createTestBar(aLegacy);
     CustomizableUI.addWidgetToArea(aWidgetID, kTestBarID);
     let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
     is(placement.area, kTestBarID,
        "Expected " + aWidgetID + " to be in the test toolbar");
 
     CustomizableUI.unregisterArea(testBar.id);
     testBar.remove();
 
     let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
     is(placement, null, "Expected " + aWidgetID + " to be in the palette");
 
-    testBar = createTestBar();
+    testBar = createTestBar(aLegacy);
 
     yield startCustomizing();
     let placement = CustomizableUI.getPlacementOfWidget(aWidgetID);
     is(placement.area, kTestBarID,
        "Expected " + aWidgetID + " to be in the test toolbar");
     yield endCustomizing();
 
     CustomizableUI.unregisterArea(testBar.id);
     testBar.remove();
 
     yield resetCustomization();
   });
 }
 
 add_task(function* () {
-  yield checkRestoredPresence("downloads-button")
+  yield checkRestoredPresence("downloads-button", false);
+  yield checkRestoredPresence("downloads-button", true);
 });
 
 add_task(function* () {
-  yield checkRestoredPresence("characterencoding-button")
-});
\ No newline at end of file
+  yield checkRestoredPresence("characterencoding-button", false);
+  yield checkRestoredPresence("characterencoding-button", true);
+});