browser_fullscreen_keydown_reservation.js (3237B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // This test verifies that whether shortcut keys of toggling fullscreen modes 7 // are reserved. 8 add_task(async function test_keydown_event_reservation_toggling_fullscreen() { 9 await SpecialPowers.pushPrefEnv({ 10 set: [ 11 ["test.wait300msAfterTabSwitch", true], 12 ["full-screen-api.transition-duration.enter", "0 0"], 13 ["full-screen-api.transition-duration.leave", "0 0"], 14 ], 15 }); 16 17 let shortcutKeys = [{ key: "KEY_F11", modifiers: {} }]; 18 if (navigator.platform.startsWith("Mac")) { 19 shortcutKeys.push({ 20 key: "f", 21 modifiers: { metaKey: true, ctrlKey: true }, 22 }); 23 shortcutKeys.push({ 24 key: "F", 25 modifiers: { metaKey: true, shiftKey: true }, 26 }); 27 } 28 function shortcutDescription(aShortcutKey) { 29 return `${ 30 aShortcutKey.metaKey ? "Meta + " : "" 31 }${aShortcutKey.shiftKey ? "Shift + " : ""}${aShortcutKey.ctrlKey ? "Ctrl + " : ""}${aShortcutKey.key.replace("KEY_", "")}`; 32 } 33 for (const shortcutKey of shortcutKeys) { 34 const tab = await BrowserTestUtils.openNewForegroundTab( 35 gBrowser, 36 "https://example.org/browser/browser/base/content/test/fullscreen/fullscreen.html" 37 ); 38 39 await SimpleTest.promiseFocus(tab.linkedBrowser); 40 41 const fullScreenEntered = BrowserTestUtils.waitForEvent( 42 window, 43 "fullscreen" 44 ); 45 46 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 47 content.wrappedJSObject.keydown = null; 48 content.window.addEventListener("keydown", event => { 49 switch (event.key) { 50 case "Shift": 51 case "Meta": 52 case "Control": 53 break; 54 default: 55 content.wrappedJSObject.keydown = event; 56 } 57 }); 58 }); 59 60 EventUtils.synthesizeKey(shortcutKey.key, shortcutKey.modifiers); 61 62 info( 63 `Waiting for entering the fullscreen mode with synthesizing ${shortcutDescription( 64 shortcutKey 65 )}...` 66 ); 67 await fullScreenEntered; 68 69 info("Retrieving the result..."); 70 Assert.ok( 71 await SpecialPowers.spawn( 72 tab.linkedBrowser, 73 [], 74 async () => !!content.wrappedJSObject.keydown 75 ), 76 `Entering the fullscreen mode with ${shortcutDescription( 77 shortcutKey 78 )} should cause "keydown" event` 79 ); 80 81 const fullScreenExited = BrowserTestUtils.waitForEvent( 82 window, 83 "fullscreen" 84 ); 85 86 await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { 87 content.wrappedJSObject.keydown = null; 88 }); 89 90 EventUtils.synthesizeKey(shortcutKey.key, shortcutKey.modifiers); 91 92 info( 93 `Waiting for exiting from the fullscreen mode with synthesizing ${shortcutDescription( 94 shortcutKey 95 )}...` 96 ); 97 await fullScreenExited; 98 99 info("Retrieving the result..."); 100 Assert.ok( 101 await SpecialPowers.spawn( 102 tab.linkedBrowser, 103 [], 104 async () => !content.wrappedJSObject.keydown 105 ), 106 `Exiting from the fullscreen mode with ${shortcutDescription( 107 shortcutKey 108 )} should not cause "keydown" event` 109 ); 110 111 BrowserTestUtils.removeTab(tab); 112 } 113 });