michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; michael@0: michael@0: function test() { michael@0: TestRunner.run(); michael@0: } michael@0: michael@0: function runTests() { michael@0: Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); michael@0: registerCleanupFunction(function () { michael@0: Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); michael@0: }); michael@0: michael@0: let state = { windows: [{ tabs: [ michael@0: { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com" }], extData: { "uniq": r() } } michael@0: ] }] }; michael@0: michael@0: let expectedCounts = [ michael@0: [3, 3, 0], michael@0: [2, 3, 1], michael@0: [1, 3, 2], michael@0: [0, 3, 3], michael@0: [0, 2, 4], michael@0: [0, 1, 5] michael@0: ]; michael@0: michael@0: let loadCount = 0; michael@0: gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { michael@0: loadCount++; michael@0: let expected = expectedCounts[loadCount - 1]; michael@0: michael@0: is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored"); michael@0: is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring"); michael@0: is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored"); michael@0: michael@0: if (loadCount == state.windows[0].tabs.length) { michael@0: gProgressListener.unsetCallback(); michael@0: executeSoon(next); michael@0: } michael@0: }); michael@0: michael@0: yield ss.setBrowserState(JSON.stringify(state)); michael@0: }