| OLD | NEW |
| 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 Loading... |
| 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 |
| OLD | NEW |