| 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 task_runner_->RunPendingTasks(); | 483 task_runner_->RunPendingTasks(); |
| 484 EXPECT_TRUE(client_.uploader()->is_uploading()); | 484 EXPECT_TRUE(client_.uploader()->is_uploading()); |
| 485 // Purge should delete all logs, including the one being sent. | 485 // Purge should delete all logs, including the one being sent. |
| 486 service.Purge(); | 486 service.Purge(); |
| 487 // Upload succeeds after logs was deleted. | 487 // Upload succeeds after logs was deleted. |
| 488 client_.uploader()->CompleteUpload(200); | 488 client_.uploader()->CompleteUpload(200); |
| 489 EXPECT_EQ(GetPersistedLogCount(), 0); | 489 EXPECT_EQ(GetPersistedLogCount(), 0); |
| 490 EXPECT_FALSE(client_.uploader()->is_uploading()); | 490 EXPECT_FALSE(client_.uploader()->is_uploading()); |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST_F(UkmServiceTest, WhitelistEntryTest) { |
| 494 base::FieldTrialList field_trial_list(nullptr /* entropy_provider */); |
| 495 // Testing two whitelisted Entries. |
| 496 ScopedUkmFeatureParams params(base::FeatureList::OVERRIDE_ENABLE_FEATURE, |
| 497 {{"WhitelistEntries", "EntryA,EntryB"}}); |
| 498 |
| 499 ClearPrefs(); |
| 500 UkmService service(&prefs_, &client_); |
| 501 EXPECT_EQ(0, GetPersistedLogCount()); |
| 502 service.Initialize(); |
| 503 task_runner_->RunUntilIdle(); |
| 504 service.EnableRecording(); |
| 505 service.EnableReporting(); |
| 506 |
| 507 auto id = UkmService::GetNewSourceID(); |
| 508 service.UpdateSourceURL(id, GURL("https://google.com/foobar1")); |
| 509 |
| 510 { |
| 511 std::unique_ptr<UkmEntryBuilder> builder = |
| 512 service.GetEntryBuilder(id, "EntryA"); |
| 513 builder->AddMetric("MetricA", 300); |
| 514 } |
| 515 { |
| 516 std::unique_ptr<UkmEntryBuilder> builder = |
| 517 service.GetEntryBuilder(id, "EntryB"); |
| 518 builder->AddMetric("MetricB", 400); |
| 519 } |
| 520 // Note that this third entry is not in the whitelist. |
| 521 { |
| 522 std::unique_ptr<UkmEntryBuilder> builder = |
| 523 service.GetEntryBuilder(id, "EntryC"); |
| 524 builder->AddMetric("MetricC", 500); |
| 525 } |
| 526 |
| 527 service.Flush(); |
| 528 EXPECT_EQ(1, GetPersistedLogCount()); |
| 529 Report proto_report = GetPersistedReport(); |
| 530 |
| 531 // Verify we've added one source and 2 entries. |
| 532 EXPECT_EQ(1, proto_report.sources_size()); |
| 533 ASSERT_EQ(2, proto_report.entries_size()); |
| 534 |
| 535 const Entry& proto_entry_a = proto_report.entries(0); |
| 536 EXPECT_EQ(id, proto_entry_a.source_id()); |
| 537 EXPECT_EQ(base::HashMetricName("EntryA"), proto_entry_a.event_hash()); |
| 538 |
| 539 const Entry& proto_entry_b = proto_report.entries(1); |
| 540 EXPECT_EQ(id, proto_entry_b.source_id()); |
| 541 EXPECT_EQ(base::HashMetricName("EntryB"), proto_entry_b.event_hash()); |
| 542 } |
| 543 |
| 493 } // namespace ukm | 544 } // namespace ukm |
| OLD | NEW |