Bug 1441904 : Test that TelemetryEnvironment gets the device data properly on Android. , r?chutten draft
authorakriti <akriti.v10@gmail.com>
Tue, 17 Apr 2018 18:48:33 +0530
changeset 783606 8b484a0b12c30c2501f417684499d9e144aec714
parent 779350 15678b283f0f62b7a27afba6e572ef8961d46c69
push id106730
push userbmo:akriti.v10@gmail.com
push dateTue, 17 Apr 2018 13:21:58 +0000
reviewerschutten
bugs1441904
milestone61.0a1
Bug 1441904 : Test that TelemetryEnvironment gets the device data properly on Android. , r?chutten MozReview-Commit-ID: 16yYT2q95Q0
toolkit/components/telemetry/tests/unit/test_TelemetryAndroidEnvironment.js
toolkit/components/telemetry/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryAndroidEnvironment.js
@@ -0,0 +1,70 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+*/
+/* Android-only TelemetryEnvironment xpcshell test that ensures that the device data is stored in the Environment.
+*/
+
+
+ChromeUtils.import("resource://gre/modules/TelemetryEnvironment.jsm", this);
+
+
+/**
+ * Check that a value is a string and not empty.
+ *
+ * @param aValue The variable to check.
+ * @return True if |aValue| has type "string" and is not empty, False otherwise.
+ */
+function checkString(aValue) {
+  return (typeof aValue == "string") && (aValue != "");
+}
+
+/**
+ * If value is non-null, check if it's a valid string.
+ *
+ * @param aValue The variable to check.
+ * @return True if it's null or a valid string, false if it's non-null and an invalid
+ *         string.
+ */
+function checkNullOrString(aValue) {
+  if (aValue) {
+    return checkString(aValue);
+  } else if (aValue === null) {
+    return true;
+  }
+
+  return false;
+}
+
+/**
+ * If value is non-null, check if it's a boolean.
+ *
+ * @param aValue The variable to check.
+ * @return True if it's null or a valid boolean, false if it's non-null and an invalid
+ *         boolean.
+ */
+function checkNullOrBool(aValue) {
+  return aValue === null || (typeof aValue == "boolean");
+}
+
+
+
+
+
+function checkSystemSection(data) {
+Assert.ok("system" in data, "There must be a system section in Environment.");
+// Device data is only available on Android.
+  if (gIsAndroid) {
+    let deviceData = data.system.device;
+    Assert.ok(checkNullOrString(deviceData.model));
+    Assert.ok(checkNullOrString(deviceData.manufacturer));
+    Assert.ok(checkNullOrString(deviceData.hardware));
+    Assert.ok(checkNullOrBool(deviceData.isTablet));
+  }
+}
+
+
+add_task(async function test_systemEnvironment() {
+  let environmentData = TelemetryEnvironment.currentEnvironment;
+  checkSystemSection(environmentData);
+});
+
--- a/toolkit/components/telemetry/tests/unit/xpcshell.ini
+++ b/toolkit/components/telemetry/tests/unit/xpcshell.ini
@@ -70,8 +70,10 @@ skip-if = toolkit == 'android'
 [test_TelemetryCaptureStack.js]
 [test_TelemetryEvents.js]
 [test_ChildEvents.js]
 skip-if = os == "android" # Disabled due to crashes (see bug 1331366)
 [test_TelemetryModules.js]
 [test_PingSender.js]
 skip-if = (os == "android") || (os == "linux" && bits == 32)
 [test_TelemetryGC.js]
+[test_TelemetryAndroidEnvironment.js]
+