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 | // Request a longer timeout because the test takes quite a while |
michael@0 | 13 | // to complete on slow Windows debug machines and we would otherwise |
michael@0 | 14 | // see a lot of (not so) intermittent test failures. |
michael@0 | 15 | requestLongerTimeout(2); |
michael@0 | 16 | |
michael@0 | 17 | Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, true); |
michael@0 | 18 | registerCleanupFunction(function () { |
michael@0 | 19 | Services.prefs.clearUserPref(PREF_RESTORE_ON_DEMAND); |
michael@0 | 20 | }); |
michael@0 | 21 | |
michael@0 | 22 | let state = { windows: [{ tabs: [ |
michael@0 | 23 | { entries: [{ url: "http://example.org/#1" }], extData: { "uniq": r() } }, |
michael@0 | 24 | { entries: [{ url: "http://example.org/#2" }], extData: { "uniq": r() } }, |
michael@0 | 25 | { entries: [{ url: "http://example.org/#3" }], extData: { "uniq": r() } }, |
michael@0 | 26 | { entries: [{ url: "http://example.org/#4" }], extData: { "uniq": r() } }, |
michael@0 | 27 | { entries: [{ url: "http://example.org/#5" }], extData: { "uniq": r() } }, |
michael@0 | 28 | { entries: [{ url: "http://example.org/#6" }], extData: { "uniq": r() } }, |
michael@0 | 29 | { entries: [{ url: "http://example.org/#7" }], extData: { "uniq": r() } }, |
michael@0 | 30 | { entries: [{ url: "http://example.org/#8" }], extData: { "uniq": r() } }, |
michael@0 | 31 | { entries: [{ url: "http://example.org/#9" }], extData: { "uniq": r() } }, |
michael@0 | 32 | { entries: [{ url: "http://example.org/#10" }], extData: { "uniq": r() } }, |
michael@0 | 33 | { entries: [{ url: "http://example.org/#11" }], extData: { "uniq": r() } }, |
michael@0 | 34 | { entries: [{ url: "http://example.org/#12" }], extData: { "uniq": r() } }, |
michael@0 | 35 | { entries: [{ url: "http://example.org/#13" }], extData: { "uniq": r() } }, |
michael@0 | 36 | { entries: [{ url: "http://example.org/#14" }], extData: { "uniq": r() } }, |
michael@0 | 37 | { entries: [{ url: "http://example.org/#15" }], extData: { "uniq": r() } }, |
michael@0 | 38 | { entries: [{ url: "http://example.org/#16" }], extData: { "uniq": r() } }, |
michael@0 | 39 | { entries: [{ url: "http://example.org/#17" }], extData: { "uniq": r() } }, |
michael@0 | 40 | { entries: [{ url: "http://example.org/#18" }], extData: { "uniq": r() } } |
michael@0 | 41 | ], selected: 1 }] }; |
michael@0 | 42 | |
michael@0 | 43 | let loadCount = 0; |
michael@0 | 44 | gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { |
michael@0 | 45 | loadCount++; |
michael@0 | 46 | is(aBrowser.currentURI.spec, state.windows[0].tabs[loadCount - 1].entries[0].url, |
michael@0 | 47 | "load " + loadCount + " - browser loaded correct url"); |
michael@0 | 48 | |
michael@0 | 49 | if (loadCount <= state.windows[0].tabs.length) { |
michael@0 | 50 | // double check that this tab was the right one |
michael@0 | 51 | let expectedData = state.windows[0].tabs[loadCount - 1].extData.uniq; |
michael@0 | 52 | let tab; |
michael@0 | 53 | for (let i = 0; i < window.gBrowser.tabs.length; i++) { |
michael@0 | 54 | if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) |
michael@0 | 55 | tab = window.gBrowser.tabs[i]; |
michael@0 | 56 | } |
michael@0 | 57 | is(ss.getTabValue(tab, "uniq"), expectedData, |
michael@0 | 58 | "load " + loadCount + " - correct tab was restored"); |
michael@0 | 59 | |
michael@0 | 60 | if (loadCount == state.windows[0].tabs.length) { |
michael@0 | 61 | gProgressListener.unsetCallback(); |
michael@0 | 62 | executeSoon(function () { |
michael@0 | 63 | reloadAllTabs(state, function () { |
michael@0 | 64 | waitForBrowserState(TestRunner.backupState, testCascade); |
michael@0 | 65 | }); |
michael@0 | 66 | }); |
michael@0 | 67 | } else { |
michael@0 | 68 | // reload the next tab |
michael@0 | 69 | window.gBrowser.reloadTab(window.gBrowser.tabs[loadCount]); |
michael@0 | 70 | } |
michael@0 | 71 | } |
michael@0 | 72 | }); |
michael@0 | 73 | |
michael@0 | 74 | yield ss.setBrowserState(JSON.stringify(state)); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function testCascade() { |
michael@0 | 78 | Services.prefs.setBoolPref(PREF_RESTORE_ON_DEMAND, false); |
michael@0 | 79 | |
michael@0 | 80 | let state = { windows: [{ tabs: [ |
michael@0 | 81 | { entries: [{ url: "http://example.com/#1" }], extData: { "uniq": r() } }, |
michael@0 | 82 | { entries: [{ url: "http://example.com/#2" }], extData: { "uniq": r() } }, |
michael@0 | 83 | { entries: [{ url: "http://example.com/#3" }], extData: { "uniq": r() } }, |
michael@0 | 84 | { entries: [{ url: "http://example.com/#4" }], extData: { "uniq": r() } }, |
michael@0 | 85 | { entries: [{ url: "http://example.com/#5" }], extData: { "uniq": r() } }, |
michael@0 | 86 | { entries: [{ url: "http://example.com/#6" }], extData: { "uniq": r() } } |
michael@0 | 87 | ] }] }; |
michael@0 | 88 | |
michael@0 | 89 | let loadCount = 0; |
michael@0 | 90 | gProgressListener.setCallback(function (aBrowser, aNeedRestore, aRestoring, aRestored) { |
michael@0 | 91 | if (++loadCount < state.windows[0].tabs.length) { |
michael@0 | 92 | return; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | gProgressListener.unsetCallback(); |
michael@0 | 96 | executeSoon(function () { |
michael@0 | 97 | reloadAllTabs(state, next); |
michael@0 | 98 | }); |
michael@0 | 99 | }); |
michael@0 | 100 | |
michael@0 | 101 | ss.setBrowserState(JSON.stringify(state)); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | function reloadAllTabs(aState, aCallback) { |
michael@0 | 105 | // Simulate a left mouse button click with no modifiers, which is what |
michael@0 | 106 | // Command-R, or clicking reload does. |
michael@0 | 107 | let fakeEvent = { |
michael@0 | 108 | button: 0, |
michael@0 | 109 | metaKey: false, |
michael@0 | 110 | altKey: false, |
michael@0 | 111 | ctrlKey: false, |
michael@0 | 112 | shiftKey: false |
michael@0 | 113 | }; |
michael@0 | 114 | |
michael@0 | 115 | let loadCount = 0; |
michael@0 | 116 | gWebProgressListener.setCallback(function (aBrowser) { |
michael@0 | 117 | if (++loadCount <= aState.windows[0].tabs.length) { |
michael@0 | 118 | // double check that this tab was the right one |
michael@0 | 119 | let expectedData = aState.windows[0].tabs[loadCount - 1].extData.uniq; |
michael@0 | 120 | let tab; |
michael@0 | 121 | for (let i = 0; i < window.gBrowser.tabs.length; i++) { |
michael@0 | 122 | if (!tab && window.gBrowser.tabs[i].linkedBrowser == aBrowser) |
michael@0 | 123 | tab = window.gBrowser.tabs[i]; |
michael@0 | 124 | } |
michael@0 | 125 | is(ss.getTabValue(tab, "uniq"), expectedData, |
michael@0 | 126 | "load " + loadCount + " - correct tab was reloaded"); |
michael@0 | 127 | |
michael@0 | 128 | if (loadCount == aState.windows[0].tabs.length) { |
michael@0 | 129 | gWebProgressListener.unsetCallback(); |
michael@0 | 130 | executeSoon(aCallback); |
michael@0 | 131 | } else { |
michael@0 | 132 | // reload the next tab |
michael@0 | 133 | window.gBrowser.selectTabAtIndex(loadCount); |
michael@0 | 134 | BrowserReloadOrDuplicate(fakeEvent); |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | }); |
michael@0 | 138 | |
michael@0 | 139 | BrowserReloadOrDuplicate(fakeEvent); |
michael@0 | 140 | } |