|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 let FormHistory = (Components.utils.import("resource://gre/modules/FormHistory.jsm", {})).FormHistory; |
|
6 |
|
7 /** Test for Bug 472396 **/ |
|
8 function test() { |
|
9 // initialization |
|
10 waitForExplicitFinish(); |
|
11 let windowsToClose = []; |
|
12 let testURI = |
|
13 "http://example.com/tests/toolkit/components/satchel/test/subtst_privbrowsing.html"; |
|
14 |
|
15 function doTest(aIsPrivateMode, aShouldValueExist, aWindow, aCallback) { |
|
16 aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
|
17 if (aWindow.content.location != testURI) { |
|
18 aWindow.gBrowser.selectedBrowser.loadURI(testURI); |
|
19 return; |
|
20 } |
|
21 aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
|
22 |
|
23 let checks = 0; |
|
24 function doneCheck() { |
|
25 checks++; |
|
26 if (checks == 2) { |
|
27 executeSoon(aCallback); |
|
28 } |
|
29 } |
|
30 |
|
31 // Wait for the second load of the page to call the callback, |
|
32 // because the first load submits the form and the page reloads after |
|
33 // the form submission. |
|
34 aWindow.gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
|
35 aWindow.gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
|
36 doneCheck(); |
|
37 }, true); |
|
38 |
|
39 let count = 0; |
|
40 FormHistory.count({ fieldname: "field", value: "value" }, |
|
41 { handleResult: function(result) { |
|
42 count = result; |
|
43 }, |
|
44 handleError: function (error) { |
|
45 do_throw("Error occurred searching form history: " + error); |
|
46 }, |
|
47 handleCompletion: function(num) { |
|
48 is(count >= 1, aShouldValueExist, "Checking value exists in form history"); |
|
49 doneCheck(); |
|
50 } |
|
51 }); |
|
52 }, true); |
|
53 |
|
54 aWindow.gBrowser.selectedBrowser.loadURI(testURI); |
|
55 } |
|
56 |
|
57 function testOnWindow(aOptions, aCallback) { |
|
58 whenNewWindowLoaded(aOptions, function(aWin) { |
|
59 windowsToClose.push(aWin); |
|
60 executeSoon(function() aCallback(aWin)); |
|
61 }); |
|
62 }; |
|
63 |
|
64 registerCleanupFunction(function() { |
|
65 windowsToClose.forEach(function(aWin) { |
|
66 aWin.close(); |
|
67 }); |
|
68 }); |
|
69 |
|
70 |
|
71 testOnWindow({private: true}, function(aWin) { |
|
72 doTest(true, false, aWin, function() { |
|
73 // Test when not on private mode after visiting a site on private |
|
74 // mode. The form history should no exist. |
|
75 testOnWindow({}, function(aWin) { |
|
76 doTest(false, false, aWin, function() { |
|
77 finish(); |
|
78 }); |
|
79 }); |
|
80 }); |
|
81 }); |
|
82 } |