Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; |
michael@0 | 6 | |
michael@0 | 7 | function test() { |
michael@0 | 8 | TestRunner.run(); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | function runTests() { |
michael@0 | 12 | Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); |
michael@0 | 13 | registerCleanupFunction(function () { |
michael@0 | 14 | Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); |
michael@0 | 15 | }); |
michael@0 | 16 | |
michael@0 | 17 | // We'll use 2 states so that we can make sure calling setWindowState doesn't |
michael@0 | 18 | // wipe out currently restoring data. |
michael@0 | 19 | let state1 = { windows: [{ tabs: [ |
michael@0 | 20 | { entries: [{ url: "http://example.com#1" }] }, |
michael@0 | 21 | { entries: [{ url: "http://example.com#2" }] }, |
michael@0 | 22 | { entries: [{ url: "http://example.com#3" }] }, |
michael@0 | 23 | { entries: [{ url: "http://example.com#4" }] }, |
michael@0 | 24 | { entries: [{ url: "http://example.com#5" }] }, |
michael@0 | 25 | ] }] }; |
michael@0 | 26 | let state2 = { windows: [{ tabs: [ |
michael@0 | 27 | { entries: [{ url: "http://example.org#1" }] }, |
michael@0 | 28 | { entries: [{ url: "http://example.org#2" }] }, |
michael@0 | 29 | { entries: [{ url: "http://example.org#3" }] }, |
michael@0 | 30 | { entries: [{ url: "http://example.org#4" }] }, |
michael@0 | 31 | { entries: [{ url: "http://example.org#5" }] } |
michael@0 | 32 | ] }] }; |
michael@0 | 33 | let numTabs = state1.windows[0].tabs.length + state2.windows[0].tabs.length; |
michael@0 | 34 | |
michael@0 | 35 | let loadCount = 0; |
michael@0 | 36 | gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { |
michael@0 | 37 | // When loadCount == 2, we'll also restore state2 into the window |
michael@0 | 38 | if (++loadCount == 2) { |
michael@0 | 39 | ss.setWindowState(window, JSON.stringify(state2), false); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | if (loadCount < numTabs) { |
michael@0 | 43 | return; |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | // We don't actually care about load order in this test, just that they all |
michael@0 | 47 | // do load. |
michael@0 | 48 | is(loadCount, numTabs, "test_setWindowStateNoOverwrite: all tabs were restored"); |
michael@0 | 49 | is(aNeedRestore, 0, "there are no tabs left needing restore"); |
michael@0 | 50 | |
michael@0 | 51 | gProgressListener.unsetCallback(); |
michael@0 | 52 | executeSoon(next); |
michael@0 | 53 | }); |
michael@0 | 54 | |
michael@0 | 55 | yield ss.setWindowState(window, JSON.stringify(state1), true); |
michael@0 | 56 | } |