# HG changeset patch # User Johann Hofmann # Date 1516288118 -3600 # Node ID 93903673b0eb1951970f412fda5c0386a38a7841 # Parent 733a9c8043f43b581892a2944ca820d5a76d5eae Bug 1167238 - Part 6 - Clean up sanitize.js usage in utils.py. r=whimboo We're turning Sanitizer.jsm into a proper module and are simplifying its API surface, and need to adjust all consumers. MozReview-Commit-ID: 7xjSpiKeG7d diff --git a/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/utils.py b/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/utils.py --- a/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/utils.py +++ b/testing/marionette/puppeteer/firefox/firefox_puppeteer/api/utils.py @@ -41,66 +41,39 @@ class Utils(BaseLib): def sanitize(self, data_type): """Sanitize user data, including cache, cookies, offlineApps, history, formdata, downloads, passwords, sessions, siteSettings. Usage: sanitize(): Clears all user data. sanitize({ "sessions": True }): Clears only session user data. - more: https://dxr.mozilla.org/mozilla-central/source/browser/base/content/sanitize.js + more: https://dxr.mozilla.org/mozilla-central/source/browser/modules/Sanitizer.jsm :param data_type: optional, Information specifying data to be sanitized """ with self.marionette.using_context('chrome'): result = self.marionette.execute_async_script(""" - Components.utils.import("resource://gre/modules/Services.jsm"); + var {Sanitizer} = Components.utils.import("resource:///modules/Sanitizer.jsm", {}); var data_type = arguments[0]; - var data_type = (typeof data_type === "undefined") ? {} : { - cache: data_type.cache || false, - cookies: data_type.cookies || false, - downloads: data_type.downloads || false, - formdata: data_type.formdata || false, - history: data_type.history || false, - offlineApps: data_type.offlineApps || false, - passwords: data_type.passwords || false, - sessions: data_type.sessions || false, - siteSettings: data_type.siteSettings || false - }; - - // Load the sanitize script - var tempScope = {}; - Components.classes["@mozilla.org/moz/jssubscript-loader;1"] - .getService(Components.interfaces.mozIJSSubScriptLoader) - .loadSubScript("chrome://browser/content/sanitize.js", tempScope); - - // Instantiate the Sanitizer - var s = new tempScope.Sanitizer(); - s.prefDomain = "privacy.cpd."; - var itemPrefs = Services.prefs.getBranch(s.prefDomain); - // Apply options for what to sanitize - for (var pref in data_type) { - itemPrefs.setBoolPref(pref, data_type[pref]); + var itemsToClear = []; + for (var pref of Object.keys(data_type)) { + if (data_type[pref]) { + itemsToClear.push(pref); + } }; // Sanitize and wait for the promise to resolve - var finished = false; - s.sanitize().then(() => { - for (let pref in data_type) { - itemPrefs.clearUserPref(pref); - }; + Sanitizer.sanitize(itemsToClear).then(() => { marionetteScriptFinished(true); }, aError => { - for (let pref in data_type) { - itemPrefs.clearUserPref(pref); - }; marionetteScriptFinished(false); }); """, script_args=[data_type]) if not result: raise MarionetteException('Sanitizing of profile data failed.')