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" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 TEST_F(UkmServiceTest, SourceSerialization) { | 101 TEST_F(UkmServiceTest, SourceSerialization) { |
102 UkmService service(&prefs_, &client_); | 102 UkmService service(&prefs_, &client_); |
103 EXPECT_EQ(GetPersistedLogCount(), 0); | 103 EXPECT_EQ(GetPersistedLogCount(), 0); |
104 service.Initialize(); | 104 service.Initialize(); |
105 task_runner_->RunUntilIdle(); | 105 task_runner_->RunUntilIdle(); |
106 service.EnableReporting(); | 106 service.EnableReporting(); |
107 | 107 |
108 std::unique_ptr<UkmSource> source = base::WrapUnique(new UkmSource()); | 108 std::unique_ptr<UkmSource> source = base::WrapUnique(new UkmSource()); |
109 source->set_committed_url(GURL("https://google.com")); | 109 source->set_committed_url(GURL("https://google.com")); |
110 base::Time test_time; | |
111 source->set_navigation_start(test_time); | |
112 source->set_first_contentful_paint(base::TimeDelta::FromMilliseconds(300)); | 110 source->set_first_contentful_paint(base::TimeDelta::FromMilliseconds(300)); |
113 | 111 |
114 service.RecordSource(std::move(source)); | 112 service.RecordSource(std::move(source)); |
115 | 113 |
116 service.Flush(); | 114 service.Flush(); |
117 EXPECT_EQ(GetPersistedLogCount(), 1); | 115 EXPECT_EQ(GetPersistedLogCount(), 1); |
118 | 116 |
119 Report proto_report = GetPersistedReport(); | 117 Report proto_report = GetPersistedReport(); |
120 EXPECT_EQ(1, proto_report.sources_size()); | 118 EXPECT_EQ(1, proto_report.sources_size()); |
121 const Source& proto_source = proto_report.sources(0); | 119 const Source& proto_source = proto_report.sources(0); |
122 | 120 |
123 EXPECT_EQ(GURL("https://google.com").spec(), proto_source.url()); | 121 EXPECT_EQ(GURL("https://google.com").spec(), proto_source.url()); |
124 base::Time navigation_time = | |
125 base::Time::UnixEpoch() + | |
126 base::TimeDelta::FromMilliseconds(proto_source.navigation_time_msec()); | |
127 EXPECT_EQ(test_time, navigation_time); | |
128 EXPECT_EQ(300, proto_source.first_contentful_paint_msec()); | 122 EXPECT_EQ(300, proto_source.first_contentful_paint_msec()); |
129 } | 123 } |
130 | 124 |
131 } // namespace ukm | 125 } // namespace ukm |
OLD | NEW |