browser/components/sessionstore/test/browser_dying_cache.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 function test() {
michael@0 5 TestRunner.run();
michael@0 6 }
michael@0 7
michael@0 8 /**
michael@0 9 * This test ensures that after closing a window we keep its state data around
michael@0 10 * as long as something keeps a reference to it. It should only be possible to
michael@0 11 * read data after closing - writing should fail.
michael@0 12 */
michael@0 13
michael@0 14 function runTests() {
michael@0 15 // Open a new window.
michael@0 16 let win = OpenBrowserWindow();
michael@0 17 yield whenDelayedStartupFinished(win, next);
michael@0 18
michael@0 19 // Load some URL in the current tab.
michael@0 20 let flags = Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY;
michael@0 21 win.gBrowser.selectedBrowser.loadURIWithFlags("about:robots", flags);
michael@0 22 yield whenBrowserLoaded(win.gBrowser.selectedBrowser);
michael@0 23
michael@0 24 // Open a second tab and close the first one.
michael@0 25 let tab = win.gBrowser.addTab("about:mozilla");
michael@0 26 yield whenBrowserLoaded(tab.linkedBrowser);
michael@0 27 SyncHandlers.get(tab.linkedBrowser).flush();
michael@0 28 win.gBrowser.removeTab(win.gBrowser.tabs[0]);
michael@0 29
michael@0 30 // Make sure our window is still tracked by sessionstore
michael@0 31 // and the window state is as expected.
michael@0 32 ok("__SSi" in win, "window is being tracked by sessionstore");
michael@0 33 ss.setWindowValue(win, "foo", "bar");
michael@0 34 checkWindowState(win);
michael@0 35
michael@0 36 let state = ss.getWindowState(win);
michael@0 37 let closedTabData = ss.getClosedTabData(win);
michael@0 38
michael@0 39 // Close our window and wait a tick.
michael@0 40 whenWindowClosed(win);
michael@0 41 yield win.close();
michael@0 42
michael@0 43 // SessionStore should no longer track our window
michael@0 44 // but it should still report the same state.
michael@0 45 ok(!("__SSi" in win), "sessionstore does no longer track our window");
michael@0 46 checkWindowState(win);
michael@0 47
michael@0 48 // Make sure we're not allowed to modify state data.
michael@0 49 ok(shouldThrow(() => ss.setWindowState(win, {})),
michael@0 50 "we're not allowed to modify state data anymore");
michael@0 51 ok(shouldThrow(() => ss.setWindowValue(win, "foo", "baz")),
michael@0 52 "we're not allowed to modify state data anymore");
michael@0 53 }
michael@0 54
michael@0 55 function checkWindowState(window) {
michael@0 56 let {windows: [{tabs}]} = JSON.parse(ss.getWindowState(window));
michael@0 57 is(tabs.length, 1, "the window has a single tab");
michael@0 58 is(tabs[0].entries[0].url, "about:mozilla", "the tab is about:mozilla");
michael@0 59
michael@0 60 is(ss.getClosedTabCount(window), 1, "the window has one closed tab");
michael@0 61 let [{state: {entries: [{url}]}}] = JSON.parse(ss.getClosedTabData(window));
michael@0 62 is(url, "about:robots", "the closed tab is about:robots");
michael@0 63
michael@0 64 is(ss.getWindowValue(window, "foo"), "bar", "correct extData value");
michael@0 65 }
michael@0 66
michael@0 67 function shouldThrow(f) {
michael@0 68 try {
michael@0 69 f();
michael@0 70 } catch (e) {
michael@0 71 return true;
michael@0 72 }
michael@0 73 }
michael@0 74
michael@0 75 function whenWindowClosed(window) {
michael@0 76 window.addEventListener("SSWindowClosing", function onClosing() {
michael@0 77 window.removeEventListener("SSWindowClosing", onClosing);
michael@0 78 executeSoon(next);
michael@0 79 });
michael@0 80 }

mercurial