Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
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/. */
5 "use strict";
7 const kToolbarName = "test-unregisterArea-placements-toolbar";
8 const kTestWidgetPfx = "test-widget-for-unregisterArea-placements-";
9 const kTestWidgetCount = 3;
10 registerCleanupFunction(removeCustomToolbars);
12 // unregisterArea should keep placements by default and restore them when re-adding the area
13 add_task(function() {
14 let widgetIds = [];
15 for (let i = 0; i < kTestWidgetCount; i++) {
16 let id = kTestWidgetPfx + i;
17 widgetIds.push(id);
18 let spec = {id: id, type: 'button', removable: true, label: "unregisterArea test", tooltiptext: "" + i};
19 CustomizableUI.createWidget(spec);
20 }
21 for (let i = kTestWidgetCount; i < kTestWidgetCount * 2; i++) {
22 let id = kTestWidgetPfx + i;
23 widgetIds.push(id);
24 createDummyXULButton(id, "unregisterArea XUL test " + i);
25 }
26 let toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds);
27 checkAbstractAndRealPlacements(toolbarNode, widgetIds);
29 // Now move one of them:
30 CustomizableUI.moveWidgetWithinArea(kTestWidgetPfx + kTestWidgetCount, 0);
31 // Clone the array so we know this is the modified one:
32 let modifiedWidgetIds = [...widgetIds];
33 let movedWidget = modifiedWidgetIds.splice(kTestWidgetCount, 1)[0];
34 modifiedWidgetIds.unshift(movedWidget);
36 // Check it:
37 checkAbstractAndRealPlacements(toolbarNode, modifiedWidgetIds);
39 // Then unregister
40 CustomizableUI.unregisterArea(kToolbarName);
42 // Check we tell the outside world no dangerous things:
43 checkWidgetFates(widgetIds);
44 // Only then remove the real node
45 toolbarNode.remove();
47 // Now move one of the items to the palette, and another to the navbar:
48 let lastWidget = modifiedWidgetIds.pop();
49 CustomizableUI.removeWidgetFromArea(lastWidget);
50 lastWidget = modifiedWidgetIds.pop();
51 CustomizableUI.addWidgetToArea(lastWidget, CustomizableUI.AREA_NAVBAR);
53 // Recreate ourselves with the default placements being the same:
54 toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds);
55 // Then check that after doing this, our actual placements match
56 // the modified list, not the default one.
57 checkAbstractAndRealPlacements(toolbarNode, modifiedWidgetIds);
59 // Now remove completely:
60 CustomizableUI.unregisterArea(kToolbarName, true);
61 checkWidgetFates(modifiedWidgetIds);
62 toolbarNode.remove();
64 // One more time:
65 // Recreate ourselves with the default placements being the same:
66 toolbarNode = createToolbarWithPlacements(kToolbarName, widgetIds);
67 // Should now be back to default:
68 checkAbstractAndRealPlacements(toolbarNode, widgetIds);
69 CustomizableUI.unregisterArea(kToolbarName, true);
70 checkWidgetFates(widgetIds);
71 toolbarNode.remove();
73 //XXXgijs: ensure cleanup function doesn't barf:
74 gAddedToolbars.delete(kToolbarName);
76 // Remove all the XUL widgets, destroy the others:
77 for (let widget of widgetIds) {
78 let widgetWrapper = CustomizableUI.getWidget(widget);
79 if (widgetWrapper.provider == CustomizableUI.PROVIDER_XUL) {
80 gNavToolbox.palette.querySelector("#" + widget).remove();
81 } else {
82 CustomizableUI.destroyWidget(widget);
83 }
84 }
85 });
87 function checkAbstractAndRealPlacements(aNode, aExpectedPlacements) {
88 assertAreaPlacements(kToolbarName, aExpectedPlacements);
89 let physicalWidgetIds = [node.id for (node of aNode.childNodes)];
90 placementArraysEqual(aNode.id, physicalWidgetIds, aExpectedPlacements);
91 }
93 function checkWidgetFates(aWidgetIds) {
94 for (let widget of aWidgetIds) {
95 ok(!CustomizableUI.getPlacementOfWidget(widget), "Widget should be in palette");
96 ok(!document.getElementById(widget), "Widget should not be in the DOM");
97 let widgetInPalette = !!gNavToolbox.palette.querySelector("#" + widget);
98 let widgetProvider = CustomizableUI.getWidget(widget).provider;
99 let widgetIsXULWidget = widgetProvider == CustomizableUI.PROVIDER_XUL;
100 is(widgetInPalette, widgetIsXULWidget, "Just XUL Widgets should be in the palette");
101 }
102 }
104 add_task(function asyncCleanup() {
105 yield resetCustomization();
106 });