michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let stateBackup = ss.getBrowserState(); michael@0: michael@0: let statePinned = {windows:[{tabs:[ michael@0: {entries:[{url:"http://example.com#1"}], pinned: true} michael@0: ]}]}; michael@0: michael@0: let state = {windows:[{tabs:[ michael@0: {entries:[{url:"http://example.com#1"}]}, michael@0: {entries:[{url:"http://example.com#2"}]}, michael@0: {entries:[{url:"http://example.com#3"}]}, michael@0: {entries:[{url:"http://example.com#4"}]}, michael@0: ]}]}; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: registerCleanupFunction(function () { michael@0: TabsProgressListener.uninit(); michael@0: ss.setBrowserState(stateBackup); michael@0: }); michael@0: michael@0: michael@0: TabsProgressListener.init(); michael@0: michael@0: window.addEventListener("SSWindowStateReady", function onReady() { michael@0: window.removeEventListener("SSWindowStateReady", onReady, false); michael@0: michael@0: let firstProgress = true; michael@0: michael@0: TabsProgressListener.setCallback(function (needsRestore, isRestoring) { michael@0: if (firstProgress) { michael@0: firstProgress = false; michael@0: is(isRestoring, 3, "restoring 3 tabs concurrently"); michael@0: } else { michael@0: ok(isRestoring <= 3, "restoring max. 2 tabs concurrently"); michael@0: } michael@0: michael@0: if (0 == needsRestore) { michael@0: TabsProgressListener.unsetCallback(); michael@0: waitForFocus(finish); michael@0: } michael@0: }); michael@0: michael@0: ss.setBrowserState(JSON.stringify(state)); michael@0: }, false); michael@0: michael@0: ss.setBrowserState(JSON.stringify(statePinned)); michael@0: } michael@0: michael@0: function countTabs() { michael@0: let needsRestore = 0, isRestoring = 0; michael@0: let windowsEnum = Services.wm.getEnumerator("navigator:browser"); michael@0: michael@0: while (windowsEnum.hasMoreElements()) { michael@0: let window = windowsEnum.getNext(); michael@0: if (window.closed) michael@0: continue; michael@0: michael@0: for (let i = 0; i < window.gBrowser.tabs.length; i++) { michael@0: let browser = window.gBrowser.tabs[i].linkedBrowser; michael@0: if (browser.__SS_restoreState == TAB_STATE_RESTORING) michael@0: isRestoring++; michael@0: else if (browser.__SS_restoreState == TAB_STATE_NEEDS_RESTORE) michael@0: needsRestore++; michael@0: } michael@0: } michael@0: michael@0: return [needsRestore, isRestoring]; michael@0: } michael@0: michael@0: let TabsProgressListener = { michael@0: init: function () { michael@0: Services.obs.addObserver(this, "sessionstore-debug-tab-restored", false); michael@0: }, michael@0: michael@0: uninit: function () { michael@0: Services.obs.removeObserver(this, "sessionstore-debug-tab-restored"); michael@0: this.unsetCallback(); michael@0: }, michael@0: michael@0: setCallback: function (callback) { michael@0: this.callback = callback; michael@0: }, michael@0: michael@0: unsetCallback: function () { michael@0: delete this.callback; michael@0: }, michael@0: michael@0: observe: function (browser, topic, data) { michael@0: TabsProgressListener.onRestored(browser); michael@0: }, michael@0: michael@0: onRestored: function (browser) { michael@0: if (this.callback && browser.__SS_restoreState == TAB_STATE_RESTORING) { michael@0: this.callback.apply(null, countTabs()); michael@0: } michael@0: } michael@0: }