browser/components/sessionstore/test/browser_464199.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 Components.utils.import("resource://gre/modules/ForgetAboutSite.jsm");
michael@0 6
michael@0 7 function waitForClearHistory(aCallback) {
michael@0 8 let observer = {
michael@0 9 observe: function(aSubject, aTopic, aData) {
michael@0 10 Services.obs.removeObserver(this, "browser:purge-domain-data");
michael@0 11 setTimeout(aCallback, 0);
michael@0 12 }
michael@0 13 };
michael@0 14 Services.obs.addObserver(observer, "browser:purge-domain-data", false);
michael@0 15 }
michael@0 16
michael@0 17 function test() {
michael@0 18 /** Test for Bug 464199 **/
michael@0 19
michael@0 20 waitForExplicitFinish();
michael@0 21
michael@0 22 const REMEMBER = Date.now(), FORGET = Math.random();
michael@0 23 let test_state = { windows: [{ "tabs": [{ "entries": [] }], _closedTabs: [
michael@0 24 { state: { entries: [{ url: "http://www.example.net/" }] }, title: FORGET },
michael@0 25 { state: { entries: [{ url: "http://www.example.org/" }] }, title: REMEMBER },
michael@0 26 { state: { entries: [{ url: "http://www.example.net/" },
michael@0 27 { url: "http://www.example.org/" }] }, title: FORGET },
michael@0 28 { state: { entries: [{ url: "http://example.net/" }] }, title: FORGET },
michael@0 29 { state: { entries: [{ url: "http://sub.example.net/" }] }, title: FORGET },
michael@0 30 { state: { entries: [{ url: "http://www.example.net:8080/" }] }, title: FORGET },
michael@0 31 { state: { entries: [{ url: "about:license" }] }, title: REMEMBER },
michael@0 32 { state: { entries: [{ url: "http://www.example.org/frameset",
michael@0 33 children: [
michael@0 34 { url: "http://www.example.org/frame" },
michael@0 35 { url: "http://www.example.org:8080/frame2" }
michael@0 36 ] }] }, title: REMEMBER },
michael@0 37 { state: { entries: [{ url: "http://www.example.org/frameset",
michael@0 38 children: [
michael@0 39 { url: "http://www.example.org/frame" },
michael@0 40 { url: "http://www.example.net/frame" }
michael@0 41 ] }] }, title: FORGET },
michael@0 42 { state: { entries: [{ url: "http://www.example.org/form",
michael@0 43 formdata: { id: { "url": "http://www.example.net/" } }
michael@0 44 }] }, title: REMEMBER },
michael@0 45 { state: { entries: [{ url: "http://www.example.org/form" }],
michael@0 46 extData: { "setTabValue": "http://example.net:80" } }, title: REMEMBER }
michael@0 47 ] }] };
michael@0 48 let remember_count = 5;
michael@0 49
michael@0 50 function countByTitle(aClosedTabList, aTitle)
michael@0 51 aClosedTabList.filter(function(aData) aData.title == aTitle).length;
michael@0 52
michael@0 53 // open a window and add the above closed tab list
michael@0 54 let newWin = openDialog(location, "", "chrome,all,dialog=no");
michael@0 55 newWin.addEventListener("load", function(aEvent) {
michael@0 56 newWin.removeEventListener("load", arguments.callee, false);
michael@0 57
michael@0 58 gPrefService.setIntPref("browser.sessionstore.max_tabs_undo",
michael@0 59 test_state.windows[0]._closedTabs.length);
michael@0 60 ss.setWindowState(newWin, JSON.stringify(test_state), true);
michael@0 61
michael@0 62 let closedTabs = JSON.parse(ss.getClosedTabData(newWin));
michael@0 63 is(closedTabs.length, test_state.windows[0]._closedTabs.length,
michael@0 64 "Closed tab list has the expected length");
michael@0 65 is(countByTitle(closedTabs, FORGET),
michael@0 66 test_state.windows[0]._closedTabs.length - remember_count,
michael@0 67 "The correct amout of tabs are to be forgotten");
michael@0 68 is(countByTitle(closedTabs, REMEMBER), remember_count,
michael@0 69 "Everything is set up.");
michael@0 70
michael@0 71 ForgetAboutSite.removeDataFromDomain("example.net");
michael@0 72 waitForClearHistory(function() {
michael@0 73 closedTabs = JSON.parse(ss.getClosedTabData(newWin));
michael@0 74 is(closedTabs.length, remember_count,
michael@0 75 "The correct amout of tabs was removed");
michael@0 76 is(countByTitle(closedTabs, FORGET), 0,
michael@0 77 "All tabs to be forgotten were indeed removed");
michael@0 78 is(countByTitle(closedTabs, REMEMBER), remember_count,
michael@0 79 "... and tabs to be remembered weren't.");
michael@0 80
michael@0 81 // clean up
michael@0 82 newWin.close();
michael@0 83 gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
michael@0 84 finish();
michael@0 85 });
michael@0 86 }, false);
michael@0 87 }

mercurial