зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1252376 - refactor browser_privatetabs.js to use BrowserTestUtils instead of using less deterministic methods and make sure to garbage collect, forcibly, after each sessionstore mochitest ended. r=Gijs
MozReview-Commit-ID: BgYllazwzLp --HG-- extra : rebase_source : a4d75ac6a4d6bcd5fa3370f2cbcc7aa5a36529e1
This commit is contained in:
Родитель
d892209f99
Коммит
ad5c134dfa
|
@ -15,15 +15,13 @@ add_task(function() {
|
|||
try {
|
||||
// Setup a public tab and a private tab
|
||||
info("Setting up public tab");
|
||||
tab1 = gBrowser.addTab(URL_PUBLIC);
|
||||
yield promiseBrowserLoaded(tab1.linkedBrowser);
|
||||
tab1 = yield BrowserTestUtils.openNewForegroundTab(gBrowser, URL_PUBLIC);
|
||||
|
||||
info("Setting up private tab");
|
||||
tab2 = gBrowser.addTab();
|
||||
yield promiseBrowserLoaded(tab2.linkedBrowser);
|
||||
tab2 = yield BrowserTestUtils.openNewForegroundTab(gBrowser);
|
||||
yield setUsePrivateBrowsing(tab2.linkedBrowser, true);
|
||||
tab2.linkedBrowser.loadURI(URL_PRIVATE);
|
||||
yield promiseBrowserLoaded(tab2.linkedBrowser);
|
||||
yield BrowserTestUtils.browserLoaded(tab2.linkedBrowser, false, URL_PRIVATE);
|
||||
|
||||
info("Flush to make sure chrome received all data.");
|
||||
yield TabStateFlusher.flush(tab1.linkedBrowser);
|
||||
|
@ -32,16 +30,15 @@ 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
|
||||
gBrowser.removeTab(tab2);
|
||||
yield BrowserTestUtils.removeTab(tab2);
|
||||
tab2 = null;
|
||||
|
||||
gBrowser.removeTab(tab1);
|
||||
yield BrowserTestUtils.removeTab(tab1);
|
||||
tab1 = null;
|
||||
|
||||
tab1 = ss.undoCloseTab(window, 0);
|
||||
|
@ -51,10 +48,10 @@ add_task(function() {
|
|||
|
||||
} finally {
|
||||
if (tab1) {
|
||||
gBrowser.removeTab(tab1);
|
||||
yield BrowserTestUtils.removeTab(tab1);
|
||||
}
|
||||
if (tab2) {
|
||||
gBrowser.removeTab(tab2);
|
||||
yield BrowserTestUtils.removeTab(tab2);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -67,14 +64,13 @@ add_task(function () {
|
|||
forgetClosedWindows();
|
||||
|
||||
// Create a new window to attach our frame script to.
|
||||
let win = yield promiseNewWindowLoaded();
|
||||
let win = yield BrowserTestUtils.openNewBrowserWindow();
|
||||
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 = win.gBrowser.addTab("about:mozilla");
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:mozilla");
|
||||
let browser = tab.linkedBrowser;
|
||||
yield promiseBrowserLoaded(browser);
|
||||
yield TabStateFlusher.flush(browser);
|
||||
|
||||
// Check that we consider the tab as private.
|
||||
|
@ -82,13 +78,12 @@ add_task(function () {
|
|||
ok(state.isPrivate, "tab considered private");
|
||||
|
||||
// Ensure we don't allow restoring closed private tabs in non-private windows.
|
||||
win.gBrowser.removeTab(tab);
|
||||
yield BrowserTestUtils.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 = win.gBrowser.addTab("about:mozilla");
|
||||
tab = yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:mozilla");
|
||||
browser = tab.linkedBrowser;
|
||||
yield promiseBrowserLoaded(browser);
|
||||
yield TabStateFlusher.flush(browser);
|
||||
|
||||
// Check that we consider the tab as private.
|
||||
|
@ -106,12 +101,11 @@ add_task(function () {
|
|||
forgetClosedWindows();
|
||||
|
||||
// Create a new window to attach our frame script to.
|
||||
let win = yield promiseNewWindowLoaded({private: true});
|
||||
let win = yield BrowserTestUtils.openNewBrowserWindow({private: true});
|
||||
|
||||
// Create a new tab in the new window that will load the frame script.
|
||||
let tab = win.gBrowser.addTab("about:mozilla");
|
||||
let tab = yield BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:mozilla");
|
||||
let browser = tab.linkedBrowser;
|
||||
yield promiseBrowserLoaded(browser);
|
||||
yield TabStateFlusher.flush(browser);
|
||||
|
||||
// Check that we consider the tab as private.
|
||||
|
@ -119,7 +113,7 @@ add_task(function () {
|
|||
ok(state.isPrivate, "tab considered private");
|
||||
|
||||
// Ensure that closed tabs in a private windows can be restored.
|
||||
win.gBrowser.removeTab(tab);
|
||||
yield BrowserTestUtils.removeTab(tab);
|
||||
is(ss.getClosedTabCount(win), 1, "there is a single tab to restore");
|
||||
|
||||
// Ensure that closed private windows can never be restored.
|
||||
|
|
|
@ -23,6 +23,10 @@ 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", {});
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
this.EXPORTED_SYMBOLS = ["PrivateBrowsingUtils"];
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const kAutoStartPref = "browser.privatebrowsing.autostart";
|
||||
|
||||
|
@ -12,14 +14,11 @@ 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 Components.interfaces.nsIDOMChromeWindow)) {
|
||||
if (!(aWindow instanceof Ci.nsIDOMChromeWindow)) {
|
||||
dump("WARNING: content window passed to PrivateBrowsingUtils.isWindowPrivate. " +
|
||||
"Use isContentWindowPrivate instead (but only for frame scripts).\n"
|
||||
+ new Error().stack);
|
||||
|
@ -45,9 +44,15 @@ this.PrivateBrowsingUtils = {
|
|||
},
|
||||
|
||||
privacyContextFromWindow: function pbu_privacyContextFromWindow(aWindow) {
|
||||
return aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
let context = { usePrivateBrowsing: false };
|
||||
try {
|
||||
context = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsILoadContext);
|
||||
} catch (ex) {
|
||||
Cu.reportError(ex);
|
||||
}
|
||||
return context;
|
||||
},
|
||||
|
||||
addToTrackingAllowlist(aURI) {
|
||||
|
@ -81,7 +86,7 @@ this.PrivateBrowsingUtils = {
|
|||
},
|
||||
|
||||
whenHiddenPrivateWindowReady: function pbu_whenHiddenPrivateWindowReady(cb) {
|
||||
Components.utils.import("resource://gre/modules/Timer.jsm");
|
||||
Cu.import("resource://gre/modules/Timer.jsm");
|
||||
|
||||
let win = Services.appShell.hiddenPrivateDOMWindow;
|
||||
function isNotLoaded() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче