Bug 1473520 - Add test coverage for applying recorded scalar actions. r=janerik
authorPetru Gurita <petru.gurita1@gmail.com>
Mon, 16 Jul 2018 23:32:01 +0300
changeset 427067 b47db3a7a809
parent 427066 c770f0740d0d
child 427068 54665bb153f1
push id34292
push usercsabou@mozilla.com
push dateWed, 18 Jul 2018 17:18:53 +0000
treeherdermozilla-central@10ca5b14dbdb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjanerik
bugs1473520
milestone63.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 1473520 - Add test coverage for applying recorded scalar actions. r=janerik Created two new test coverages, `WrongscalarOperator' and 'WrongKeyedScalarOperator', that test scalar operations on wrong type of scalars. MozReview-Commit-ID: 6FIMqRi0dgk
toolkit/components/telemetry/tests/gtest/TestScalars.cpp
--- a/toolkit/components/telemetry/tests/gtest/TestScalars.cpp
+++ b/toolkit/components/telemetry/tests/gtest/TestScalars.cpp
@@ -311,8 +311,62 @@ TEST_F(TelemetryTestFixture, ScalarEvent
   // Check the recorded value.
   JS::RootedValue scalarsSnapshot(cx.GetJSContext());
   GetScalarsSnapshot(true, cx.GetJSContext(), &scalarsSnapshot, ProcessID::Dynamic);
 
   // Recording in parent or content doesn't matter for dynamic scalars
   // which all end up in the same place.
   CheckKeyedUintScalar(kScalarName, kLongestEvent, cx.GetJSContext(), scalarsSnapshot, 2);
 }
+
+TEST_F(TelemetryTestFixture, WrongScalarOperator) {
+  AutoJSContextWithGlobal cx(mCleanGlobal);
+
+  // Make sure we don't get scalars from other tests.
+  Unused << mTelemetry->ClearScalars();
+
+  Telemetry::ScalarSet(Telemetry::ScalarID::TELEMETRY_TEST_STRING_KIND, NS_LITERAL_STRING(EXPECTED_STRING));
+  Telemetry::ScalarSet(Telemetry::ScalarID::TELEMETRY_TEST_BOOLEAN_KIND, true);
+
+  TelemetryScalar::DeserializationStarted();
+
+  Telemetry::ScalarAdd(Telemetry::ScalarID::TELEMETRY_TEST_STRING_KIND, 1447);
+  Telemetry::ScalarAdd(Telemetry::ScalarID::TELEMETRY_TEST_BOOLEAN_KIND, 1447);
+  TelemetryScalar::ApplyPendingOperations();
+
+  JS::RootedValue scalarsSnapshot(cx.GetJSContext());
+  GetScalarsSnapshot(false, cx.GetJSContext(), &scalarsSnapshot);
+  CheckStringScalar("telemetry.test.string_kind", cx.GetJSContext(), scalarsSnapshot, EXPECTED_STRING);
+  CheckBoolScalar("telemetry.test.boolean_kind", cx.GetJSContext(), scalarsSnapshot, true);
+}
+
+TEST_F(TelemetryTestFixture, WrongKeyedScalarOperator) {
+
+  AutoJSContextWithGlobal cx(mCleanGlobal);
+
+  // Make sure we don't get scalars from other tests.
+  Unused << mTelemetry->ClearScalars();
+
+
+  const uint32_t kExpectedUint = 1172017;
+
+  Telemetry::ScalarSet(Telemetry::ScalarID::TELEMETRY_TEST_KEYED_UNSIGNED_INT,
+                       NS_LITERAL_STRING("key1"), kExpectedUint);
+  Telemetry::ScalarSet(Telemetry::ScalarID::TELEMETRY_TEST_KEYED_BOOLEAN_KIND,
+                       NS_LITERAL_STRING("key2"), true);
+
+  TelemetryScalar::DeserializationStarted();
+
+  Telemetry::ScalarSet(Telemetry::ScalarID::TELEMETRY_TEST_KEYED_UNSIGNED_INT,
+                       NS_LITERAL_STRING("key1"), false);
+  Telemetry::ScalarSet(Telemetry::ScalarID::TELEMETRY_TEST_KEYED_BOOLEAN_KIND,
+                       NS_LITERAL_STRING("key2"), static_cast<uint32_t>(13));
+
+  TelemetryScalar::ApplyPendingOperations();
+
+  JS::RootedValue scalarsSnapshot(cx.GetJSContext());
+  GetScalarsSnapshot(true, cx.GetJSContext(), &scalarsSnapshot);
+  CheckKeyedUintScalar("telemetry.test.keyed_unsigned_int", "key1",
+                       cx.GetJSContext(), scalarsSnapshot, kExpectedUint);
+  CheckKeyedBoolScalar("telemetry.test.keyed_boolean_kind", "key2",
+                       cx.GetJSContext(), scalarsSnapshot, true);
+
+}