browser_1284886_suspend_tab.js (3228B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 add_task(async function test() { 5 await SpecialPowers.pushPrefEnv({ 6 set: [["dom.require_user_interaction_for_beforeunload", false]], 7 }); 8 9 let url = "about:robots"; 10 let tab0 = gBrowser.tabs[0]; 11 let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, url); 12 13 const staleAttributes = [ 14 "activemedia-blocked", 15 "busy", 16 "pendingicon", 17 "progress", 18 "soundplaying", 19 ]; 20 for (let attr of staleAttributes) { 21 tab0.toggleAttribute(attr, true); 22 } 23 gBrowser.discardBrowser(tab0); 24 ok(!tab0.linkedPanel, "tab0 is suspended"); 25 for (let attr of staleAttributes) { 26 ok( 27 !tab0.hasAttribute(attr), 28 `discarding browser removes "${attr}" tab attribute` 29 ); 30 } 31 32 await BrowserTestUtils.switchTab(gBrowser, tab0); 33 ok(tab0.linkedPanel, "selecting tab unsuspends it"); 34 35 // Test that active tab is not able to be suspended. 36 gBrowser.discardBrowser(tab0); 37 ok(tab0.linkedPanel, "active tab is not able to be suspended"); 38 39 // Test that tab that is closing is not able to be suspended. 40 gBrowser._beginRemoveTab(tab1); 41 gBrowser.discardBrowser(tab1); 42 43 ok(tab1.linkedPanel, "cannot suspend a tab that is closing"); 44 45 gBrowser._endRemoveTab(tab1); 46 47 // Open tab containing a page which has a beforeunload handler which shows a prompt. 48 url = 49 "http://example.com/browser/browser/components/sessionstore/test/browser_1284886_suspend_tab.html"; 50 tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, url); 51 await BrowserTestUtils.switchTab(gBrowser, tab0); 52 53 // Test that tab with beforeunload handler which would show a prompt cannot be suspended. 54 gBrowser.discardBrowser(tab1); 55 ok( 56 tab1.linkedPanel, 57 "cannot suspend a tab with beforeunload handler which would show a prompt" 58 ); 59 60 // Test that tab with beforeunload handler which would show a prompt will be suspended if forced. 61 gBrowser.discardBrowser(tab1, true); 62 ok( 63 !tab1.linkedPanel, 64 "force suspending a tab with beforeunload handler which would show a prompt" 65 ); 66 67 BrowserTestUtils.removeTab(tab1); 68 69 // Open tab containing a page which has a beforeunload handler which does not show a prompt. 70 url = 71 "http://example.com/browser/browser/components/sessionstore/test/browser_1284886_suspend_tab_2.html"; 72 tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, url); 73 await BrowserTestUtils.switchTab(gBrowser, tab0); 74 75 // Test that tab with beforeunload handler which would not show a prompt can be suspended. 76 gBrowser.discardBrowser(tab1); 77 ok( 78 !tab1.linkedPanel, 79 "can suspend a tab with beforeunload handler which would not show a prompt" 80 ); 81 82 BrowserTestUtils.removeTab(tab1); 83 84 // Test that non-remote tab is not able to be suspended. 85 url = "about:robots"; 86 tab1 = BrowserTestUtils.addTab(gBrowser, url, { forceNotRemote: true }); 87 await promiseBrowserLoaded(tab1.linkedBrowser, true, url); 88 await BrowserTestUtils.switchTab(gBrowser, tab1); 89 await BrowserTestUtils.switchTab(gBrowser, tab0); 90 91 gBrowser.discardBrowser(tab1); 92 ok(tab1.linkedPanel, "cannot suspend a remote tab"); 93 94 BrowserTestUtils.removeTab(tab1); 95 });