Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
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 | let button, menuButton; |
michael@0 | 8 | /* Clicking a button should close the panel */ |
michael@0 | 9 | add_task(function() { |
michael@0 | 10 | button = document.createElement("toolbarbutton"); |
michael@0 | 11 | button.id = "browser_940307_button"; |
michael@0 | 12 | button.setAttribute("label", "Button"); |
michael@0 | 13 | PanelUI.contents.appendChild(button); |
michael@0 | 14 | yield PanelUI.show(); |
michael@0 | 15 | let hiddenAgain = promisePanelHidden(window); |
michael@0 | 16 | EventUtils.synthesizeMouseAtCenter(button, {}); |
michael@0 | 17 | yield hiddenAgain; |
michael@0 | 18 | button.remove(); |
michael@0 | 19 | }); |
michael@0 | 20 | |
michael@0 | 21 | /* Clicking a menu button should close the panel, opening the popup shouldn't. */ |
michael@0 | 22 | add_task(function() { |
michael@0 | 23 | menuButton = document.createElement("toolbarbutton"); |
michael@0 | 24 | menuButton.setAttribute("type", "menu-button"); |
michael@0 | 25 | menuButton.id = "browser_940307_menubutton"; |
michael@0 | 26 | menuButton.setAttribute("label", "Menu button"); |
michael@0 | 27 | |
michael@0 | 28 | let menuPopup = document.createElement("menupopup"); |
michael@0 | 29 | menuPopup.id = "browser_940307_menupopup"; |
michael@0 | 30 | |
michael@0 | 31 | let menuItem = document.createElement("menuitem"); |
michael@0 | 32 | menuItem.setAttribute("label", "Menu item"); |
michael@0 | 33 | menuItem.id = "browser_940307_menuitem"; |
michael@0 | 34 | |
michael@0 | 35 | menuPopup.appendChild(menuItem); |
michael@0 | 36 | menuButton.appendChild(menuPopup); |
michael@0 | 37 | PanelUI.contents.appendChild(menuButton); |
michael@0 | 38 | |
michael@0 | 39 | yield PanelUI.show(); |
michael@0 | 40 | let hiddenAgain = promisePanelHidden(window); |
michael@0 | 41 | let innerButton = document.getAnonymousElementByAttribute(menuButton, "anonid", "button"); |
michael@0 | 42 | EventUtils.synthesizeMouseAtCenter(innerButton, {}); |
michael@0 | 43 | yield hiddenAgain; |
michael@0 | 44 | |
michael@0 | 45 | // Now click the dropmarker to show the menu |
michael@0 | 46 | yield PanelUI.show(); |
michael@0 | 47 | hiddenAgain = promisePanelHidden(window); |
michael@0 | 48 | let menuShown = promisePanelElementShown(window, menuPopup); |
michael@0 | 49 | let dropmarker = document.getAnonymousElementByAttribute(menuButton, "type", "menu-button"); |
michael@0 | 50 | EventUtils.synthesizeMouseAtCenter(dropmarker, {}); |
michael@0 | 51 | yield menuShown; |
michael@0 | 52 | // Panel should stay open: |
michael@0 | 53 | ok(isPanelUIOpen(), "Panel should still be open"); |
michael@0 | 54 | let menuHidden = promisePanelElementHidden(window, menuPopup); |
michael@0 | 55 | // Then click the menu item to close all the things |
michael@0 | 56 | EventUtils.synthesizeMouseAtCenter(menuItem, {}); |
michael@0 | 57 | yield menuHidden; |
michael@0 | 58 | yield hiddenAgain; |
michael@0 | 59 | menuButton.remove(); |
michael@0 | 60 | }); |
michael@0 | 61 | |
michael@0 | 62 | add_task(function() { |
michael@0 | 63 | let searchbar = document.getElementById("searchbar"); |
michael@0 | 64 | gCustomizeMode.addToPanel(searchbar); |
michael@0 | 65 | let placement = CustomizableUI.getPlacementOfWidget("search-container"); |
michael@0 | 66 | is(placement.area, CustomizableUI.AREA_PANEL, "Should be in panel"); |
michael@0 | 67 | yield PanelUI.show(); |
michael@0 | 68 | yield waitForCondition(() => "value" in searchbar && searchbar.value === ""); |
michael@0 | 69 | |
michael@0 | 70 | searchbar.value = "foo"; |
michael@0 | 71 | searchbar.focus(); |
michael@0 | 72 | // Reaching into this context menu is pretty evil, but hey... it's a test. |
michael@0 | 73 | let textbox = document.getAnonymousElementByAttribute(searchbar.textbox, "anonid", "textbox-input-box"); |
michael@0 | 74 | let contextmenu = document.getAnonymousElementByAttribute(textbox, "anonid", "input-box-contextmenu"); |
michael@0 | 75 | let contextMenuShown = promisePanelElementShown(window, contextmenu); |
michael@0 | 76 | EventUtils.synthesizeMouseAtCenter(searchbar, {type: "contextmenu", button: 2}); |
michael@0 | 77 | yield contextMenuShown; |
michael@0 | 78 | |
michael@0 | 79 | ok(isPanelUIOpen(), "Panel should still be open"); |
michael@0 | 80 | |
michael@0 | 81 | let selectAll = contextmenu.querySelector("[cmd='cmd_selectAll']"); |
michael@0 | 82 | let contextMenuHidden = promisePanelElementHidden(window, contextmenu); |
michael@0 | 83 | EventUtils.synthesizeMouseAtCenter(selectAll, {}); |
michael@0 | 84 | yield contextMenuHidden; |
michael@0 | 85 | |
michael@0 | 86 | ok(isPanelUIOpen(), "Panel should still be open"); |
michael@0 | 87 | |
michael@0 | 88 | let hiddenPanelPromise = promisePanelHidden(window); |
michael@0 | 89 | EventUtils.synthesizeKey("VK_ESCAPE", {}); |
michael@0 | 90 | yield hiddenPanelPromise; |
michael@0 | 91 | ok(!isPanelUIOpen(), "Panel should no longer be open"); |
michael@0 | 92 | }); |
michael@0 | 93 | |
michael@0 | 94 | registerCleanupFunction(function() { |
michael@0 | 95 | if (button && button.parentNode) { |
michael@0 | 96 | button.remove(); |
michael@0 | 97 | } |
michael@0 | 98 | if (menuButton && menuButton.parentNode) { |
michael@0 | 99 | menuButton.remove(); |
michael@0 | 100 | } |
michael@0 | 101 | // Sadly this isn't task.jsm-enabled, so we can't wait for this to happen. But we should |
michael@0 | 102 | // definitely close it here and hope it won't interfere with other tests. |
michael@0 | 103 | // Of course, all the tests are meant to do this themselves, but if they fail... |
michael@0 | 104 | if (isPanelUIOpen()) { |
michael@0 | 105 | PanelUI.hide(); |
michael@0 | 106 | } |
michael@0 | 107 | }); |
michael@0 | 108 |