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

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

Issue 2855053002: Allow empty UKM entries to be recorded. (Closed)
Patch Set: Fix test Created 3 years, 7 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.h ('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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 EXPECT_EQ(2, proto_entry_foo.metrics_size()); 252 EXPECT_EQ(2, proto_entry_foo.metrics_size());
253 const Entry::Metric proto_entry_foo_start = proto_entry_foo.metrics(0); 253 const Entry::Metric proto_entry_foo_start = proto_entry_foo.metrics(0);
254 EXPECT_EQ(base::HashMetricName("foo_start"), 254 EXPECT_EQ(base::HashMetricName("foo_start"),
255 proto_entry_foo_start.metric_hash()); 255 proto_entry_foo_start.metric_hash());
256 EXPECT_EQ(0, proto_entry_foo_start.value()); 256 EXPECT_EQ(0, proto_entry_foo_start.value());
257 const Entry::Metric proto_entry_foo_end = proto_entry_foo.metrics(1); 257 const Entry::Metric proto_entry_foo_end = proto_entry_foo.metrics(1);
258 EXPECT_EQ(base::HashMetricName("foo_end"), proto_entry_foo_end.metric_hash()); 258 EXPECT_EQ(base::HashMetricName("foo_end"), proto_entry_foo_end.metric_hash());
259 EXPECT_EQ(10, proto_entry_foo_end.value()); 259 EXPECT_EQ(10, proto_entry_foo_end.value());
260 } 260 }
261 261
262 TEST_F(UkmServiceTest, AddEntryOnlyWithNonEmptyMetrics) { 262 TEST_F(UkmServiceTest, AddEntryWithEmptyMetrics) {
263 UkmService service(&prefs_, &client_); 263 UkmService service(&prefs_, &client_);
264 EXPECT_EQ(0, GetPersistedLogCount()); 264 EXPECT_EQ(0, GetPersistedLogCount());
265 service.Initialize(); 265 service.Initialize();
266 task_runner_->RunUntilIdle(); 266 task_runner_->RunUntilIdle();
267 service.EnableRecording(); 267 service.EnableRecording();
268 service.EnableReporting(); 268 service.EnableReporting();
269 269
270 int32_t id = UkmService::GetNewSourceID(); 270 int32_t id = UkmService::GetNewSourceID();
271 service.UpdateSourceURL(id, GURL("https://google.com/foobar")); 271 service.UpdateSourceURL(id, GURL("https://google.com/foobar"));
272 272
273 { 273 {
274 std::unique_ptr<UkmEntryBuilder> builder = 274 std::unique_ptr<UkmEntryBuilder> builder =
275 service.GetEntryBuilder(id, "PageLoad"); 275 service.GetEntryBuilder(id, "PageLoad");
276 } 276 }
277 service.Flush(); 277 service.Flush();
278 EXPECT_EQ(1, GetPersistedLogCount()); 278 EXPECT_EQ(1, GetPersistedLogCount());
279 Report proto_report = GetPersistedReport(); 279 Report proto_report = GetPersistedReport();
280 EXPECT_EQ(0, proto_report.entries_size()); 280 EXPECT_EQ(1, proto_report.entries_size());
281
282 {
283 std::unique_ptr<UkmEntryBuilder> builder =
284 service.GetEntryBuilder(id, "PageLoad");
285 builder->AddMetric("FirstContentfulPaint", 300);
286 }
287 service.Flush();
288 EXPECT_EQ(2, GetPersistedLogCount());
289 Report proto_report_with_entries = GetPersistedReport();
290 EXPECT_EQ(1, proto_report_with_entries.entries_size());
291 } 281 }
292 282
293 TEST_F(UkmServiceTest, MetricsProviderTest) { 283 TEST_F(UkmServiceTest, MetricsProviderTest) {
294 UkmService service(&prefs_, &client_); 284 UkmService service(&prefs_, &client_);
295 285
296 metrics::TestMetricsProvider* provider = new metrics::TestMetricsProvider(); 286 metrics::TestMetricsProvider* provider = new metrics::TestMetricsProvider();
297 service.RegisterMetricsProvider( 287 service.RegisterMetricsProvider(
298 std::unique_ptr<metrics::MetricsProvider>(provider)); 288 std::unique_ptr<metrics::MetricsProvider>(provider));
299 289
300 service.Initialize(); 290 service.Initialize();
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 service.Flush(); 548 service.Flush();
559 EXPECT_EQ(1, GetPersistedLogCount()); 549 EXPECT_EQ(1, GetPersistedLogCount());
560 550
561 auto proto_report = GetPersistedReport(); 551 auto proto_report = GetPersistedReport();
562 ASSERT_EQ(1, proto_report.sources_size()); 552 ASSERT_EQ(1, proto_report.sources_size());
563 const Source& proto_source = proto_report.sources(0); 553 const Source& proto_source = proto_report.sources(0);
564 EXPECT_EQ("URLTooLong", proto_source.url()); 554 EXPECT_EQ("URLTooLong", proto_source.url());
565 } 555 }
566 556
567 } // namespace ukm 557 } // namespace ukm
OLDNEW
« no previous file with comments | « components/ukm/ukm_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698