|
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 requestLongerTimeout(2); |
|
8 |
|
9 // One orphaned item should have two placeholders next to it. |
|
10 add_task(function() { |
|
11 yield startCustomizing(); |
|
12 let btn = document.getElementById("open-file-button"); |
|
13 let panel = document.getElementById(CustomizableUI.AREA_PANEL); |
|
14 let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); |
|
15 |
|
16 if (isInWin8()) { |
|
17 CustomizableUI.removeWidgetFromArea("switch-to-metro-button"); |
|
18 placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); |
|
19 ok(!CustomizableUI.inDefaultState, "Should no longer be in default state."); |
|
20 } else { |
|
21 ok(CustomizableUI.inDefaultState, "Should be in default state."); |
|
22 } |
|
23 |
|
24 assertAreaPlacements(CustomizableUI.AREA_PANEL, placements); |
|
25 is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders before exiting"); |
|
26 |
|
27 yield endCustomizing(); |
|
28 yield startCustomizing(); |
|
29 is(getVisiblePlaceholderCount(panel), 2, "Should only have 2 visible placeholders after re-entering"); |
|
30 |
|
31 if (isInWin8()) { |
|
32 CustomizableUI.addWidgetToArea("switch-to-metro-button", CustomizableUI.AREA_PANEL); |
|
33 } |
|
34 ok(CustomizableUI.inDefaultState, "Should be in default state again."); |
|
35 }); |
|
36 |
|
37 // Two orphaned items should have one placeholder next to them (case 1). |
|
38 add_task(function() { |
|
39 yield startCustomizing(); |
|
40 let btn = document.getElementById("open-file-button"); |
|
41 let panel = document.getElementById(CustomizableUI.AREA_PANEL); |
|
42 let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); |
|
43 |
|
44 let placementsAfterAppend = placements; |
|
45 |
|
46 if (!isInWin8()) { |
|
47 placementsAfterAppend = placements.concat(["open-file-button"]); |
|
48 simulateItemDrag(btn, panel); |
|
49 } |
|
50 |
|
51 assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend); |
|
52 is(CustomizableUI.inDefaultState, isInWin8(), "Should only be in default state if on Win8"); |
|
53 is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting"); |
|
54 |
|
55 yield endCustomizing(); |
|
56 yield startCustomizing(); |
|
57 is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering"); |
|
58 |
|
59 let palette = document.getElementById("customization-palette"); |
|
60 simulateItemDrag(btn, palette); |
|
61 |
|
62 if (!isInWin8()) { |
|
63 btn = document.getElementById("open-file-button"); |
|
64 simulateItemDrag(btn, palette); |
|
65 } |
|
66 ok(CustomizableUI.inDefaultState, "Should be in default state again."); |
|
67 }); |
|
68 |
|
69 // Two orphaned items should have one placeholder next to them (case 2). |
|
70 add_task(function() { |
|
71 yield startCustomizing(); |
|
72 let btn = document.getElementById("add-ons-button"); |
|
73 let btn2 = document.getElementById("developer-button"); |
|
74 let btn3 = document.getElementById("switch-to-metro-button"); |
|
75 let panel = document.getElementById(CustomizableUI.AREA_PANEL); |
|
76 let palette = document.getElementById("customization-palette"); |
|
77 let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); |
|
78 |
|
79 let placementsAfterAppend = placements.filter(p => p != btn.id && p != btn2.id); |
|
80 simulateItemDrag(btn, palette); |
|
81 simulateItemDrag(btn2, palette); |
|
82 |
|
83 if (isInWin8()) { |
|
84 placementsAfterAppend = placementsAfterAppend.filter(p => p != btn3.id); |
|
85 simulateItemDrag(btn3, palette); |
|
86 } |
|
87 |
|
88 assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend); |
|
89 ok(!CustomizableUI.inDefaultState, "Should no longer be in default state."); |
|
90 is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder before exiting"); |
|
91 |
|
92 yield endCustomizing(); |
|
93 yield startCustomizing(); |
|
94 is(getVisiblePlaceholderCount(panel), 1, "Should only have 1 visible placeholder after re-entering"); |
|
95 |
|
96 simulateItemDrag(btn, panel); |
|
97 simulateItemDrag(btn2, panel); |
|
98 |
|
99 if (isInWin8()) { |
|
100 simulateItemDrag(btn3, panel); |
|
101 } |
|
102 |
|
103 assertAreaPlacements(CustomizableUI.AREA_PANEL, placements); |
|
104 ok(CustomizableUI.inDefaultState, "Should be in default state again."); |
|
105 }); |
|
106 |
|
107 // A wide widget at the bottom of the panel should have three placeholders after it. |
|
108 add_task(function() { |
|
109 yield startCustomizing(); |
|
110 let btn = document.getElementById("edit-controls"); |
|
111 let developerButton = document.getElementById("developer-button"); |
|
112 let metroBtn = document.getElementById("switch-to-metro-button"); |
|
113 let panel = document.getElementById(CustomizableUI.AREA_PANEL); |
|
114 let palette = document.getElementById("customization-palette"); |
|
115 let placements = getAreaWidgetIds(CustomizableUI.AREA_PANEL); |
|
116 |
|
117 placements.pop(); |
|
118 simulateItemDrag(developerButton, palette); |
|
119 if (isInWin8()) { |
|
120 // Remove switch-to-metro-button |
|
121 placements.pop(); |
|
122 simulateItemDrag(metroBtn, palette); |
|
123 } |
|
124 |
|
125 let placementsAfterAppend = placements.concat([placements.shift()]); |
|
126 simulateItemDrag(btn, panel); |
|
127 assertAreaPlacements(CustomizableUI.AREA_PANEL, placementsAfterAppend); |
|
128 ok(!CustomizableUI.inDefaultState, "Should no longer be in default state."); |
|
129 is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders before exiting"); |
|
130 |
|
131 yield endCustomizing(); |
|
132 yield startCustomizing(); |
|
133 is(getVisiblePlaceholderCount(panel), 3, "Should have 3 visible placeholders after re-entering"); |
|
134 |
|
135 simulateItemDrag(developerButton, panel); |
|
136 if (isInWin8()) { |
|
137 simulateItemDrag(metroBtn, panel); |
|
138 } |
|
139 let zoomControls = document.getElementById("zoom-controls"); |
|
140 simulateItemDrag(btn, zoomControls); |
|
141 ok(CustomizableUI.inDefaultState, "Should be in default state again."); |
|
142 }); |
|
143 |
|
144 // The default placements should have two placeholders at the bottom (or 1 in win8). |
|
145 add_task(function() { |
|
146 yield startCustomizing(); |
|
147 let numPlaceholders = isInWin8() ? 1 : 2; |
|
148 let panel = document.getElementById(CustomizableUI.AREA_PANEL); |
|
149 ok(CustomizableUI.inDefaultState, "Should be in default state."); |
|
150 is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders before exiting"); |
|
151 |
|
152 yield endCustomizing(); |
|
153 yield startCustomizing(); |
|
154 is(getVisiblePlaceholderCount(panel), numPlaceholders, "Should have " + numPlaceholders + " visible placeholders after re-entering"); |
|
155 |
|
156 ok(CustomizableUI.inDefaultState, "Should still be in default state."); |
|
157 }); |
|
158 |
|
159 add_task(function asyncCleanup() { |
|
160 yield endCustomizing(); |
|
161 yield resetCustomization(); |
|
162 }); |
|
163 |
|
164 function getVisiblePlaceholderCount(aPanel) { |
|
165 let visiblePlaceholders = aPanel.querySelectorAll(".panel-customization-placeholder:not([hidden=true])"); |
|
166 return visiblePlaceholders.length; |
|
167 } |