Bug 943683 - add API and test for items migrated out of the add-on bar by Australis, r=mconley
☠☠ backed out by 947c1845e42a ☠ ☠
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 03 Dec 2013 19:37:45 +0100
changeset 173165 f99da61e40100c2cdcebcae8f01c48da6b608923
parent 173164 c7f35fd43aa9f1e91ccdadb729fcf99f0346ef05
child 173166 98a3ae4372afade9e62cf0df971f882e4ad1b649
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs943683
milestone28.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 943683 - add API and test for items migrated out of the add-on bar by Australis, r=mconley
browser/components/customizableui/content/toolbar.xml
browser/components/customizableui/test/browser.ini
browser/components/customizableui/test/browser_943683_migration_test.js
--- a/browser/components/customizableui/content/toolbar.xml
+++ b/browser/components/customizableui/content/toolbar.xml
@@ -420,16 +420,20 @@
               // out if the user has customized things / we've been here before:
               if (!this._whiteListed.has(node.id)) {
                 node.setAttribute("removable", "true");
               }
               children.push(node);
             }
           }
           CustomizableUI.registerToolbarNode(this, children);
+          let existingMigratedItems = (this.getAttribute("migratedset") || "").split(',');
+          for (let migratedItem of existingMigratedItems.filter((x) => !!x)) {
+            this._currentSetMigrated.add(migratedItem);
+          }
           this.evictNodes();
           // We can't easily use |this| or strong bindings for the observer fn here
           // because that creates leaky circular references when the node goes away,
           // and XBL destructors are unreliable.
           let mutationObserver = new MutationObserver(function(mutations) {
             if (!mutations.length) {
               return;
             }
@@ -452,28 +456,30 @@
             let node = this.childNodes[i];
             if (this.childNodes[i].id) {
               this.evictNode(this.childNodes[i]);
             } else {
               node.remove();
             }
           }
           this._isModifying = false;
+          this._updateMigratedSet();
         ]]></body>
       </method>
       <method name="evictNode">
         <parameter name="aNode"/>
         <body>
         <![CDATA[
           if (this._whiteListed.has(aNode.id) || CustomizableUI.isSpecialWidget(aNode.id)) {
             return;
           }
           const kItemMaxWidth = 100;
           let oldParent = aNode.parentNode;
           aNode.setAttribute("removable", "true");
+          this._currentSetMigrated.add(aNode.id);
 
           let movedOut = false;
           if (!this._wasCollapsed) {
             try {
               let nodeWidth = aNode.getBoundingClientRect().width;
               if (nodeWidth == 0 || nodeWidth > kItemMaxWidth) {
                 throw new Error(aNode.id + " is too big (" + nodeWidth +
                                 "px wide), moving to the palette");
@@ -526,42 +532,58 @@
             return null;
           }
 
           this._isModifying = true;
           // Temporarily add it here so it can have a width, then ditch it:
           this.appendChild(node);
           this.evictNode(node);
           this._isModifying = false;
+          this._updateMigratedSet();
           // We will now have moved stuff around; kick off an aftercustomization event
           // so add-ons know we've just moved their stuff:
           if (window.gCustomizeMode) {
             window.gCustomizeMode.dispatchToolboxEvent("aftercustomization");
           }
           return node;
         ]]></body>
       </method>
+      <method name="getMigratedItems">
+        <body><![CDATA[
+          return [... this._currentSetMigrated];
+        ]]></body>
+      </method>
+      <method name="_updateMigratedSet">
+        <body><![CDATA[
+          let newMigratedItems = this.getMigratedItems().join(',');
+          if (this.getAttribute("migratedset") != newMigratedItems) {
+            this.setAttribute("migratedset", newMigratedItems);
+            this.ownerDocument.persist(this.id, "migratedset");
+          }
+        ]]></body>
+      </method>
       <property name="customizationTarget" readonly="true">
         <getter><![CDATA[
           return this;
         ]]></getter>
       </property>
       <property name="currentSet">
         <getter><![CDATA[
           return [node.id for (node of this.children)].join(',');
         ]]></getter>
         <setter><![CDATA[
           let v = val.split(',');
           let newButtons = v.filter(x => x && (!this._whiteListed.has(x) &&
                                                !CustomizableUI.isSpecialWidget(x) &&
                                                !this._currentSetMigrated.has(x)));
-          for (x of newButtons) {
-            this._currentSetMigrated.add(x);
-            this.insertItem(x);
+          for (let newButton of newButtons) {
+            this._currentSetMigrated.add(newButton);
+            this.insertItem(newButton);
           }
+          this._updateMigratedSet();
         ]]></setter>
       </property>
       <property name="toolbox" readonly="true">
         <getter><![CDATA[
           if (!this._toolbox && this.parentNode &&
               this.parentNode.localName == "toolbox") {
             this._toolbox = this.parentNode;
           }
--- a/browser/components/customizableui/test/browser.ini
+++ b/browser/components/customizableui/test/browser.ini
@@ -37,9 +37,10 @@ skip-if = true
 skip-if = os == "mac"
 
 [browser_938980_navbar_collapsed.js]
 [browser_938995_indefaultstate_nonremovable.js]
 [browser_940013_registerToolbarNode_calls_registerArea.js]
 [browser_940946_removable_from_navbar_customizemode.js]
 [browser_941083_invalidate_wrapper_cache_createWidget.js]
 [browser_942581_unregisterArea_keeps_placements.js]
+[browser_943683_migration_test.js]
 [browser_panel_toggle.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/customizableui/test/browser_943683_migration_test.js
@@ -0,0 +1,62 @@
+/* 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-addonbar-migration";
+const kWidgetId2 = "test-addonbar-migration2";
+
+let addonbar = document.getElementById(CustomizableUI.AREA_ADDONBAR);
+let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR);
+
+let btn;
+let btn2;
+
+let gTests = [
+  {
+    desc: "Check we migrate normal stuff to the navbar",
+    setup: function() {
+      btn = createDummyXULButton(kWidgetId, "Test");
+      btn2 = createDummyXULButton(kWidgetId2, "Test2");
+    },
+    run: function() {
+      addonbar.insertItem(btn.id);
+      ok(btn.parentNode == navbar.customizationTarget, "Button should end up in navbar");
+      let migrationArray = addonbar.getMigratedItems();
+      is(migrationArray.length, 1, "Should have migrated 1 item");
+      is(migrationArray[0], kWidgetId, "Should have migrated our 1 item");
+
+      addonbar.currentSet = addonbar.currentSet + "," + kWidgetId2;
+      ok(btn2.parentNode == navbar.customizationTarget, "Second button should end up in the navbar");
+      migrationArray = addonbar.getMigratedItems();
+      is(migrationArray.length, 2, "Should have migrated 2 items");
+      isnot(migrationArray.indexOf(kWidgetId2), -1, "Should have migrated our second item");
+
+      let otherWindow = yield openAndLoadWindow(undefined, true);
+      try {
+        let addonBar = otherWindow.document.getElementById("addon-bar");
+        let otherMigrationArray = addonBar.getMigratedItems();
+        is(migrationArray.length, otherMigrationArray.length,
+           "Other window should have the same number of migrated items.");
+        if (migrationArray.length == otherMigrationArray.length) {
+          for (let widget of migrationArray) {
+            isnot(otherMigrationArray.indexOf(widget), -1,
+                  "Migrated widget " + widget + " should also be listed as migrated in the other window.");
+          }
+        }
+      } finally {
+        otherWindow.close();
+      }
+    },
+    teardown: function() {
+      btn.remove();
+      btn2.remove();
+      CustomizableUI.reset();
+    },
+  },
+];
+
+function test() {
+  waitForExplicitFinish();
+  runTests(gTests);
+}
+