Bug 1551072 - Need xpcshell check in addition to automation. r=Felipe
authorMichael Kaply <mozilla@kaply.com>
Mon, 13 May 2019 01:21:40 +0000
changeset 532405 7bb36c2fe72cbc073b1fdd64da8bc15ec5ec8d87
parent 532404 a0d20ab6be8b779fdd96a14f0cfd07ffe73c8e3d
child 532406 87e01787d465cfcb89c0e593685c15d43a30f61e
push id11268
push usercsabou@mozilla.com
push dateTue, 14 May 2019 15:24:22 +0000
treeherdermozilla-beta@5fb7fcd568d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersFelipe
bugs1551072
milestone68.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 1551072 - Need xpcshell check in addition to automation. r=Felipe Differential Revision: https://phabricator.services.mozilla.com/D30812
toolkit/components/enterprisepolicies/EnterprisePolicies.js
--- a/toolkit/components/enterprisepolicies/EnterprisePolicies.js
+++ b/toolkit/components/enterprisepolicies/EnterprisePolicies.js
@@ -39,16 +39,19 @@ XPCOMUtils.defineLazyGetter(this, "log",
     prefix: "Enterprise Policies",
     // 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,
   });
 });
 
+let env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
+const isXpcshell = env.exists("XPCSHELL_TEST_PROFILE_DIR");
+
 function EnterprisePoliciesManager() {
   Services.obs.addObserver(this, "profile-after-change", true);
   Services.obs.addObserver(this, "final-ui-startup", true);
   Services.obs.addObserver(this, "sessionstore-windows-restored", true);
   Services.obs.addObserver(this, "EnterprisePolicies:Restart", true);
 }
 
 EnterprisePoliciesManager.prototype = {
@@ -331,17 +334,17 @@ function areEnterpriseOnlyPoliciesAllowe
   if (Services.prefs.getBoolPref(PREF_DISALLOW_ENTERPRISE, false)) {
     // This is used as an override to test the "enterprise_only"
     // functionality itself on tests, which would always return
     // true due to the Cu.isInAutomation check below.
     return false;
   }
 
   if (AppConstants.MOZ_UPDATE_CHANNEL != "release" ||
-      Cu.isInAutomation) {
+      Cu.isInAutomation || isXpcshell) {
     return true;
   }
 
   return false;
 }
 
 /*
  * JSON PROVIDER OF POLICIES
@@ -383,17 +386,17 @@ class JSONPoliciesProvider {
     let alternatePath = Services.prefs.getStringPref(PREF_ALTERNATE_PATH, "");
 
     // Check if we are in automation *before* we use the synchronous
     // nsIFile.exists() function or allow the config file to be overriden
     // An alternate policy path can also be used in Nightly builds (for
     // testing purposes), but the Background Update Agent will be unable to
     // detect the alternate policy file so the DisableAppUpdate policy may not
     // work as expected.
-    if (alternatePath && (Cu.isInAutomation || AppConstants.NIGHTLY_BUILD) &&
+    if (alternatePath && (Cu.isInAutomation || AppConstants.NIGHTLY_BUILD || isXpcshell) &&
         (!configFile || !configFile.exists())) {
       if (alternatePath.startsWith(MAGIC_TEST_ROOT_PREFIX)) {
         // Intentionally not using a default value on this pref lookup. If no
         // test root is set, we are not currently testing and this function
         // should throw rather than returning something.
         let testRoot = Services.prefs.getStringPref(PREF_TEST_ROOT);
         let relativePath = alternatePath.substring(MAGIC_TEST_ROOT_PREFIX.length);
         if (AppConstants.platform == "win") {