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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const PREF_RESTORE_ON_DEMAND = "browser.sessionstore.restore_on_demand"; |
michael@0 | 6 | |
michael@0 | 7 | function test() { |
michael@0 | 8 | TestRunner.run(); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | function runTests() { |
michael@0 | 12 | Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); |
michael@0 | 13 | registerCleanupFunction(function () { |
michael@0 | 14 | Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); |
michael@0 | 15 | }); |
michael@0 | 16 | |
michael@0 | 17 | // The first window will be put into the already open window and the second |
michael@0 | 18 | // window will be opened with _openWindowWithState, which is the source of the problem. |
michael@0 | 19 | let state = { windows: [ |
michael@0 | 20 | { |
michael@0 | 21 | tabs: [ |
michael@0 | 22 | { entries: [{ url: "http://example.org#0" }], extData: { "uniq": r() } } |
michael@0 | 23 | ], |
michael@0 | 24 | selected: 1 |
michael@0 | 25 | }, |
michael@0 | 26 | { |
michael@0 | 27 | tabs: [ |
michael@0 | 28 | { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } }, |
michael@0 | 29 | { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } }, |
michael@0 | 30 | { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } }, |
michael@0 | 31 | { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } }, |
michael@0 | 32 | { entries: [{ url: "http://example.com#5" }], extData: { "uniq": r() } }, |
michael@0 | 33 | { entries: [{ url: "http://example.com#6" }], extData: { "uniq": r() } } |
michael@0 | 34 | ], |
michael@0 | 35 | selected: 4 |
michael@0 | 36 | } |
michael@0 | 37 | ] }; |
michael@0 | 38 | let numTabs = state.windows[0].tabs.length + state.windows[1].tabs.length; |
michael@0 | 39 | |
michael@0 | 40 | let loadCount = 0; |
michael@0 | 41 | gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { |
michael@0 | 42 | if (++loadCount == numTabs) { |
michael@0 | 43 | // We don't actually care about load order in this test, just that they all |
michael@0 | 44 | // do load. |
michael@0 | 45 | is(loadCount, numTabs, "all tabs were restored"); |
michael@0 | 46 | is(aNeedRestore, 0, "there are no tabs left needing restore"); |
michael@0 | 47 | |
michael@0 | 48 | gProgressListener.unsetCallback(); |
michael@0 | 49 | executeSoon(next); |
michael@0 | 50 | } |
michael@0 | 51 | }); |
michael@0 | 52 | |
michael@0 | 53 | // We also want to catch the 2nd window, so we need to observe domwindowopened |
michael@0 | 54 | Services.ww.registerNotification(function observer(aSubject, aTopic, aData) { |
michael@0 | 55 | if (aTopic == "domwindowopened") { |
michael@0 | 56 | let win = aSubject.QueryInterface(Ci.nsIDOMWindow); |
michael@0 | 57 | win.addEventListener("load", function onLoad() { |
michael@0 | 58 | win.removeEventListener("load", onLoad); |
michael@0 | 59 | Services.ww.unregisterNotification(observer); |
michael@0 | 60 | win.gBrowser.addTabsProgressListener(gProgressListener); |
michael@0 | 61 | }); |
michael@0 | 62 | } |
michael@0 | 63 | }); |
michael@0 | 64 | |
michael@0 | 65 | yield ss.setBrowserState(JSON.stringify(state)); |
michael@0 | 66 | } |