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

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

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