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