|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 let Imports = {}; |
|
5 Cu.import("resource:///modules/sessionstore/SessionSaver.jsm", Imports); |
|
6 let {SessionSaver} = Imports; |
|
7 |
|
8 add_task(function cleanup() { |
|
9 info("Forgetting closed tabs"); |
|
10 while (ss.getClosedTabCount(window)) { |
|
11 ss.forgetClosedTab(window, 0); |
|
12 } |
|
13 }); |
|
14 |
|
15 add_task(function() { |
|
16 let URL_PUBLIC = "http://example.com/public/" + Math.random(); |
|
17 let URL_PRIVATE = "http://example.com/private/" + Math.random(); |
|
18 let tab1, tab2; |
|
19 try { |
|
20 // Setup a public tab and a private tab |
|
21 info("Setting up public tab"); |
|
22 tab1 = gBrowser.addTab(URL_PUBLIC); |
|
23 yield promiseBrowserLoaded(tab1.linkedBrowser); |
|
24 |
|
25 info("Setting up private tab"); |
|
26 tab2 = gBrowser.addTab(); |
|
27 yield promiseBrowserLoaded(tab2.linkedBrowser); |
|
28 yield setUsePrivateBrowsing(tab2.linkedBrowser, true); |
|
29 tab2.linkedBrowser.loadURI(URL_PRIVATE); |
|
30 yield promiseBrowserLoaded(tab2.linkedBrowser); |
|
31 |
|
32 info("Flush to make sure chrome received all data."); |
|
33 SyncHandlers.get(tab1.linkedBrowser).flush(); |
|
34 SyncHandlers.get(tab2.linkedBrowser).flush(); |
|
35 |
|
36 info("Checking out state"); |
|
37 yield SessionSaver.run(); |
|
38 let path = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); |
|
39 let data = yield OS.File.read(path); |
|
40 let state = new TextDecoder().decode(data); |
|
41 info("State: " + state); |
|
42 // Ensure that sessionstore.js only knows about the public tab |
|
43 ok(state.indexOf(URL_PUBLIC) != -1, "State contains public tab"); |
|
44 ok(state.indexOf(URL_PRIVATE) == -1, "State does not contain private tab"); |
|
45 |
|
46 // Ensure that we can close and undo close the public tab but not the private tab |
|
47 gBrowser.removeTab(tab2); |
|
48 tab2 = null; |
|
49 |
|
50 gBrowser.removeTab(tab1); |
|
51 tab1 = null; |
|
52 |
|
53 tab1 = ss.undoCloseTab(window, 0); |
|
54 ok(true, "Public tab supports undo close"); |
|
55 |
|
56 is(ss.getClosedTabCount(window), 0, "Private tab does not support undo close"); |
|
57 |
|
58 } finally { |
|
59 if (tab1) { |
|
60 gBrowser.removeTab(tab1); |
|
61 } |
|
62 if (tab2) { |
|
63 gBrowser.removeTab(tab2); |
|
64 } |
|
65 } |
|
66 }); |
|
67 |
|
68 add_task(function () { |
|
69 const FRAME_SCRIPT = "data:," + |
|
70 "docShell.QueryInterface%28Ci.nsILoadContext%29.usePrivateBrowsing%3Dtrue"; |
|
71 |
|
72 // Clear the list of closed windows. |
|
73 while (ss.getClosedWindowCount()) { |
|
74 ss.forgetClosedWindow(0); |
|
75 } |
|
76 |
|
77 // Create a new window to attach our frame script to. |
|
78 let win = yield promiseNewWindowLoaded(); |
|
79 win.messageManager.loadFrameScript(FRAME_SCRIPT, true); |
|
80 |
|
81 // Create a new tab in the new window that will load the frame script. |
|
82 let tab = win.gBrowser.addTab("about:mozilla"); |
|
83 let browser = tab.linkedBrowser; |
|
84 yield promiseBrowserLoaded(browser); |
|
85 SyncHandlers.get(browser).flush(); |
|
86 |
|
87 // Check that we consider the tab as private. |
|
88 let state = JSON.parse(ss.getTabState(tab)); |
|
89 ok(state.isPrivate, "tab considered private"); |
|
90 |
|
91 // Ensure we don't allow restoring closed private tabs in non-private windows. |
|
92 win.gBrowser.removeTab(tab); |
|
93 is(ss.getClosedTabCount(win), 0, "no tabs to restore"); |
|
94 |
|
95 // Create a new tab in the new window that will load the frame script. |
|
96 let tab = win.gBrowser.addTab("about:mozilla"); |
|
97 let browser = tab.linkedBrowser; |
|
98 yield promiseBrowserLoaded(browser); |
|
99 SyncHandlers.get(browser).flush(); |
|
100 |
|
101 // Check that we consider the tab as private. |
|
102 let state = JSON.parse(ss.getTabState(tab)); |
|
103 ok(state.isPrivate, "tab considered private"); |
|
104 |
|
105 // Check that all private tabs are removed when the non-private |
|
106 // window is closed and we don't save windows without any tabs. |
|
107 yield promiseWindowClosed(win); |
|
108 is(ss.getClosedWindowCount(), 0, "no windows to restore"); |
|
109 }); |
|
110 |
|
111 add_task(function () { |
|
112 // Clear the list of closed windows. |
|
113 while (ss.getClosedWindowCount()) { |
|
114 ss.forgetClosedWindow(0); |
|
115 } |
|
116 |
|
117 // Create a new window to attach our frame script to. |
|
118 let win = yield promiseNewWindowLoaded({private: true}); |
|
119 |
|
120 // Create a new tab in the new window that will load the frame script. |
|
121 let tab = win.gBrowser.addTab("about:mozilla"); |
|
122 let browser = tab.linkedBrowser; |
|
123 yield promiseBrowserLoaded(browser); |
|
124 SyncHandlers.get(browser).flush(); |
|
125 |
|
126 // Check that we consider the tab as private. |
|
127 let state = JSON.parse(ss.getTabState(tab)); |
|
128 ok(state.isPrivate, "tab considered private"); |
|
129 |
|
130 // Ensure that closed tabs in a private windows can be restored. |
|
131 win.gBrowser.removeTab(tab); |
|
132 is(ss.getClosedTabCount(win), 1, "there is a single tab to restore"); |
|
133 |
|
134 // Ensure that closed private windows can never be restored. |
|
135 yield promiseWindowClosed(win); |
|
136 is(ss.getClosedWindowCount(), 0, "no windows to restore"); |
|
137 }); |
|
138 |
|
139 function setUsePrivateBrowsing(browser, val) { |
|
140 return sendMessage(browser, "ss-test:setUsePrivateBrowsing", val); |
|
141 } |
|
142 |