|
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 XPCOMUtils.defineLazyModuleGetter(this, "FormHistory", |
|
6 "resource://gre/modules/FormHistory.jsm"); |
|
7 |
|
8 function test() { |
|
9 waitForExplicitFinish(); |
|
10 |
|
11 // This test relies on the form history being empty to start with delete |
|
12 // all the items first. |
|
13 FormHistory.update({ op: "remove" }, |
|
14 { handleError: function (error) { |
|
15 do_throw("Error occurred updating form history: " + error); |
|
16 }, |
|
17 handleCompletion: function (reason) { if (!reason) test2(); }, |
|
18 }); |
|
19 } |
|
20 |
|
21 function test2() |
|
22 { |
|
23 let prefService = Cc["@mozilla.org/preferences-service;1"] |
|
24 .getService(Components.interfaces.nsIPrefBranch2); |
|
25 |
|
26 let findBar = gFindBar; |
|
27 let textbox = gFindBar.getElement("findbar-textbox"); |
|
28 |
|
29 let tempScope = {}; |
|
30 Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader) |
|
31 .loadSubScript("chrome://browser/content/sanitize.js", tempScope); |
|
32 let Sanitizer = tempScope.Sanitizer; |
|
33 let s = new Sanitizer(); |
|
34 s.prefDomain = "privacy.cpd."; |
|
35 let prefBranch = prefService.getBranch(s.prefDomain); |
|
36 |
|
37 prefBranch.setBoolPref("cache", false); |
|
38 prefBranch.setBoolPref("cookies", false); |
|
39 prefBranch.setBoolPref("downloads", false); |
|
40 prefBranch.setBoolPref("formdata", true); |
|
41 prefBranch.setBoolPref("history", false); |
|
42 prefBranch.setBoolPref("offlineApps", false); |
|
43 prefBranch.setBoolPref("passwords", false); |
|
44 prefBranch.setBoolPref("sessions", false); |
|
45 prefBranch.setBoolPref("siteSettings", false); |
|
46 |
|
47 // Sanitize now so we can test that canClear is correct. Formdata is cleared asynchronously. |
|
48 s.sanitize().then(function() { |
|
49 s.canClearItem("formdata", clearDone1, s); |
|
50 }); |
|
51 } |
|
52 |
|
53 function clearDone1(aItemName, aResult, aSanitizer) |
|
54 { |
|
55 ok(!aResult, "pre-test baseline for sanitizer"); |
|
56 gFindBar.getElement("findbar-textbox").value = "m"; |
|
57 aSanitizer.canClearItem("formdata", inputEntered, aSanitizer); |
|
58 } |
|
59 |
|
60 function inputEntered(aItemName, aResult, aSanitizer) |
|
61 { |
|
62 ok(aResult, "formdata can be cleared after input"); |
|
63 aSanitizer.sanitize().then(function() { |
|
64 aSanitizer.canClearItem("formdata", clearDone2); |
|
65 }); |
|
66 } |
|
67 |
|
68 function clearDone2(aItemName, aResult) |
|
69 { |
|
70 is(gFindBar.getElement("findbar-textbox").value, "", "findBar textbox should be empty after sanitize"); |
|
71 ok(!aResult, "canClear now false after sanitize"); |
|
72 finish(); |
|
73 } |