browser_menuButtonFitts.js (2230B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ 3 */ 4 5 "use strict"; 6 7 function getNavBarEndPosition() { 8 let navBar = document.getElementById("nav-bar"); 9 let boundingRect = navBar.getBoundingClientRect(); 10 11 // Find where the nav-bar is vertically. 12 let y = boundingRect.top + Math.floor(boundingRect.height / 2); 13 // Use the last pixel of the screen since it is maximized. 14 let x = boundingRect.width - 1; 15 return { x, y }; 16 } 17 18 /** 19 * Clicking the right end of a maximized window should open the hamburger menu. 20 */ 21 add_task(async function test_clicking_hamburger_edge_fitts() { 22 if (window.windowState != window.STATE_MAXIMIZED) { 23 info(`Waiting for maximize, current state: ${window.windowState}`); 24 let resizeDone = BrowserTestUtils.waitForEvent( 25 window, 26 "resize", 27 false, 28 () => window.outerWidth >= screen.width - 1 29 ); 30 let maximizeDone = BrowserTestUtils.waitForEvent(window, "sizemodechange"); 31 window.maximize(); 32 await maximizeDone; 33 await resizeDone; 34 } 35 36 is(window.windowState, window.STATE_MAXIMIZED, "should be maximized"); 37 38 let { x, y } = getNavBarEndPosition(); 39 info(`Clicking in ${x}, ${y}`); 40 41 let popupHiddenResolve; 42 let popupHiddenPromise = new Promise(resolve => { 43 popupHiddenResolve = resolve; 44 }); 45 async function onPopupHidden() { 46 PanelUI.panel.removeEventListener("popuphidden", onPopupHidden); 47 48 info("Waiting for restore"); 49 50 let restoreDone = BrowserTestUtils.waitForEvent(window, "sizemodechange"); 51 window.restore(); 52 await restoreDone; 53 54 popupHiddenResolve(); 55 } 56 function onPopupShown() { 57 PanelUI.panel.removeEventListener("popupshown", onPopupShown); 58 ok(true, "Clicking at the far edge of the window opened the menu popup."); 59 PanelUI.panel.addEventListener("popuphidden", onPopupHidden); 60 PanelUI.hide(); 61 } 62 registerCleanupFunction(function () { 63 PanelUI.panel.removeEventListener("popupshown", onPopupShown); 64 PanelUI.panel.removeEventListener("popuphidden", onPopupHidden); 65 }); 66 PanelUI.panel.addEventListener("popupshown", onPopupShown); 67 EventUtils.synthesizeMouseAtPoint(x, y, {}, window); 68 await popupHiddenPromise; 69 });