browser_586068-cascade.js (2709B)
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 const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; 6 7 add_task(async function test() { 8 Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); 9 registerCleanupFunction(function () { 10 Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); 11 }); 12 13 let state = { 14 windows: [ 15 { 16 tabs: [ 17 { 18 entries: [ 19 { url: "http://example.com", triggeringPrincipal_base64 }, 20 ], 21 extData: { uniq: r() }, 22 }, 23 { 24 entries: [ 25 { url: "http://example.com", triggeringPrincipal_base64 }, 26 ], 27 extData: { uniq: r() }, 28 }, 29 { 30 entries: [ 31 { url: "http://example.com", triggeringPrincipal_base64 }, 32 ], 33 extData: { uniq: r() }, 34 }, 35 { 36 entries: [ 37 { url: "http://example.com", triggeringPrincipal_base64 }, 38 ], 39 extData: { uniq: r() }, 40 }, 41 { 42 entries: [ 43 { url: "http://example.com", triggeringPrincipal_base64 }, 44 ], 45 extData: { uniq: r() }, 46 }, 47 { 48 entries: [ 49 { url: "http://example.com", triggeringPrincipal_base64 }, 50 ], 51 extData: { uniq: r() }, 52 }, 53 ], 54 }, 55 ], 56 }; 57 58 let expectedCounts = [ 59 [3, 3, 0], 60 [2, 3, 1], 61 [1, 3, 2], 62 [0, 3, 3], 63 [0, 2, 4], 64 [0, 1, 5], 65 ]; 66 67 let loadCount = 0; 68 let promiseRestoringTabs = new Promise(resolve => { 69 gProgressListener.setCallback( 70 function (aBrowser, aNeedRestore, aRestoring, aRestored) { 71 loadCount++; 72 let expected = expectedCounts[loadCount - 1]; 73 74 is( 75 aNeedRestore, 76 expected[0], 77 "load " + loadCount + " - # tabs that need to be restored" 78 ); 79 is( 80 aRestoring, 81 expected[1], 82 "load " + loadCount + " - # tabs that are restoring" 83 ); 84 is( 85 aRestored, 86 expected[2], 87 "load " + loadCount + " - # tabs that has been restored" 88 ); 89 90 if (loadCount == state.windows[0].tabs.length) { 91 gProgressListener.unsetCallback(); 92 resolve(); 93 } 94 } 95 ); 96 }); 97 98 let backupState = ss.getBrowserState(); 99 ss.setBrowserState(JSON.stringify(state)); 100 await promiseRestoringTabs; 101 102 // Cleanup. 103 await promiseBrowserState(backupState); 104 });