browser_490040.js (2572B)
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 // Only windows with open tabs are restorable. Windows where a lone tab is 6 // detached may have _closedTabs, but is left with just an empty tab. 7 const STATES = [ 8 { 9 shouldBeAdded: true, 10 windowState: { 11 windows: [ 12 { 13 tabs: [ 14 { 15 entries: [ 16 { 17 url: "http://example.com", 18 triggeringPrincipal_base64, 19 title: "example.com", 20 }, 21 ], 22 }, 23 ], 24 selected: 1, 25 _closedTabs: [], 26 }, 27 ], 28 }, 29 }, 30 { 31 shouldBeAdded: false, 32 windowState: { 33 windows: [ 34 { 35 tabs: [{ entries: [] }], 36 _closedTabs: [], 37 }, 38 ], 39 }, 40 }, 41 { 42 shouldBeAdded: false, 43 windowState: { 44 windows: [ 45 { 46 tabs: [{ entries: [] }], 47 _closedTabs: [ 48 { 49 state: { 50 entries: [ 51 { 52 url: "http://example.com", 53 triggeringPrincipal_base64, 54 index: 1, 55 }, 56 ], 57 }, 58 }, 59 ], 60 }, 61 ], 62 }, 63 }, 64 { 65 shouldBeAdded: false, 66 windowState: { 67 windows: [ 68 { 69 tabs: [{ entries: [] }], 70 _closedTabs: [], 71 extData: { keyname: "pi != " + Math.random() }, 72 }, 73 ], 74 }, 75 }, 76 ]; 77 78 add_task(async function test_bug_490040() { 79 for (let state of STATES) { 80 // Ensure we can store the window if needed. 81 let startingClosedWindowCount = ss.getClosedWindowCount(); 82 await pushPrefs([ 83 "browser.sessionstore.max_windows_undo", 84 startingClosedWindowCount + 1, 85 ]); 86 87 let curClosedWindowCount = ss.getClosedWindowCount(); 88 let win = await BrowserTestUtils.openNewBrowserWindow(); 89 90 await setWindowState(win, state.windowState, true); 91 if (state.windowState.windows[0].tabs.length) { 92 await BrowserTestUtils.browserLoaded(win.gBrowser.selectedBrowser, { 93 wantLoad: () => true, 94 }); 95 } 96 97 await BrowserTestUtils.closeWindow(win); 98 99 is( 100 ss.getClosedWindowCount(), 101 curClosedWindowCount + (state.shouldBeAdded ? 1 : 0), 102 "That window should " + 103 (state.shouldBeAdded ? "" : "not ") + 104 "be restorable" 105 ); 106 } 107 });