Bug 1466490 - Extract common test functionality into a header. r?dexter draft
authorJan-Erik Rediger <jrediger@mozilla.com>
Fri, 15 Jun 2018 09:49:02 -0700
changeset 807765 4a193f7f3c29449c9536b86a4c9b81de3297240e
parent 807566 8cd0c760bc208adb689c9e0d4ae597b600be8f0d
child 807766 e7c0b613eabf7c82d24418d182b8b95d7db5ec3d
child 807881 bf97d9bd4800da033f5a10084238e7db61a5462c
child 808457 92f03d54bcddc2ffe4b0cd53a0f79cccaa05dd8f
child 808459 bf31b0c08502d573ca09946d861078833d984732
child 808656 a7b3ea1036ffce66a66e85ba45047fac41cdfe4b
push id113206
push userbmo:jrediger@mozilla.com
push dateFri, 15 Jun 2018 18:07:54 +0000
reviewersdexter
bugs1466490
milestone62.0a1
Bug 1466490 - Extract common test functionality into a header. r?dexter MozReview-Commit-ID: 81Gj0FyCBqG
toolkit/components/telemetry/tests/unit/head_GeckoView.js
toolkit/components/telemetry/tests/unit/test_GeckoView.js
toolkit/components/telemetry/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/head_GeckoView.js
@@ -0,0 +1,61 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/
+*/
+"use strict";
+
+ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm", this);
+ChromeUtils.import("resource://gre/modules/Services.jsm", this);
+ChromeUtils.import("resource://testing-common/ContentTaskUtils.jsm", this);
+
+const Telemetry = Services.telemetry;
+const TelemetryGeckoView = Cc["@mozilla.org/telemetry/geckoview-testing;1"]
+                             .createInstance(Ci.nsITelemetryGeckoViewTesting);
+
+/**
+ * Run a file in the content process.
+ * @param aFileName - The file to execute in the content process.
+ * @return {Promise} A promise resolved after the execution in the other process
+ *         finishes.
+ */
+async function run_in_child(aFileName) {
+  const PREF_GECKOVIEW_MODE = "toolkit.telemetry.isGeckoViewMode";
+  // We don't ship GeckoViewTelemetryController.jsm outside of Android. If
+  // |toolkit.telemetry.isGeckoViewMode| is true, this makes Gecko crash on
+  // other platforms because ContentProcessSingleton.js requires it. Work
+  // around this by temporarily setting the pref to false.
+  const currentValue = Services.prefs.getBoolPref(PREF_GECKOVIEW_MODE, false);
+  Services.prefs.setBoolPref(PREF_GECKOVIEW_MODE, false);
+  await run_test_in_child(aFileName);
+  Services.prefs.setBoolPref(PREF_GECKOVIEW_MODE, currentValue);
+}
+
+/**
+ * Builds a promise to wait for the GeckoView data loading to finish.
+ * @return {Promise} A promise resolved when the data loading finishes.
+ */
+function waitGeckoViewLoadComplete() {
+  return new Promise(resolve => {
+    Services.obs.addObserver(function observe() {
+      Services.obs.removeObserver(observe, "internal-telemetry-geckoview-load-complete");
+      resolve();
+    }, "internal-telemetry-geckoview-load-complete");
+  });
+}
+
+/**
+ * This function waits until the desired histogram is reported into the
+ * snapshot of the relevant process.
+ * @param aHistogramName - The name of the histogram to look for.
+ * @param aProcessName - The name of the process to look in.
+ * @param aKeyed - Whether or not to look in keyed snapshots.
+ */
+async function waitForHistogramSnapshotData(aHistogramName, aProcessName, aKeyed) {
+  await ContentTaskUtils.waitForCondition(() => {
+    const data = aKeyed
+      ? Telemetry.snapshotKeyedHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false)
+      : Telemetry.snapshotHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
+
+    return (aProcessName in data)
+           && (aHistogramName in data[aProcessName]);
+  });
+}
--- a/toolkit/components/telemetry/tests/unit/test_GeckoView.js
+++ b/toolkit/components/telemetry/tests/unit/test_GeckoView.js
@@ -2,69 +2,16 @@
    http://creativecommons.org/publicdomain/zero/1.0/
 */
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm", this);
 ChromeUtils.import("resource://gre/modules/Services.jsm", this);
 ChromeUtils.import("resource://testing-common/ContentTaskUtils.jsm", this);
 
-const Telemetry = Services.telemetry;
-const TelemetryGeckoView = Cc["@mozilla.org/telemetry/geckoview-testing;1"]
-                             .createInstance(Ci.nsITelemetryGeckoViewTesting);
-
-/**
- * Run a file in the content process.
- * @param aFileName - The file to execute in the content process.
- * @return {Promise} A promise resolved after the execution in the other process
- *         finishes.
- */
-async function run_in_child(aFileName) {
-  const PREF_GECKOVIEW_MODE = "toolkit.telemetry.isGeckoViewMode";
-  // We don't ship GeckoViewTelemetryController.jsm outside of Android. If
-  // |toolkit.telemetry.isGeckoViewMode| is true, this makes Gecko crash on
-  // other platforms because ContentProcessSingleton.js requires it. Work
-  // around this by temporarily setting the pref to false.
-  const currentValue = Services.prefs.getBoolPref(PREF_GECKOVIEW_MODE, false);
-  Services.prefs.setBoolPref(PREF_GECKOVIEW_MODE, false);
-  await run_test_in_child(aFileName);
-  Services.prefs.setBoolPref(PREF_GECKOVIEW_MODE, currentValue);
-}
-
-/**
- * Builds a promise to wait for the GeckoView data loading to finish.
- * @return {Promise} A promise resolved when the data loading finishes.
- */
-function waitGeckoViewLoadComplete() {
-  return new Promise(resolve => {
-    Services.obs.addObserver(function observe() {
-      Services.obs.removeObserver(observe, "internal-telemetry-geckoview-load-complete");
-      resolve();
-    }, "internal-telemetry-geckoview-load-complete");
-  });
-}
-
-/**
- * This function waits until the desired histogram is reported into the
- * snapshot of the relevant process.
- * @param aHistogramName - The name of the histogram to look for.
- * @param aProcessName - The name of the process to look in.
- * @param aKeyed - Whether or not to look in keyed snapshots.
- */
-async function waitForSnapshotData(aHistogramName, aProcessName, aKeyed) {
-  await ContentTaskUtils.waitForCondition(() => {
-    const data = aKeyed
-      ? Telemetry.snapshotKeyedHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false)
-      : Telemetry.snapshotHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
-
-    return (aProcessName in data)
-           && (aHistogramName in data[aProcessName]);
-  });
-}
-
 add_task(async function setup() {
   // Init the profile.
   let profileDir = do_get_profile(true);
 
   // Set geckoview mode.
   Services.prefs.setBoolPref("toolkit.telemetry.isGeckoViewMode", true);
 
   // Set the ANDROID_DATA_DIR to the profile dir.
@@ -85,18 +32,18 @@ add_task(async function test_persistCont
   plainHist.add(37);
   keyedHist.add("parent-test-key", 73);
 
   // Set content histograms and wait for the execution in the other
   // process to finish.
   await run_in_child("test_GeckoView_content_histograms.js");
 
   // Wait for the data to be collected by the parent process.
-  await waitForSnapshotData("TELEMETRY_TEST_MULTIPRODUCT", "content", false /* aKeyed */);
-  await waitForSnapshotData("TELEMETRY_TEST_KEYED_COUNT", "content", true /* aKeyed */);
+  await waitForHistogramSnapshotData("TELEMETRY_TEST_MULTIPRODUCT", "content", false /* aKeyed */);
+  await waitForHistogramSnapshotData("TELEMETRY_TEST_KEYED_COUNT", "content", true /* aKeyed */);
 
   // Force persisting the measurements to file.
   TelemetryGeckoView.forcePersist();
   TelemetryGeckoView.deInitPersistence();
 
   // Clear the histograms for all processes.
   Telemetry.snapshotHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true /* clear */);
   Telemetry.snapshotKeyedHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, true /* clear */);
--- a/toolkit/components/telemetry/tests/unit/xpcshell.ini
+++ b/toolkit/components/telemetry/tests/unit/xpcshell.ini
@@ -19,17 +19,17 @@ support-files =
 generated-files =
   dictionary.xpi
   experiment.xpi
   system.xpi
   restartless.xpi
 
 [test_GeckoView.js]
 skip-if = os == "android" # Disabled due to crashes (see bug 1331366)
-head =
+head = head_GeckoView.js
 support-files =
   test_GeckoView_content_histograms.js
 [test_MigratePendingPings.js]
 [test_TelemetryHistograms.js]
 [test_TelemetryStorage.js]
 [test_SubsessionChaining.js]
 tags = addons
 [test_TelemetryEnvironment.js]