Bug 1167238 - Part 5 - Clean up sanitize.js usage in remaining tests. r=mak
This cleans up all tests that were not moved into the sanitize directory
as part of the previous commit, but still use sanitize.js
MozReview-Commit-ID: 1CVa0ByVYDk
--- a/browser/base/content/test/newtab/browser_newtab_bug722273.js
+++ b/browser/base/content/test/newtab/browser_newtab_bug722273.js
@@ -1,29 +1,24 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const NOW = Date.now() * 1000;
const URL = "http://fake-site.com/";
-var tmp = {};
-Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", tmp);
-
-var {Sanitizer} = tmp;
-
add_task(async function() {
- await promiseSanitizeHistory();
+ await Sanitizer.sanitize(["history"]);
await promiseAddFakeVisits();
await addNewTabPageTab();
let cellUrl = await performOnCell(0, cell => { return cell.site.url; });
is(cellUrl, URL, "first site is our fake site");
let updatedPromise = whenPagesUpdated();
- await promiseSanitizeHistory();
+ await Sanitizer.sanitize(["history"]);
await updatedPromise;
let isGone = await performOnCell(0, cell => { return cell.site == null; });
ok(isGone, "fake site is gone");
});
function promiseAddFakeVisits() {
let visits = [];
@@ -46,26 +41,8 @@ function promiseAddFakeVisits() {
NewTabUtils.links.populateCache(function() {
NewTabUtils.allPages.update();
resolve();
}, true);
}
});
});
}
-
-function promiseSanitizeHistory() {
- let s = new Sanitizer();
- s.prefDomain = "privacy.cpd.";
-
- let prefs = Services.prefs.getBranch(s.prefDomain);
- prefs.setBoolPref("history", true);
- prefs.setBoolPref("downloads", false);
- prefs.setBoolPref("cache", false);
- prefs.setBoolPref("cookies", false);
- prefs.setBoolPref("formdata", false);
- prefs.setBoolPref("offlineApps", false);
- prefs.setBoolPref("passwords", false);
- prefs.setBoolPref("sessions", false);
- prefs.setBoolPref("siteSettings", false);
-
- return s.sanitize();
-}
--- a/browser/base/content/test/newtab/head.js
+++ b/browser/base/content/test/newtab/head.js
@@ -10,22 +10,24 @@ Services.prefs.setBoolPref(PREF_NEWTAB_A
// Opens and closes a new tab to clear any existing preloaded ones. This is
// necessary to prevent any left-over activity-stream preloaded new tabs from
// affecting these tests.
BrowserOpenTab();
const initialTab = gBrowser.selectedTab;
gBrowser.removeTab(initialTab);
-var tmp = {};
-ChromeUtils.import("resource://gre/modules/NewTabUtils.jsm", tmp);
-ChromeUtils.import("resource:///modules/DirectoryLinksProvider.jsm", tmp);
-ChromeUtils.import("resource://testing-common/PlacesTestUtils.jsm", tmp);
-Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", tmp);
-var {NewTabUtils, Sanitizer, DirectoryLinksProvider, PlacesTestUtils} = tmp;
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+ NewTabUtils: "resource://gre/modules/NewTabUtils.jsm",
+ DirectoryLinksProvider: "resource:///modules/DirectoryLinksProvider.jsm",
+ PlacesTestUtils: "resource://testing-common/PlacesTestUtils.jsm",
+ Sanitizer: "resource:///modules/Sanitizer.jsm",
+});
var gWindow = window;
// Default to dummy/empty directory links
var gDirectorySource = 'data:application/json,{"test":1}';
var gOrigDirectorySource;
// The tests assume all 3 rows and all 3 columns of sites are shown, but the
--- a/browser/base/content/test/plugins/browser_clearplugindata.js
+++ b/browser/base/content/test/plugins/browser_clearplugindata.js
@@ -1,26 +1,23 @@
var gTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
var gTestBrowser = null;
-// Test clearing plugin data using sanitize.js.
+// Test clearing plugin data using Sanitizer.jsm.
const testURL1 = gTestRoot + "browser_clearplugindata.html";
const testURL2 = gTestRoot + "browser_clearplugindata_noage.html";
-var tempScope = {};
-Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", tempScope);
-var Sanitizer = tempScope.Sanitizer;
+const {Sanitizer} = ChromeUtils.import("resource:///modules/Sanitizer.jsm", {});
const pluginHostIface = Ci.nsIPluginHost;
var pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
pluginHost.QueryInterface(pluginHostIface);
var pluginTag = getTestPlugin();
-var sanitizer = null;
function stored(needles) {
let something = pluginHost.siteHasData(this.pluginTag, null);
if (!needles)
return something;
if (!something)
return false;
@@ -48,20 +45,17 @@ add_task(async function() {
Services.prefs.setBoolPref("plugins.click_to_play", true);
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Test Plug-in");
setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Second Test Plug-in");
});
function setPrefs(cookies, pluginData) {
- sanitizer = new Sanitizer();
- sanitizer.ignoreTimespan = false;
- sanitizer.prefDomain = "privacy.cpd.";
- let itemPrefs = Services.prefs.getBranch(sanitizer.prefDomain);
+ let itemPrefs = Services.prefs.getBranch("privacy.cpd.");
itemPrefs.setBoolPref("history", false);
itemPrefs.setBoolPref("downloads", false);
itemPrefs.setBoolPref("cache", false);
itemPrefs.setBoolPref("cookies", cookies);
itemPrefs.setBoolPref("formdata", false);
itemPrefs.setBoolPref("offlineApps", false);
itemPrefs.setBoolPref("passwords", false);
itemPrefs.setBoolPref("sessions", false);
@@ -81,38 +75,37 @@ async function testClearingData(url) {
ok(stored(["foo.com", "bar.com", "baz.com", "qux.com"]),
"Data stored for sites");
// Clear 20 seconds ago.
// In the case of testURL2 the plugin will throw
// NS_ERROR_PLUGIN_TIME_RANGE_NOT_SUPPORTED, which should result in us
// clearing all data regardless of age.
let now_uSec = Date.now() * 1000;
- sanitizer.range = [now_uSec - 20 * 1000000, now_uSec];
- await sanitizer.sanitize();
+ let range = [now_uSec - 20 * 1000000, now_uSec];
+ await Sanitizer.sanitize(null, {range, ignoreTimespan: false});
if (url == testURL1) {
ok(stored(["bar.com", "qux.com"]), "Data stored for sites");
ok(!stored(["foo.com"]), "Data cleared for foo.com");
ok(!stored(["baz.com"]), "Data cleared for baz.com");
// Clear everything.
- sanitizer.range = null;
- await sanitizer.sanitize();
+ await Sanitizer.sanitize(null, {ignoreTimespan: false});
}
ok(!stored(null), "All data cleared");
gBrowser.removeCurrentTab();
gTestBrowser = null;
}
add_task(async function() {
- // Test when santizing cookies.
+ // Test when sanitizing cookies.
await setPrefs(true, false);
await testClearingData(testURL1);
await testClearingData(testURL2);
- // Test when santizing pluginData.
+ // Test when sanitizing pluginData.
await setPrefs(false, true);
await testClearingData(testURL1);
await testClearingData(testURL2);
});
--- a/browser/components/originattributes/test/browser/browser_sanitize.js
+++ b/browser/components/originattributes/test/browser/browser_sanitize.js
@@ -1,20 +1,17 @@
/**
* Bug 1270338 - Add a mochitest to ensure Sanitizer clears data for all containers
*/
const { classes: Cc, Constructor: CC, interfaces: Ci, utils: Cu } = Components;
const TEST_DOMAIN = "http://example.net/";
-let tempScope = {};
-Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js",
- tempScope);
-let Sanitizer = tempScope.Sanitizer;
+const {Sanitizer} = ChromeUtils.import("resource:///modules/Sanitizer.jsm", {});
function setCookies(aBrowser) {
ContentTask.spawn(aBrowser, null, function() {
content.document.cookie = "key=value";
});
}
function cacheDataForContext(loadContextInfo) {
@@ -72,14 +69,13 @@ add_task(async function setup() {
});
// This will set the cookies and the cache.
IsolationTestTools.runTests(TEST_DOMAIN, setCookies, () => true);
add_task(checkCacheExists(true));
add_task(async function sanitize() {
- let sanitizer = new Sanitizer();
- await sanitizer.sanitize(["cookies", "cache"]);
+ await Sanitizer.sanitize(["cookies", "cache"]);
});
add_task(checkCacheExists(false));
IsolationTestTools.runTests(TEST_DOMAIN, checkCookiesSanitized, () => true);
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js
@@ -3,67 +3,31 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
// Check about:cache after private browsing
// This test covers MozTrap test 6047
// bug 880621
var tmp = {};
-Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", tmp);
-
-var Sanitizer = tmp.Sanitizer;
+const {Sanitizer} = ChromeUtils.import("resource:///modules/Sanitizer.jsm", {});
function test() {
waitForExplicitFinish();
- sanitizeCache();
+ Sanitizer.sanitize(["cache"], {ignoreTimespan: false});
getStorageEntryCount("regular", function(nrEntriesR1) {
is(nrEntriesR1, 0, "Disk cache reports 0KB and has no entries");
get_cache_for_private_window();
});
}
-function cleanup() {
- let prefs = Services.prefs.getBranch("privacy.cpd.");
-
- prefs.clearUserPref("history");
- prefs.clearUserPref("downloads");
- prefs.clearUserPref("cache");
- prefs.clearUserPref("cookies");
- prefs.clearUserPref("formdata");
- prefs.clearUserPref("offlineApps");
- prefs.clearUserPref("passwords");
- prefs.clearUserPref("sessions");
- prefs.clearUserPref("siteSettings");
-}
-
-function sanitizeCache() {
-
- let s = new Sanitizer();
- s.ignoreTimespan = false;
- s.prefDomain = "privacy.cpd.";
-
- let prefs = Services.prefs.getBranch(s.prefDomain);
- prefs.setBoolPref("history", false);
- prefs.setBoolPref("downloads", false);
- prefs.setBoolPref("cache", true);
- prefs.setBoolPref("cookies", false);
- prefs.setBoolPref("formdata", false);
- prefs.setBoolPref("offlineApps", false);
- prefs.setBoolPref("passwords", false);
- prefs.setBoolPref("sessions", false);
- prefs.setBoolPref("siteSettings", false);
-
- s.sanitize();
-}
-
function getStorageEntryCount(device, goon) {
var storage;
switch (device) {
case "private":
storage = Services.cache2.diskCacheStorage(Services.loadContextInfo.private, false);
break;
case "regular":
storage = Services.cache2.diskCacheStorage(Services.loadContextInfo.default, false);
@@ -105,18 +69,16 @@ function get_cache_for_private_window()
executeSoon(function() {
getStorageEntryCount("private", function(nrEntriesP) {
ok(nrEntriesP >= 1, "Memory cache reports some entries from example.org domain");
getStorageEntryCount("regular", function(nrEntriesR2) {
is(nrEntriesR2, 0, "Disk cache reports 0KB and has no entries");
- cleanup();
-
win.close();
finish();
});
});
});
});
});
});
--- a/toolkit/components/thumbnails/test/browser_thumbnails_storage.js
+++ b/toolkit/components/thumbnails/test/browser_thumbnails_storage.js
@@ -1,19 +1,15 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const URL = "http://mochi.test:8888/";
const URL_COPY = URL + "#copy";
-XPCOMUtils.defineLazyGetter(this, "Sanitizer", function() {
- let tmp = {};
- Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", tmp);
- return tmp.Sanitizer;
-});
+const {Sanitizer} = ChromeUtils.import("resource:///modules/Sanitizer.jsm", {});
/**
* These tests ensure that the thumbnail storage is working as intended.
* Newly captured thumbnails should be saved as files and they should as well
* be removed when the user sanitizes their history.
*/
function* runTests() {
yield (async function() {
@@ -67,40 +63,23 @@ async function promiseClearFile(aFile, a
// is called again.
await PlacesTestUtils.addVisits(makeURI(aURL));
await promiseClearHistory(true);
// Then retry.
return promiseClearFile(aFile, aURL);
}
function promiseClearHistory(aUseRange) {
- let s = new Sanitizer();
- s.prefDomain = "privacy.cpd.";
-
- let prefs = Services.prefs.getBranch(s.prefDomain);
- prefs.setBoolPref("history", true);
- prefs.setBoolPref("downloads", false);
- prefs.setBoolPref("cache", false);
- prefs.setBoolPref("cookies", false);
- prefs.setBoolPref("formdata", false);
- prefs.setBoolPref("offlineApps", false);
- prefs.setBoolPref("passwords", false);
- prefs.setBoolPref("sessions", false);
- prefs.setBoolPref("siteSettings", false);
-
+ let options = {};
if (aUseRange) {
let usec = Date.now() * 1000;
- s.range = [usec - 10 * 60 * 1000 * 1000, usec];
- s.ignoreTimespan = false;
+ options.range = [usec - 10 * 60 * 1000 * 1000, usec];
+ options.ignoreTimespan = false;
}
-
- return s.sanitize().then(() => {
- s.range = null;
- s.ignoreTimespan = true;
- });
+ return Sanitizer.sanitize(["history"], options);
}
function promiseCreateThumbnail() {
return new Promise(resolve => {
addTab(URL, function() {
gBrowserThumbnails.clearTopSiteURLCache();
whenFileExists(URL, function() {
gBrowser.removeTab(gBrowser.selectedTab);