1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +let FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory; 1.9 + 1.10 +/** Test for Bug 472396 **/ 1.11 +function test() { 1.12 + // initialization 1.13 + waitForExplicitFinish(); 1.14 + let windowsToClose = []; 1.15 + let testURI = 1.16 + "http://example.com/tests/toolkit/components/satchel/test/subtst_privbrowsing.html"; 1.17 + 1.18 + function doTest(aIsPrivateMode, aShouldValueExist, aWindow, aCallback) { 1.19 + aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { 1.20 + if (aWindow.content.location != testURI) { 1.21 + aWindow.gBrowser.selectedBrowser.loadURI(testURI); 1.22 + return; 1.23 + } 1.24 + aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); 1.25 + 1.26 + let checks = 0; 1.27 + function doneCheck() { 1.28 + checks++; 1.29 + if (checks == 2) { 1.30 + executeSoon(aCallback); 1.31 + } 1.32 + } 1.33 + 1.34 + // Wait for the second load of the page to call the callback, 1.35 + // because the first load submits the form and the page reloads after 1.36 + // the form submission. 1.37 + aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { 1.38 + aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); 1.39 + doneCheck(); 1.40 + }, true); 1.41 + 1.42 + let count = 0; 1.43 + FormHistory.count({ fieldname: "field", value: "value" }, 1.44 + { handleResult: function(result) { 1.45 + count = result; 1.46 + }, 1.47 + handleError: function (error) { 1.48 + do_throw("Error occurred searching form history: " + error); 1.49 + }, 1.50 + handleCompletion: function(num) { 1.51 + is(count >= 1, aShouldValueExist, "Checking value exists in form history"); 1.52 + doneCheck(); 1.53 + } 1.54 + }); 1.55 + }, true); 1.56 + 1.57 + aWindow.gBrowser.selectedBrowser.loadURI(testURI); 1.58 + } 1.59 + 1.60 + function testOnWindow(aOptions, aCallback) { 1.61 + whenNewWindowLoaded(aOptions, function(aWin) { 1.62 + windowsToClose.push(aWin); 1.63 + executeSoon(function() aCallback(aWin)); 1.64 + }); 1.65 + }; 1.66 + 1.67 + registerCleanupFunction(function() { 1.68 + windowsToClose.forEach(function(aWin) { 1.69 + aWin.close(); 1.70 + }); 1.71 + }); 1.72 + 1.73 + 1.74 + testOnWindow({private: true}, function(aWin) { 1.75 + doTest(true, false, aWin, function() { 1.76 + // Test when not on private mode after visiting a site on private 1.77 + // mode. The form history should no exist. 1.78 + testOnWindow({}, function(aWin) { 1.79 + doTest(false, false, aWin, function() { 1.80 + finish(); 1.81 + }); 1.82 + }); 1.83 + }); 1.84 + }); 1.85 +}