Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: components/ukm/ukm_service_unittest.cc

Issue 2749433002: Create Field Trial param for whitelisting UKM Entries. (Closed)
Patch Set: add comment Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/ukm/ukm_service_unittest.cc
diff --git a/components/ukm/ukm_service_unittest.cc b/components/ukm/ukm_service_unittest.cc
index 8a2782af38c4d9ba014a65d4c9b200a95d49cd89..0871287f5d4e5b19fd4bdcf562ba6364a2bfc31d 100644
--- a/components/ukm/ukm_service_unittest.cc
+++ b/components/ukm/ukm_service_unittest.cc
@@ -470,4 +470,55 @@ TEST_F(UkmServiceTest, SourceSize) {
EXPECT_EQ(2, proto_report.sources_size());
}
+TEST_F(UkmServiceTest, WhitelistEntryTest) {
+ base::FieldTrialList field_trial_list(nullptr /* entropy_provider */);
+ // Testing two whitelisted Entries.
+ ScopedUkmFeatureParams params(base::FeatureList::OVERRIDE_ENABLE_FEATURE,
+ {{"WhitelistEntries", "EntryA,EntryB"}});
+
+ ClearPrefs();
+ UkmService service(&prefs_, &client_);
+ EXPECT_EQ(0, GetPersistedLogCount());
+ service.Initialize();
+ task_runner_->RunUntilIdle();
+ service.EnableRecording();
+ service.EnableReporting();
+
+ auto id = UkmService::GetNewSourceID();
+ service.UpdateSourceURL(id, GURL("https://google.com/foobar1"));
+
+ {
+ std::unique_ptr<UkmEntryBuilder> builder =
+ service.GetEntryBuilder(id, "EntryA");
+ builder->AddMetric("MetricA", 300);
+ }
+ {
+ std::unique_ptr<UkmEntryBuilder> builder =
+ service.GetEntryBuilder(id, "EntryB");
+ builder->AddMetric("MetricB", 400);
+ }
+ // Note that this third entry is not in the whitelist.
+ {
+ std::unique_ptr<UkmEntryBuilder> builder =
+ service.GetEntryBuilder(id, "EntryC");
+ builder->AddMetric("MetricC", 500);
+ }
+
+ service.Flush();
+ EXPECT_EQ(1, GetPersistedLogCount());
+ Report proto_report = GetPersistedReport();
+
+ // Verify we've added one source and 2 entries.
+ EXPECT_EQ(1, proto_report.sources_size());
+ ASSERT_EQ(2, proto_report.entries_size());
+
+ const Entry& proto_entry_a = proto_report.entries(0);
+ EXPECT_EQ(id, proto_entry_a.source_id());
+ EXPECT_EQ(base::HashMetricName("EntryA"), proto_entry_a.event_hash());
+
+ const Entry& proto_entry_b = proto_report.entries(1);
+ EXPECT_EQ(id, proto_entry_b.source_id());
+ EXPECT_EQ(base::HashMetricName("EntryB"), proto_entry_b.event_hash());
+}
+
} // namespace ukm

Powered by Google App Engine
This is Rietveld 408576698