michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const NOW = Date.now() * 1000; michael@0: const URL = "http://fake-site.com/"; michael@0: michael@0: let tmp = {}; michael@0: Cc["@mozilla.org/moz/jssubscript-loader;1"] michael@0: .getService(Ci.mozIJSSubScriptLoader) michael@0: .loadSubScript("chrome://browser/content/sanitize.js", tmp); michael@0: michael@0: let {Sanitizer} = tmp; michael@0: michael@0: function runTests() { michael@0: sanitizeHistory(); michael@0: yield addFakeVisits(); michael@0: yield addNewTabPageTab(); michael@0: michael@0: is(getCell(0).site.url, URL, "first site is our fake site"); michael@0: michael@0: whenPagesUpdated(); michael@0: yield sanitizeHistory(); michael@0: michael@0: ok(!getCell(0).site, "the fake site is gone"); michael@0: } michael@0: michael@0: function addFakeVisits() { michael@0: let visits = []; michael@0: for (let i = 59; i > 0; i--) { michael@0: visits.push({ michael@0: visitDate: NOW - i * 60 * 1000000, michael@0: transitionType: Ci.nsINavHistoryService.TRANSITION_LINK michael@0: }); michael@0: } michael@0: let place = { michael@0: uri: makeURI(URL), michael@0: title: "fake site", michael@0: visits: visits michael@0: }; michael@0: PlacesUtils.asyncHistory.updatePlaces(place, { michael@0: handleError: function () ok(false, "couldn't add visit"), michael@0: handleResult: function () {}, michael@0: handleCompletion: function () { michael@0: NewTabUtils.links.populateCache(function () { michael@0: NewTabUtils.allPages.update(); michael@0: TestRunner.next(); michael@0: }, true); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: function sanitizeHistory() { michael@0: let s = new Sanitizer(); michael@0: s.prefDomain = "privacy.cpd."; michael@0: michael@0: let prefs = gPrefService.getBranch(s.prefDomain); michael@0: prefs.setBoolPref("history", true); michael@0: prefs.setBoolPref("downloads", false); michael@0: prefs.setBoolPref("cache", false); michael@0: prefs.setBoolPref("cookies", false); michael@0: prefs.setBoolPref("formdata", false); michael@0: prefs.setBoolPref("offlineApps", false); michael@0: prefs.setBoolPref("passwords", false); michael@0: prefs.setBoolPref("sessions", false); michael@0: prefs.setBoolPref("siteSettings", false); michael@0: michael@0: s.sanitize(); michael@0: }