Bug 1315906 - Add test coverage. r=gfritzsche
authorAlessio Placitelli <alessio.placitelli@gmail.com>
Wed, 21 Dec 2016 01:13:00 +0100
changeset 452468 473bef59dcfa065110ec044a8326a3ccd78affaa
parent 452467 02d37af6e76fc7f8b13f62f9a7ddf82ccb8c5d45
child 452469 73c80c1709a3ac2a8f085ce297d880cb92c6f7f5
push id39415
push usermozilla@noorenberghe.ca
push dateWed, 21 Dec 2016 20:49:14 +0000
reviewersgfritzsche
bugs1315906
milestone53.0a1
Bug 1315906 - Add test coverage. r=gfritzsche MozReview-Commit-ID: FFskMOrwvLO
toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
--- a/toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
+++ b/toolkit/components/telemetry/tests/unit/test_nsITelemetry.js
@@ -228,16 +228,45 @@ add_task(function* test_categorical_hist
   }
 
   snapshot = h2.snapshot();
   Assert.equal(snapshot.sum, 7);
   Assert.deepEqual(snapshot.ranges, [0, 1, 2, 3, 4]);
   Assert.deepEqual(snapshot.counts, [3, 2, 1, 1, 0]);
 });
 
+add_task(function* test_add_error_behaviour() {
+  const PLAIN_HISTOGRAMS_TO_TEST = [
+    "TELEMETRY_TEST_FLAG",
+    "TELEMETRY_TEST_EXPONENTIAL",
+    "TELEMETRY_TEST_LINEAR",
+    "TELEMETRY_TEST_BOOLEAN"
+  ];
+
+  const KEYED_HISTOGRAMS_TO_TEST = [
+    "TELEMETRY_TEST_KEYED_FLAG",
+    "TELEMETRY_TEST_KEYED_COUNT",
+    "TELEMETRY_TEST_KEYED_BOOLEAN"
+  ];
+
+  // Check that |add| doesn't throw for plain histograms.
+  for (let hist of PLAIN_HISTOGRAMS_TO_TEST) {
+    const returnValue = Telemetry.getHistogramById(hist).add("unexpected-value");
+    Assert.strictEqual(returnValue, undefined,
+                       "Adding to an histogram must return 'undefined'.");
+  }
+
+  // And for keyed histograms.
+  for (let hist of KEYED_HISTOGRAMS_TO_TEST) {
+    const returnValue = Telemetry.getKeyedHistogramById(hist).add("some-key", "unexpected-value");
+    Assert.strictEqual(returnValue, undefined,
+                       "Adding to a keyed histogram must return 'undefined'.");
+  }
+});
+
 add_task(function* test_getHistogramById() {
   try {
     Telemetry.getHistogramById("nonexistent");
     do_throw("This can't happen");
   } catch (e) {
 
   }
   var h = Telemetry.getHistogramById("CYCLE_COLLECTOR");