|
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 isOSX = (Services.appinfo.OS === "Darwin"); |
|
8 |
|
9 // Right-click on the home button should |
|
10 // show a context menu with options to move it. |
|
11 add_task(function() { |
|
12 let contextMenu = document.getElementById("toolbar-context-menu"); |
|
13 let shownPromise = popupShown(contextMenu); |
|
14 let homeButton = document.getElementById("home-button"); |
|
15 EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2 }); |
|
16 yield shownPromise; |
|
17 |
|
18 let expectedEntries = [ |
|
19 [".customize-context-moveToPanel", true], |
|
20 [".customize-context-removeFromToolbar", true], |
|
21 ["---"] |
|
22 ]; |
|
23 if (!isOSX) { |
|
24 expectedEntries.push(["#toggle_toolbar-menubar", true]); |
|
25 } |
|
26 expectedEntries.push( |
|
27 ["#toggle_PersonalToolbar", true], |
|
28 ["---"], |
|
29 [".viewCustomizeToolbar", true] |
|
30 ); |
|
31 checkContextMenu(contextMenu, expectedEntries); |
|
32 |
|
33 let hiddenPromise = popupHidden(contextMenu); |
|
34 contextMenu.hidePopup(); |
|
35 yield hiddenPromise; |
|
36 }); |
|
37 |
|
38 // Right-click on an empty bit of extra toolbar should |
|
39 // show a context menu with moving options disabled, |
|
40 // and a toggle option for the extra toolbar |
|
41 add_task(function() { |
|
42 let contextMenu = document.getElementById("toolbar-context-menu"); |
|
43 let shownPromise = popupShown(contextMenu); |
|
44 let toolbar = createToolbarWithPlacements("880164_empty_toolbar", []); |
|
45 toolbar.setAttribute("context", "toolbar-context-menu"); |
|
46 toolbar.setAttribute("toolbarname", "Fancy Toolbar for Context Menu"); |
|
47 EventUtils.synthesizeMouseAtCenter(toolbar, {type: "contextmenu", button: 2 }); |
|
48 yield shownPromise; |
|
49 |
|
50 let expectedEntries = [ |
|
51 [".customize-context-moveToPanel", false], |
|
52 [".customize-context-removeFromToolbar", false], |
|
53 ["---"] |
|
54 ]; |
|
55 if (!isOSX) { |
|
56 expectedEntries.push(["#toggle_toolbar-menubar", true]); |
|
57 } |
|
58 expectedEntries.push( |
|
59 ["#toggle_PersonalToolbar", true], |
|
60 ["#toggle_880164_empty_toolbar", true], |
|
61 ["---"], |
|
62 [".viewCustomizeToolbar", true] |
|
63 ); |
|
64 checkContextMenu(contextMenu, expectedEntries); |
|
65 |
|
66 let hiddenPromise = popupHidden(contextMenu); |
|
67 contextMenu.hidePopup(); |
|
68 yield hiddenPromise; |
|
69 removeCustomToolbars(); |
|
70 }); |
|
71 |
|
72 |
|
73 // Right-click on the urlbar-container should |
|
74 // show a context menu with disabled options to move it. |
|
75 add_task(function() { |
|
76 let contextMenu = document.getElementById("toolbar-context-menu"); |
|
77 let shownPromise = popupShown(contextMenu); |
|
78 let urlBarContainer = document.getElementById("urlbar-container"); |
|
79 // Need to make sure not to click within an edit field. |
|
80 let urlbarRect = urlBarContainer.getBoundingClientRect(); |
|
81 EventUtils.synthesizeMouse(urlBarContainer, 100, urlbarRect.height - 1, {type: "contextmenu", button: 2 }); |
|
82 yield shownPromise; |
|
83 |
|
84 let expectedEntries = [ |
|
85 [".customize-context-moveToPanel", false], |
|
86 [".customize-context-removeFromToolbar", false], |
|
87 ["---"] |
|
88 ]; |
|
89 if (!isOSX) { |
|
90 expectedEntries.push(["#toggle_toolbar-menubar", true]); |
|
91 } |
|
92 expectedEntries.push( |
|
93 ["#toggle_PersonalToolbar", true], |
|
94 ["---"], |
|
95 [".viewCustomizeToolbar", true] |
|
96 ); |
|
97 checkContextMenu(contextMenu, expectedEntries); |
|
98 |
|
99 let hiddenPromise = popupHidden(contextMenu); |
|
100 contextMenu.hidePopup(); |
|
101 yield hiddenPromise; |
|
102 }); |
|
103 |
|
104 // Right-click on the searchbar and moving it to the menu |
|
105 // and back should move the search-container instead. |
|
106 add_task(function() { |
|
107 let searchbar = document.getElementById("searchbar"); |
|
108 gCustomizeMode.addToPanel(searchbar); |
|
109 let placement = CustomizableUI.getPlacementOfWidget("search-container"); |
|
110 is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel"); |
|
111 |
|
112 let shownPanelPromise = promisePanelShown(window); |
|
113 PanelUI.toggle({type: "command"}); |
|
114 yield shownPanelPromise; |
|
115 let hiddenPanelPromise = promisePanelHidden(window); |
|
116 PanelUI.toggle({type: "command"}); |
|
117 yield hiddenPanelPromise; |
|
118 |
|
119 gCustomizeMode.addToToolbar(searchbar); |
|
120 placement = CustomizableUI.getPlacementOfWidget("search-container"); |
|
121 is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar"); |
|
122 gCustomizeMode.removeFromArea(searchbar); |
|
123 placement = CustomizableUI.getPlacementOfWidget("search-container"); |
|
124 is(placement, null, "Should be in palette"); |
|
125 CustomizableUI.reset(); |
|
126 placement = CustomizableUI.getPlacementOfWidget("search-container"); |
|
127 is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar"); |
|
128 }); |
|
129 |
|
130 // Right-click on an item within the menu panel should |
|
131 // show a context menu with options to move it. |
|
132 add_task(function() { |
|
133 let shownPanelPromise = promisePanelShown(window); |
|
134 PanelUI.toggle({type: "command"}); |
|
135 yield shownPanelPromise; |
|
136 |
|
137 let contextMenu = document.getElementById("customizationPanelItemContextMenu"); |
|
138 let shownContextPromise = popupShown(contextMenu); |
|
139 let newWindowButton = document.getElementById("new-window-button"); |
|
140 ok(newWindowButton, "new-window-button was found"); |
|
141 EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}); |
|
142 yield shownContextPromise; |
|
143 |
|
144 is(PanelUI.panel.state, "open", "The PanelUI should still be open."); |
|
145 |
|
146 let expectedEntries = [ |
|
147 [".customize-context-moveToToolbar", true], |
|
148 [".customize-context-removeFromPanel", true], |
|
149 ["---"], |
|
150 [".viewCustomizeToolbar", true] |
|
151 ]; |
|
152 checkContextMenu(contextMenu, expectedEntries); |
|
153 |
|
154 let hiddenContextPromise = popupHidden(contextMenu); |
|
155 contextMenu.hidePopup(); |
|
156 yield hiddenContextPromise; |
|
157 |
|
158 let hiddenPromise = promisePanelHidden(window); |
|
159 PanelUI.toggle({type: "command"}); |
|
160 yield hiddenPromise; |
|
161 }); |
|
162 |
|
163 // Right-click on the home button while in customization mode |
|
164 // should show a context menu with options to move it. |
|
165 add_task(function() { |
|
166 yield startCustomizing(); |
|
167 let contextMenu = document.getElementById("toolbar-context-menu"); |
|
168 let shownPromise = popupShown(contextMenu); |
|
169 let homeButton = document.getElementById("wrapper-home-button"); |
|
170 EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2}); |
|
171 yield shownPromise; |
|
172 |
|
173 let expectedEntries = [ |
|
174 [".customize-context-moveToPanel", true], |
|
175 [".customize-context-removeFromToolbar", true], |
|
176 ["---"] |
|
177 ]; |
|
178 if (!isOSX) { |
|
179 expectedEntries.push(["#toggle_toolbar-menubar", true]); |
|
180 } |
|
181 expectedEntries.push( |
|
182 ["#toggle_PersonalToolbar", true], |
|
183 ["---"], |
|
184 [".viewCustomizeToolbar", false] |
|
185 ); |
|
186 checkContextMenu(contextMenu, expectedEntries); |
|
187 |
|
188 let hiddenContextPromise = popupHidden(contextMenu); |
|
189 contextMenu.hidePopup(); |
|
190 yield hiddenContextPromise; |
|
191 }); |
|
192 |
|
193 // Right-click on an item in the palette should |
|
194 // show a context menu with options to move it. |
|
195 add_task(function() { |
|
196 let contextMenu = document.getElementById("customizationPaletteItemContextMenu"); |
|
197 let shownPromise = popupShown(contextMenu); |
|
198 let openFileButton = document.getElementById("wrapper-open-file-button"); |
|
199 EventUtils.synthesizeMouse(openFileButton, 2, 2, {type: "contextmenu", button: 2}); |
|
200 yield shownPromise; |
|
201 |
|
202 let expectedEntries = [ |
|
203 [".customize-context-addToToolbar", true], |
|
204 [".customize-context-addToPanel", true] |
|
205 ]; |
|
206 checkContextMenu(contextMenu, expectedEntries); |
|
207 |
|
208 let hiddenContextPromise = popupHidden(contextMenu); |
|
209 contextMenu.hidePopup(); |
|
210 yield hiddenContextPromise; |
|
211 }); |
|
212 |
|
213 // Right-click on an item in the panel while in customization mode |
|
214 // should show a context menu with options to move it. |
|
215 add_task(function() { |
|
216 let contextMenu = document.getElementById("customizationPanelItemContextMenu"); |
|
217 let shownPromise = popupShown(contextMenu); |
|
218 let newWindowButton = document.getElementById("wrapper-new-window-button"); |
|
219 EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}); |
|
220 yield shownPromise; |
|
221 |
|
222 let expectedEntries = [ |
|
223 [".customize-context-moveToToolbar", true], |
|
224 [".customize-context-removeFromPanel", true], |
|
225 ["---"], |
|
226 [".viewCustomizeToolbar", false] |
|
227 ]; |
|
228 checkContextMenu(contextMenu, expectedEntries); |
|
229 |
|
230 let hiddenContextPromise = popupHidden(contextMenu); |
|
231 contextMenu.hidePopup(); |
|
232 yield hiddenContextPromise; |
|
233 yield endCustomizing(); |
|
234 }); |
|
235 |
|
236 // Test the toolbarbutton panel context menu in customization mode |
|
237 // without opening the panel before customization mode |
|
238 add_task(function() { |
|
239 this.otherWin = yield openAndLoadWindow(null, true); |
|
240 |
|
241 yield startCustomizing(this.otherWin); |
|
242 |
|
243 let contextMenu = this.otherWin.document.getElementById("customizationPanelItemContextMenu"); |
|
244 let shownPromise = popupShown(contextMenu); |
|
245 let newWindowButton = this.otherWin.document.getElementById("wrapper-new-window-button"); |
|
246 EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}, this.otherWin); |
|
247 yield shownPromise; |
|
248 |
|
249 let expectedEntries = [ |
|
250 [".customize-context-moveToToolbar", true], |
|
251 [".customize-context-removeFromPanel", true], |
|
252 ["---"], |
|
253 [".viewCustomizeToolbar", false] |
|
254 ]; |
|
255 checkContextMenu(contextMenu, expectedEntries, this.otherWin); |
|
256 |
|
257 let hiddenContextPromise = popupHidden(contextMenu); |
|
258 contextMenu.hidePopup(); |
|
259 yield hiddenContextPromise; |
|
260 yield endCustomizing(this.otherWin); |
|
261 yield promiseWindowClosed(this.otherWin); |
|
262 this.otherWin = null; |
|
263 }); |
|
264 |
|
265 // Bug 945191 - Combined buttons show wrong context menu options |
|
266 // when they are in the toolbar. |
|
267 add_task(function() { |
|
268 yield startCustomizing(); |
|
269 let contextMenu = document.getElementById("customizationPanelItemContextMenu"); |
|
270 let shownPromise = popupShown(contextMenu); |
|
271 let zoomControls = document.getElementById("wrapper-zoom-controls"); |
|
272 EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2}); |
|
273 yield shownPromise; |
|
274 // Execute the command to move the item from the panel to the toolbar. |
|
275 contextMenu.childNodes[0].doCommand(); |
|
276 let hiddenPromise = popupHidden(contextMenu); |
|
277 contextMenu.hidePopup(); |
|
278 yield hiddenPromise; |
|
279 yield endCustomizing(); |
|
280 |
|
281 zoomControls = document.getElementById("zoom-controls"); |
|
282 is(zoomControls.parentNode.id, "nav-bar-customization-target", "Zoom-controls should be on the nav-bar"); |
|
283 |
|
284 contextMenu = document.getElementById("toolbar-context-menu"); |
|
285 shownPromise = popupShown(contextMenu); |
|
286 EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2}); |
|
287 yield shownPromise; |
|
288 |
|
289 let expectedEntries = [ |
|
290 [".customize-context-moveToPanel", true], |
|
291 [".customize-context-removeFromToolbar", true], |
|
292 ["---"] |
|
293 ]; |
|
294 if (!isOSX) { |
|
295 expectedEntries.push(["#toggle_toolbar-menubar", true]); |
|
296 } |
|
297 expectedEntries.push( |
|
298 ["#toggle_PersonalToolbar", true], |
|
299 ["---"], |
|
300 [".viewCustomizeToolbar", true] |
|
301 ); |
|
302 checkContextMenu(contextMenu, expectedEntries); |
|
303 |
|
304 hiddenPromise = popupHidden(contextMenu); |
|
305 contextMenu.hidePopup(); |
|
306 yield hiddenPromise; |
|
307 yield resetCustomization(); |
|
308 }); |
|
309 |
|
310 // Bug 947586 - After customization, panel items show wrong context menu options |
|
311 add_task(function() { |
|
312 yield startCustomizing(); |
|
313 yield endCustomizing(); |
|
314 |
|
315 yield PanelUI.show(); |
|
316 |
|
317 let contextMenu = document.getElementById("customizationPanelItemContextMenu"); |
|
318 let shownContextPromise = popupShown(contextMenu); |
|
319 let newWindowButton = document.getElementById("new-window-button"); |
|
320 ok(newWindowButton, "new-window-button was found"); |
|
321 EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}); |
|
322 yield shownContextPromise; |
|
323 |
|
324 is(PanelUI.panel.state, "open", "The PanelUI should still be open."); |
|
325 |
|
326 let expectedEntries = [ |
|
327 [".customize-context-moveToToolbar", true], |
|
328 [".customize-context-removeFromPanel", true], |
|
329 ["---"], |
|
330 [".viewCustomizeToolbar", true] |
|
331 ]; |
|
332 checkContextMenu(contextMenu, expectedEntries); |
|
333 |
|
334 let hiddenContextPromise = popupHidden(contextMenu); |
|
335 contextMenu.hidePopup(); |
|
336 yield hiddenContextPromise; |
|
337 |
|
338 let hiddenPromise = promisePanelHidden(window); |
|
339 PanelUI.hide(); |
|
340 yield hiddenPromise; |
|
341 }); |
|
342 |
|
343 |
|
344 // Bug 982027 - moving icon around removes custom context menu. |
|
345 add_task(function() { |
|
346 let widgetId = "custom-context-menu-toolbarbutton"; |
|
347 let expectedContext = "myfancycontext"; |
|
348 let widget = createDummyXULButton(widgetId, "Test ctxt menu"); |
|
349 widget.setAttribute("context", expectedContext); |
|
350 CustomizableUI.addWidgetToArea(widgetId, CustomizableUI.AREA_NAVBAR); |
|
351 is(widget.getAttribute("context"), expectedContext, "Should have context menu when added to the toolbar."); |
|
352 |
|
353 yield startCustomizing(); |
|
354 is(widget.getAttribute("context"), "", "Should not have own context menu in the toolbar now that we're customizing."); |
|
355 is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped when in toolbar."); |
|
356 |
|
357 let panel = PanelUI.contents; |
|
358 simulateItemDrag(widget, panel); |
|
359 is(widget.getAttribute("context"), "", "Should not have own context menu when in the panel."); |
|
360 is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're in the panel."); |
|
361 |
|
362 simulateItemDrag(widget, document.getElementById("nav-bar").customizationTarget); |
|
363 is(widget.getAttribute("context"), "", "Should not have own context menu when back in toolbar because we're still customizing."); |
|
364 is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're back in the toolbar."); |
|
365 |
|
366 yield endCustomizing(); |
|
367 is(widget.getAttribute("context"), expectedContext, "Should have context menu again now that we're out of customize mode."); |
|
368 CustomizableUI.removeWidgetFromArea(widgetId); |
|
369 widget.remove(); |
|
370 ok(CustomizableUI.inDefaultState, "Should be in default state after removing button."); |
|
371 }); |