|
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 add_task(function customizeToolbarAndKeepIt() { |
|
8 ok(gNavToolbox.toolbarset, "There should be a toolbarset"); |
|
9 let toolbarID = "testAustralisCustomToolbar"; |
|
10 gNavToolbox.appendCustomToolbar(toolbarID, ""); |
|
11 let toolbarDOMID = getToolboxCustomToolbarId(toolbarID); |
|
12 let toolbarElement = document.getElementById(toolbarDOMID); |
|
13 ok(toolbarElement, "There should be a toolbar"); |
|
14 if (!toolbarElement) { |
|
15 ok(false, "No toolbar created, bailing out of the test."); |
|
16 return; |
|
17 } |
|
18 is(toolbarElement.nextSibling, gNavToolbox.toolbarset, |
|
19 "Toolbar should have been inserted in toolbox, before toolbarset element"); |
|
20 let cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
|
21 is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, |
|
22 "CustomizableUI should know the area and think it's a toolbar"); |
|
23 if (cuiAreaType != CustomizableUI.TYPE_TOOLBAR) { |
|
24 ok(false, "Toolbar not registered successfully, bailing out of the test."); |
|
25 toolbarElement.remove(); |
|
26 return; |
|
27 } |
|
28 ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet."); |
|
29 CustomizableUI.addWidgetToArea("open-file-button", toolbarDOMID, 0); |
|
30 ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button."); |
|
31 assertAreaPlacements(toolbarDOMID, ["open-file-button"]); |
|
32 |
|
33 gNavToolbox.toolbarset.setAttribute("toolbar1", toolbarID + ":open-file-button"); |
|
34 document.persist(gNavToolbox.toolbarset.id, "toolbar1"); |
|
35 |
|
36 yield startCustomizing(); |
|
37 // First, exit customize mode without doing anything, and verify the toolbar doesn't get removed. |
|
38 yield endCustomizing(); |
|
39 ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state, the toolbar should still be there."); |
|
40 cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
|
41 is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, |
|
42 "CustomizableUI should still know the area and think it's a toolbar"); |
|
43 ok(toolbarElement.parentNode, "Toolbar should still be in the DOM."); |
|
44 ok(toolbarElement.hasChildNodes(), "Toolbar should still have items in it."); |
|
45 assertAreaPlacements(toolbarDOMID, ["open-file-button"]); |
|
46 |
|
47 let newWindow = yield openAndLoadWindow({}, true); |
|
48 is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar1"), |
|
49 gNavToolbox.toolbarset.getAttribute("toolbar1"), |
|
50 "Attribute should be the same in new window"); |
|
51 yield promiseWindowClosed(newWindow); |
|
52 |
|
53 // Then customize again, and this time empty out the toolbar and verify it *does* get removed. |
|
54 yield startCustomizing(); |
|
55 let openFileButton = document.getElementById("open-file-button"); |
|
56 let palette = document.getElementById("customization-palette"); |
|
57 simulateItemDrag(openFileButton, palette); |
|
58 ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's still a non-collapsed toolbar."); |
|
59 ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes."); |
|
60 |
|
61 toolbarElement.collapsed = true; |
|
62 ok(CustomizableUI.inDefaultState, "Should be in default state because there's now just a collapsed toolbar."); |
|
63 toolbarElement.collapsed = false; |
|
64 ok(!CustomizableUI.inDefaultState, "Shouldn't be in default state because there's a non-collapsed toolbar again."); |
|
65 yield endCustomizing(); |
|
66 ok(CustomizableUI.inDefaultState, "Should be in default state because the toolbar should have been removed."); |
|
67 |
|
68 newWindow = yield openAndLoadWindow({}, true); |
|
69 ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar1"), |
|
70 "Attribute should be gone in new window"); |
|
71 yield promiseWindowClosed(newWindow); |
|
72 |
|
73 ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM."); |
|
74 cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
|
75 is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area"); |
|
76 }); |
|
77 |
|
78 add_task(function resetShouldDealWithCustomToolbars() { |
|
79 ok(gNavToolbox.toolbarset, "There should be a toolbarset"); |
|
80 let toolbarID = "testAustralisCustomToolbar"; |
|
81 gNavToolbox.appendCustomToolbar(toolbarID, ""); |
|
82 let toolbarDOMID = getToolboxCustomToolbarId(toolbarID); |
|
83 let toolbarElement = document.getElementById(toolbarDOMID); |
|
84 ok(toolbarElement, "There should be a toolbar"); |
|
85 if (!toolbarElement) { |
|
86 ok(false, "No toolbar created, bailing out of the test."); |
|
87 return; |
|
88 } |
|
89 is(toolbarElement.nextSibling, gNavToolbox.toolbarset, |
|
90 "Toolbar should have been inserted in toolbox, before toolbarset element"); |
|
91 let cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
|
92 is(cuiAreaType, CustomizableUI.TYPE_TOOLBAR, |
|
93 "CustomizableUI should know the area and think it's a toolbar"); |
|
94 if (cuiAreaType != CustomizableUI.TYPE_TOOLBAR) { |
|
95 ok(false, "Toolbar not registered successfully, bailing out of the test."); |
|
96 toolbarElement.remove(); |
|
97 return; |
|
98 } |
|
99 ok(!CustomizableUI.getWidgetIdsInArea(toolbarDOMID).length, "There should be no widgets in the area yet."); |
|
100 CustomizableUI.addWidgetToArea("sync-button", toolbarDOMID, 0); |
|
101 ok(toolbarElement.hasChildNodes(), "Toolbar should now have a button."); |
|
102 assertAreaPlacements(toolbarDOMID, ["sync-button"]); |
|
103 |
|
104 gNavToolbox.toolbarset.setAttribute("toolbar2", toolbarID + ":sync-button"); |
|
105 document.persist(gNavToolbox.toolbarset.id, "toolbar2"); |
|
106 |
|
107 let newWindow = yield openAndLoadWindow({}, true); |
|
108 is(newWindow.gNavToolbox.toolbarset.getAttribute("toolbar2"), |
|
109 gNavToolbox.toolbarset.getAttribute("toolbar2"), |
|
110 "Attribute should be the same in new window"); |
|
111 yield promiseWindowClosed(newWindow); |
|
112 |
|
113 CustomizableUI.reset(); |
|
114 |
|
115 newWindow = yield openAndLoadWindow({}, true); |
|
116 ok(!newWindow.gNavToolbox.toolbarset.hasAttribute("toolbar2"), |
|
117 "Attribute should be gone in new window"); |
|
118 yield promiseWindowClosed(newWindow); |
|
119 |
|
120 ok(CustomizableUI.inDefaultState, "Should be in default state after reset."); |
|
121 let syncButton = document.getElementById("sync-button"); |
|
122 ok(!syncButton, "Sync button shouldn't be in the document anymore."); |
|
123 ok(gNavToolbox.palette.querySelector("#sync-button"), "Sync button should be in the palette"); |
|
124 ok(!toolbarElement.hasChildNodes(), "Toolbar should have no more child nodes."); |
|
125 ok(!toolbarElement.parentNode, "Toolbar should no longer be in the DOM."); |
|
126 cuiAreaType = CustomizableUI.getAreaType(toolbarDOMID); |
|
127 is(cuiAreaType, null, "CustomizableUI should have forgotten all about the area"); |
|
128 }); |
|
129 |
|
130 |
|
131 add_task(function() { |
|
132 let newWin = yield openAndLoadWindow({}, true); |
|
133 ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar1"), "New window shouldn't have attribute toolbar1"); |
|
134 ok(!newWin.gNavToolbox.toolbarset.hasAttribute("toolbar2"), "New window shouldn't have attribute toolbar2"); |
|
135 yield promiseWindowClosed(newWin); |
|
136 }); |