Bug 1313741 - Use AppConstants in DOM and XPConnect tests instead of manual detection. r=bzbarsky
authorRyan VanderMeulen <ryanvm@gmail.com>
Tue, 14 May 2019 21:01:05 +0000
changeset 532653 51b73cca09ea7dfe1511bede8409dd2260d404aa
parent 532652 7b3a1ee70cd723a6370e0f080f9fa36c2947d0de
child 532654 aedbe6cdd06fdda240d262c366c594a463df71d0
push id11270
push userrgurzau@mozilla.com
push dateWed, 15 May 2019 15:07:19 +0000
treeherdermozilla-beta@571bc76da583 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1313741
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 1313741 - Use AppConstants in DOM and XPConnect tests instead of manual detection. r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D30973
dom/media/tests/mochitest/pc.js
dom/serviceworkers/test/test_serviceworker_interfaces.html
dom/serviceworkers/test/test_serviceworker_interfaces.js
dom/tests/mochitest/general/test_interfaces.js
dom/workers/test/test_navigator_iframe.js
dom/workers/test/test_worker_interfaces.js
dom/workers/test/worker_driver.js
js/xpconnect/tests/chrome/test_xrayToJS.xul
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -2171,20 +2171,19 @@ var setupIceServerConfig = useIceServer 
   return enableHttpProxy(false)
     .then(spawnIceServer)
     .then(iceServersStr => { iceServersArray = JSON.parse(iceServersStr); })
     .then(addTurnsSelfsignedCerts);
 };
 
 async function runNetworkTest(testFunction, fixtureOptions = {}) {
 
-  let version = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].
-    getService(SpecialPowers.Ci.nsIXULAppInfo).version;
-  let isNightly = version.endsWith("a1");
-  let isAndroid = !!navigator.userAgent.includes("Android");
+  let {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
+  let isNightly = AppConstants.NIGHTLY_BUILD;
+  let isAndroid = AppConstants.platform == "android";
 
   await scriptsReady;
   await runTestWhenReady(async options =>
     {
       await startNetworkAndTest();
       await setupIceServerConfig(fixtureOptions.useIceServer);
 
       // currently we set android hardware encoder default enabled in nightly.
--- a/dom/serviceworkers/test/test_serviceworker_interfaces.html
+++ b/dom/serviceworkers/test/test_serviceworker_interfaces.html
@@ -37,30 +37,31 @@
         });
         worker.postMessage({
           type: 'returnPrefs',
           prefs: event.data.prefs,
           result: result
         });
 
       } else if (event.data.type == 'getHelperData') {
-        const version = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
-        const isNightly = version.endsWith("a1");
-        const isEarlyBetaOrEarlier = SpecialPowers.EARLY_BETA_OR_EARLIER;
-        const isRelease = !version.includes("a");
+        const {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
+        const isNightly = AppConstants.NIGHTLY_BUILD;
+        const isEarlyBetaOrEarlier = AppConstants.EARLY_BETA_OR_EARLIER;
+        const isRelease = AppConstants.RELEASE_OR_BETA;
         const isDesktop = !/Mobile|Tablet/.test(navigator.userAgent);
-        const isMac = /Mac OS/.test(navigator.oscpu);
-        const isWindows = /Windows/.test(navigator.oscpu);
-        const isAndroid = navigator.userAgent.includes("Android");
-        const isLinux = /Linux/.test(navigator.oscpu) && !isAndroid;
+        const isMac = AppConstants.platform == "macosx";
+        const isWindows = AppConstants.platform == "win";
+        const isAndroid = AppConstants.platform == "android";
+        const isLinux = AppConstants.platform == "linux";
         const isInsecureContext = !window.isSecureContext;
+        // Currently, MOZ_APP_NAME is always "fennec" for all mobile builds, so we can't use AppConstants for this
         const isFennec = isAndroid && SpecialPowers.Cc["@mozilla.org/android/bridge;1"].getService(SpecialPowers.Ci.nsIAndroidBridge).isFennec;
 
         const result = {
-          version, isNightly, isEarlyBetaOrEarlier, isRelease, isDesktop, isMac,
+          isNightly, isEarlyBetaOrEarlier, isRelease, isDesktop, isMac,
           isWindows, isAndroid, isLinux, isInsecureContext, isFennec
         };
 
         worker.postMessage({
           type: 'returnHelperData', result
         });
       }
     }
--- a/dom/serviceworkers/test/test_serviceworker_interfaces.js
+++ b/dom/serviceworkers/test/test_serviceworker_interfaces.js
@@ -237,17 +237,17 @@ var interfaceNamesInGlobalScope =
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "WorkerLocation",
 // IMPORTANT: Do not change this list without review from a DOM peer!
     "WorkerNavigator",
 // IMPORTANT: Do not change this list without review from a DOM peer!
   ];
 // IMPORTANT: Do not change the list above without review from a DOM peer!
 
-function createInterfaceMap({ version, isNightly, isRelease, isDesktop, isAndroid, isInsecureContext, isFennec }) {
+function createInterfaceMap({ isNightly, isRelease, isDesktop, isAndroid, isInsecureContext, isFennec }) {
   var interfaceMap = {};
 
   function addInterfaces(interfaces)
   {
     for (var entry of interfaces) {
       if (typeof(entry) === "string") {
         interfaceMap[entry] = true;
       } else {
--- a/dom/tests/mochitest/general/test_interfaces.js
+++ b/dom/tests/mochitest/general/test_interfaces.js
@@ -20,26 +20,28 @@
 //
 // See createInterfaceMap() below for a complete list of properties.
 //
 // The values of the properties need to be either literal true/false
 // (e.g. indicating whether something is enabled on a particular
 // channel/OS) or one of the is* constants below (in cases when
 // exposure is affected by channel or OS in a nontrivial way).
 
-const version = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
-const isNightly = version.endsWith("a1");
-const isEarlyBetaOrEarlier = SpecialPowers.EARLY_BETA_OR_EARLIER;
-const isRelease = !version.includes("a");
+const {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
+
+const isNightly = AppConstants.NIGHTLY_BUILD;
+const isEarlyBetaOrEarlier = AppConstants.EARLY_BETA_OR_EARLIER;
+const isRelease = AppConstants.RELEASE_OR_BETA;
 const isDesktop = !/Mobile|Tablet/.test(navigator.userAgent);
-const isMac = /Mac OS/.test(navigator.oscpu);
-const isWindows = /Windows/.test(navigator.oscpu);
-const isAndroid = navigator.userAgent.includes("Android");
-const isLinux = /Linux/.test(navigator.oscpu) && !isAndroid;
+const isMac = AppConstants.platform == "macosx";
+const isWindows = AppConstants.platform == "win";
+const isAndroid = AppConstants.platform == "android";
+const isLinux = AppConstants.platform == "linux";
 const isInsecureContext = !window.isSecureContext;
+// Currently, MOZ_APP_NAME is always "fennec" for all mobile builds, so we can't use AppConstants for this
 const isFennec = isAndroid && SpecialPowers.Cc["@mozilla.org/android/bridge;1"].getService(SpecialPowers.Ci.nsIAndroidBridge).isFennec;
 
 // IMPORTANT: Do not change this list without review from
 //            a JavaScript Engine peer!
 var ecmaGlobals =
   [
     {name: "Array", insecureContext: true},
     {name: "ArrayBuffer", insecureContext: true},
--- a/dom/workers/test/test_navigator_iframe.js
+++ b/dom/workers/test/test_navigator_iframe.js
@@ -41,13 +41,13 @@ worker.onmessage = function(event) {
      "Mismatched navigator string for " + args.name + "!");
 };
 
 worker.onerror = function(event) {
   ok(false, "Worker had an error: " + event.message);
   SimpleTest.finish();
 }
 
-var version = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
-var isNightly = version.endsWith("a1");
-var isRelease = !version.includes("a");
+var {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
+var isNightly = AppConstants.NIGHTLY_BUILD;
+var isRelease = AppConstants.RELEASE_OR_BETA;
 
 worker.postMessage({ isNightly, isRelease });
--- a/dom/workers/test/test_worker_interfaces.js
+++ b/dom/workers/test/test_worker_interfaces.js
@@ -257,17 +257,17 @@ var interfaceNamesInGlobalScope =
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "WorkerLocation", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
     {name: "WorkerNavigator", insecureContext: true},
 // IMPORTANT: Do not change this list without review from a DOM peer!
   ];
 // IMPORTANT: Do not change the list above without review from a DOM peer!
 
-function createInterfaceMap({ version, isNightly, isRelease, isDesktop, isAndroid, isInsecureContext, isFennec }) {
+function createInterfaceMap({ isNightly, isRelease, isDesktop, isAndroid, isInsecureContext, isFennec }) {
   var interfaceMap = {};
 
   function addInterfaces(interfaces)
   {
     for (var entry of interfaces) {
       if (typeof(entry) === "string") {
         interfaceMap[entry] = !isInsecureContext;
       } else {
--- a/dom/workers/test/worker_driver.js
+++ b/dom/workers/test/worker_driver.js
@@ -31,30 +31,31 @@ function workerTestExec(script) {
   worker.onmessage = function(event) {
     if (event.data.type == 'finish') {
       SimpleTest.finish();
 
     } else if (event.data.type == 'status') {
       ok(event.data.status, event.data.msg);
 
     } else if (event.data.type == 'getHelperData') {
-      const version = SpecialPowers.Cc["@mozilla.org/xre/app-info;1"].getService(SpecialPowers.Ci.nsIXULAppInfo).version;
-      const isNightly = version.endsWith("a1");
-      const isEarlyBetaOrEarlier = SpecialPowers.EARLY_BETA_OR_EARLIER;
-      const isRelease = !version.includes("a");
+      const {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
+      const isNightly = AppConstants.NIGHTLY_BUILD;
+      const isEarlyBetaOrEarlier = AppConstants.EARLY_BETA_OR_EARLIER;
+      const isRelease = AppConstants.RELEASE_OR_BETA;
       const isDesktop = !/Mobile|Tablet/.test(navigator.userAgent);
-      const isMac = /Mac OS/.test(navigator.oscpu);
-      const isWindows = /Windows/.test(navigator.oscpu);
-      const isAndroid = navigator.userAgent.includes("Android");
-      const isLinux = /Linux/.test(navigator.oscpu) && !isAndroid;
+      const isMac = AppConstants.platform == "macosx";
+      const isWindows = AppConstants.platform == "win";
+      const isAndroid = AppConstants.platform == "android";
+      const isLinux = AppConstants.platform == "linux";
       const isInsecureContext = !window.isSecureContext;
+      // Currently, MOZ_APP_NAME is always "fennec" for all mobile builds, so we can't use AppConstants for this
       const isFennec = isAndroid && SpecialPowers.Cc["@mozilla.org/android/bridge;1"].getService(SpecialPowers.Ci.nsIAndroidBridge).isFennec;
 
       const result = {
-        version, isNightly, isEarlyBetaOrEarlier, isRelease, isDesktop, isMac,
+        isNightly, isEarlyBetaOrEarlier, isRelease, isDesktop, isMac,
         isWindows, isAndroid, isLinux, isInsecureContext, isFennec
       };
 
       worker.postMessage({
         type: 'returnHelperData', result
       });
     }
   }
--- a/js/xpconnect/tests/chrome/test_xrayToJS.xul
+++ b/js/xpconnect/tests/chrome/test_xrayToJS.xul
@@ -165,19 +165,19 @@ https://bugzilla.mozilla.org/show_bug.cg
     SimpleTest.finish();
   }
 
   // Maintain a static list of the properties that are available on each standard
   // prototype, so that we make sure to audit any new ones to make sure they're
   // Xray-safe.
   //
   // DO NOT CHANGE WTIHOUT REVIEW FROM AN XPCONNECT PEER.
-  var version = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).version;
-  var isNightlyBuild = version.endsWith("a1");
-  var isReleaseOrBeta = !version.includes("a");
+  var {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {});
+  var isNightlyBuild = AppConstants.NIGHTLY_BUILD;
+  var isReleaseOrBeta = AppConstants.RELEASE_OR_BETA;
   var gPrototypeProperties = {};
   var gConstructorProperties = {};
   function constructorProps(arr) {
     // Some props live on all constructors
     return arr.concat(["prototype", "length", "name"]);
   }
   gPrototypeProperties['Date'] =
     ["getTime", "getTimezoneOffset", "getYear", "getFullYear", "getUTCFullYear",