browser_browser_toolbox.js (2155B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 // There are shutdown issues for which multiple rejections are left uncaught. 5 // See bug 1018184 for resolving these issues. 6 const { PromiseTestUtils } = ChromeUtils.importESModule( 7 "resource://testing-common/PromiseTestUtils.sys.mjs" 8 ); 9 PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/); 10 11 // On debug test machine, it takes about 50s to run the test. 12 requestLongerTimeout(4); 13 14 add_task(async function () { 15 const ToolboxTask = await initBrowserToolboxTask(); 16 await ToolboxTask.importFunctions({}); 17 18 const hasCloseButton = await ToolboxTask.spawn(null, async () => { 19 /* global gToolbox */ 20 return !!gToolbox.doc.getElementById("toolbox-close"); 21 }); 22 ok(!hasCloseButton, "Browser toolbox doesn't have a close button"); 23 24 info("Trigger F5 key shortcut and ensure nothing happens"); 25 info( 26 "If F5 triggers a full reload, the mochitest will stop here as firefox instance will be restarted" 27 ); 28 const previousInnerWindowId = 29 window.browsingContext.currentWindowGlobal.innerWindowId; 30 function onUnload() { 31 ok(false, "The top level window shouldn't be reloaded/closed"); 32 } 33 window.addEventListener("unload", onUnload); 34 await ToolboxTask.spawn(null, async () => { 35 const isMacOS = Services.appinfo.OS === "Darwin"; 36 const { win } = gToolbox; 37 // Simulate CmdOrCtrl+R 38 win.dispatchEvent( 39 new win.KeyboardEvent("keydown", { 40 bubbles: true, 41 ctrlKey: !isMacOS, 42 metaKey: isMacOS, 43 keyCode: "r".charCodeAt(0), 44 }) 45 ); 46 // Simulate F5 47 win.dispatchEvent( 48 new win.KeyboardEvent("keydown", { 49 bubbles: true, 50 keyCode: win.KeyEvent.DOM_VK_F5, 51 }) 52 ); 53 }); 54 55 // Let a chance to trigger the regression where the top level document closes or reloads 56 await wait(1000); 57 58 is( 59 window.browsingContext.currentWindowGlobal.innerWindowId, 60 previousInnerWindowId, 61 "Check the browser.xhtml wasn't reloaded when pressing F5" 62 ); 63 window.removeEventListener("unload", onUnload); 64 65 await ToolboxTask.destroy(); 66 });