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, true); 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.org" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } } michael@0: ], selected: 1 }] }; michael@0: michael@0: let expectedCounts = [ michael@0: [5, 1, 0], michael@0: [4, 1, 1], michael@0: [3, 1, 2], michael@0: [2, 1, 3], michael@0: [1, 1, 4], michael@0: [0, 1, 5] michael@0: ]; michael@0: let tabOrder = [0, 5, 1, 4, 3, 2]; 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: // double check that this tab was the right one michael@0: let expectedData = state.windows[0].tabs[tabOrder[loadCount - 1]].extData.uniq; michael@0: let tab; michael@0: for (let i = 0; i < window.gBrowser.tabs.length; i++) { michael@0: if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) michael@0: tab = window.gBrowser.tabs[i]; michael@0: } michael@0: michael@0: is(ss.getTabValue(tab, "uniq"), expectedData, michael@0: "load " + loadCount + " - correct tab was restored"); michael@0: michael@0: // select the next tab michael@0: window.gBrowser.selectTabAtIndex(tabOrder[loadCount]); michael@0: } else { michael@0: gProgressListener.unsetCallback(); michael@0: executeSoon(next); michael@0: } michael@0: }); michael@0: michael@0: yield ss.setBrowserState(JSON.stringify(state)); michael@0: }