browser/components/sessionstore/test/browser_595601-restore_hidden.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 /* 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 state = {windows:[{tabs:[
michael@0 5 {entries:[{url:"http://example.com#1"}]},
michael@0 6 {entries:[{url:"http://example.com#2"}]},
michael@0 7 {entries:[{url:"http://example.com#3"}]},
michael@0 8 {entries:[{url:"http://example.com#4"}]},
michael@0 9 {entries:[{url:"http://example.com#5"}], hidden: true},
michael@0 10 {entries:[{url:"http://example.com#6"}], hidden: true},
michael@0 11 {entries:[{url:"http://example.com#7"}], hidden: true},
michael@0 12 {entries:[{url:"http://example.com#8"}], hidden: true}
michael@0 13 ]}]};
michael@0 14
michael@0 15 function test() {
michael@0 16 waitForExplicitFinish();
michael@0 17
michael@0 18 registerCleanupFunction(function () {
michael@0 19 Services.prefs.clearUserPref("browser.sessionstore.restore_hidden_tabs");
michael@0 20 });
michael@0 21
michael@0 22 // First stage: restoreHiddenTabs = true
michael@0 23 // Second stage: restoreHiddenTabs = false
michael@0 24 test_loadTabs(true, function () {
michael@0 25 test_loadTabs(false, finish);
michael@0 26 });
michael@0 27 }
michael@0 28
michael@0 29 function test_loadTabs(restoreHiddenTabs, callback) {
michael@0 30 Services.prefs.setBoolPref("browser.sessionstore.restore_hidden_tabs", restoreHiddenTabs);
michael@0 31
michael@0 32 let expectedTabs = restoreHiddenTabs ? 8 : 4;
michael@0 33 let firstProgress = true;
michael@0 34
michael@0 35 newWindowWithState(state, function (win, needsRestore, isRestoring) {
michael@0 36 if (firstProgress) {
michael@0 37 firstProgress = false;
michael@0 38 is(isRestoring, 3, "restoring 3 tabs concurrently");
michael@0 39 } else {
michael@0 40 ok(isRestoring < 4, "restoring max. 3 tabs concurrently");
michael@0 41 }
michael@0 42
michael@0 43 // We're explicity checking for (isRestoring == 1) here because the test
michael@0 44 // progress listener is called before the session store one. So when we're
michael@0 45 // called with one tab left to restore we know that the last tab has
michael@0 46 // finished restoring and will soon be handled by the SS listener.
michael@0 47 let tabsNeedingRestore = win.gBrowser.tabs.length - needsRestore;
michael@0 48 if (isRestoring == 1 && tabsNeedingRestore == expectedTabs) {
michael@0 49 is(win.gBrowser.visibleTabs.length, 4, "only 4 visible tabs");
michael@0 50
michael@0 51 TabsProgressListener.uninit();
michael@0 52 executeSoon(callback);
michael@0 53 }
michael@0 54 });
michael@0 55 }
michael@0 56
michael@0 57 let TabsProgressListener = {
michael@0 58 init: function (win) {
michael@0 59 this.window = win;
michael@0 60 Services.obs.addObserver(this, "sessionstore-debug-tab-restored", false);
michael@0 61 },
michael@0 62
michael@0 63 uninit: function () {
michael@0 64 Services.obs.removeObserver(this, "sessionstore-debug-tab-restored");
michael@0 65
michael@0 66 delete this.window;
michael@0 67 delete this.callback;
michael@0 68 },
michael@0 69
michael@0 70 setCallback: function (callback) {
michael@0 71 this.callback = callback;
michael@0 72 },
michael@0 73
michael@0 74 observe: function (browser) {
michael@0 75 TabsProgressListener.onRestored(browser);
michael@0 76 },
michael@0 77
michael@0 78 onRestored: function (browser) {
michael@0 79 if (this.callback && browser.__SS_restoreState == TAB_STATE_RESTORING)
michael@0 80 this.callback.apply(null, [this.window].concat(this.countTabs()));
michael@0 81 },
michael@0 82
michael@0 83 countTabs: function () {
michael@0 84 let needsRestore = 0, isRestoring = 0;
michael@0 85
michael@0 86 for (let i = 0; i < this.window.gBrowser.tabs.length; i++) {
michael@0 87 let browser = this.window.gBrowser.tabs[i].linkedBrowser;
michael@0 88 if (browser.__SS_restoreState == TAB_STATE_RESTORING)
michael@0 89 isRestoring++;
michael@0 90 else if (browser.__SS_restoreState == TAB_STATE_NEEDS_RESTORE)
michael@0 91 needsRestore++;
michael@0 92 }
michael@0 93
michael@0 94 return [needsRestore, isRestoring];
michael@0 95 }
michael@0 96 }
michael@0 97
michael@0 98 // ----------
michael@0 99 function newWindowWithState(state, callback) {
michael@0 100 let opts = "chrome,all,dialog=no,height=800,width=800";
michael@0 101 let win = window.openDialog(getBrowserURL(), "_blank", opts);
michael@0 102
michael@0 103 registerCleanupFunction(function () win.close());
michael@0 104
michael@0 105 whenWindowLoaded(win, function onWindowLoaded(aWin) {
michael@0 106 TabsProgressListener.init(aWin);
michael@0 107 TabsProgressListener.setCallback(callback);
michael@0 108
michael@0 109 ss.setWindowState(aWin, JSON.stringify(state), true);
michael@0 110 });
michael@0 111 }

mercurial