Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | let stateBackup = ss.getBrowserState(); |
michael@0 | 5 | |
michael@0 | 6 | let statePinned = {windows:[{tabs:[ |
michael@0 | 7 | {entries:[{url:"http://example.com#1"}], pinned: true} |
michael@0 | 8 | ]}]}; |
michael@0 | 9 | |
michael@0 | 10 | let state = {windows:[{tabs:[ |
michael@0 | 11 | {entries:[{url:"http://example.com#1"}]}, |
michael@0 | 12 | {entries:[{url:"http://example.com#2"}]}, |
michael@0 | 13 | {entries:[{url:"http://example.com#3"}]}, |
michael@0 | 14 | {entries:[{url:"http://example.com#4"}]}, |
michael@0 | 15 | ]}]}; |
michael@0 | 16 | |
michael@0 | 17 | function test() { |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | registerCleanupFunction(function () { |
michael@0 | 21 | TabsProgressListener.uninit(); |
michael@0 | 22 | ss.setBrowserState(stateBackup); |
michael@0 | 23 | }); |
michael@0 | 24 | |
michael@0 | 25 | |
michael@0 | 26 | TabsProgressListener.init(); |
michael@0 | 27 | |
michael@0 | 28 | window.addEventListener("SSWindowStateReady", function onReady() { |
michael@0 | 29 | window.removeEventListener("SSWindowStateReady", onReady, false); |
michael@0 | 30 | |
michael@0 | 31 | let firstProgress = true; |
michael@0 | 32 | |
michael@0 | 33 | TabsProgressListener.setCallback(function (needsRestore, isRestoring) { |
michael@0 | 34 | if (firstProgress) { |
michael@0 | 35 | firstProgress = false; |
michael@0 | 36 | is(isRestoring, 3, "restoring 3 tabs concurrently"); |
michael@0 | 37 | } else { |
michael@0 | 38 | ok(isRestoring <= 3, "restoring max. 2 tabs concurrently"); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | if (0 == needsRestore) { |
michael@0 | 42 | TabsProgressListener.unsetCallback(); |
michael@0 | 43 | waitForFocus(finish); |
michael@0 | 44 | } |
michael@0 | 45 | }); |
michael@0 | 46 | |
michael@0 | 47 | ss.setBrowserState(JSON.stringify(state)); |
michael@0 | 48 | }, false); |
michael@0 | 49 | |
michael@0 | 50 | ss.setBrowserState(JSON.stringify(statePinned)); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function countTabs() { |
michael@0 | 54 | let needsRestore = 0, isRestoring = 0; |
michael@0 | 55 | let windowsEnum = Services.wm.getEnumerator("navigator:browser"); |
michael@0 | 56 | |
michael@0 | 57 | while (windowsEnum.hasMoreElements()) { |
michael@0 | 58 | let window = windowsEnum.getNext(); |
michael@0 | 59 | if (window.closed) |
michael@0 | 60 | continue; |
michael@0 | 61 | |
michael@0 | 62 | for (let i = 0; i < window.gBrowser.tabs.length; i++) { |
michael@0 | 63 | let browser = window.gBrowser.tabs[i].linkedBrowser; |
michael@0 | 64 | if (browser.__SS_restoreState == TAB_STATE_RESTORING) |
michael@0 | 65 | isRestoring++; |
michael@0 | 66 | else if (browser.__SS_restoreState == TAB_STATE_NEEDS_RESTORE) |
michael@0 | 67 | needsRestore++; |
michael@0 | 68 | } |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | return [needsRestore, isRestoring]; |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | let TabsProgressListener = { |
michael@0 | 75 | init: function () { |
michael@0 | 76 | Services.obs.addObserver(this, "sessionstore-debug-tab-restored", false); |
michael@0 | 77 | }, |
michael@0 | 78 | |
michael@0 | 79 | uninit: function () { |
michael@0 | 80 | Services.obs.removeObserver(this, "sessionstore-debug-tab-restored"); |
michael@0 | 81 | this.unsetCallback(); |
michael@0 | 82 | }, |
michael@0 | 83 | |
michael@0 | 84 | setCallback: function (callback) { |
michael@0 | 85 | this.callback = callback; |
michael@0 | 86 | }, |
michael@0 | 87 | |
michael@0 | 88 | unsetCallback: function () { |
michael@0 | 89 | delete this.callback; |
michael@0 | 90 | }, |
michael@0 | 91 | |
michael@0 | 92 | observe: function (browser, topic, data) { |
michael@0 | 93 | TabsProgressListener.onRestored(browser); |
michael@0 | 94 | }, |
michael@0 | 95 | |
michael@0 | 96 | onRestored: function (browser) { |
michael@0 | 97 | if (this.callback && browser.__SS_restoreState == TAB_STATE_RESTORING) { |
michael@0 | 98 | this.callback.apply(null, countTabs()); |
michael@0 | 99 | } |
michael@0 | 100 | } |
michael@0 | 101 | } |