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: // The first window will be put into the already open window and the second michael@0: // window will be opened with _openWindowWithState, which is the source of the problem. michael@0: let state = { windows: [ michael@0: { michael@0: tabs: [ michael@0: { entries: [{ url: "http://example.org#0" }], extData: { "uniq": r() } } michael@0: ], michael@0: selected: 1 michael@0: }, michael@0: { michael@0: tabs: [ michael@0: { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com#5" }], extData: { "uniq": r() } }, michael@0: { entries: [{ url: "http://example.com#6" }], extData: { "uniq": r() } } michael@0: ], michael@0: selected: 4 michael@0: } michael@0: ] }; michael@0: let numTabs = state.windows[0].tabs.length + state.windows[1].tabs.length; michael@0: michael@0: let loadCount = 0; michael@0: gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { michael@0: if (++loadCount == numTabs) { michael@0: // We don't actually care about load order in this test, just that they all michael@0: // do load. michael@0: is(loadCount, numTabs, "all tabs were restored"); michael@0: is(aNeedRestore, 0, "there are no tabs left needing restore"); michael@0: michael@0: gProgressListener.unsetCallback(); michael@0: executeSoon(next); michael@0: } michael@0: }); michael@0: michael@0: // We also want to catch the 2nd window, so we need to observe domwindowopened michael@0: Services.ww.registerNotification(function observer(aSubject, aTopic, aData) { michael@0: if (aTopic == "domwindowopened") { michael@0: let win = aSubject.QueryInterface(Ci.nsIDOMWindow); michael@0: win.addEventListener("load", function onLoad() { michael@0: win.removeEventListener("load", onLoad); michael@0: Services.ww.unregisterNotification(observer); michael@0: win.gBrowser.addTabsProgressListener(gProgressListener); michael@0: }); michael@0: } michael@0: }); michael@0: michael@0: yield ss.setBrowserState(JSON.stringify(state)); michael@0: }