diff --git a/browser/components/customizableui/content/toolbar.xml b/browser/components/customizableui/content/toolbar.xml index ebba4ee13001..c7c407af1ff9 100644 --- a/browser/components/customizableui/content/toolbar.xml +++ b/browser/components/customizableui/content/toolbar.xml @@ -425,6 +425,10 @@ } } 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, @@ -457,6 +461,7 @@ } } this._isModifying = false; + this._updateMigratedSet(); ]]> @@ -469,6 +474,7 @@ const kItemMaxWidth = 100; let oldParent = aNode.parentNode; aNode.setAttribute("removable", "true"); + this._currentSetMigrated.add(aNode.id); let movedOut = false; if (!this._wasCollapsed) { @@ -531,6 +537,7 @@ 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) { @@ -539,6 +546,20 @@ return node; ]]> + + + + + + 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(); ]]> diff --git a/browser/components/customizableui/test/browser.ini b/browser/components/customizableui/test/browser.ini index 7c2591d8e1ce..2eab4b6dba32 100644 --- a/browser/components/customizableui/test/browser.ini +++ b/browser/components/customizableui/test/browser.ini @@ -42,4 +42,5 @@ skip-if = os == "mac" [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] diff --git a/browser/components/customizableui/test/browser_943683_migration_test.js b/browser/components/customizableui/test/browser_943683_migration_test.js new file mode 100644 index 000000000000..7c661f854e4b --- /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); +} +