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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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, true);
michael@0 13 registerCleanupFunction(function () {
michael@0 14 Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND);
michael@0 15 });
michael@0 16
michael@0 17 let state = { windows: [{ tabs: [
michael@0 18 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
michael@0 19 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
michael@0 20 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
michael@0 21 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
michael@0 22 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } },
michael@0 23 { entries: [{ url: "http://example.org" }], extData: { "uniq": r() } }
michael@0 24 ], selected: 1 }] };
michael@0 25
michael@0 26 let expectedCounts = [
michael@0 27 [5, 1, 0],
michael@0 28 [4, 1, 1],
michael@0 29 [3, 1, 2],
michael@0 30 [2, 1, 3],
michael@0 31 [1, 1, 4],
michael@0 32 [0, 1, 5]
michael@0 33 ];
michael@0 34 let tabOrder = [0, 5, 1, 4, 3, 2];
michael@0 35
michael@0 36 let loadCount = 0;
michael@0 37 gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) {
michael@0 38 loadCount++;
michael@0 39 let expected = expectedCounts[loadCount - 1];
michael@0 40
michael@0 41 is(aNeedRestore, expected[0], "load " + loadCount + " - # tabs that need to be restored");
michael@0 42 is(aRestoring, expected[1], "load " + loadCount + " - # tabs that are restoring");
michael@0 43 is(aRestored, expected[2], "load " + loadCount + " - # tabs that has been restored");
michael@0 44
michael@0 45 if (loadCount < state.windows[0].tabs.length) {
michael@0 46 // double check that this tab was the right one
michael@0 47 let expectedData = state.windows[0].tabs[tabOrder[loadCount - 1]].extData.uniq;
michael@0 48 let tab;
michael@0 49 for (let i = 0; i < window.gBrowser.tabs.length; i++) {
michael@0 50 if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser)
michael@0 51 tab = window.gBrowser.tabs[i];
michael@0 52 }
michael@0 53
michael@0 54 is(ss.getTabValue(tab, "uniq"), expectedData,
michael@0 55 "load " + loadCount + " - correct tab was restored");
michael@0 56
michael@0 57 // select the next tab
michael@0 58 window.gBrowser.selectTabAtIndex(tabOrder[loadCount]);
michael@0 59 } else {
michael@0 60 gProgressListener.unsetCallback();
michael@0 61 executeSoon(next);
michael@0 62 }
michael@0 63 });
michael@0 64
michael@0 65 yield ss.setBrowserState(JSON.stringify(state));
michael@0 66 }

mercurial