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

Side by Side Diff: components/ukm/ukm_service_unittest.cc

Issue 2727343004: Add Feature params for UKM Service to control thresholds on sources and entries. (Closed)
Patch Set: wording 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
« no previous file with comments | « components/ukm/ukm_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 416
417 TEST_F(UkmServiceTest, RecordSessionId) { 417 TEST_F(UkmServiceTest, RecordSessionId) {
418 for (bool should_record_session_id : {true, false}) { 418 for (bool should_record_session_id : {true, false}) {
419 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); 419 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */);
420 ScopedUkmFeatureParams params( 420 ScopedUkmFeatureParams params(
421 base::FeatureList::OVERRIDE_ENABLE_FEATURE, 421 base::FeatureList::OVERRIDE_ENABLE_FEATURE,
422 {{"RecordSessionId", should_record_session_id ? "true" : "false"}}); 422 {{"RecordSessionId", should_record_session_id ? "true" : "false"}});
423 423
424 ClearPrefs(); 424 ClearPrefs();
425 UkmService service(&prefs_, &client_); 425 UkmService service(&prefs_, &client_);
426 EXPECT_EQ(GetPersistedLogCount(), 0); 426 EXPECT_EQ(0, GetPersistedLogCount());
427 service.Initialize(); 427 service.Initialize();
428 task_runner_->RunUntilIdle(); 428 task_runner_->RunUntilIdle();
429 service.EnableRecording(); 429 service.EnableRecording();
430 service.EnableReporting(); 430 service.EnableReporting();
431 431
432 int32_t id = UkmService::GetNewSourceID(); 432 auto id = UkmService::GetNewSourceID();
433 service.UpdateSourceURL(id, GURL("https://google.com/foobar")); 433 service.UpdateSourceURL(id, GURL("https://google.com/foobar"));
434 434
435 service.Flush(); 435 service.Flush();
436 EXPECT_EQ(GetPersistedLogCount(), 1); 436 EXPECT_EQ(1, GetPersistedLogCount());
437 437
438 Report proto_report = GetPersistedReport(); 438 auto proto_report = GetPersistedReport();
439 EXPECT_EQ(should_record_session_id, proto_report.has_session_id()); 439 EXPECT_EQ(should_record_session_id, proto_report.has_session_id());
440 } 440 }
441 } 441 }
442 442
443 TEST_F(UkmServiceTest, SourceSize) {
444 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */);
445 // Set a threshold of number of Sources via Feature Params.
446 ScopedUkmFeatureParams params(base::FeatureList::OVERRIDE_ENABLE_FEATURE,
447 {{"MaxSources", "2"}});
448
449 ClearPrefs();
450 UkmService service(&prefs_, &client_);
451 EXPECT_EQ(0, GetPersistedLogCount());
452 service.Initialize();
453 task_runner_->RunUntilIdle();
454 service.EnableRecording();
455 service.EnableReporting();
456
457 auto id = UkmService::GetNewSourceID();
458 service.UpdateSourceURL(id, GURL("https://google.com/foobar1"));
459 id = UkmService::GetNewSourceID();
460 service.UpdateSourceURL(id, GURL("https://google.com/foobar2"));
461 id = UkmService::GetNewSourceID();
462 service.UpdateSourceURL(id, GURL("https://google.com/foobar3"));
463
464 service.Flush();
465 EXPECT_EQ(1, GetPersistedLogCount());
466
467 auto proto_report = GetPersistedReport();
468 // Note, 2 instead of 3 sources, since we overrode the max number of sources
469 // via Feature params.
470 EXPECT_EQ(2, proto_report.sources_size());
471 }
472
443 } // namespace ukm 473 } // namespace ukm
OLDNEW
« no previous file with comments | « components/ukm/ukm_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698