browser/components/sessionstore/test/browser_586068-browser_state_interrupted.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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 state will be loaded using setBrowserState, followed by the 2nd
michael@0 18 // state also being loaded using setBrowserState, interrupting the first restore.
michael@0 19 let state1 = { windows: [
michael@0 20 {
michael@0 21 tabs: [
michael@0 22 { entries: [{ url: "http://example.org#1" }], extData: { "uniq": r() } },
michael@0 23 { entries: [{ url: "http://example.org#2" }], extData: { "uniq": r() } },
michael@0 24 { entries: [{ url: "http://example.org#3" }], extData: { "uniq": r() } },
michael@0 25 { entries: [{ url: "http://example.org#4" }], extData: { "uniq": r() } }
michael@0 26 ],
michael@0 27 selected: 1
michael@0 28 },
michael@0 29 {
michael@0 30 tabs: [
michael@0 31 { entries: [{ url: "http://example.com#1" }], extData: { "uniq": r() } },
michael@0 32 { entries: [{ url: "http://example.com#2" }], extData: { "uniq": r() } },
michael@0 33 { entries: [{ url: "http://example.com#3" }], extData: { "uniq": r() } },
michael@0 34 { entries: [{ url: "http://example.com#4" }], extData: { "uniq": r() } },
michael@0 35 ],
michael@0 36 selected: 3
michael@0 37 }
michael@0 38 ] };
michael@0 39 let state2 = { windows: [
michael@0 40 {
michael@0 41 tabs: [
michael@0 42 { entries: [{ url: "http://example.org#5" }], extData: { "uniq": r() } },
michael@0 43 { entries: [{ url: "http://example.org#6" }], extData: { "uniq": r() } },
michael@0 44 { entries: [{ url: "http://example.org#7" }], extData: { "uniq": r() } },
michael@0 45 { entries: [{ url: "http://example.org#8" }], extData: { "uniq": r() } }
michael@0 46 ],
michael@0 47 selected: 3
michael@0 48 },
michael@0 49 {
michael@0 50 tabs: [
michael@0 51 { entries: [{ url: "http://example.com#5" }], extData: { "uniq": r() } },
michael@0 52 { entries: [{ url: "http://example.com#6" }], extData: { "uniq": r() } },
michael@0 53 { entries: [{ url: "http://example.com#7" }], extData: { "uniq": r() } },
michael@0 54 { entries: [{ url: "http://example.com#8" }], extData: { "uniq": r() } },
michael@0 55 ],
michael@0 56 selected: 1
michael@0 57 }
michael@0 58 ] };
michael@0 59
michael@0 60 // interruptedAfter will be set after the selected tab from each window have loaded.
michael@0 61 let interruptedAfter = 0;
michael@0 62 let loadedWindow1 = false;
michael@0 63 let loadedWindow2 = false;
michael@0 64 let numTabs = state2.windows[0].tabs.length + state2.windows[1].tabs.length;
michael@0 65
michael@0 66 let loadCount = 0;
michael@0 67 gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
michael@0 68 loadCount++;
michael@0 69
michael@0 70 if (aBrowser.currentURI.spec == state1.windows[0].tabs[2].entries[0].url)
michael@0 71 loadedWindow1 = true;
michael@0 72 if (aBrowser.currentURI.spec == state1.windows[1].tabs[0].entries[0].url)
michael@0 73 loadedWindow2 = true;
michael@0 74
michael@0 75 if (!interruptedAfter && loadedWindow1 && loadedWindow2) {
michael@0 76 interruptedAfter = loadCount;
michael@0 77 ss.setBrowserState(JSON.stringify(state2));
michael@0 78 return;
michael@0 79 }
michael@0 80
michael@0 81 if (loadCount < numTabs + interruptedAfter)
michael@0 82 return;
michael@0 83
michael@0 84 // We don't actually care about load order in this test, just that they all
michael@0 85 // do load.
michael@0 86 is(loadCount, numTabs + interruptedAfter, "all tabs were restored");
michael@0 87 is(aNeedRestore, 0, "there are no tabs left needing restore");
michael@0 88
michael@0 89 // Remove the progress listener from this window, it will be removed from
michael@0 90 // theWin when that window is closed (in setBrowserState).
michael@0 91 gProgressListener.unsetCallback();
michael@0 92 executeSoon(next);
michael@0 93 });
michael@0 94
michael@0 95 // We also want to catch the extra windows (there should be 2), so we need to observe domwindowopened
michael@0 96 Services.ww.registerNotification(function observer(aSubject, aTopic, aData) {
michael@0 97 if (aTopic == "domwindowopened") {
michael@0 98 let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
michael@0 99 win.addEventListener("load", function onLoad() {
michael@0 100 win.removeEventListener("load", onLoad);
michael@0 101 Services.ww.unregisterNotification(observer);
michael@0 102 win.gBrowser.addTabsProgressListener(gProgressListener);
michael@0 103 });
michael@0 104 }
michael@0 105 });
michael@0 106
michael@0 107 yield ss.setBrowserState(JSON.stringify(state1));
michael@0 108 }

mercurial