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: XPCOMUtils.defineLazyModuleGetter(this, "FormHistory", michael@0: "resource://gre/modules/FormHistory.jsm"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: // This test relies on the form history being empty to start with delete michael@0: // all the items first. michael@0: FormHistory.update({ op: "remove" }, michael@0: { handleError: function (error) { michael@0: do_throw("Error occurred updating form history: " + error); michael@0: }, michael@0: handleCompletion: function (reason) { if (!reason) test2(); }, michael@0: }); michael@0: } michael@0: michael@0: function test2() michael@0: { michael@0: let prefService = Cc["@mozilla.org/preferences-service;1"] michael@0: .getService(Components.interfaces.nsIPrefBranch2); michael@0: michael@0: let findBar = gFindBar; michael@0: let textbox = gFindBar.getElement("findbar-textbox"); michael@0: michael@0: let tempScope = {}; michael@0: Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader) michael@0: .loadSubScript("chrome://browser/content/sanitize.js", tempScope); michael@0: let Sanitizer = tempScope.Sanitizer; michael@0: let s = new Sanitizer(); michael@0: s.prefDomain = "privacy.cpd."; michael@0: let prefBranch = prefService.getBranch(s.prefDomain); michael@0: michael@0: prefBranch.setBoolPref("cache", false); michael@0: prefBranch.setBoolPref("cookies", false); michael@0: prefBranch.setBoolPref("downloads", false); michael@0: prefBranch.setBoolPref("formdata", true); michael@0: prefBranch.setBoolPref("history", false); michael@0: prefBranch.setBoolPref("offlineApps", false); michael@0: prefBranch.setBoolPref("passwords", false); michael@0: prefBranch.setBoolPref("sessions", false); michael@0: prefBranch.setBoolPref("siteSettings", false); michael@0: michael@0: // Sanitize now so we can test that canClear is correct. Formdata is cleared asynchronously. michael@0: s.sanitize().then(function() { michael@0: s.canClearItem("formdata", clearDone1, s); michael@0: }); michael@0: } michael@0: michael@0: function clearDone1(aItemName, aResult, aSanitizer) michael@0: { michael@0: ok(!aResult, "pre-test baseline for sanitizer"); michael@0: gFindBar.getElement("findbar-textbox").value = "m"; michael@0: aSanitizer.canClearItem("formdata", inputEntered, aSanitizer); michael@0: } michael@0: michael@0: function inputEntered(aItemName, aResult, aSanitizer) michael@0: { michael@0: ok(aResult, "formdata can be cleared after input"); michael@0: aSanitizer.sanitize().then(function() { michael@0: aSanitizer.canClearItem("formdata", clearDone2); michael@0: }); michael@0: } michael@0: michael@0: function clearDone2(aItemName, aResult) michael@0: { michael@0: is(gFindBar.getElement("findbar-textbox").value, "", "findBar textbox should be empty after sanitize"); michael@0: ok(!aResult, "canClear now false after sanitize"); michael@0: finish(); michael@0: }