Bug 806744 - Port the satchel test_privbrowsing.html to the new per-tab PB APIs. r=jdm

--HG--
rename : toolkit/components/satchel/test/test_privbrowsing.html => toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js
This commit is contained in:
Mario Alvarado [:marioalv] 2012-12-19 15:08:09 -06:00
parent 48e34b3a88
commit 93f58ad2c1
4 changed files with 95 additions and 0 deletions

View File

@ -12,6 +12,9 @@ relativesrcdir = @relativesrcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = test_satchel
DIRS = \
browser \
$(NULL)
XPCSHELL_TESTS = \
unit \

View File

@ -0,0 +1,25 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
DEPTH = @DEPTH@
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = @relativesrcdir@
include $(DEPTH)/config/autoconf.mk
MOCHITEST_BROWSER_FILES = \
head.js \
../subtst_privbrowsing.html \
$(NULL)
ifdef MOZ_PER_WINDOW_PRIVATE_BROWSING
MOCHITEST_BROWSER_FILES += \
browser_privbrowsing_perwindowpb.js \
$(NULL)
endif
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,59 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/** Test for Bug 472396 **/
function test() {
// initialization
waitForExplicitFinish();
let windowsToClose = [];
let testURI =
"http://example.com/tests/toolkit/components/satchel/test/subtst_privbrowsing.html";
let formHistory = Cc["@mozilla.org/satchel/form-history;1"].
getService(Ci.nsIFormHistory2);
function doTest(aIsPrivateMode, aShouldValueExist, aWindow, aCallback) {
aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
// Wait for the second load of the page to call the callback,
// because the first load submits the form and the page reloads after
// the form submission.
aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
executeSoon(aCallback);
}, true);
is(formHistory.entryExists("field", "value"), aShouldValueExist,
"Checking value exists in form history");
}, true);
aWindow.gBrowser.selectedBrowser.loadURI(testURI);
}
function testOnWindow(aOptions, aCallback) {
whenNewWindowLoaded(aOptions, function(aWin) {
windowsToClose.push(aWin);
executeSoon(function() aCallback(aWin));
});
};
registerCleanupFunction(function() {
windowsToClose.forEach(function(aWin) {
aWin.close();
});
});
testOnWindow({private: true}, function(aWin) {
doTest(true, false, aWin, function() {
// Test when not on private mode after visiting a site on private
// mode. The form history should no exist.
testOnWindow({}, function(aWin) {
doTest(false, false, aWin, function() {
finish();
});
});
});
});
}

View File

@ -0,0 +1,8 @@
function whenNewWindowLoaded(aOptions, aCallback) {
let win = OpenBrowserWindow(aOptions);
win.addEventListener("load", function onLoad() {
win.removeEventListener("load", onLoad, false);
aCallback(win);
}, false);
}