browser_940307_panel_click_closure_handling.js (4740B)
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 var button, menuButton; 8 /* Clicking a button should close the panel */ 9 add_task(async function plain_button() { 10 button = document.createXULElement("toolbarbutton"); 11 button.id = "browser_940307_button"; 12 button.setAttribute("label", "Button"); 13 gNavToolbox.palette.appendChild(button); 14 CustomizableUI.addWidgetToArea( 15 button.id, 16 CustomizableUI.AREA_FIXED_OVERFLOW_PANEL 17 ); 18 19 await waitForOverflowButtonShown(); 20 21 await document.getElementById("nav-bar").overflowable.show(); 22 let hiddenAgain = promiseOverflowHidden(window); 23 EventUtils.synthesizeMouseAtCenter(button, {}); 24 await hiddenAgain; 25 CustomizableUI.removeWidgetFromArea(button.id); 26 button.remove(); 27 }); 28 29 add_task(async function searchbar_in_panel() { 30 SpecialPowers.pushPrefEnv({ 31 set: [["browser.search.widget.new", false]], 32 }); 33 34 CustomizableUI.addWidgetToArea( 35 "search-container", 36 CustomizableUI.AREA_FIXED_OVERFLOW_PANEL 37 ); 38 39 await waitForOverflowButtonShown(); 40 41 await document.getElementById("nav-bar").overflowable.show(); 42 43 let searchbar = document.getElementById("searchbar"); 44 await TestUtils.waitForCondition( 45 () => "value" in searchbar && searchbar.value === "" 46 ); 47 48 // Focusing a non-empty searchbox will cause us to open the 49 // autocomplete panel and search for suggestions, which would 50 // trigger network requests. Temporarily disable suggestions. 51 await SpecialPowers.pushPrefEnv({ 52 set: [["browser.search.suggest.enabled", false]], 53 }); 54 let dontShowPopup = e => e.preventDefault(); 55 let searchbarPopup = searchbar.textbox.popup; 56 searchbarPopup.addEventListener("popupshowing", dontShowPopup); 57 58 searchbar.value = "foo"; 59 searchbar.focus(); 60 61 // Can't use promisePanelElementShown() here since the search bar 62 // creates its context menu lazily the first time it is opened. 63 let contextMenuShown = new Promise(resolve => { 64 let listener = event => { 65 if (searchbar._menupopup && event.target == searchbar._menupopup) { 66 window.removeEventListener("popupshown", listener); 67 resolve(searchbar._menupopup); 68 } 69 }; 70 window.addEventListener("popupshown", listener); 71 }); 72 EventUtils.synthesizeMouseAtCenter(searchbar, { 73 type: "contextmenu", 74 button: 2, 75 }); 76 let contextmenu = await contextMenuShown; 77 78 ok(isOverflowOpen(), "Panel should still be open"); 79 80 let selectAll = contextmenu.querySelector("[cmd='cmd_selectAll']"); 81 let contextMenuHidden = promisePanelElementHidden(window, contextmenu); 82 contextmenu.activateItem(selectAll); 83 await contextMenuHidden; 84 85 ok(isOverflowOpen(), "Panel should still be open"); 86 87 let hiddenPanelPromise = promiseOverflowHidden(window); 88 EventUtils.synthesizeKey("KEY_Escape"); 89 await hiddenPanelPromise; 90 ok(!isOverflowOpen(), "Panel should no longer be open"); 91 92 // Allow search bar popup to show again. 93 searchbarPopup.removeEventListener("popupshowing", dontShowPopup); 94 95 // We focused the search bar earlier - ensure we don't keep doing that. 96 gURLBar.select(); 97 98 CustomizableUI.reset(); 99 }); 100 101 add_task(async function disabled_button_in_panel() { 102 button = document.createXULElement("toolbarbutton"); 103 button.id = "browser_946166_button_disabled"; 104 button.setAttribute("disabled", "true"); 105 button.setAttribute("label", "Button"); 106 gNavToolbox.palette.appendChild(button); 107 CustomizableUI.addWidgetToArea( 108 button.id, 109 CustomizableUI.AREA_FIXED_OVERFLOW_PANEL 110 ); 111 112 await waitForOverflowButtonShown(); 113 114 await document.getElementById("nav-bar").overflowable.show(); 115 // We intentionally turn off a11y_checks, because the following click 116 // is targeting a disabled control to confirm the click event won't come through. 117 // It is not meant to be interactive and is not expected to be accessible: 118 AccessibilityUtils.setEnv({ 119 mustBeEnabled: false, 120 }); 121 EventUtils.synthesizeMouseAtCenter(button, {}); 122 AccessibilityUtils.resetEnv(); 123 is(PanelUI.overflowPanel.state, "open", "Popup stays open"); 124 button.removeAttribute("disabled"); 125 let hiddenAgain = promiseOverflowHidden(window); 126 EventUtils.synthesizeMouseAtCenter(button, {}); 127 await hiddenAgain; 128 button.remove(); 129 }); 130 131 registerCleanupFunction(async function () { 132 if (button && button.parentNode) { 133 button.remove(); 134 } 135 if (menuButton && menuButton.parentNode) { 136 menuButton.remove(); 137 } 138 if (isOverflowOpen()) { 139 let panelHiddenPromise = promiseOverflowHidden(window); 140 PanelUI.overflowPanel.hidePopup(); 141 await panelHiddenPromise; 142 } 143 CustomizableUI.reset(); 144 });