browser_contextmenu_touch.js (3347B)
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 /* This test checks that context menus are in touchmode 6 * when opened through a touch event (long tap). */ 7 8 async function openAndCheckContextMenu(contextMenu, target) { 9 is(contextMenu.state, "closed", "Context menu is initally closed."); 10 11 let popupshown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown"); 12 EventUtils.synthesizeNativeTapAtCenter(target, true); 13 await popupshown; 14 15 is(contextMenu.state, "open", "Context menu is open."); 16 is( 17 contextMenu.getAttribute("touchmode"), 18 "true", 19 "Context menu is in touchmode." 20 ); 21 22 contextMenu.hidePopup(); 23 24 popupshown = BrowserTestUtils.waitForEvent(contextMenu, "popupshown"); 25 EventUtils.synthesizeMouseAtCenter(target, { type: "contextmenu" }); 26 await popupshown; 27 28 is(contextMenu.state, "open", "Context menu is open."); 29 ok( 30 !contextMenu.hasAttribute("touchmode"), 31 "Context menu is not in touchmode." 32 ); 33 34 contextMenu.hidePopup(); 35 } 36 37 // Ensure that we can run touch events properly for windows 38 add_setup(async function () { 39 let isWindows = AppConstants.platform == "win"; 40 await SpecialPowers.pushPrefEnv({ 41 set: [["apz.test.fails_with_native_injection", isWindows]], 42 }); 43 }); 44 45 // Test the content area context menu. 46 add_task(async function test_contentarea_contextmenu_touch() { 47 await BrowserTestUtils.withNewTab("about:blank", async function (browser) { 48 let contextMenu = document.getElementById("contentAreaContextMenu"); 49 await openAndCheckContextMenu(contextMenu, browser); 50 }); 51 }); 52 53 // Test the back and forward buttons. 54 add_task(async function test_back_forward_button_contextmenu_touch() { 55 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 56 await BrowserTestUtils.withNewTab( 57 "http://example.com", 58 async function (browser) { 59 let contextMenu = document.getElementById("backForwardMenu"); 60 61 let backbutton = document.getElementById("back-button"); 62 let notDisabled = TestUtils.waitForCondition( 63 () => !backbutton.hasAttribute("disabled") 64 ); 65 // eslint-disable-next-line @microsoft/sdl/no-insecure-url 66 BrowserTestUtils.startLoadingURIString(browser, "http://example.org"); 67 await notDisabled; 68 await openAndCheckContextMenu(contextMenu, backbutton); 69 70 let forwardbutton = document.getElementById("forward-button"); 71 notDisabled = TestUtils.waitForCondition( 72 () => !forwardbutton.hasAttribute("disabled") 73 ); 74 backbutton.click(); 75 await notDisabled; 76 await openAndCheckContextMenu(contextMenu, forwardbutton); 77 } 78 ); 79 }); 80 81 // Test the toolbar context menu. 82 add_task(async function test_toolbar_contextmenu_touch() { 83 let toolbarContextMenu = document.getElementById("toolbar-context-menu"); 84 let target = document.getElementById("PanelUI-menu-button"); 85 await openAndCheckContextMenu(toolbarContextMenu, target); 86 }); 87 88 // Test the urlbar input context menu. 89 add_task(async function test_urlbar_contextmenu_touch() { 90 let urlbar = document.getElementById("urlbar"); 91 let textBox = urlbar.querySelector("moz-input-box"); 92 let menu = textBox.menupopup; 93 await openAndCheckContextMenu(menu, textBox); 94 });