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: let button, menuButton; michael@0: /* Clicking a button should close the panel */ michael@0: add_task(function() { michael@0: button = document.createElement("toolbarbutton"); michael@0: button.id = "browser_940307_button"; michael@0: button.setAttribute("label", "Button"); michael@0: PanelUI.contents.appendChild(button); michael@0: yield PanelUI.show(); michael@0: let hiddenAgain = promisePanelHidden(window); michael@0: EventUtils.synthesizeMouseAtCenter(button, {}); michael@0: yield hiddenAgain; michael@0: button.remove(); michael@0: }); michael@0: michael@0: /* Clicking a menu button should close the panel, opening the popup shouldn't. */ michael@0: add_task(function() { michael@0: menuButton = document.createElement("toolbarbutton"); michael@0: menuButton.setAttribute("type", "menu-button"); michael@0: menuButton.id = "browser_940307_menubutton"; michael@0: menuButton.setAttribute("label", "Menu button"); michael@0: michael@0: let menuPopup = document.createElement("menupopup"); michael@0: menuPopup.id = "browser_940307_menupopup"; michael@0: michael@0: let menuItem = document.createElement("menuitem"); michael@0: menuItem.setAttribute("label", "Menu item"); michael@0: menuItem.id = "browser_940307_menuitem"; michael@0: michael@0: menuPopup.appendChild(menuItem); michael@0: menuButton.appendChild(menuPopup); michael@0: PanelUI.contents.appendChild(menuButton); michael@0: michael@0: yield PanelUI.show(); michael@0: let hiddenAgain = promisePanelHidden(window); michael@0: let innerButton = document.getAnonymousElementByAttribute(menuButton, "anonid", "button"); michael@0: EventUtils.synthesizeMouseAtCenter(innerButton, {}); michael@0: yield hiddenAgain; michael@0: michael@0: // Now click the dropmarker to show the menu michael@0: yield PanelUI.show(); michael@0: hiddenAgain = promisePanelHidden(window); michael@0: let menuShown = promisePanelElementShown(window, menuPopup); michael@0: let dropmarker = document.getAnonymousElementByAttribute(menuButton, "type", "menu-button"); michael@0: EventUtils.synthesizeMouseAtCenter(dropmarker, {}); michael@0: yield menuShown; michael@0: // Panel should stay open: michael@0: ok(isPanelUIOpen(), "Panel should still be open"); michael@0: let menuHidden = promisePanelElementHidden(window, menuPopup); michael@0: // Then click the menu item to close all the things michael@0: EventUtils.synthesizeMouseAtCenter(menuItem, {}); michael@0: yield menuHidden; michael@0: yield hiddenAgain; michael@0: menuButton.remove(); michael@0: }); michael@0: 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: yield PanelUI.show(); michael@0: yield waitForCondition(() => "value" in searchbar && searchbar.value === ""); michael@0: michael@0: searchbar.value = "foo"; michael@0: searchbar.focus(); michael@0: // Reaching into this context menu is pretty evil, but hey... it's a test. michael@0: let textbox = document.getAnonymousElementByAttribute(searchbar.textbox, "anonid", "textbox-input-box"); michael@0: let contextmenu = document.getAnonymousElementByAttribute(textbox, "anonid", "input-box-contextmenu"); michael@0: let contextMenuShown = promisePanelElementShown(window, contextmenu); michael@0: EventUtils.synthesizeMouseAtCenter(searchbar, {type: "contextmenu", button: 2}); michael@0: yield contextMenuShown; michael@0: michael@0: ok(isPanelUIOpen(), "Panel should still be open"); michael@0: michael@0: let selectAll = contextmenu.querySelector("[cmd='cmd_selectAll']"); michael@0: let contextMenuHidden = promisePanelElementHidden(window, contextmenu); michael@0: EventUtils.synthesizeMouseAtCenter(selectAll, {}); michael@0: yield contextMenuHidden; michael@0: michael@0: ok(isPanelUIOpen(), "Panel should still be open"); michael@0: michael@0: let hiddenPanelPromise = promisePanelHidden(window); michael@0: EventUtils.synthesizeKey("VK_ESCAPE", {}); michael@0: yield hiddenPanelPromise; michael@0: ok(!isPanelUIOpen(), "Panel should no longer be open"); michael@0: }); michael@0: michael@0: registerCleanupFunction(function() { michael@0: if (button && button.parentNode) { michael@0: button.remove(); michael@0: } michael@0: if (menuButton && menuButton.parentNode) { michael@0: menuButton.remove(); michael@0: } michael@0: // Sadly this isn't task.jsm-enabled, so we can't wait for this to happen. But we should michael@0: // definitely close it here and hope it won't interfere with other tests. michael@0: // Of course, all the tests are meant to do this themselves, but if they fail... michael@0: if (isPanelUIOpen()) { michael@0: PanelUI.hide(); michael@0: } michael@0: }); michael@0: