browser_637020.js (2622B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 const TEST_URL = 5 "http://mochi.test:8888/browser/browser/components/" + 6 "sessionstore/test/browser_637020_slow.sjs"; 7 8 const TEST_STATE = { 9 windows: [ 10 { 11 tabs: [ 12 { entries: [{ url: "about:mozilla", triggeringPrincipal_base64 }] }, 13 { entries: [{ url: "about:robots", triggeringPrincipal_base64 }] }, 14 ], 15 }, 16 { 17 tabs: [ 18 { entries: [{ url: TEST_URL, triggeringPrincipal_base64 }] }, 19 { entries: [{ url: TEST_URL, triggeringPrincipal_base64 }] }, 20 ], 21 }, 22 ], 23 }; 24 25 /** 26 * This test ensures that windows that have just been restored will be marked 27 * as dirty, otherwise _getCurrentState() might ignore them when collecting 28 * state for the first time and we'd just save them as empty objects. 29 * 30 * The dirty state acts as a cache to not collect data from all windows all the 31 * time, so at the beginning, each window must be dirty so that we collect 32 * their state at least once. 33 */ 34 35 add_task(async function test() { 36 // Wait until the new window has been opened. 37 let promiseWindow = new Promise(resolve => { 38 Services.obs.addObserver(function onOpened(subject) { 39 Services.obs.removeObserver(onOpened, "domwindowopened"); 40 resolve(subject); 41 }, "domwindowopened"); 42 }); 43 44 // Set the new browser state that will 45 // restore a window with two slowly loading tabs. 46 let backupState = SessionStore.getBrowserState(); 47 SessionStore.setBrowserState(JSON.stringify(TEST_STATE)); 48 let win = await promiseWindow; 49 let delayedStartupFinished = new Promise(resolve => 50 whenDelayedStartupFinished(win, resolve) 51 ); 52 let restoring = promiseWindowRestoring(win); 53 let restored = promiseWindowRestored(win); 54 await restoring; 55 await restored; 56 57 // The window has now been opened. Check the state that is returned, 58 // this should come from the cache while the window isn't restored, yet. 59 info("the window has been opened"); 60 checkWindows(); 61 62 // The history has now been restored and the tabs are loading. The data must 63 // now come from the window, if it's correctly been marked as dirty before. 64 await delayedStartupFinished; 65 info("the delayed startup has finished"); 66 checkWindows(); 67 68 // Cleanup. 69 await BrowserTestUtils.closeWindow(win); 70 await promiseBrowserState(backupState); 71 }); 72 73 function checkWindows() { 74 let state = JSON.parse(SessionStore.getBrowserState()); 75 is(state.windows[0].tabs.length, 2, "first window has two tabs"); 76 is(state.windows[1].tabs.length, 2, "second window has two tabs"); 77 }