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.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /** Private Browsing Test for Bug 394759 **/
6 function test() {
7 waitForExplicitFinish();
9 let windowsToClose = [];
10 let closedWindowCount = 0;
11 // Prevent VM timers issues, cache now and increment it manually.
12 let now = Date.now();
13 const TESTS = [
14 { url: "about:config",
15 key: "bug 394759 Non-PB",
16 value: "uniq" + (++now) },
17 { url: "about:mozilla",
18 key: "bug 394759 PB",
19 value: "uniq" + (++now) },
20 ];
22 registerCleanupFunction(function() {
23 Services.prefs.clearUserPref("browser.sessionstore.interval");
24 windowsToClose.forEach(function(win) {
25 win.close();
26 });
27 });
29 function testOpenCloseWindow(aIsPrivate, aTest, aCallback) {
30 whenNewWindowLoaded({ private: aIsPrivate }, function(win) {
31 whenBrowserLoaded(win.gBrowser.selectedBrowser, function() {
32 executeSoon(function() {
33 // Mark the window with some unique data to be restored later on.
34 ss.setWindowValue(win, aTest.key, aTest.value);
35 // Close.
36 win.close();
37 aCallback();
38 });
39 });
40 win.gBrowser.selectedBrowser.loadURI(aTest.url);
41 });
42 }
44 function testOnWindow(aIsPrivate, aValue, aCallback) {
45 whenNewWindowLoaded({ private: aIsPrivate }, function(win) {
46 windowsToClose.push(win);
47 executeSoon(function() checkClosedWindows(aIsPrivate, aValue, aCallback));
48 });
49 }
51 function checkClosedWindows(aIsPrivate, aValue, aCallback) {
52 let data = JSON.parse(ss.getClosedWindowData())[0];
53 is(ss.getClosedWindowCount(), 1, "Check the closed window count");
54 ok(JSON.stringify(data).indexOf(aValue) > -1,
55 "Check the closed window data was stored correctly");
56 aCallback();
57 }
59 function setupBlankState(aCallback) {
60 // Set interval to a large time so state won't be written while we setup
61 // environment.
62 Services.prefs.setIntPref("browser.sessionstore.interval", 100000);
64 // Set up the browser in a blank state. Popup windows in previous tests
65 // result in different states on different platforms.
66 let blankState = JSON.stringify({
67 windows: [{
68 tabs: [{ entries: [{ url: "about:blank" }] }],
69 _closedTabs: []
70 }],
71 _closedWindows: []
72 });
73 ss.setBrowserState(blankState);
75 // Wait for the sessionstore.js file to be written before going on.
76 // Note: we don't wait for the complete event, since if asyncCopy fails we
77 // would timeout.
78 waitForSaveState(function(writing) {
79 ok(writing, "sessionstore.js is being written");
80 closedWindowCount = ss.getClosedWindowCount();
81 is(closedWindowCount, 0, "Correctly set window count");
83 executeSoon(aCallback);
84 });
86 // Remove the sessionstore.js file before setting the interval to 0
87 let profilePath = Services.dirsvc.get("ProfD", Ci.nsIFile);
88 let sessionStoreJS = profilePath.clone();
89 sessionStoreJS.append("sessionstore.js");
90 if (sessionStoreJS.exists())
91 sessionStoreJS.remove(false);
92 info("sessionstore.js was correctly removed: " + (!sessionStoreJS.exists()));
94 // Make sure that sessionstore.js can be forced to be created by setting
95 // the interval pref to 0.
96 Services.prefs.setIntPref("browser.sessionstore.interval", 0);
97 }
99 setupBlankState(function() {
100 testOpenCloseWindow(false, TESTS[0], function() {
101 testOpenCloseWindow(true, TESTS[1], function() {
102 testOnWindow(false, TESTS[0].value, function() {
103 testOnWindow(true, TESTS[0].value, finish);
104 });
105 });
106 });
107 });
108 }