|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 const kWidgetId = "test-addonbar-migration"; |
|
8 const kWidgetId2 = "test-addonbar-migration2"; |
|
9 |
|
10 let addonbar = document.getElementById(CustomizableUI.AREA_ADDONBAR); |
|
11 let navbar = document.getElementById(CustomizableUI.AREA_NAVBAR); |
|
12 |
|
13 let btn; |
|
14 let btn2; |
|
15 |
|
16 // Check we migrate normal stuff to the navbar |
|
17 add_task(function() { |
|
18 btn = createDummyXULButton(kWidgetId, "Test"); |
|
19 btn2 = createDummyXULButton(kWidgetId2, "Test2"); |
|
20 addonbar.insertItem(btn.id); |
|
21 ok(btn.parentNode == navbar.customizationTarget, "Button should end up in navbar"); |
|
22 let migrationArray = addonbar.getMigratedItems(); |
|
23 is(migrationArray.length, 1, "Should have migrated 1 item"); |
|
24 is(migrationArray[0], kWidgetId, "Should have migrated our 1 item"); |
|
25 |
|
26 addonbar.currentSet = addonbar.currentSet + "," + kWidgetId2; |
|
27 ok(btn2.parentNode == navbar.customizationTarget, "Second button should end up in the navbar"); |
|
28 migrationArray = addonbar.getMigratedItems(); |
|
29 is(migrationArray.length, 2, "Should have migrated 2 items"); |
|
30 isnot(migrationArray.indexOf(kWidgetId2), -1, "Should have migrated our second item"); |
|
31 |
|
32 let otherWindow = yield openAndLoadWindow(undefined, true); |
|
33 try { |
|
34 let addonBar = otherWindow.document.getElementById("addon-bar"); |
|
35 let otherMigrationArray = addonBar.getMigratedItems(); |
|
36 is(migrationArray.length, otherMigrationArray.length, |
|
37 "Other window should have the same number of migrated items."); |
|
38 if (migrationArray.length == otherMigrationArray.length) { |
|
39 for (let widget of migrationArray) { |
|
40 isnot(otherMigrationArray.indexOf(widget), -1, |
|
41 "Migrated widget " + widget + " should also be listed as migrated in the other window."); |
|
42 } |
|
43 } |
|
44 } finally { |
|
45 yield promiseWindowClosed(otherWindow); |
|
46 } |
|
47 btn.remove(); |
|
48 btn2.remove(); |
|
49 CustomizableUI.reset(); |
|
50 }); |