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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/ukm/ukm_service.h" 5 #include "components/ukm/ukm_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 service.Flush(); 464 service.Flush();
465 EXPECT_EQ(1, GetPersistedLogCount()); 465 EXPECT_EQ(1, GetPersistedLogCount());
466 466
467 auto proto_report = GetPersistedReport(); 467 auto proto_report = GetPersistedReport();
468 // Note, 2 instead of 3 sources, since we overrode the max number of sources 468 // Note, 2 instead of 3 sources, since we overrode the max number of sources
469 // via Feature params. 469 // via Feature params.
470 EXPECT_EQ(2, proto_report.sources_size()); 470 EXPECT_EQ(2, proto_report.sources_size());
471 } 471 }
472 472
473 TEST_F(UkmServiceTest, WhitelistEntryTest) {
474 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */);
475 // Testing two whitelisted Entries.
476 ScopedUkmFeatureParams params(base::FeatureList::OVERRIDE_ENABLE_FEATURE,
477 {{"WhitelistEntries", "EntryA,EntryB"}});
478
479 ClearPrefs();
480 UkmService service(&prefs_, &client_);
481 EXPECT_EQ(0, GetPersistedLogCount());
482 service.Initialize();
483 task_runner_->RunUntilIdle();
484 service.EnableRecording();
485 service.EnableReporting();
486
487 auto id = UkmService::GetNewSourceID();
488 service.UpdateSourceURL(id, GURL("https://google.com/foobar1"));
489
490 {
491 std::unique_ptr<UkmEntryBuilder> builder =
492 service.GetEntryBuilder(id, "EntryA");
493 builder->AddMetric("MetricA", 300);
494 }
495 {
496 std::unique_ptr<UkmEntryBuilder> builder =
497 service.GetEntryBuilder(id, "EntryB");
498 builder->AddMetric("MetricB", 400);
499 }
500 // Note that this third entry is not in the whitelist.
501 {
502 std::unique_ptr<UkmEntryBuilder> builder =
503 service.GetEntryBuilder(id, "EntryC");
504 builder->AddMetric("MetricC", 500);
505 }
506
507 service.Flush();
508 EXPECT_EQ(1, GetPersistedLogCount());
509 Report proto_report = GetPersistedReport();
510
511 // Verify we've added one source and 2 entries.
512 EXPECT_EQ(1, proto_report.sources_size());
513 ASSERT_EQ(2, proto_report.entries_size());
514
515 const Entry& proto_entry_a = proto_report.entries(0);
516 EXPECT_EQ(id, proto_entry_a.source_id());
517 EXPECT_EQ(base::HashMetricName("EntryA"), proto_entry_a.event_hash());
518
519 const Entry& proto_entry_b = proto_report.entries(1);
520 EXPECT_EQ(id, proto_entry_b.source_id());
521 EXPECT_EQ(base::HashMetricName("EntryB"), proto_entry_b.event_hash());
522 }
523
473 } // namespace ukm 524 } // namespace ukm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698