Bug 1551410 - Part 2: test case; r=chutten
authorLiang-Heng Chen <xeonchen@gmail.com>
Fri, 17 May 2019 00:53:33 +0000
changeset 474302 366103f41d7ddaaaaba111db727f4db3b51ef6bd
parent 474301 d5a1f414d631aa02482f1c650387bc14c5e31b62
child 474303 a68c01cb895d83dea76e8dc74336aa2440ba6fc9
push id36027
push usershindli@mozilla.com
push dateFri, 17 May 2019 16:24:38 +0000
treeherdermozilla-central@c94c54aff466 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschutten
bugs1551410
milestone68.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 1551410 - Part 2: test case; r=chutten Differential Revision: https://phabricator.services.mozilla.com/D31109
toolkit/components/telemetry/tests/gtest/TelemetryTestHelpers.cpp
toolkit/components/telemetry/tests/gtest/TestOrigins.cpp
--- a/toolkit/components/telemetry/tests/gtest/TelemetryTestHelpers.cpp
+++ b/toolkit/components/telemetry/tests/gtest/TelemetryTestHelpers.cpp
@@ -228,20 +228,20 @@ void GetEncodedOriginStrings(
     JS::RootedObject arrayItemObj(aCx, &arrayItem.toObject());
 
     JS::RootedValue encodingVal(aCx);
     ASSERT_TRUE(JS_GetProperty(aCx, arrayItemObj, "encoding", &encodingVal));
     ASSERT_TRUE(encodingVal.isString());
     nsAutoJSString jsStr;
     ASSERT_TRUE(jsStr.init(aCx, encodingVal));
 
-    nsPrintfCString encoding(aEncoding.get(), i);
+    nsPrintfCString encoding(aEncoding.get(), i % TelemetryOrigin::SizeOfPrioDatasPerMetric());
     ASSERT_TRUE(NS_ConvertUTF16toUTF8(jsStr) == encoding)
     << "Actual 'encoding' (" << NS_ConvertUTF16toUTF8(jsStr).get()
-    << ") must match expected (" << encoding;
+    << ") must match expected (" << encoding << ")";
 
     JS::RootedValue prioVal(aCx);
     ASSERT_TRUE(JS_GetProperty(aCx, arrayItemObj, "prio", &prioVal));
     ASSERT_TRUE(prioVal.isObject());
     ASSERT_FALSE(prioVal.isNullOrUndefined());
 
     JS::RootedObject prioObj(aCx, &prioVal.toObject());
 
--- a/toolkit/components/telemetry/tests/gtest/TestOrigins.cpp
+++ b/toolkit/components/telemetry/tests/gtest/TestOrigins.cpp
@@ -105,16 +105,31 @@ TEST_F(TelemetryTestFixture, RecordOrigi
   const nsLiteralCString doubleclick("doubleclick.net");
   const nsLiteralCString doubleclickHash(
       "uXNT1PzjAVau8b402OMAIGDejKbiXfQX5iXvPASfO/s=");
   const nsLiteralCString telemetryTest1("telemetry.test_test1");
 
   Telemetry::RecordOrigin(OriginMetricID::TelemetryTest_Test1, doubleclick);
   Telemetry::RecordOrigin(OriginMetricID::TelemetryTest_Test1, doubleclickHash);
 
+  // Properly prepare the prio prefs
+  // (Sourced from PrioEncoder.cpp from when it was being prototyped)
+  const nsLiteralCString prioKeyA(
+      "35AC1C7576C7C6EDD7FED6BCFC337B34D48CB4EE45C86BEEFB40BD8875707733");
+  const nsLiteralCString prioKeyB(
+      "26E6674E65425B823F1F1D5F96E3BB3EF9E406EC7FBA7DEF8B08A35DD135AF50");
+  Preferences::SetCString("prio.publicKeyA", prioKeyA);
+  Preferences::SetCString("prio.publicKeyB", prioKeyB);
+
+  nsTArray<Tuple<nsCString, nsCString>> encodedStrings;
+  GetEncodedOriginStrings(aCx, telemetryTest1 + NS_LITERAL_CSTRING("-%u"),
+                          encodedStrings);
+  ASSERT_EQ(2 * TelemetryOrigin::SizeOfPrioDatasPerMetric(),
+            encodedStrings.Length());
+
   JS::RootedValue originSnapshot(aCx);
   GetOriginSnapshot(aCx, &originSnapshot, true /* aClear */);
 
   ASSERT_FALSE(originSnapshot.isNullOrUndefined())
   << "Origin snapshot must not be null/undefined.";
 
   JS::RootedValue origins(aCx);
   JS::RootedObject snapshotObj(aCx, &originSnapshot.toObject());