diff --git a/browser/components/sessionstore/test/browser_privatetabs.js b/browser/components/sessionstore/test/browser_privatetabs.js index 625046478758..cc02e56cfa71 100644 --- a/browser/components/sessionstore/test/browser_privatetabs.js +++ b/browser/components/sessionstore/test/browser_privatetabs.js @@ -15,13 +15,15 @@ add_task(function() { try { // Setup a public tab and a private tab info("Setting up public tab"); - tab1 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, URL_PUBLIC); + tab1 = gBrowser.addTab(URL_PUBLIC); + yield promiseBrowserLoaded(tab1.linkedBrowser); info("Setting up private tab"); - tab2 = yield BrowserTestUtils.openNewForegroundTab(gBrowser); + tab2 = gBrowser.addTab(); + yield promiseBrowserLoaded(tab2.linkedBrowser); yield setUsePrivateBrowsing(tab2.linkedBrowser, true); tab2.linkedBrowser.loadURI(URL_PRIVATE); - yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser, false, URL_PRIVATE); + yield promiseBrowserLoaded(tab2.linkedBrowser); info("Flush to make sure chrome received all data."); yield TabStateFlusher.flush(tab1.linkedBrowser); @@ -30,15 +32,16 @@ add_task(function() { info("Checking out state"); let state = yield promiseRecoveryFileContents(); + info("State: " + state); // Ensure that sessionstore.js only knows about the public tab ok(state.indexOf(URL_PUBLIC) != -1, "State contains public tab"); ok(state.indexOf(URL_PRIVATE) == -1, "State does not contain private tab"); // Ensure that we can close and undo close the public tab but not the private tab - yield BrowserTestUtils.removeTab(tab2); + gBrowser.removeTab(tab2); tab2 = null; - yield BrowserTestUtils.removeTab(tab1); + gBrowser.removeTab(tab1); tab1 = null; tab1 = ss.undoCloseTab(window, 0); @@ -48,10 +51,10 @@ add_task(function() { } finally { if (tab1) { - yield BrowserTestUtils.removeTab(tab1); + gBrowser.removeTab(tab1); } if (tab2) { - yield BrowserTestUtils.removeTab(tab2); + gBrowser.removeTab(tab2); } } }); @@ -64,13 +67,14 @@ add_task(function () { forgetClosedWindows(); // Create a new window to attach our frame script to. - let win = yield BrowserTestUtils.openNewBrowserWindow(); + let win = yield promiseNewWindowLoaded(); let mm = win.getGroupMessageManager("browsers"); mm.loadFrameScript(FRAME_SCRIPT, true); // Create a new tab in the new window that will load the frame script. - let tab = yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:mozilla"); + let tab = win.gBrowser.addTab("about:mozilla"); let browser = tab.linkedBrowser; + yield promiseBrowserLoaded(browser); yield TabStateFlusher.flush(browser); // Check that we consider the tab as private. @@ -78,12 +82,13 @@ add_task(function () { ok(state.isPrivate, "tab considered private"); // Ensure we don't allow restoring closed private tabs in non-private windows. - yield BrowserTestUtils.removeTab(tab); + win.gBrowser.removeTab(tab); is(ss.getClosedTabCount(win), 0, "no tabs to restore"); // Create a new tab in the new window that will load the frame script. - tab = yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:mozilla"); + tab = win.gBrowser.addTab("about:mozilla"); browser = tab.linkedBrowser; + yield promiseBrowserLoaded(browser); yield TabStateFlusher.flush(browser); // Check that we consider the tab as private. @@ -101,11 +106,12 @@ add_task(function () { forgetClosedWindows(); // Create a new window to attach our frame script to. - let win = yield BrowserTestUtils.openNewBrowserWindow({private: true}); + let win = yield promiseNewWindowLoaded({private: true}); // Create a new tab in the new window that will load the frame script. - let tab = yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:mozilla"); + let tab = win.gBrowser.addTab("about:mozilla"); let browser = tab.linkedBrowser; + yield promiseBrowserLoaded(browser); yield TabStateFlusher.flush(browser); // Check that we consider the tab as private. @@ -113,7 +119,7 @@ add_task(function () { ok(state.isPrivate, "tab considered private"); // Ensure that closed tabs in a private windows can be restored. - yield BrowserTestUtils.removeTab(tab); + win.gBrowser.removeTab(tab); is(ss.getClosedTabCount(win), 1, "there is a single tab to restore"); // Ensure that closed private windows can never be restored. diff --git a/browser/components/sessionstore/test/head.js b/browser/components/sessionstore/test/head.js index 5ed7160c2370..565baaeb7461 100644 --- a/browser/components/sessionstore/test/head.js +++ b/browser/components/sessionstore/test/head.js @@ -23,10 +23,6 @@ registerCleanupFunction(() => { for (let script of FRAME_SCRIPTS) { mm.removeDelayedFrameScript(script, true); } - - // Force a garbage collect after the end of each test run, to make sure that it - // won't interfere with the timing of the next test to be run from the suite. - window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).garbageCollect(); }); const {Promise} = Cu.import("resource://gre/modules/Promise.jsm", {}); diff --git a/toolkit/modules/PrivateBrowsingUtils.jsm b/toolkit/modules/PrivateBrowsingUtils.jsm index 6eff48336fb7..6a84eef93fa8 100644 --- a/toolkit/modules/PrivateBrowsingUtils.jsm +++ b/toolkit/modules/PrivateBrowsingUtils.jsm @@ -4,9 +4,7 @@ this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"]; -const {classes: Cc, interfaces: Ci, utils: Cu} = Components; - -Cu.import("resource://gre/modules/Services.jsm"); +Components.utils.import("resource://gre/modules/Services.jsm"); const kAutoStartPref = "browser.privatebrowsing.autostart"; @@ -14,11 +12,14 @@ const kAutoStartPref = "browser.privatebrowsing.autostart"; // line for the current session. var gTemporaryAutoStartMode = false; +const Cc = Components.classes; +const Ci = Components.interfaces; + this.PrivateBrowsingUtils = { // Rather than passing content windows to this function, please use // isBrowserPrivate since it works with e10s. isWindowPrivate: function pbu_isWindowPrivate(aWindow) { - if (!(aWindow instanceof Ci.nsIDOMChromeWindow)) { + if (!(aWindow instanceof Components.interfaces.nsIDOMChromeWindow)) { dump("WARNING: content window passed to PrivateBrowsingUtils.isWindowPrivate. " + "Use isContentWindowPrivate instead (but only for frame scripts).\n" + new Error().stack); @@ -44,15 +45,9 @@ this.PrivateBrowsingUtils = { }, privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) { - let context = { usePrivateBrowsing: false }; - try { - context = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIWebNavigation) - .QueryInterface(Ci.nsILoadContext); - } catch (ex) { - Cu.reportError(ex); - } - return context; + return aWindow.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIWebNavigation) + .QueryInterface(Ci.nsILoadContext); }, addToTrackingAllowlist(aURI) { @@ -86,7 +81,7 @@ this.PrivateBrowsingUtils = { }, whenHiddenPrivateWindowReady: function pbu_whenHiddenPrivateWindowReady(cb) { - Cu.import("resource://gre/modules/Timer.jsm"); + Components.utils.import("resource://gre/modules/Timer.jsm"); let win = Services.appShell.hiddenPrivateDOMWindow; function isNotLoaded() {