|
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 let kWidgetId = "test-removable-widget-default"; |
|
8 const kNavBar = CustomizableUI.AREA_NAVBAR; |
|
9 let widgetCounter = 0; |
|
10 |
|
11 registerCleanupFunction(removeCustomToolbars); |
|
12 |
|
13 // Sanity checks |
|
14 add_task(function() { |
|
15 let brokenSpec = {id: kWidgetId + (widgetCounter++), removable: false}; |
|
16 SimpleTest.doesThrow(function() CustomizableUI.createWidget(brokenSpec), |
|
17 "Creating non-removable widget without defaultArea should throw."); |
|
18 |
|
19 // Widget without removable set should be removable: |
|
20 let wrapper = CustomizableUI.createWidget({id: kWidgetId + (widgetCounter++)}); |
|
21 ok(CustomizableUI.isWidgetRemovable(wrapper.id), "Should be removable by default."); |
|
22 CustomizableUI.destroyWidget(wrapper.id); |
|
23 }); |
|
24 |
|
25 // Test non-removable widget with defaultArea |
|
26 add_task(function() { |
|
27 // Non-removable widget with defaultArea should work: |
|
28 let spec = {id: kWidgetId + (widgetCounter++), removable: false, |
|
29 defaultArea: kNavBar}; |
|
30 let widgetWrapper; |
|
31 try { |
|
32 widgetWrapper = CustomizableUI.createWidget(spec); |
|
33 } catch (ex) { |
|
34 ok(false, "Creating a non-removable widget with a default area should not throw."); |
|
35 return; |
|
36 } |
|
37 |
|
38 let placement = CustomizableUI.getPlacementOfWidget(spec.id); |
|
39 ok(placement, "Widget should be placed."); |
|
40 is(placement.area, kNavBar, "Widget should be in navbar"); |
|
41 let singleWrapper = widgetWrapper.forWindow(window); |
|
42 ok(singleWrapper, "Widget should exist in window."); |
|
43 ok(singleWrapper.node, "Widget node should exist in window."); |
|
44 let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, window); |
|
45 is(singleWrapper.node.parentNode, expectedParent, "Widget should be in navbar."); |
|
46 |
|
47 let otherWin = yield openAndLoadWindow(true); |
|
48 placement = CustomizableUI.getPlacementOfWidget(spec.id); |
|
49 ok(placement, "Widget should be placed."); |
|
50 is(placement && placement.area, kNavBar, "Widget should be in navbar"); |
|
51 |
|
52 singleWrapper = widgetWrapper.forWindow(otherWin); |
|
53 ok(singleWrapper, "Widget should exist in other window."); |
|
54 if (singleWrapper) { |
|
55 ok(singleWrapper.node, "Widget node should exist in other window."); |
|
56 if (singleWrapper.node) { |
|
57 let expectedParent = CustomizableUI.getCustomizeTargetForArea(kNavBar, otherWin); |
|
58 is(singleWrapper.node.parentNode, expectedParent, |
|
59 "Widget should be in navbar in other window."); |
|
60 } |
|
61 } |
|
62 CustomizableUI.destroyWidget(spec.id); |
|
63 yield promiseWindowClosed(otherWin); |
|
64 }); |
|
65 |
|
66 add_task(function asyncCleanup() { |
|
67 yield resetCustomization(); |
|
68 }); |