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