michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const isOSX = (Services.appinfo.OS === "Darwin"); michael@0: michael@0: // Right-click on the home button should michael@0: // show a context menu with options to move it. michael@0: add_task(function() { michael@0: let contextMenu = document.getElementById("toolbar-context-menu"); michael@0: let shownPromise = popupShown(contextMenu); michael@0: let homeButton = document.getElementById("home-button"); michael@0: EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2 }); michael@0: yield shownPromise; michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToPanel", true], michael@0: [".customize-context-removeFromToolbar", true], michael@0: ["---"] michael@0: ]; michael@0: if (!isOSX) { michael@0: expectedEntries.push(["#toggle_toolbar-menubar", true]); michael@0: } michael@0: expectedEntries.push( michael@0: ["#toggle_PersonalToolbar", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", true] michael@0: ); michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: let hiddenPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenPromise; michael@0: }); michael@0: michael@0: // Right-click on an empty bit of extra toolbar should michael@0: // show a context menu with moving options disabled, michael@0: // and a toggle option for the extra toolbar michael@0: add_task(function() { michael@0: let contextMenu = document.getElementById("toolbar-context-menu"); michael@0: let shownPromise = popupShown(contextMenu); michael@0: let toolbar = createToolbarWithPlacements("880164_empty_toolbar", []); michael@0: toolbar.setAttribute("context", "toolbar-context-menu"); michael@0: toolbar.setAttribute("toolbarname", "Fancy Toolbar for Context Menu"); michael@0: EventUtils.synthesizeMouseAtCenter(toolbar, {type: "contextmenu", button: 2 }); michael@0: yield shownPromise; michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToPanel", false], michael@0: [".customize-context-removeFromToolbar", false], michael@0: ["---"] michael@0: ]; michael@0: if (!isOSX) { michael@0: expectedEntries.push(["#toggle_toolbar-menubar", true]); michael@0: } michael@0: expectedEntries.push( michael@0: ["#toggle_PersonalToolbar", true], michael@0: ["#toggle_880164_empty_toolbar", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", true] michael@0: ); michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: let hiddenPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenPromise; michael@0: removeCustomToolbars(); michael@0: }); michael@0: michael@0: michael@0: // Right-click on the urlbar-container should michael@0: // show a context menu with disabled options to move it. michael@0: add_task(function() { michael@0: let contextMenu = document.getElementById("toolbar-context-menu"); michael@0: let shownPromise = popupShown(contextMenu); michael@0: let urlBarContainer = document.getElementById("urlbar-container"); michael@0: // Need to make sure not to click within an edit field. michael@0: let urlbarRect = urlBarContainer.getBoundingClientRect(); michael@0: EventUtils.synthesizeMouse(urlBarContainer, 100, urlbarRect.height - 1, {type: "contextmenu", button: 2 }); michael@0: yield shownPromise; michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToPanel", false], michael@0: [".customize-context-removeFromToolbar", false], michael@0: ["---"] michael@0: ]; michael@0: if (!isOSX) { michael@0: expectedEntries.push(["#toggle_toolbar-menubar", true]); michael@0: } michael@0: expectedEntries.push( michael@0: ["#toggle_PersonalToolbar", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", true] michael@0: ); michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: let hiddenPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenPromise; michael@0: }); michael@0: michael@0: // Right-click on the searchbar and moving it to the menu michael@0: // and back should move the search-container instead. michael@0: add_task(function() { michael@0: let searchbar = document.getElementById("searchbar"); michael@0: gCustomizeMode.addToPanel(searchbar); michael@0: let placement = CustomizableUI.getPlacementOfWidget("search-container"); michael@0: is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel"); michael@0: michael@0: let shownPanelPromise = promisePanelShown(window); michael@0: PanelUI.toggle({type: "command"}); michael@0: yield shownPanelPromise; michael@0: let hiddenPanelPromise = promisePanelHidden(window); michael@0: PanelUI.toggle({type: "command"}); michael@0: yield hiddenPanelPromise; michael@0: michael@0: gCustomizeMode.addToToolbar(searchbar); michael@0: placement = CustomizableUI.getPlacementOfWidget("search-container"); michael@0: is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar"); michael@0: gCustomizeMode.removeFromArea(searchbar); michael@0: placement = CustomizableUI.getPlacementOfWidget("search-container"); michael@0: is(placement, null, "Should be in palette"); michael@0: CustomizableUI.reset(); michael@0: placement = CustomizableUI.getPlacementOfWidget("search-container"); michael@0: is(placement.area, CustomizableUI.AREA_NAVBAR, "Should be in navbar"); michael@0: }); michael@0: michael@0: // Right-click on an item within the menu panel should michael@0: // show a context menu with options to move it. michael@0: add_task(function() { michael@0: let shownPanelPromise = promisePanelShown(window); michael@0: PanelUI.toggle({type: "command"}); michael@0: yield shownPanelPromise; michael@0: michael@0: let contextMenu = document.getElementById("customizationPanelItemContextMenu"); michael@0: let shownContextPromise = popupShown(contextMenu); michael@0: let newWindowButton = document.getElementById("new-window-button"); michael@0: ok(newWindowButton, "new-window-button was found"); michael@0: EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}); michael@0: yield shownContextPromise; michael@0: michael@0: is(PanelUI.panel.state, "open", "The PanelUI should still be open."); michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToToolbar", true], michael@0: [".customize-context-removeFromPanel", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", true] michael@0: ]; michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: let hiddenContextPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenContextPromise; michael@0: michael@0: let hiddenPromise = promisePanelHidden(window); michael@0: PanelUI.toggle({type: "command"}); michael@0: yield hiddenPromise; michael@0: }); michael@0: michael@0: // Right-click on the home button while in customization mode michael@0: // should show a context menu with options to move it. michael@0: add_task(function() { michael@0: yield startCustomizing(); michael@0: let contextMenu = document.getElementById("toolbar-context-menu"); michael@0: let shownPromise = popupShown(contextMenu); michael@0: let homeButton = document.getElementById("wrapper-home-button"); michael@0: EventUtils.synthesizeMouse(homeButton, 2, 2, {type: "contextmenu", button: 2}); michael@0: yield shownPromise; michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToPanel", true], michael@0: [".customize-context-removeFromToolbar", true], michael@0: ["---"] michael@0: ]; michael@0: if (!isOSX) { michael@0: expectedEntries.push(["#toggle_toolbar-menubar", true]); michael@0: } michael@0: expectedEntries.push( michael@0: ["#toggle_PersonalToolbar", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", false] michael@0: ); michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: let hiddenContextPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenContextPromise; michael@0: }); michael@0: michael@0: // Right-click on an item in the palette should michael@0: // show a context menu with options to move it. michael@0: add_task(function() { michael@0: let contextMenu = document.getElementById("customizationPaletteItemContextMenu"); michael@0: let shownPromise = popupShown(contextMenu); michael@0: let openFileButton = document.getElementById("wrapper-open-file-button"); michael@0: EventUtils.synthesizeMouse(openFileButton, 2, 2, {type: "contextmenu", button: 2}); michael@0: yield shownPromise; michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-addToToolbar", true], michael@0: [".customize-context-addToPanel", true] michael@0: ]; michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: let hiddenContextPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenContextPromise; michael@0: }); michael@0: michael@0: // Right-click on an item in the panel while in customization mode michael@0: // should show a context menu with options to move it. michael@0: add_task(function() { michael@0: let contextMenu = document.getElementById("customizationPanelItemContextMenu"); michael@0: let shownPromise = popupShown(contextMenu); michael@0: let newWindowButton = document.getElementById("wrapper-new-window-button"); michael@0: EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}); michael@0: yield shownPromise; michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToToolbar", true], michael@0: [".customize-context-removeFromPanel", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", false] michael@0: ]; michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: let hiddenContextPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenContextPromise; michael@0: yield endCustomizing(); michael@0: }); michael@0: michael@0: // Test the toolbarbutton panel context menu in customization mode michael@0: // without opening the panel before customization mode michael@0: add_task(function() { michael@0: this.otherWin = yield openAndLoadWindow(null, true); michael@0: michael@0: yield startCustomizing(this.otherWin); michael@0: michael@0: let contextMenu = this.otherWin.document.getElementById("customizationPanelItemContextMenu"); michael@0: let shownPromise = popupShown(contextMenu); michael@0: let newWindowButton = this.otherWin.document.getElementById("wrapper-new-window-button"); michael@0: EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}, this.otherWin); michael@0: yield shownPromise; michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToToolbar", true], michael@0: [".customize-context-removeFromPanel", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", false] michael@0: ]; michael@0: checkContextMenu(contextMenu, expectedEntries, this.otherWin); michael@0: michael@0: let hiddenContextPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenContextPromise; michael@0: yield endCustomizing(this.otherWin); michael@0: yield promiseWindowClosed(this.otherWin); michael@0: this.otherWin = null; michael@0: }); michael@0: michael@0: // Bug 945191 - Combined buttons show wrong context menu options michael@0: // when they are in the toolbar. michael@0: add_task(function() { michael@0: yield startCustomizing(); michael@0: let contextMenu = document.getElementById("customizationPanelItemContextMenu"); michael@0: let shownPromise = popupShown(contextMenu); michael@0: let zoomControls = document.getElementById("wrapper-zoom-controls"); michael@0: EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2}); michael@0: yield shownPromise; michael@0: // Execute the command to move the item from the panel to the toolbar. michael@0: contextMenu.childNodes[0].doCommand(); michael@0: let hiddenPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenPromise; michael@0: yield endCustomizing(); michael@0: michael@0: zoomControls = document.getElementById("zoom-controls"); michael@0: is(zoomControls.parentNode.id, "nav-bar-customization-target", "Zoom-controls should be on the nav-bar"); michael@0: michael@0: contextMenu = document.getElementById("toolbar-context-menu"); michael@0: shownPromise = popupShown(contextMenu); michael@0: EventUtils.synthesizeMouse(zoomControls, 2, 2, {type: "contextmenu", button: 2}); michael@0: yield shownPromise; michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToPanel", true], michael@0: [".customize-context-removeFromToolbar", true], michael@0: ["---"] michael@0: ]; michael@0: if (!isOSX) { michael@0: expectedEntries.push(["#toggle_toolbar-menubar", true]); michael@0: } michael@0: expectedEntries.push( michael@0: ["#toggle_PersonalToolbar", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", true] michael@0: ); michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: hiddenPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenPromise; michael@0: yield resetCustomization(); michael@0: }); michael@0: michael@0: // Bug 947586 - After customization, panel items show wrong context menu options michael@0: add_task(function() { michael@0: yield startCustomizing(); michael@0: yield endCustomizing(); michael@0: michael@0: yield PanelUI.show(); michael@0: michael@0: let contextMenu = document.getElementById("customizationPanelItemContextMenu"); michael@0: let shownContextPromise = popupShown(contextMenu); michael@0: let newWindowButton = document.getElementById("new-window-button"); michael@0: ok(newWindowButton, "new-window-button was found"); michael@0: EventUtils.synthesizeMouse(newWindowButton, 2, 2, {type: "contextmenu", button: 2}); michael@0: yield shownContextPromise; michael@0: michael@0: is(PanelUI.panel.state, "open", "The PanelUI should still be open."); michael@0: michael@0: let expectedEntries = [ michael@0: [".customize-context-moveToToolbar", true], michael@0: [".customize-context-removeFromPanel", true], michael@0: ["---"], michael@0: [".viewCustomizeToolbar", true] michael@0: ]; michael@0: checkContextMenu(contextMenu, expectedEntries); michael@0: michael@0: let hiddenContextPromise = popupHidden(contextMenu); michael@0: contextMenu.hidePopup(); michael@0: yield hiddenContextPromise; michael@0: michael@0: let hiddenPromise = promisePanelHidden(window); michael@0: PanelUI.hide(); michael@0: yield hiddenPromise; michael@0: }); michael@0: michael@0: michael@0: // Bug 982027 - moving icon around removes custom context menu. michael@0: add_task(function() { michael@0: let widgetId = "custom-context-menu-toolbarbutton"; michael@0: let expectedContext = "myfancycontext"; michael@0: let widget = createDummyXULButton(widgetId, "Test ctxt menu"); michael@0: widget.setAttribute("context", expectedContext); michael@0: CustomizableUI.addWidgetToArea(widgetId, CustomizableUI.AREA_NAVBAR); michael@0: is(widget.getAttribute("context"), expectedContext, "Should have context menu when added to the toolbar."); michael@0: michael@0: yield startCustomizing(); michael@0: is(widget.getAttribute("context"), "", "Should not have own context menu in the toolbar now that we're customizing."); michael@0: is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped when in toolbar."); michael@0: michael@0: let panel = PanelUI.contents; michael@0: simulateItemDrag(widget, panel); michael@0: is(widget.getAttribute("context"), "", "Should not have own context menu when in the panel."); michael@0: is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're in the panel."); michael@0: michael@0: simulateItemDrag(widget, document.getElementById("nav-bar").customizationTarget); michael@0: is(widget.getAttribute("context"), "", "Should not have own context menu when back in toolbar because we're still customizing."); michael@0: is(widget.getAttribute("wrapped-context"), expectedContext, "Should keep own context menu wrapped now that we're back in the toolbar."); michael@0: michael@0: yield endCustomizing(); michael@0: is(widget.getAttribute("context"), expectedContext, "Should have context menu again now that we're out of customize mode."); michael@0: CustomizableUI.removeWidgetFromArea(widgetId); michael@0: widget.remove(); michael@0: ok(CustomizableUI.inDefaultState, "Should be in default state after removing button."); michael@0: });