Bug 1436851 - Prevent AddonTestUtils.jsm from overriding a pref value draft
authorKirk Steuber <ksteuber@mozilla.com>
Wed, 14 Feb 2018 14:55:27 -0800
changeset 763270 36b90814f04c1bab00e02e63f7675a6bf9d08ae6
parent 763269 8d77889b6712e1dc9739fab17c6d2013acf60e29
child 763271 dcc24cd242b9b2bc757dab89240ffb170ee6d12b
child 763859 49a49423b2f0e168b280ace047877768030574da
push id101390
push userksteuber@mozilla.com
push dateMon, 05 Mar 2018 18:18:23 +0000
bugs1436851
milestone60.0a1
Bug 1436851 - Prevent AddonTestUtils.jsm from overriding a pref value AddonTestUtils.overrideBuiltIns sets |security.turn_off_all_security_so_that_viruses_can_take_over_this_computer| to true when it starts. It then naively sets it to false, assuming that that was the original value. This patch simply corrects that behavior to return the value to the previously set value, whatever that may have been. MozReview-Commit-ID: KbhmoixBvpW
toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
--- a/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonTestUtils.jsm
@@ -1281,28 +1281,29 @@ var AddonTestUtils = {
    * Override chrome URL for specifying allowed built-in add-ons.
    *
    * @param {object} data - An object specifying which add-on IDs are permitted
    *                        to load, for instance: { "system": ["id1", "..."] }
    */
   async overrideBuiltIns(data) {
     // We need to set this in order load the URL preloader service, which
     // is only possible when running in automation.
+    let prevPrefVal = Services.prefs.getBoolPref(PREF_DISABLE_SECURITY, false);
     Services.prefs.setBoolPref(PREF_DISABLE_SECURITY, true);
     aomStartup.initializeURLPreloader();
 
     let file = FileUtils.getFile("TmpD", "override.txt");
     let manifest = Services.io.newFileURI(file);
     await OS.File.writeAtomic(file.path,
       new TextEncoder().encode(JSON.stringify(data)));
     this.overrideEntry = aomStartup.registerChrome(manifest, [
       ["override", "chrome://browser/content/built_in_addons.json",
        Services.io.newFileURI(file).spec],
     ]);
-    Services.prefs.setBoolPref(PREF_DISABLE_SECURITY, false);
+    Services.prefs.setBoolPref(PREF_DISABLE_SECURITY, prevPrefVal);
   }
 };
 
 for (let [key, val] of Object.entries(AddonTestUtils)) {
   if (typeof val == "function")
     AddonTestUtils[key] = val.bind(AddonTestUtils);
 }