browser_test_key_press_in_popup.js (3036B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 Services.scriptloader.loadSubScript( 7 "chrome://mochikit/content/tests/SimpleTest/paint_listener.js", 8 this 9 ); 10 11 Services.scriptloader.loadSubScript( 12 new URL("apz_test_utils.js", gTestPath).href, 13 this 14 ); 15 16 Services.scriptloader.loadSubScript( 17 new URL("apz_test_native_event_utils.js", gTestPath).href, 18 this 19 ); 20 21 /* import-globals-from helper_browser_test_utils.js */ 22 // For openSelectPopup. 23 Services.scriptloader.loadSubScript( 24 new URL("helper_browser_test_utils.js", gTestPath).href, 25 this 26 ); 27 28 const { UrlbarTestUtils } = ChromeUtils.importESModule( 29 "resource://testing-common/UrlbarTestUtils.sys.mjs" 30 ); 31 32 // Cleanup for paint_listener.js. 33 add_task(() => { 34 registerCleanupFunction(() => { 35 delete window.waitForAllPaintsFlushed; 36 delete window.waitForAllPaints; 37 delete window.promiseAllPaintsDone; 38 }); 39 }); 40 41 // Setup preferences. 42 add_task(async () => { 43 await SpecialPowers.pushPrefEnv({ 44 set: [ 45 ["apz.popups.enabled", true], 46 ["apz.popups_without_remote.enabled", true], 47 ["test.events.async.enabled", true], 48 ], 49 }); 50 }); 51 52 add_task(async () => { 53 // Open the given file with chrome:// scheme. 54 const tab = await BrowserTestUtils.openNewForegroundTab( 55 gBrowser, 56 getRootDirectory(gTestPath) + "helper_popup_menu_in_parent_process-2.html" 57 ); 58 59 // Make sure the document gets loaded in the parent process. 60 await SpecialPowers.spawn(tab.linkedBrowser, [], () => { 61 Assert.ok(SpecialPowers.isMainProcess()); 62 }); 63 64 await promiseApzFlushedRepaints(); 65 await waitUntilApzStable(); 66 67 // Focus to the select element. This stuff is necessary for `openSelectPopup()` 68 // since the function is triggered on the focused element. 69 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 70 const select = content.document.querySelector("select"); 71 const focusPromise = new Promise(resolve => { 72 select.addEventListener("focus", resolve, { once: true }); 73 }); 74 select.focus(); 75 await focusPromise; 76 }); 77 78 // Open the select popup. 79 const selectPopup = await openSelectPopup(); 80 81 // And make sure APZ is ready there. 82 await promiseApzFlushedRepaints(selectPopup); 83 84 // Send a bunch of mousemove events on the popup window. 85 // NOTE: We need to use nsIDOMWindowUtils.sendMouseEvent directly rather than 86 // synthesizeNativeMouseEventWithAPZ since synthesizeNativeMouseEventWithAPZ 87 // causes a paint which prevents the assertion in FocusState::IsCurrent(). 88 const utils = SpecialPowers.DOMWindowUtils; 89 for (let x = 0; x < 20; x++) { 90 await new Promise(resolve => { 91 utils.sendNativeMouseEvent( 92 10 + x, 93 10, 94 utils.NATIVE_MOUSE_MESSAGE_MOVE, 95 0 /* button */, 96 0 /* modifiers */, 97 selectPopup, 98 resolve 99 ); 100 }); 101 } 102 103 // Do a key down on popup. 104 info("pressing a key"); 105 EventUtils.synthesizeKey("Key_Escape"); 106 107 BrowserTestUtils.removeTab(tab); 108 });