| 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 "base/test/test_simple_task_runner.h" | 7 #include "base/test/test_simple_task_runner.h" |
| 8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "components/metrics/proto/ukm/report.pb.h" | 9 #include "components/metrics/proto/ukm/report.pb.h" |
| 10 #include "components/metrics/proto/ukm/source.pb.h" | 10 #include "components/metrics/proto/ukm/source.pb.h" |
| 11 #include "components/metrics/test_metrics_provider.h" |
| 11 #include "components/metrics/test_metrics_service_client.h" | 12 #include "components/metrics/test_metrics_service_client.h" |
| 12 #include "components/prefs/testing_pref_service.h" | 13 #include "components/prefs/testing_pref_service.h" |
| 13 #include "components/ukm/persisted_logs_metrics_impl.h" | 14 #include "components/ukm/persisted_logs_metrics_impl.h" |
| 14 #include "components/ukm/ukm_pref_names.h" | 15 #include "components/ukm/ukm_pref_names.h" |
| 15 #include "components/ukm/ukm_source.h" | 16 #include "components/ukm/ukm_source.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "third_party/zlib/google/compression_utils.h" | 18 #include "third_party/zlib/google/compression_utils.h" |
| 18 | 19 |
| 19 namespace ukm { | 20 namespace ukm { |
| 20 | 21 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 EXPECT_EQ(GetPersistedLogCount(), 1); | 116 EXPECT_EQ(GetPersistedLogCount(), 1); |
| 116 | 117 |
| 117 Report proto_report = GetPersistedReport(); | 118 Report proto_report = GetPersistedReport(); |
| 118 EXPECT_EQ(1, proto_report.sources_size()); | 119 EXPECT_EQ(1, proto_report.sources_size()); |
| 119 const Source& proto_source = proto_report.sources(0); | 120 const Source& proto_source = proto_report.sources(0); |
| 120 | 121 |
| 121 EXPECT_EQ(GURL("https://google.com").spec(), proto_source.url()); | 122 EXPECT_EQ(GURL("https://google.com").spec(), proto_source.url()); |
| 122 EXPECT_EQ(300, proto_source.first_contentful_paint_msec()); | 123 EXPECT_EQ(300, proto_source.first_contentful_paint_msec()); |
| 123 } | 124 } |
| 124 | 125 |
| 126 TEST_F(UkmServiceTest, MetricsProviderTest) { |
| 127 UkmService service(&prefs_, &client_); |
| 128 |
| 129 metrics::TestMetricsProvider* provider = new metrics::TestMetricsProvider(); |
| 130 service.RegisterMetricsProvider( |
| 131 std::unique_ptr<metrics::MetricsProvider>(provider)); |
| 132 |
| 133 service.Initialize(); |
| 134 |
| 135 // Providers have not supplied system profile information yet. |
| 136 EXPECT_FALSE(provider->provide_system_profile_metrics_called()); |
| 137 |
| 138 task_runner_->RunUntilIdle(); |
| 139 service.EnableReporting(); |
| 140 |
| 141 service.RecordSource(base::WrapUnique(new UkmSource())); |
| 142 service.Flush(); |
| 143 EXPECT_EQ(GetPersistedLogCount(), 1); |
| 144 |
| 145 Report proto_report = GetPersistedReport(); |
| 146 EXPECT_EQ(1, proto_report.sources_size()); |
| 147 |
| 148 // Providers have now supplied system profile information. |
| 149 EXPECT_TRUE(provider->provide_system_profile_metrics_called()); |
| 150 } |
| 151 |
| 125 } // namespace ukm | 152 } // namespace ukm |
| OLD | NEW |