michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: let FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory; michael@0: michael@0: /** Test for Bug 472396 **/ michael@0: function test() { michael@0: // initialization michael@0: waitForExplicitFinish(); michael@0: let windowsToClose = []; michael@0: let testURI = michael@0: "http://example.com/tests/toolkit/components/satchel/test/subtst_privbrowsing.html"; michael@0: michael@0: function doTest(aIsPrivateMode, aShouldValueExist, aWindow, aCallback) { michael@0: aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: if (aWindow.content.location != testURI) { michael@0: aWindow.gBrowser.selectedBrowser.loadURI(testURI); michael@0: return; michael@0: } michael@0: aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: michael@0: let checks = 0; michael@0: function doneCheck() { michael@0: checks++; michael@0: if (checks == 2) { michael@0: executeSoon(aCallback); michael@0: } michael@0: } michael@0: michael@0: // Wait for the second load of the page to call the callback, michael@0: // because the first load submits the form and the page reloads after michael@0: // the form submission. michael@0: aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { michael@0: aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); michael@0: doneCheck(); michael@0: }, true); michael@0: michael@0: let count = 0; michael@0: FormHistory.count({ fieldname: "field", value: "value" }, michael@0: { handleResult: function(result) { michael@0: count = result; michael@0: }, michael@0: handleError: function (error) { michael@0: do_throw("Error occurred searching form history: " + error); michael@0: }, michael@0: handleCompletion: function(num) { michael@0: is(count >= 1, aShouldValueExist, "Checking value exists in form history"); michael@0: doneCheck(); michael@0: } michael@0: }); michael@0: }, true); michael@0: michael@0: aWindow.gBrowser.selectedBrowser.loadURI(testURI); michael@0: } michael@0: michael@0: function testOnWindow(aOptions, aCallback) { michael@0: whenNewWindowLoaded(aOptions, function(aWin) { michael@0: windowsToClose.push(aWin); michael@0: executeSoon(function() aCallback(aWin)); michael@0: }); michael@0: }; michael@0: michael@0: registerCleanupFunction(function() { michael@0: windowsToClose.forEach(function(aWin) { michael@0: aWin.close(); michael@0: }); michael@0: }); michael@0: michael@0: michael@0: testOnWindow({private: true}, function(aWin) { michael@0: doTest(true, false, aWin, function() { michael@0: // Test when not on private mode after visiting a site on private michael@0: // mode. The form history should no exist. michael@0: testOnWindow({}, function(aWin) { michael@0: doTest(false, false, aWin, function() { michael@0: finish(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }