Bug 1473520 - Add test coverage for applying recorded scalar actions. r?janerik draft
authorPetru Gurita <petru.gurita1@gmail.com>
Sun, 08 Jul 2018 11:13:59 +0300
changeset 815400 45a60e99546f
parent 812853 f4e2f23cd8a8
child 815489 017bcba3290b
push id115511
push userbmo:petru.gurita1@gmail.com
push dateSun, 08 Jul 2018 08:14:48 +0000
reviewersjanerik
bugs1473520
milestone63.0a1
Bug 1473520 - Add test coverage for applying recorded scalar actions. r?janerik Created a new test coverage, 'WrongScalarOperator', that tests scalar operations on wrong type of scalars. MozReview-Commit-ID: JbgrYvoCEId
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,29 @@ 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);
+}