michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let Imports = {}; michael@0: Cu.import("resource:///modules/sessionstore/SessionSaver.jsm", Imports); michael@0: let {SessionSaver} = Imports; michael@0: michael@0: add_task(function cleanup() { michael@0: info("Forgetting closed tabs"); michael@0: while (ss.getClosedTabCount(window)) { michael@0: ss.forgetClosedTab(window, 0); michael@0: } michael@0: }); michael@0: michael@0: add_task(function() { michael@0: let URL_PUBLIC = "http://example.com/public/" + Math.random(); michael@0: let URL_PRIVATE = "http://example.com/private/" + Math.random(); michael@0: let tab1, tab2; michael@0: try { michael@0: // Setup a public tab and a private tab michael@0: info("Setting up public tab"); michael@0: tab1 = gBrowser.addTab(URL_PUBLIC); michael@0: yield promiseBrowserLoaded(tab1.linkedBrowser); michael@0: michael@0: info("Setting up private tab"); michael@0: tab2 = gBrowser.addTab(); michael@0: yield promiseBrowserLoaded(tab2.linkedBrowser); michael@0: yield setUsePrivateBrowsing(tab2.linkedBrowser, true); michael@0: tab2.linkedBrowser.loadURI(URL_PRIVATE); michael@0: yield promiseBrowserLoaded(tab2.linkedBrowser); michael@0: michael@0: info("Flush to make sure chrome received all data."); michael@0: SyncHandlers.get(tab1.linkedBrowser).flush(); michael@0: SyncHandlers.get(tab2.linkedBrowser).flush(); michael@0: michael@0: info("Checking out state"); michael@0: yield SessionSaver.run(); michael@0: let path = OS.Path.join(OS.Constants.Path.profileDir, "sessionstore.js"); michael@0: let data = yield OS.File.read(path); michael@0: let state = new TextDecoder().decode(data); michael@0: info("State: " + state); michael@0: // Ensure that sessionstore.js only knows about the public tab michael@0: ok(state.indexOf(URL_PUBLIC) != -1, "State contains public tab"); michael@0: ok(state.indexOf(URL_PRIVATE) == -1, "State does not contain private tab"); michael@0: michael@0: // Ensure that we can close and undo close the public tab but not the private tab michael@0: gBrowser.removeTab(tab2); michael@0: tab2 = null; michael@0: michael@0: gBrowser.removeTab(tab1); michael@0: tab1 = null; michael@0: michael@0: tab1 = ss.undoCloseTab(window, 0); michael@0: ok(true, "Public tab supports undo close"); michael@0: michael@0: is(ss.getClosedTabCount(window), 0, "Private tab does not support undo close"); michael@0: michael@0: } finally { michael@0: if (tab1) { michael@0: gBrowser.removeTab(tab1); michael@0: } michael@0: if (tab2) { michael@0: gBrowser.removeTab(tab2); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: add_task(function () { michael@0: const FRAME_SCRIPT = "data:," + michael@0: "docShell.QueryInterface%28Ci.nsILoadContext%29.usePrivateBrowsing%3Dtrue"; michael@0: michael@0: // Clear the list of closed windows. michael@0: while (ss.getClosedWindowCount()) { michael@0: ss.forgetClosedWindow(0); michael@0: } michael@0: michael@0: // Create a new window to attach our frame script to. michael@0: let win = yield promiseNewWindowLoaded(); michael@0: win.messageManager.loadFrameScript(FRAME_SCRIPT, true); michael@0: michael@0: // Create a new tab in the new window that will load the frame script. michael@0: let tab = win.gBrowser.addTab("about:mozilla"); michael@0: let browser = tab.linkedBrowser; michael@0: yield promiseBrowserLoaded(browser); michael@0: SyncHandlers.get(browser).flush(); michael@0: michael@0: // Check that we consider the tab as private. michael@0: let state = JSON.parse(ss.getTabState(tab)); michael@0: ok(state.isPrivate, "tab considered private"); michael@0: michael@0: // Ensure we don't allow restoring closed private tabs in non-private windows. michael@0: win.gBrowser.removeTab(tab); michael@0: is(ss.getClosedTabCount(win), 0, "no tabs to restore"); michael@0: michael@0: // Create a new tab in the new window that will load the frame script. michael@0: let tab = win.gBrowser.addTab("about:mozilla"); michael@0: let browser = tab.linkedBrowser; michael@0: yield promiseBrowserLoaded(browser); michael@0: SyncHandlers.get(browser).flush(); michael@0: michael@0: // Check that we consider the tab as private. michael@0: let state = JSON.parse(ss.getTabState(tab)); michael@0: ok(state.isPrivate, "tab considered private"); michael@0: michael@0: // Check that all private tabs are removed when the non-private michael@0: // window is closed and we don't save windows without any tabs. michael@0: yield promiseWindowClosed(win); michael@0: is(ss.getClosedWindowCount(), 0, "no windows to restore"); michael@0: }); michael@0: michael@0: add_task(function () { michael@0: // Clear the list of closed windows. michael@0: while (ss.getClosedWindowCount()) { michael@0: ss.forgetClosedWindow(0); michael@0: } michael@0: michael@0: // Create a new window to attach our frame script to. michael@0: let win = yield promiseNewWindowLoaded({private: true}); michael@0: michael@0: // Create a new tab in the new window that will load the frame script. michael@0: let tab = win.gBrowser.addTab("about:mozilla"); michael@0: let browser = tab.linkedBrowser; michael@0: yield promiseBrowserLoaded(browser); michael@0: SyncHandlers.get(browser).flush(); michael@0: michael@0: // Check that we consider the tab as private. michael@0: let state = JSON.parse(ss.getTabState(tab)); michael@0: ok(state.isPrivate, "tab considered private"); michael@0: michael@0: // Ensure that closed tabs in a private windows can be restored. michael@0: win.gBrowser.removeTab(tab); michael@0: is(ss.getClosedTabCount(win), 1, "there is a single tab to restore"); michael@0: michael@0: // Ensure that closed private windows can never be restored. michael@0: yield promiseWindowClosed(win); michael@0: is(ss.getClosedWindowCount(), 0, "no windows to restore"); michael@0: }); michael@0: michael@0: function setUsePrivateBrowsing(browser, val) { michael@0: return sendMessage(browser, "ss-test:setUsePrivateBrowsing", val); michael@0: } michael@0: