Bug 943683 - add API and test for items migrated out of the add-on bar by Australis, r=mconley

--HG--
extra : rebase_source : 27bc7715ec3ea46514b6e7241a7df82e1e0d8de4
This commit is contained in:
Gijs Kruitbosch 2013-12-03 19:37:45 +01:00
Родитель afbef0c196
Коммит 25b1e398c3
3 изменённых файлов: 88 добавлений и 3 удалений

Просмотреть файл

@ -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();
]]></body>
</method>
<method name="evictNode">
@ -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;
]]></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;
@ -553,10 +574,11 @@
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">

Просмотреть файл

@ -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]

Просмотреть файл

@ -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);
}