Bug 1320052 - Test that clearing subsession data still works. r?chutten draft
authorJan-Erik Rediger <jrediger@mozilla.com>
Fri, 04 May 2018 14:32:33 +0200
changeset 791452 ecf8ba8e58f98c6bca7e768accf9ca2507daeec6
parent 791451 9463ec0f52bc7781bf6c992942e7290cf6560500
child 792893 cace0f3ff41e82d5fcc7d4015878e57ddd1b5c2e
push id108818
push userbmo:jrediger@mozilla.com
push dateFri, 04 May 2018 13:17:24 +0000
reviewerschutten
bugs1320052
milestone61.0a1
Bug 1320052 - Test that clearing subsession data still works. r?chutten MozReview-Commit-ID: K2djulsH2jZ
toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryHistograms.js
@@ -1033,8 +1033,48 @@ async function test_mobileSpecificHistog
                                                 false /* clear */).parent;
 
   Assert.ok(DEFAULT_PLATFORMS_HISTOGRAM in histograms, "Should have recorded default platforms histogram");
   Assert.ok(MOBILE_ONLY_HISTOGRAM in histograms, "Should have recorded mobile-only histogram");
   Assert.ok(MULTIPLATFORM_HISTOGRAM in histograms, "Should have recorded multiplatform histogram");
 
   Assert.ok(!(DESKTOP_ONLY_HISTOGRAM in histograms), "Should not have recorded desktop-only histogram");
 });
+
+add_task({
+  skip_if: () => gIsAndroid
+},
+async function test_clearHistogramsOnSnapshot() {
+  const COUNT = "TELEMETRY_TEST_COUNT";
+  let h = Telemetry.getHistogramById(COUNT);
+  h.clear();
+  let snapshot;
+
+  // The first snapshot should be empty, nothing recorded.
+  snapshot = Telemetry.snapshotHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN,
+                                              false /* clear */).parent;
+  Assert.ok(!(COUNT in snapshot));
+
+  // After recording into a histogram, the data should be in the snapshot. Don't delete it.
+  h.add(1);
+
+  Assert.equal(h.snapshot().sum, 1);
+  snapshot = Telemetry.snapshotHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN,
+                                              false /* clear */).parent;
+  Assert.ok(COUNT in snapshot);
+  Assert.equal(snapshot[COUNT].sum, 1);
+
+  // After recording into a histogram again, the data should be updated and in the snapshot.
+  // Clean up after.
+  h.add(41);
+
+  Assert.equal(h.snapshot().sum, 42);
+  snapshot = Telemetry.snapshotHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN,
+                                              true /* clear */).parent;
+  Assert.ok(COUNT in snapshot);
+  Assert.equal(snapshot[COUNT].sum, 42);
+
+  // Finally, no data should be in the snapshot.
+  Assert.equal(h.snapshot().sum, 0);
+  snapshot = Telemetry.snapshotHistograms(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN,
+                                              false /* clear */).parent;
+  Assert.ok(!(COUNT in snapshot));
+});