Bug 1448945 - Add test coverage for dynamic builtin events. r=chutten
authorJan-Erik Rediger <jrediger@mozilla.com>
Mon, 09 Apr 2018 15:07:58 +0200
changeset 467819 441de7a08d1cc193118c8a3804769ba861369c03
parent 467818 d7199d45cfd921f22049185555b84cafd9d2761b
child 467820 c8fb850a6d66e28f51870e03a4d04b253fd53557
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1448945
milestone61.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 1448945 - Add test coverage for dynamic builtin events. r=chutten MozReview-Commit-ID: AFZPTBM7QqQ
toolkit/components/telemetry/tests/unit/test_TelemetryEvents_buildFaster.js
toolkit/components/telemetry/tests/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEvents_buildFaster.js
@@ -0,0 +1,48 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/
+*/
+
+add_task(async function test_dynamicBuiltinEvents() {
+  Telemetry.clearEvents();
+  Telemetry.canRecordExtended = true;
+
+  const TEST_EVENT_NAME = "telemetry.test.dynamicbuiltin";
+
+  // Register some dynbamic builtin test events.
+  Telemetry.registerBuiltinEvents(TEST_EVENT_NAME, {
+    // Event with only required fields.
+    "test1": {
+      methods: ["test1"],
+      objects: ["object1"],
+    },
+    // Event with extra_keys.
+    "test2": {
+      methods: ["test2", "test2b"],
+      objects: ["object1", "object2"],
+      extra_keys: ["key1", "key2"],
+    },
+  });
+
+  // Record some events.
+  Telemetry.recordEvent(TEST_EVENT_NAME, "test1", "object1");
+  Telemetry.recordEvent(TEST_EVENT_NAME, "test2", "object1", null,
+                        {"key1": "foo", "key2": "bar"});
+  Telemetry.recordEvent(TEST_EVENT_NAME, "test2b", "object2", null,
+                        {"key2": "bar"});
+  // Now check that the snapshot contains the expected data.
+  let snapshot =
+    Telemetry.snapshotEvents(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN, false);
+  Assert.ok(("parent" in snapshot), "Should have parent events in the snapshot.");
+
+  let expected = [
+    [TEST_EVENT_NAME, "test1", "object1"],
+    [TEST_EVENT_NAME, "test2", "object1", null, {key1: "foo", key2: "bar"}],
+    [TEST_EVENT_NAME, "test2b", "object2", null, {key2: "bar"}],
+  ];
+  let events = snapshot.parent;
+  Assert.equal(events.length, expected.length, "Should have recorded the right amount of events.");
+  for (let i = 0; i < expected.length; ++i) {
+    Assert.deepEqual(events[i].slice(1), expected[i],
+                     "Should have recorded the expected event data.");
+  }
+});
--- a/toolkit/components/telemetry/tests/unit/xpcshell.ini
+++ b/toolkit/components/telemetry/tests/unit/xpcshell.ini
@@ -63,14 +63,15 @@ skip-if = os == "android" # Disabled due
 skip-if = os == "android" # Disabled due to crashes (see bug 1367762)
 tags = addons
 [test_TelemetryScalars.js]
 [test_TelemetryScalars_buildFaster.js]
 [test_TelemetryTimestamps.js]
 skip-if = toolkit == 'android'
 [test_TelemetryCaptureStack.js]
 [test_TelemetryEvents.js]
+[test_TelemetryEvents_buildFaster.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]