diff --git a/toolkit/components/satchel/test/Makefile.in b/toolkit/components/satchel/test/Makefile.in index c2cae96c342..a3f92fc4832 100644 --- a/toolkit/components/satchel/test/Makefile.in +++ b/toolkit/components/satchel/test/Makefile.in @@ -12,6 +12,9 @@ relativesrcdir = @relativesrcdir@ include $(DEPTH)/config/autoconf.mk MODULE = test_satchel +DIRS = \ + browser \ + $(NULL) XPCSHELL_TESTS = \ unit \ diff --git a/toolkit/components/satchel/test/browser/Makefile.in b/toolkit/components/satchel/test/browser/Makefile.in new file mode 100644 index 00000000000..93b26d953b4 --- /dev/null +++ b/toolkit/components/satchel/test/browser/Makefile.in @@ -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 + diff --git a/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js b/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js new file mode 100644 index 00000000000..d6dd7299315 --- /dev/null +++ b/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js @@ -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(); + }); + }); + }); + }); +} diff --git a/toolkit/components/satchel/test/browser/head.js b/toolkit/components/satchel/test/browser/head.js new file mode 100644 index 00000000000..e10222e4ea7 --- /dev/null +++ b/toolkit/components/satchel/test/browser/head.js @@ -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); +}