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

mercurial