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

Unified Diff: components/ukm/ukm_service_unittest.cc

Issue 2749433002: Create Field Trial param for whitelisting UKM Entries. (Closed)
Patch Set: add missing } from merge 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
« no previous file with comments | « components/ukm/ukm_service.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/ukm/ukm_service_unittest.cc
diff --git a/components/ukm/ukm_service_unittest.cc b/components/ukm/ukm_service_unittest.cc
index 4cfc97d80f1b6571f1da3e18ce88ca1f8b0fabd7..b7b1d61a5fc0b2e284516cf48e0c62cf44d46aab 100644
--- a/components/ukm/ukm_service_unittest.cc
+++ b/components/ukm/ukm_service_unittest.cc
@@ -490,4 +490,55 @@ TEST_F(UkmServiceTest, PurgeMidUpload) {
EXPECT_FALSE(client_.uploader()->is_uploading());
}
+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
« no previous file with comments | « components/ukm/ukm_service.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698