1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/sessionstore/test/browser_586068-window_state.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,56 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; 1.9 + 1.10 +function test() { 1.11 + TestRunner.run(); 1.12 +} 1.13 + 1.14 +function runTests() { 1.15 + Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); 1.16 + registerCleanupFunction(function () { 1.17 + Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); 1.18 + }); 1.19 + 1.20 + // We'll use 2 states so that we can make sure calling setWindowState doesn't 1.21 + // wipe out currently restoring data. 1.22 + let state1 = { windows: [{ tabs: [ 1.23 + { entries: [{ url: "http://example.com#1" }] }, 1.24 + { entries: [{ url: "http://example.com#2" }] }, 1.25 + { entries: [{ url: "http://example.com#3" }] }, 1.26 + { entries: [{ url: "http://example.com#4" }] }, 1.27 + { entries: [{ url: "http://example.com#5" }] }, 1.28 + ] }] }; 1.29 + let state2 = { windows: [{ tabs: [ 1.30 + { entries: [{ url: "http://example.org#1" }] }, 1.31 + { entries: [{ url: "http://example.org#2" }] }, 1.32 + { entries: [{ url: "http://example.org#3" }] }, 1.33 + { entries: [{ url: "http://example.org#4" }] }, 1.34 + { entries: [{ url: "http://example.org#5" }] } 1.35 + ] }] }; 1.36 + let numTabs = state1.windows[0].tabs.length + state2.windows[0].tabs.length; 1.37 + 1.38 + let loadCount = 0; 1.39 + gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { 1.40 + // When loadCount == 2, we'll also restore state2 into the window 1.41 + if (++loadCount == 2) { 1.42 + ss.setWindowState(window, JSON.stringify(state2), false); 1.43 + } 1.44 + 1.45 + if (loadCount < numTabs) { 1.46 + return; 1.47 + } 1.48 + 1.49 + // We don't actually care about load order in this test, just that they all 1.50 + // do load. 1.51 + is(loadCount, numTabs, "test_setWindowStateNoOverwrite: all tabs were restored"); 1.52 + is(aNeedRestore, 0, "there are no tabs left needing restore"); 1.53 + 1.54 + gProgressListener.unsetCallback(); 1.55 + executeSoon(next); 1.56 + }); 1.57 + 1.58 + yield ss.setWindowState(window, JSON.stringify(state1), true); 1.59 +}