Bug 1733549 - Remove uses of ChromeUtils.import(..., null) in enterprise policy code. r=Standard8,mkaply
authorraquelvargas <raquelvargas@gmail.com>
Fri, 05 Nov 2021 09:49:47 +0000
changeset 598350 c4f862d825ca665ec8fd52b125a1bc2cd8566485
parent 598349 40d6a06abbdd987f5ef4685668f8125d8d7b5a47
child 598351 78d6ea95a82f56d7ab0a11eef586870f45172602
push id38953
push usermlaza@mozilla.com
push dateFri, 05 Nov 2021 21:47:12 +0000
treeherdermozilla-central@019196b56630 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, mkaply
bugs1733549
milestone96.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1733549 - Remove uses of ChromeUtils.import(..., null) in enterprise policy code. r=Standard8,mkaply Differential Revision: https://phabricator.services.mozilla.com/D129649
.eslintrc.js
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/helpers/ProxyPolicies.jsm
browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js
browser/components/enterprisepolicies/tests/xpcshell/test_proxy.js
browser/components/enterprisepolicies/tests/xpcshell/test_runOnce_helper.js
toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -538,20 +538,16 @@ module.exports = {
         "browser/base/content/test/sync/browser_fxa_web_channel.js",
         "browser/components/customizableui/test/browser_1042100_default_placements_update.js",
         "browser/components/customizableui/test/browser_1096763_seen_widgets_post_reset.js",
         "browser/components/customizableui/test/browser_1161838_inserted_new_default_buttons.js",
         "browser/components/customizableui/test/browser_989338_saved_placements_not_resaved.js",
         "browser/components/customizableui/test/browser_currentset_post_reset.js",
         "browser/components/customizableui/test/browser_panel_keyboard_navigation.js",
         "browser/components/customizableui/test/browser_proton_toolbar_hide_toolbarbuttons.js",
-        "browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js",
-        "browser/components/enterprisepolicies/tests/xpcshell/head.js",
-        "browser/components/enterprisepolicies/tests/xpcshell/test_proxy.js",
-        "browser/components/enterprisepolicies/tests/xpcshell/test_runOnce_helper.js",
         "browser/components/migration/tests/unit/test_Edge_db_migration.js",
         "browser/components/translation/test/unit/test_cld2.js",
         "browser/extensions/formautofill/test/unit/test_sync.js",
         "devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js",
         "dom/ipc/tests/browser_memory_distribution_telemetry.js",
         "dom/push/test/xpcshell/head.js",
         "dom/push/test/xpcshell/test_broadcast_success.js",
         "dom/push/test/xpcshell/test_crypto.js",
@@ -564,17 +560,16 @@ module.exports = {
         "services/fxaccounts/tests/xpcshell/test_oauth_tokens.js",
         "services/fxaccounts/tests/xpcshell/test_web_channel.js",
         "services/sync/modules-testing/utils.js",
         "services/sync/tests/unit/test_postqueue.js",
         "toolkit/components/cloudstorage/tests/unit/test_cloudstorage.js",
         "toolkit/components/crashes/tests/xpcshell/test_crash_manager.js",
         "toolkit/components/crashes/tests/xpcshell/test_crash_service.js",
         "toolkit/components/crashes/tests/xpcshell/test_crash_store.js",
-        "toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm",
         "toolkit/components/featuregates/test/unit/test_FeatureGate.js",
         "toolkit/components/normandy/test/browser/browser_actions_ShowHeartbeatAction.js",
         "toolkit/modules/subprocess/test/xpcshell/test_subprocess.js",
         "toolkit/modules/tests/xpcshell/test_GMPInstallManager.js",
         "toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
         "toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
         "toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
         "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js",
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -52,17 +52,22 @@ XPCOMUtils.defineLazyGetter(this, "log",
     prefix: "Policies.jsm",
     // tip: set maxLogLevel to "debug" and use log.debug() to create detailed
     // messages during development. See LOG_LEVELS in Console.jsm for details.
     maxLogLevel: "error",
     maxLogLevelPref: PREF_LOGLEVEL,
   });
 });
 
-var EXPORTED_SYMBOLS = ["Policies"];
+var EXPORTED_SYMBOLS = [
+  "Policies",
+  "setAndLockPref",
+  "PoliciesUtils",
+  "runOnce",
+];
 
 /*
  * ============================
  * = POLICIES IMPLEMENTATIONS =
  * ============================
  *
  * The Policies object below is where the implementation for each policy
  * happens. An object for each policy should be defined, containing
@@ -149,70 +154,70 @@ var Policies = {
   Authentication: {
     onBeforeAddons(manager, param) {
       let locked = true;
       if ("Locked" in param) {
         locked = param.Locked;
       }
 
       if ("SPNEGO" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "network.negotiate-auth.trusted-uris",
           param.SPNEGO.join(", "),
           locked
         );
       }
       if ("Delegated" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "network.negotiate-auth.delegation-uris",
           param.Delegated.join(", "),
           locked
         );
       }
       if ("NTLM" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "network.automatic-ntlm-auth.trusted-uris",
           param.NTLM.join(", "),
           locked
         );
       }
       if ("AllowNonFQDN" in param) {
         if ("NTLM" in param.AllowNonFQDN) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "network.automatic-ntlm-auth.allow-non-fqdn",
             param.AllowNonFQDN.NTLM,
             locked
           );
         }
         if ("SPNEGO" in param.AllowNonFQDN) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "network.negotiate-auth.allow-non-fqdn",
             param.AllowNonFQDN.SPNEGO,
             locked
           );
         }
       }
       if ("AllowProxies" in param) {
         if ("NTLM" in param.AllowProxies) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "network.automatic-ntlm-auth.allow-proxies",
             param.AllowProxies.NTLM,
             locked
           );
         }
         if ("SPNEGO" in param.AllowProxies) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "network.negotiate-auth.allow-proxies",
             param.AllowProxies.SPNEGO,
             locked
           );
         }
       }
       if ("PrivateBrowsing" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "network.auth.private-browsing-sso",
           param.PrivateBrowsing,
           locked
         );
       }
     },
   },
 
@@ -443,49 +448,52 @@ var Policies = {
             newCookieBehavior = REJECT_THIRD_PARTY_COOKIES;
           } else if (param.AcceptThirdParty == "from-visited") {
             newCookieBehavior = REJECT_UNVISITED_THIRD_PARTY;
           }
         } else if (param.RejectTracker !== undefined && param.RejectTracker) {
           newCookieBehavior = REJECT_TRACKER;
         }
 
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "network.cookie.cookieBehavior",
           newCookieBehavior,
           param.Locked
         );
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "network.cookie.cookieBehavior.pbmode",
           newCookieBehavior,
           param.Locked
         );
       }
 
       const KEEP_COOKIES_UNTIL_EXPIRATION = 0;
       const KEEP_COOKIES_UNTIL_END_OF_SESSION = 2;
 
       if (param.ExpireAtSessionEnd !== undefined || param.Locked) {
         let newLifetimePolicy = KEEP_COOKIES_UNTIL_EXPIRATION;
         if (param.ExpireAtSessionEnd) {
           newLifetimePolicy = KEEP_COOKIES_UNTIL_END_OF_SESSION;
         }
 
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "network.cookie.lifetimePolicy",
           newLifetimePolicy,
           param.Locked
         );
       }
     },
   },
 
   DefaultDownloadDirectory: {
     onBeforeAddons(manager, param) {
-      setDefaultPref("browser.download.dir", replacePathVariables(param));
+      PoliciesUtils.setDefaultPref(
+        "browser.download.dir",
+        replacePathVariables(param)
+      );
       // If a custom download directory is being used, just lock folder list to 2.
       setAndLockPref("browser.download.folderList", 2);
     },
   },
 
   DisableAppUpdate: {
     onBeforeAddons(manager, param) {
       if (param) {
@@ -837,23 +845,27 @@ var Policies = {
   DNSOverHTTPS: {
     onBeforeAddons(manager, param) {
       let locked = false;
       if ("Locked" in param) {
         locked = param.Locked;
       }
       if ("Enabled" in param) {
         let mode = param.Enabled ? 2 : 5;
-        setDefaultPref("network.trr.mode", mode, locked);
+        PoliciesUtils.setDefaultPref("network.trr.mode", mode, locked);
       }
       if ("ProviderURL" in param) {
-        setDefaultPref("network.trr.uri", param.ProviderURL.href, locked);
+        PoliciesUtils.setDefaultPref(
+          "network.trr.uri",
+          param.ProviderURL.href,
+          locked
+        );
       }
       if ("ExcludedDomains" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "network.trr.excluded-domains",
           param.ExcludedDomains.join(","),
           locked
         );
       }
     },
   },
 
@@ -872,39 +884,39 @@ var Policies = {
       // if this is set.
       setAndLockPref("browser.download.useDownloadDir", true);
     },
   },
 
   EnableTrackingProtection: {
     onBeforeUIStartup(manager, param) {
       if (param.Value) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "privacy.trackingprotection.enabled",
           true,
           param.Locked
         );
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "privacy.trackingprotection.pbmode.enabled",
           true,
           param.Locked
         );
       } else {
         setAndLockPref("privacy.trackingprotection.enabled", false);
         setAndLockPref("privacy.trackingprotection.pbmode.enabled", false);
       }
       if ("Cryptomining" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "privacy.trackingprotection.cryptomining.enabled",
           param.Cryptomining,
           param.Locked
         );
       }
       if ("Fingerprinting" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "privacy.trackingprotection.fingerprinting.enabled",
           param.Fingerprinting,
           param.Locked
         );
       }
       if ("Exceptions" in param) {
         addAllowDenyPermissions("trackingprotection", param.Exceptions);
       }
@@ -913,17 +925,21 @@ var Policies = {
 
   EncryptedMediaExtensions: {
     onBeforeAddons(manager, param) {
       let locked = false;
       if ("Locked" in param) {
         locked = param.Locked;
       }
       if ("Enabled" in param) {
-        setDefaultPref("media.eme.enabled", param.Enabled, locked);
+        PoliciesUtils.setDefaultPref(
+          "media.eme.enabled",
+          param.Enabled,
+          locked
+        );
       }
     },
   },
 
   Extensions: {
     onBeforeUIStartup(manager, param) {
       let uninstallingPromise = Promise.resolve();
       if ("Uninstall" in param) {
@@ -1101,64 +1117,64 @@ var Policies = {
       }
     },
   },
 
   FirefoxHome: {
     onBeforeAddons(manager, param) {
       let locked = param.Locked || false;
       if ("Search" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.showSearch",
           param.Search,
           locked
         );
       }
       if ("TopSites" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.feeds.topsites",
           param.TopSites,
           locked
         );
       }
       if ("SponsoredTopSites" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.showSponsoredTopSites",
           param.SponsoredTopSites,
           locked
         );
       }
       if ("Highlights" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.feeds.section.highlights",
           param.Highlights,
           locked
         );
       }
       if ("Pocket" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.feeds.system.topstories",
           param.Pocket,
           locked
         );
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.feeds.section.topstories",
           param.Pocket,
           locked
         );
       }
       if ("SponsoredPocket" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.showSponsored",
           param.SponsoredPocket,
           locked
         );
       }
       if ("Snippets" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.feeds.snippets",
           param.Snippets,
           locked
         );
       }
     },
   },
 
@@ -1173,17 +1189,17 @@ var Policies = {
       if (param.Default === undefined || param.Default) {
         flashPrefVal = FLASH_ASK_TO_ACTIVATE;
       } else {
         flashPrefVal = FLASH_NEVER_ACTIVATE;
       }
       if (param.Locked) {
         setAndLockPref("plugin.state.flash", flashPrefVal);
       } else if (param.Default !== undefined) {
-        setDefaultPref("plugin.state.flash", flashPrefVal);
+        PoliciesUtils.setDefaultPref("plugin.state.flash", flashPrefVal);
       }
     },
   },
 
   Handlers: {
     onBeforeAddons(manager, param) {
       if ("mimeTypes" in param) {
         for (let mimeType in param.mimeTypes) {
@@ -1236,17 +1252,21 @@ var Policies = {
       // |homepages| will be a string containing a pipe-separated ('|') list of
       // URLs because that is what the "Home page" section of about:preferences
       // (and therefore what the pref |browser.startup.homepage|) accepts.
       if ("URL" in param) {
         let homepages = param.URL.href;
         if (param.Additional && param.Additional.length) {
           homepages += "|" + param.Additional.map(url => url.href).join("|");
         }
-        setDefaultPref("browser.startup.homepage", homepages, param.Locked);
+        PoliciesUtils.setDefaultPref(
+          "browser.startup.homepage",
+          homepages,
+          param.Locked
+        );
         if (param.Locked) {
           setAndLockPref(
             "pref.browser.homepage.disable_button.current_page",
             true
           );
           setAndLockPref(
             "pref.browser.homepage.disable_button.bookmark_page",
             true
@@ -1271,17 +1291,17 @@ var Policies = {
           case "homepage-locked":
           case "none":
             prefValue = 1;
             break;
           case "previous-session":
             prefValue = 3;
             break;
         }
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.startup.page",
           prefValue,
           param.StartPage == "homepage-locked"
         );
       }
     },
   },
 
@@ -1309,23 +1329,26 @@ var Policies = {
   },
 
   LegacyProfiles: {
     // Handled in nsToolkitProfileService.cpp (Windows only)
   },
 
   LegacySameSiteCookieBehaviorEnabled: {
     onBeforeAddons(manager, param) {
-      setDefaultPref("network.cookie.sameSite.laxByDefault", !param);
+      PoliciesUtils.setDefaultPref(
+        "network.cookie.sameSite.laxByDefault",
+        !param
+      );
     },
   },
 
   LegacySameSiteCookieBehaviorEnabledForDomainList: {
     onBeforeAddons(manager, param) {
-      setDefaultPref(
+      PoliciesUtils.setDefaultPref(
         "network.cookie.sameSite.laxByDefault.disabledHosts",
         param.join(",")
       );
     },
   },
 
   LocalFileLinks: {
     onBeforeAddons(manager, param) {
@@ -1387,17 +1410,17 @@ var Policies = {
   OfferToSaveLoginsDefault: {
     onBeforeUIStartup(manager, param) {
       let policies = Services.policies.getActivePolicies();
       if ("OfferToSaveLogins" in policies) {
         log.error(
           `OfferToSaveLoginsDefault ignored because OfferToSaveLogins is present.`
         );
       } else {
-        setDefaultPref("signon.rememberSignons", param);
+        PoliciesUtils.setDefaultPref("signon.rememberSignons", param);
       }
     },
   },
 
   OverrideFirstRunPage: {
     onProfileAfterChange(manager, param) {
       let url = param ? param : "";
       setAndLockPref("startup.homepage_welcome_url", url);
@@ -1471,17 +1494,17 @@ var Policies = {
               break;
             case "block-audio":
               prefValue = 1;
               break;
             case "block-audio-video":
               prefValue = 5;
               break;
           }
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "media.autoplay.default",
             prefValue,
             param.Autoplay.Locked
           );
         }
       }
 
       if (param.Location) {
@@ -1511,17 +1534,17 @@ var Policies = {
         setDefaultPermission("xr", param.VirtualReality);
       }
     },
   },
 
   PictureInPicture: {
     onBeforeAddons(manager, param) {
       if ("Enabled" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "media.videocontrols.picture-in-picture.video-toggle.enabled",
           param.Enabled
         );
       }
       if (param.Locked) {
         Services.prefs.lockPref(
           "media.videocontrols.picture-in-picture.video-toggle.enabled"
         );
@@ -1535,17 +1558,20 @@ var Policies = {
 
       if (param.Locked) {
         let blockValue = true;
         if (param.Default !== undefined && !param.Default) {
           blockValue = false;
         }
         setAndLockPref("dom.disable_open_during_load", blockValue);
       } else if (param.Default !== undefined) {
-        setDefaultPref("dom.disable_open_during_load", !!param.Default);
+        PoliciesUtils.setDefaultPref(
+          "dom.disable_open_during_load",
+          !!param.Default
+        );
       }
     },
   },
 
   Preferences: {
     onBeforeAddons(manager, param) {
       const allowedPrefixes = [
         "accessibility.",
@@ -1689,17 +1715,20 @@ var Policies = {
   },
 
   Proxy: {
     onBeforeAddons(manager, param) {
       if (param.Locked) {
         manager.disallowFeature("changeProxySettings");
         ProxyPolicies.configureProxySettings(param, setAndLockPref);
       } else {
-        ProxyPolicies.configureProxySettings(param, setDefaultPref);
+        ProxyPolicies.configureProxySettings(
+          param,
+          PoliciesUtils.setDefaultPref
+        );
       }
     },
   },
 
   RequestedLocales: {
     onBeforeAddons(manager, param) {
       let requestedLocales;
       if (Array.isArray(param)) {
@@ -1734,100 +1763,108 @@ var Policies = {
       } else {
         let locked = true;
         // Needed to preserve original behavior in perpetuity.
         let lockDefaultPrefs = true;
         if ("Locked" in param) {
           locked = param.Locked;
           lockDefaultPrefs = false;
         }
-        setDefaultPref("privacy.sanitize.sanitizeOnShutdown", true, locked);
+        PoliciesUtils.setDefaultPref(
+          "privacy.sanitize.sanitizeOnShutdown",
+          true,
+          locked
+        );
         if ("Cache" in param) {
-          setDefaultPref("privacy.clearOnShutdown.cache", param.Cache, locked);
+          PoliciesUtils.setDefaultPref(
+            "privacy.clearOnShutdown.cache",
+            param.Cache,
+            locked
+          );
         } else {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.cache",
             false,
             lockDefaultPrefs
           );
         }
         if ("Cookies" in param) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.cookies",
             param.Cookies,
             locked
           );
         } else {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.cookies",
             false,
             lockDefaultPrefs
           );
         }
         if ("Downloads" in param) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.downloads",
             param.Downloads,
             locked
           );
         } else {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.downloads",
             false,
             lockDefaultPrefs
           );
         }
         if ("FormData" in param) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.formdata",
             param.FormData,
             locked
           );
         } else {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.formdata",
             false,
             lockDefaultPrefs
           );
         }
         if ("History" in param) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.history",
             param.History,
             locked
           );
         } else {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.history",
             false,
             lockDefaultPrefs
           );
         }
         if ("Sessions" in param) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.sessions",
             param.Sessions,
             locked
           );
         } else {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.sessions",
             false,
             lockDefaultPrefs
           );
         }
         if ("SiteSettings" in param) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.siteSettings",
             param.SiteSettings,
             locked
           );
         }
         if ("OfflineApps" in param) {
-          setDefaultPref(
+          PoliciesUtils.setDefaultPref(
             "privacy.clearOnShutdown.offlineApps",
             param.OfflineApps,
             locked
           );
         }
       }
     },
   },
@@ -2091,41 +2128,41 @@ var Policies = {
 
   UserMessaging: {
     onBeforeAddons(manager, param) {
       let locked = false;
       if ("Locked" in param) {
         locked = param.Locked;
       }
       if ("WhatsNew" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.messaging-system.whatsNewPanel.enabled",
           param.WhatsNew,
           locked
         );
       }
       if ("ExtensionRecommendations" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.asrouter.userprefs.cfr.addons",
           param.ExtensionRecommendations,
           locked
         );
       }
       if ("FeatureRecommendations" in param) {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.newtabpage.activity-stream.asrouter.userprefs.cfr.features",
           param.FeatureRecommendations,
           locked
         );
       }
       if ("UrlbarInterventions" in param && !param.UrlbarInterventions) {
         manager.disallowFeature("urlbarinterventions");
       }
       if ("SkipOnboarding") {
-        setDefaultPref(
+        PoliciesUtils.setDefaultPref(
           "browser.aboutwelcome.enabled",
           !param.SkipOnboarding,
           locked
         );
       }
     },
   },
 
@@ -2159,93 +2196,96 @@ var Policies = {
  * The value is only changed in memory, and not stored to disk.
  *
  * @param {string} prefName
  *        The pref to be changed
  * @param {boolean,number,string} prefValue
  *        The value to set and lock
  */
 function setAndLockPref(prefName, prefValue) {
-  setDefaultPref(prefName, prefValue, true);
+  PoliciesUtils.setDefaultPref(prefName, prefValue, true);
 }
 
 /**
  * setDefaultPref
  *
  * Sets the _default_ value of a pref and optionally locks it.
  * The value is only changed in memory, and not stored to disk.
  *
  * @param {string} prefName
  *        The pref to be changed
  * @param {boolean,number,string} prefValue
  *        The value to set
  * @param {boolean} locked
  *        Optionally lock the pref
  */
-function setDefaultPref(prefName, prefValue, locked = false) {
-  if (Services.prefs.prefIsLocked(prefName)) {
-    Services.prefs.unlockPref(prefName);
-  }
 
-  let defaults = Services.prefs.getDefaultBranch("");
+var PoliciesUtils = {
+  setDefaultPref(prefName, prefValue, locked = false) {
+    if (Services.prefs.prefIsLocked(prefName)) {
+      Services.prefs.unlockPref(prefName);
+    }
+
+    let defaults = Services.prefs.getDefaultBranch("");
 
-  switch (typeof prefValue) {
-    case "boolean":
-      defaults.setBoolPref(prefName, prefValue);
-      break;
+    switch (typeof prefValue) {
+      case "boolean":
+        defaults.setBoolPref(prefName, prefValue);
+        break;
 
-    case "number":
-      if (!Number.isInteger(prefValue)) {
-        throw new Error(`Non-integer value for ${prefName}`);
-      }
+      case "number":
+        if (!Number.isInteger(prefValue)) {
+          throw new Error(`Non-integer value for ${prefName}`);
+        }
 
-      // This is ugly, but necessary. On Windows GPO and macOS
-      // configs, booleans are converted to 0/1. In the previous
-      // Preferences implementation, the schema took care of
-      // automatically converting these values to booleans.
-      // Since we allow arbitrary prefs now, we have to do
-      // something different. See bug 1666836.
-      if (
-        defaults.getPrefType(prefName) == defaults.PREF_INT ||
-        ![0, 1].includes(prefValue)
-      ) {
-        defaults.setIntPref(prefName, prefValue);
-      } else {
-        defaults.setBoolPref(prefName, !!prefValue);
-      }
-      break;
+        // This is ugly, but necessary. On Windows GPO and macOS
+        // configs, booleans are converted to 0/1. In the previous
+        // Preferences implementation, the schema took care of
+        // automatically converting these values to booleans.
+        // Since we allow arbitrary prefs now, we have to do
+        // something different. See bug 1666836.
+        if (
+          defaults.getPrefType(prefName) == defaults.PREF_INT ||
+          ![0, 1].includes(prefValue)
+        ) {
+          defaults.setIntPref(prefName, prefValue);
+        } else {
+          defaults.setBoolPref(prefName, !!prefValue);
+        }
+        break;
 
-    case "string":
-      defaults.setStringPref(prefName, prefValue);
-      break;
-  }
+      case "string":
+        defaults.setStringPref(prefName, prefValue);
+        break;
+    }
 
-  if (locked) {
-    Services.prefs.lockPref(prefName);
-  }
-}
+    if (locked) {
+      Services.prefs.lockPref(prefName);
+    }
+  },
+};
 
 /**
  * setDefaultPermission
  *
  * Helper function to set preferences appropriately for the policy
  *
  * @param {string} policyName
  *        The name of the policy to set
  * @param {object} policyParam
  *        The object containing param for the policy
  */
 function setDefaultPermission(policyName, policyParam) {
   if ("BlockNewRequests" in policyParam) {
     let prefName = "permissions.default." + policyName;
 
     if (policyParam.BlockNewRequests) {
-      setDefaultPref(prefName, 2, policyParam.Locked);
+      PoliciesUtils.setDefaultPref(prefName, 2, policyParam.Locked);
     } else {
-      setDefaultPref(prefName, 0, policyParam.Locked);
+      PoliciesUtils.setDefaultPref(prefName, 0, policyParam.Locked);
     }
   }
 }
 
 /**
  * addAllowDenyPermissions
  *
  * Helper function to call the permissions manager (Services.perms.addFromPrincipal)
--- a/browser/components/enterprisepolicies/helpers/ProxyPolicies.jsm
+++ b/browser/components/enterprisepolicies/helpers/ProxyPolicies.jsm
@@ -28,17 +28,17 @@ XPCOMUtils.defineLazyGetter(this, "log",
 var PROXY_TYPES_MAP = new Map([
   ["none", Ci.nsIProtocolProxyService.PROXYCONFIG_DIRECT],
   ["system", Ci.nsIProtocolProxyService.PROXYCONFIG_SYSTEM],
   ["manual", Ci.nsIProtocolProxyService.PROXYCONFIG_MANUAL],
   ["autoDetect", Ci.nsIProtocolProxyService.PROXYCONFIG_WPAD],
   ["autoConfig", Ci.nsIProtocolProxyService.PROXYCONFIG_PAC],
 ]);
 
-var EXPORTED_SYMBOLS = ["ProxyPolicies"];
+var EXPORTED_SYMBOLS = ["ProxyPolicies", "PROXY_TYPES_MAP"];
 
 var ProxyPolicies = {
   configureProxySettings(param, setPref) {
     if (param.Mode) {
       setPref("network.proxy.type", PROXY_TYPES_MAP.get(param.Mode));
     }
 
     if (param.AutoConfigURL) {
--- a/browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js
+++ b/browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js
@@ -1,16 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
-let { Policies, setAndLockPref, setDefaultPref } = ChromeUtils.import(
-  "resource:///modules/policies/Policies.jsm",
-  null
+let { Policies, setAndLockPref, PoliciesUtils } = ChromeUtils.import(
+  "resource:///modules/policies/Policies.jsm"
 );
 
 add_task(async function test_API_directly() {
   await setupPolicyEngineWithJson("");
   setAndLockPref("policies.test.boolPref", true);
   checkLockedPref("policies.test.boolPref", true);
 
   // Check that a previously-locked pref can be changed
@@ -19,17 +18,21 @@ add_task(async function test_API_directl
   checkLockedPref("policies.test.boolPref", false);
 
   setAndLockPref("policies.test.intPref", 2);
   checkLockedPref("policies.test.intPref", 2);
 
   setAndLockPref("policies.test.stringPref", "policies test");
   checkLockedPref("policies.test.stringPref", "policies test");
 
-  setDefaultPref("policies.test.lockedPref", "policies test", true);
+  PoliciesUtils.setDefaultPref(
+    "policies.test.lockedPref",
+    "policies test",
+    true
+  );
   checkLockedPref("policies.test.lockedPref", "policies test");
 
   // Test that user values do not override the prefs, and the get*Pref call
   // still return the value set through setAndLockPref
   Services.prefs.setBoolPref("policies.test.boolPref", true);
   checkLockedPref("policies.test.boolPref", false);
 
   Services.prefs.setIntPref("policies.test.intPref", 10);
@@ -122,19 +125,19 @@ add_task(async function test_pref_tracke
 
   let defaults = Services.prefs.getDefaultBranch("");
 
   // Test prefs that had a default value and got changed to another
   defaults.setIntPref("test1.pref1", 10);
   defaults.setStringPref("test1.pref2", "test");
 
   setAndLockPref("test1.pref1", 20);
-  setDefaultPref("test1.pref2", "NEW VALUE");
+  PoliciesUtils.setDefaultPref("test1.pref2", "NEW VALUE");
   setAndLockPref("test1.pref3", "NEW VALUE");
-  setDefaultPref("test1.pref4", 20);
+  PoliciesUtils.setDefaultPref("test1.pref4", 20);
 
   PoliciesPrefTracker.restoreDefaultValues();
 
   is(
     Services.prefs.getIntPref("test1.pref1"),
     10,
     "Expected value for test1.pref1"
   );
--- a/browser/components/enterprisepolicies/tests/xpcshell/test_proxy.js
+++ b/browser/components/enterprisepolicies/tests/xpcshell/test_proxy.js
@@ -4,18 +4,17 @@
 
 add_task(async function test_proxy_modes_and_autoconfig() {
   // Directly test the proxy Mode and AutoconfigURL parameters through
   // the API instead of the policy engine, because the test harness
   // uses these prefs, and changing them interfere with the harness.
 
   // Checks that every Mode value translates correctly to the expected pref value
   let { ProxyPolicies, PROXY_TYPES_MAP } = ChromeUtils.import(
-    "resource:///modules/policies/ProxyPolicies.jsm",
-    null
+    "resource:///modules/policies/ProxyPolicies.jsm"
   );
 
   for (let [mode, expectedValue] of PROXY_TYPES_MAP) {
     ProxyPolicies.configureProxySettings({ Mode: mode }, (_, value) => {
       equal(value, expectedValue, "Correct proxy mode");
     });
   }
 
--- a/browser/components/enterprisepolicies/tests/xpcshell/test_runOnce_helper.js
+++ b/browser/components/enterprisepolicies/tests/xpcshell/test_runOnce_helper.js
@@ -1,16 +1,15 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 let { runOnce } = ChromeUtils.import(
-  "resource:///modules/policies/Policies.jsm",
-  null
+  "resource:///modules/policies/Policies.jsm"
 );
 
 let runCount = 0;
 function callback() {
   runCount++;
 }
 
 add_task(async function test_runonce_helper() {
--- a/toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
+++ b/toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm
@@ -50,18 +50,17 @@ var EnterprisePolicyTesting = {
       }, "EnterprisePolicies:AllPoliciesApplied");
     });
 
     // Clear any previously used custom schema
     Cu.unload("resource:///modules/policies/schema.jsm");
 
     if (customSchema) {
       let schemaModule = ChromeUtils.import(
-        "resource:///modules/policies/schema.jsm",
-        null
+        "resource:///modules/policies/schema.jsm"
       );
       schemaModule.schema = customSchema;
     }
 
     Services.obs.notifyObservers(null, "EnterprisePolicies:Restart");
     return promise;
   },
 
@@ -103,32 +102,30 @@ var EnterprisePolicyTesting = {
  * that they are restored to their original values when
  * the test ends or another test case restarts the engine.
  */
 var PoliciesPrefTracker = {
   _originalFunc: null,
   _originalValues: new Map(),
 
   start() {
-    let PoliciesBackstage = ChromeUtils.import(
-      "resource:///modules/policies/Policies.jsm",
-      null
+    let { PoliciesUtils } = ChromeUtils.import(
+      "resource:///modules/policies/Policies.jsm"
     );
-    this._originalFunc = PoliciesBackstage.setDefaultPref;
-    PoliciesBackstage.setDefaultPref = this.hoistedSetDefaultPref.bind(this);
+    this._originalFunc = PoliciesUtils.setDefaultPref;
+    PoliciesUtils.setDefaultPref = this.hoistedSetDefaultPref.bind(this);
   },
 
   stop() {
     this.restoreDefaultValues();
 
-    let PoliciesBackstage = ChromeUtils.import(
-      "resource:///modules/policies/Policies.jsm",
-      null
+    let { PoliciesUtils } = ChromeUtils.import(
+      "resource:///modules/policies/Policies.jsm"
     );
-    PoliciesBackstage.setDefaultPref = this._originalFunc;
+    PoliciesUtils.setDefaultPref = this._originalFunc;
     this._originalFunc = null;
   },
 
   hoistedSetDefaultPref(prefName, prefValue, locked = false) {
     // If this pref is seen multiple times, the very first
     // value seen is the one that is actually the default.
     if (!this._originalValues.has(prefName)) {
       let defaults = new Preferences({ defaultBranch: true });