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/#1" }], extData: { "uniq": r() }, pinned: true }, michael@0: { entries: [{ url: "http://example.org/#2" }], extData: { "uniq": r() }, pinned: true }, michael@0: { entries: [{ url: "http://example.org/#3" }], extData: { "uniq": r() }, pinned: true }, michael@0: { entries: [{ url: "http://example.org/#4" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.org/#5" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.org/#6" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.org/#7" }], extData: { "uniq": r() } }, michael@0: ], selected: 5 }] }; michael@0: michael@0: let loadCount = 0; michael@0: gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { michael@0: loadCount++; michael@0: michael@0: // We'll make sure that the loads we get come from pinned tabs or the michael@0: // the selected tab. michael@0: michael@0: // get the tab 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: ok(tab.pinned || tab.selected, michael@0: "load came from pinned or selected tab"); michael@0: michael@0: // We should get 4 loads: 3 app tabs + 1 normal selected tab michael@0: if (loadCount < 4) michael@0: return; michael@0: michael@0: gProgressListener.unsetCallback(); michael@0: executeSoon(next); michael@0: }); michael@0: michael@0: yield ss.setBrowserState(JSON.stringify(state)); michael@0: }