OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse
rver.h" | 5 #include "chrome/browser/page_load_metrics/observers/core_page_load_metrics_obse
rver.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" | 8 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" |
9 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 9 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
10 #include "chrome/test/base/testing_browser_process.h" | 10 #include "chrome/test/base/testing_browser_process.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, 0); | 41 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, 0); |
42 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 0); | 42 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 0); |
43 histogram_tester().ExpectTotalCount(internal::kHistogramFirstLayout, 0); | 43 histogram_tester().ExpectTotalCount(internal::kHistogramFirstLayout, 0); |
44 histogram_tester().ExpectTotalCount(internal::kHistogramFirstTextPaint, 0); | 44 histogram_tester().ExpectTotalCount(internal::kHistogramFirstTextPaint, 0); |
45 } | 45 } |
46 | 46 |
47 TEST_F(CorePageLoadMetricsObserverTest, | 47 TEST_F(CorePageLoadMetricsObserverTest, |
48 SameDocumentNoTriggerUntilTrueNavCommit) { | 48 SameDocumentNoTriggerUntilTrueNavCommit) { |
49 base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1); | 49 base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1); |
50 | 50 |
51 page_load_metrics::PageLoadTiming timing; | 51 page_load_metrics::mojom::PageLoadTiming timing; |
| 52 page_load_metrics::InitPageLoadTimingForTest(&timing); |
52 timing.navigation_start = base::Time::FromDoubleT(1); | 53 timing.navigation_start = base::Time::FromDoubleT(1); |
53 timing.document_timing.first_layout = first_layout; | 54 timing.document_timing->first_layout = first_layout; |
54 PopulateRequiredTimingFields(&timing); | 55 PopulateRequiredTimingFields(&timing); |
55 | 56 |
56 NavigateAndCommit(GURL(kDefaultTestUrl)); | 57 NavigateAndCommit(GURL(kDefaultTestUrl)); |
57 SimulateTimingUpdate(timing); | 58 SimulateTimingUpdate(timing); |
58 | 59 |
59 NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); | 60 NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); |
60 | 61 |
61 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 62 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
62 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, 0); | 63 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, 0); |
63 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 0); | 64 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 0); |
64 histogram_tester().ExpectTotalCount(internal::kHistogramFirstLayout, 1); | 65 histogram_tester().ExpectTotalCount(internal::kHistogramFirstLayout, 1); |
65 histogram_tester().ExpectBucketCount(internal::kHistogramFirstLayout, | 66 histogram_tester().ExpectBucketCount(internal::kHistogramFirstLayout, |
66 first_layout.InMilliseconds(), 1); | 67 first_layout.InMilliseconds(), 1); |
67 histogram_tester().ExpectTotalCount(internal::kHistogramFirstTextPaint, 0); | 68 histogram_tester().ExpectTotalCount(internal::kHistogramFirstTextPaint, 0); |
68 } | 69 } |
69 | 70 |
70 TEST_F(CorePageLoadMetricsObserverTest, SingleMetricAfterCommit) { | 71 TEST_F(CorePageLoadMetricsObserverTest, SingleMetricAfterCommit) { |
71 base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1); | 72 base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1); |
72 base::TimeDelta parse_start = base::TimeDelta::FromMilliseconds(1); | 73 base::TimeDelta parse_start = base::TimeDelta::FromMilliseconds(1); |
73 base::TimeDelta parse_stop = base::TimeDelta::FromMilliseconds(5); | 74 base::TimeDelta parse_stop = base::TimeDelta::FromMilliseconds(5); |
74 base::TimeDelta parse_script_load_duration = | 75 base::TimeDelta parse_script_load_duration = |
75 base::TimeDelta::FromMilliseconds(3); | 76 base::TimeDelta::FromMilliseconds(3); |
76 base::TimeDelta parse_script_exec_duration = | 77 base::TimeDelta parse_script_exec_duration = |
77 base::TimeDelta::FromMilliseconds(1); | 78 base::TimeDelta::FromMilliseconds(1); |
78 | 79 |
79 page_load_metrics::PageLoadTiming timing; | 80 page_load_metrics::mojom::PageLoadTiming timing; |
| 81 page_load_metrics::InitPageLoadTimingForTest(&timing); |
80 timing.navigation_start = base::Time::FromDoubleT(1); | 82 timing.navigation_start = base::Time::FromDoubleT(1); |
81 timing.document_timing.first_layout = first_layout; | 83 timing.document_timing->first_layout = first_layout; |
82 timing.parse_timing.parse_start = parse_start; | 84 timing.parse_timing->parse_start = parse_start; |
83 timing.parse_timing.parse_stop = parse_stop; | 85 timing.parse_timing->parse_stop = parse_stop; |
84 timing.parse_timing.parse_blocked_on_script_load_duration = | 86 timing.parse_timing->parse_blocked_on_script_load_duration = |
85 parse_script_load_duration; | 87 parse_script_load_duration; |
86 timing.parse_timing.parse_blocked_on_script_execution_duration = | 88 timing.parse_timing->parse_blocked_on_script_execution_duration = |
87 parse_script_exec_duration; | 89 parse_script_exec_duration; |
88 PopulateRequiredTimingFields(&timing); | 90 PopulateRequiredTimingFields(&timing); |
89 | 91 |
90 NavigateAndCommit(GURL(kDefaultTestUrl)); | 92 NavigateAndCommit(GURL(kDefaultTestUrl)); |
91 SimulateTimingUpdate(timing); | 93 SimulateTimingUpdate(timing); |
92 | 94 |
93 // Navigate again to force histogram recording. | 95 // Navigate again to force histogram recording. |
94 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 96 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
95 | 97 |
96 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, 0); | 98 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, 0); |
(...skipping 18 matching lines...) Expand all Loading... |
115 | 117 |
116 TEST_F(CorePageLoadMetricsObserverTest, MultipleMetricsAfterCommits) { | 118 TEST_F(CorePageLoadMetricsObserverTest, MultipleMetricsAfterCommits) { |
117 base::TimeDelta response = base::TimeDelta::FromMilliseconds(1); | 119 base::TimeDelta response = base::TimeDelta::FromMilliseconds(1); |
118 base::TimeDelta first_layout_1 = base::TimeDelta::FromMilliseconds(10); | 120 base::TimeDelta first_layout_1 = base::TimeDelta::FromMilliseconds(10); |
119 base::TimeDelta first_layout_2 = base::TimeDelta::FromMilliseconds(20); | 121 base::TimeDelta first_layout_2 = base::TimeDelta::FromMilliseconds(20); |
120 base::TimeDelta first_text_paint = base::TimeDelta::FromMilliseconds(30); | 122 base::TimeDelta first_text_paint = base::TimeDelta::FromMilliseconds(30); |
121 base::TimeDelta first_contentful_paint = first_text_paint; | 123 base::TimeDelta first_contentful_paint = first_text_paint; |
122 base::TimeDelta dom_content = base::TimeDelta::FromMilliseconds(40); | 124 base::TimeDelta dom_content = base::TimeDelta::FromMilliseconds(40); |
123 base::TimeDelta load = base::TimeDelta::FromMilliseconds(100); | 125 base::TimeDelta load = base::TimeDelta::FromMilliseconds(100); |
124 | 126 |
125 page_load_metrics::PageLoadTiming timing; | 127 page_load_metrics::mojom::PageLoadTiming timing; |
| 128 page_load_metrics::InitPageLoadTimingForTest(&timing); |
126 timing.navigation_start = base::Time::FromDoubleT(1); | 129 timing.navigation_start = base::Time::FromDoubleT(1); |
127 timing.response_start = response; | 130 timing.response_start = response; |
128 timing.document_timing.first_layout = first_layout_1; | 131 timing.document_timing->first_layout = first_layout_1; |
129 timing.paint_timing.first_text_paint = first_text_paint; | 132 timing.paint_timing->first_text_paint = first_text_paint; |
130 timing.paint_timing.first_contentful_paint = first_contentful_paint; | 133 timing.paint_timing->first_contentful_paint = first_contentful_paint; |
131 timing.document_timing.dom_content_loaded_event_start = dom_content; | 134 timing.document_timing->dom_content_loaded_event_start = dom_content; |
132 timing.document_timing.load_event_start = load; | 135 timing.document_timing->load_event_start = load; |
133 PopulateRequiredTimingFields(&timing); | 136 PopulateRequiredTimingFields(&timing); |
134 | 137 |
135 NavigateAndCommit(GURL(kDefaultTestUrl)); | 138 NavigateAndCommit(GURL(kDefaultTestUrl)); |
136 SimulateTimingUpdate(timing); | 139 SimulateTimingUpdate(timing); |
137 | 140 |
138 histogram_tester().ExpectTotalCount(internal::kHistogramFirstContentfulPaint, | 141 histogram_tester().ExpectTotalCount(internal::kHistogramFirstContentfulPaint, |
139 1); | 142 1); |
140 histogram_tester().ExpectBucketCount(internal::kHistogramFirstContentfulPaint, | 143 histogram_tester().ExpectBucketCount(internal::kHistogramFirstContentfulPaint, |
141 first_contentful_paint.InMilliseconds(), | 144 first_contentful_paint.InMilliseconds(), |
142 1); | 145 1); |
143 | 146 |
144 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 147 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
145 | 148 |
146 page_load_metrics::PageLoadTiming timing2; | 149 page_load_metrics::mojom::PageLoadTiming timing2; |
| 150 page_load_metrics::InitPageLoadTimingForTest(&timing2); |
147 timing2.navigation_start = base::Time::FromDoubleT(200); | 151 timing2.navigation_start = base::Time::FromDoubleT(200); |
148 timing2.document_timing.first_layout = first_layout_2; | 152 timing2.document_timing->first_layout = first_layout_2; |
149 PopulateRequiredTimingFields(&timing2); | 153 PopulateRequiredTimingFields(&timing2); |
150 | 154 |
151 SimulateTimingUpdate(timing2); | 155 SimulateTimingUpdate(timing2); |
152 | 156 |
153 NavigateAndCommit(GURL(kDefaultTestUrl)); | 157 NavigateAndCommit(GURL(kDefaultTestUrl)); |
154 | 158 |
155 histogram_tester().ExpectTotalCount(internal::kHistogramFirstLayout, 2); | 159 histogram_tester().ExpectTotalCount(internal::kHistogramFirstLayout, 2); |
156 histogram_tester().ExpectBucketCount(internal::kHistogramFirstLayout, | 160 histogram_tester().ExpectBucketCount(internal::kHistogramFirstLayout, |
157 first_layout_1.InMilliseconds(), 1); | 161 first_layout_1.InMilliseconds(), 1); |
158 histogram_tester().ExpectBucketCount(internal::kHistogramFirstLayout, | 162 histogram_tester().ExpectBucketCount(internal::kHistogramFirstLayout, |
(...skipping 13 matching lines...) Expand all Loading... |
172 dom_content.InMilliseconds(), 1); | 176 dom_content.InMilliseconds(), 1); |
173 | 177 |
174 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 1); | 178 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 1); |
175 histogram_tester().ExpectBucketCount(internal::kHistogramLoad, | 179 histogram_tester().ExpectBucketCount(internal::kHistogramLoad, |
176 load.InMilliseconds(), 1); | 180 load.InMilliseconds(), 1); |
177 } | 181 } |
178 | 182 |
179 TEST_F(CorePageLoadMetricsObserverTest, BackgroundDifferentHistogram) { | 183 TEST_F(CorePageLoadMetricsObserverTest, BackgroundDifferentHistogram) { |
180 base::TimeDelta first_layout = base::TimeDelta::FromSeconds(2); | 184 base::TimeDelta first_layout = base::TimeDelta::FromSeconds(2); |
181 | 185 |
182 page_load_metrics::PageLoadTiming timing; | 186 page_load_metrics::mojom::PageLoadTiming timing; |
| 187 page_load_metrics::InitPageLoadTimingForTest(&timing); |
183 timing.navigation_start = base::Time::FromDoubleT(1); | 188 timing.navigation_start = base::Time::FromDoubleT(1); |
184 timing.document_timing.first_layout = first_layout; | 189 timing.document_timing->first_layout = first_layout; |
185 PopulateRequiredTimingFields(&timing); | 190 PopulateRequiredTimingFields(&timing); |
186 | 191 |
187 // Simulate "Open link in new tab." | 192 // Simulate "Open link in new tab." |
188 web_contents()->WasHidden(); | 193 web_contents()->WasHidden(); |
189 NavigateAndCommit(GURL(kDefaultTestUrl)); | 194 NavigateAndCommit(GURL(kDefaultTestUrl)); |
190 SimulateTimingUpdate(timing); | 195 SimulateTimingUpdate(timing); |
191 | 196 |
192 // Simulate switching to the tab and making another navigation. | 197 // Simulate switching to the tab and making another navigation. |
193 web_contents()->WasShown(); | 198 web_contents()->WasShown(); |
194 | 199 |
(...skipping 11 matching lines...) Expand all Loading... |
206 histogram_tester().ExpectTotalCount( | 211 histogram_tester().ExpectTotalCount( |
207 internal::kBackgroundHistogramFirstTextPaint, 0); | 212 internal::kBackgroundHistogramFirstTextPaint, 0); |
208 | 213 |
209 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, 0); | 214 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, 0); |
210 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 0); | 215 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 0); |
211 histogram_tester().ExpectTotalCount(internal::kHistogramFirstLayout, 0); | 216 histogram_tester().ExpectTotalCount(internal::kHistogramFirstLayout, 0); |
212 histogram_tester().ExpectTotalCount(internal::kHistogramFirstTextPaint, 0); | 217 histogram_tester().ExpectTotalCount(internal::kHistogramFirstTextPaint, 0); |
213 } | 218 } |
214 | 219 |
215 TEST_F(CorePageLoadMetricsObserverTest, OnlyBackgroundLaterEvents) { | 220 TEST_F(CorePageLoadMetricsObserverTest, OnlyBackgroundLaterEvents) { |
216 page_load_metrics::PageLoadTiming timing; | 221 page_load_metrics::mojom::PageLoadTiming timing; |
| 222 page_load_metrics::InitPageLoadTimingForTest(&timing); |
217 timing.navigation_start = base::Time::FromDoubleT(1); | 223 timing.navigation_start = base::Time::FromDoubleT(1); |
218 timing.document_timing.dom_content_loaded_event_start = | 224 timing.document_timing->dom_content_loaded_event_start = |
219 base::TimeDelta::FromMicroseconds(1); | 225 base::TimeDelta::FromMicroseconds(1); |
220 PopulateRequiredTimingFields(&timing); | 226 PopulateRequiredTimingFields(&timing); |
221 | 227 |
222 // Make sure first_text_paint hasn't been set (wasn't set by | 228 // Make sure first_text_paint hasn't been set (wasn't set by |
223 // PopulateRequiredTimingFields), since we want to defer setting it until | 229 // PopulateRequiredTimingFields), since we want to defer setting it until |
224 // after backgrounding. | 230 // after backgrounding. |
225 ASSERT_FALSE(timing.paint_timing.first_text_paint); | 231 ASSERT_FALSE(timing.paint_timing->first_text_paint); |
226 | 232 |
227 NavigateAndCommit(GURL(kDefaultTestUrl)); | 233 NavigateAndCommit(GURL(kDefaultTestUrl)); |
228 SimulateTimingUpdate(timing); | 234 SimulateTimingUpdate(timing); |
229 | 235 |
230 // Background the tab, then foreground it. | 236 // Background the tab, then foreground it. |
231 web_contents()->WasHidden(); | 237 web_contents()->WasHidden(); |
232 web_contents()->WasShown(); | 238 web_contents()->WasShown(); |
233 timing.paint_timing.first_text_paint = base::TimeDelta::FromSeconds(4); | 239 timing.paint_timing->first_text_paint = base::TimeDelta::FromSeconds(4); |
234 PopulateRequiredTimingFields(&timing); | 240 PopulateRequiredTimingFields(&timing); |
235 SimulateTimingUpdate(timing); | 241 SimulateTimingUpdate(timing); |
236 | 242 |
237 // If the system clock is low resolution, PageLoadTracker's | 243 // If the system clock is low resolution, PageLoadTracker's |
238 // first_background_time_ may be same as other times such as | 244 // first_background_time_ may be same as other times such as |
239 // dom_content_loaded_event_start. | 245 // dom_content_loaded_event_start. |
240 page_load_metrics::PageLoadExtraInfo info = | 246 page_load_metrics::PageLoadExtraInfo info = |
241 GetPageLoadExtraInfoForCommittedLoad(); | 247 GetPageLoadExtraInfoForCommittedLoad(); |
242 | 248 |
243 // Navigate again to force histogram recording. | 249 // Navigate again to force histogram recording. |
244 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 250 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
245 | 251 |
246 if (page_load_metrics::WasStartedInForegroundOptionalEventInForeground( | 252 if (page_load_metrics::WasStartedInForegroundOptionalEventInForeground( |
247 timing.document_timing.dom_content_loaded_event_start, info)) { | 253 timing.document_timing->dom_content_loaded_event_start, info)) { |
248 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, | 254 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, |
249 1); | 255 1); |
250 histogram_tester().ExpectBucketCount( | 256 histogram_tester().ExpectBucketCount( |
251 internal::kHistogramDomContentLoaded, | 257 internal::kHistogramDomContentLoaded, |
252 timing.document_timing.dom_content_loaded_event_start.value() | 258 timing.document_timing->dom_content_loaded_event_start.value() |
253 .InMilliseconds(), | 259 .InMilliseconds(), |
254 1); | 260 1); |
255 histogram_tester().ExpectTotalCount( | 261 histogram_tester().ExpectTotalCount( |
256 internal::kBackgroundHistogramDomContentLoaded, 0); | 262 internal::kBackgroundHistogramDomContentLoaded, 0); |
257 } else { | 263 } else { |
258 histogram_tester().ExpectTotalCount( | 264 histogram_tester().ExpectTotalCount( |
259 internal::kBackgroundHistogramDomContentLoaded, 1); | 265 internal::kBackgroundHistogramDomContentLoaded, 1); |
260 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, | 266 histogram_tester().ExpectTotalCount(internal::kHistogramDomContentLoaded, |
261 0); | 267 0); |
262 } | 268 } |
263 | 269 |
264 histogram_tester().ExpectTotalCount(internal::kBackgroundHistogramLoad, 0); | 270 histogram_tester().ExpectTotalCount(internal::kBackgroundHistogramLoad, 0); |
265 histogram_tester().ExpectTotalCount( | 271 histogram_tester().ExpectTotalCount( |
266 internal::kBackgroundHistogramFirstTextPaint, 1); | 272 internal::kBackgroundHistogramFirstTextPaint, 1); |
267 histogram_tester().ExpectBucketCount( | 273 histogram_tester().ExpectBucketCount( |
268 internal::kBackgroundHistogramFirstTextPaint, | 274 internal::kBackgroundHistogramFirstTextPaint, |
269 timing.paint_timing.first_text_paint.value().InMilliseconds(), 1); | 275 timing.paint_timing->first_text_paint.value().InMilliseconds(), 1); |
270 | 276 |
271 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 0); | 277 histogram_tester().ExpectTotalCount(internal::kHistogramLoad, 0); |
272 histogram_tester().ExpectTotalCount(internal::kHistogramFirstTextPaint, 0); | 278 histogram_tester().ExpectTotalCount(internal::kHistogramFirstTextPaint, 0); |
273 | 279 |
274 histogram_tester().ExpectTotalCount( | 280 histogram_tester().ExpectTotalCount( |
275 internal::kHistogramPageTimingForegroundDuration, 1); | 281 internal::kHistogramPageTimingForegroundDuration, 1); |
276 } | 282 } |
277 | 283 |
278 TEST_F(CorePageLoadMetricsObserverTest, DontBackgroundQuickerLoad) { | 284 TEST_F(CorePageLoadMetricsObserverTest, DontBackgroundQuickerLoad) { |
279 // Set this event at 1 microsecond so it occurs before we foreground later in | 285 // Set this event at 1 microsecond so it occurs before we foreground later in |
280 // the test. | 286 // the test. |
281 base::TimeDelta first_layout = base::TimeDelta::FromMicroseconds(1); | 287 base::TimeDelta first_layout = base::TimeDelta::FromMicroseconds(1); |
282 | 288 |
283 page_load_metrics::PageLoadTiming timing; | 289 page_load_metrics::mojom::PageLoadTiming timing; |
| 290 page_load_metrics::InitPageLoadTimingForTest(&timing); |
284 timing.navigation_start = base::Time::FromDoubleT(1); | 291 timing.navigation_start = base::Time::FromDoubleT(1); |
285 timing.document_timing.first_layout = first_layout; | 292 timing.document_timing->first_layout = first_layout; |
286 PopulateRequiredTimingFields(&timing); | 293 PopulateRequiredTimingFields(&timing); |
287 | 294 |
288 web_contents()->WasHidden(); | 295 web_contents()->WasHidden(); |
289 | 296 |
290 // Open in new tab | 297 // Open in new tab |
291 StartNavigation(GURL(kDefaultTestUrl)); | 298 StartNavigation(GURL(kDefaultTestUrl)); |
292 | 299 |
293 // Switch to the tab | 300 // Switch to the tab |
294 web_contents()->WasShown(); | 301 web_contents()->WasShown(); |
295 | 302 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 } | 357 } |
351 | 358 |
352 TEST_F(CorePageLoadMetricsObserverTest, NoRappor) { | 359 TEST_F(CorePageLoadMetricsObserverTest, NoRappor) { |
353 rappor::TestSample::Shadow* sample_obj = | 360 rappor::TestSample::Shadow* sample_obj = |
354 rappor_tester_.GetRecordedSampleForMetric( | 361 rappor_tester_.GetRecordedSampleForMetric( |
355 internal::kRapporMetricsNameCoarseTiming); | 362 internal::kRapporMetricsNameCoarseTiming); |
356 EXPECT_EQ(sample_obj, nullptr); | 363 EXPECT_EQ(sample_obj, nullptr); |
357 } | 364 } |
358 | 365 |
359 TEST_F(CorePageLoadMetricsObserverTest, RapporLongPageLoad) { | 366 TEST_F(CorePageLoadMetricsObserverTest, RapporLongPageLoad) { |
360 page_load_metrics::PageLoadTiming timing; | 367 page_load_metrics::mojom::PageLoadTiming timing; |
| 368 page_load_metrics::InitPageLoadTimingForTest(&timing); |
361 timing.navigation_start = base::Time::FromDoubleT(1); | 369 timing.navigation_start = base::Time::FromDoubleT(1); |
362 timing.paint_timing.first_contentful_paint = base::TimeDelta::FromSeconds(40); | 370 timing.paint_timing->first_contentful_paint = |
| 371 base::TimeDelta::FromSeconds(40); |
363 PopulateRequiredTimingFields(&timing); | 372 PopulateRequiredTimingFields(&timing); |
364 NavigateAndCommit(GURL(kDefaultTestUrl)); | 373 NavigateAndCommit(GURL(kDefaultTestUrl)); |
365 SimulateTimingUpdate(timing); | 374 SimulateTimingUpdate(timing); |
366 | 375 |
367 // Navigate again to force logging RAPPOR. | 376 // Navigate again to force logging RAPPOR. |
368 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 377 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
369 rappor::TestSample::Shadow* sample_obj = | 378 rappor::TestSample::Shadow* sample_obj = |
370 rappor_tester_.GetRecordedSampleForMetric( | 379 rappor_tester_.GetRecordedSampleForMetric( |
371 internal::kRapporMetricsNameCoarseTiming); | 380 internal::kRapporMetricsNameCoarseTiming); |
372 const auto& string_it = sample_obj->string_fields.find("Domain"); | 381 const auto& string_it = sample_obj->string_fields.find("Domain"); |
373 EXPECT_NE(string_it, sample_obj->string_fields.end()); | 382 EXPECT_NE(string_it, sample_obj->string_fields.end()); |
374 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)), | 383 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)), |
375 string_it->second); | 384 string_it->second); |
376 | 385 |
377 const auto& flag_it = sample_obj->flag_fields.find("IsSlow"); | 386 const auto& flag_it = sample_obj->flag_fields.find("IsSlow"); |
378 EXPECT_NE(flag_it, sample_obj->flag_fields.end()); | 387 EXPECT_NE(flag_it, sample_obj->flag_fields.end()); |
379 EXPECT_EQ(1u, flag_it->second); | 388 EXPECT_EQ(1u, flag_it->second); |
380 } | 389 } |
381 | 390 |
382 TEST_F(CorePageLoadMetricsObserverTest, RapporQuickPageLoad) { | 391 TEST_F(CorePageLoadMetricsObserverTest, RapporQuickPageLoad) { |
383 page_load_metrics::PageLoadTiming timing; | 392 page_load_metrics::mojom::PageLoadTiming timing; |
| 393 page_load_metrics::InitPageLoadTimingForTest(&timing); |
384 timing.navigation_start = base::Time::FromDoubleT(1); | 394 timing.navigation_start = base::Time::FromDoubleT(1); |
385 timing.paint_timing.first_contentful_paint = base::TimeDelta::FromSeconds(1); | 395 timing.paint_timing->first_contentful_paint = base::TimeDelta::FromSeconds(1); |
386 PopulateRequiredTimingFields(&timing); | 396 PopulateRequiredTimingFields(&timing); |
387 | 397 |
388 NavigateAndCommit(GURL(kDefaultTestUrl)); | 398 NavigateAndCommit(GURL(kDefaultTestUrl)); |
389 SimulateTimingUpdate(timing); | 399 SimulateTimingUpdate(timing); |
390 | 400 |
391 // Navigate again to force logging RAPPOR. | 401 // Navigate again to force logging RAPPOR. |
392 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 402 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
393 rappor::TestSample::Shadow* sample_obj = | 403 rappor::TestSample::Shadow* sample_obj = |
394 rappor_tester_.GetRecordedSampleForMetric( | 404 rappor_tester_.GetRecordedSampleForMetric( |
395 internal::kRapporMetricsNameCoarseTiming); | 405 internal::kRapporMetricsNameCoarseTiming); |
396 const auto& string_it = sample_obj->string_fields.find("Domain"); | 406 const auto& string_it = sample_obj->string_fields.find("Domain"); |
397 EXPECT_NE(string_it, sample_obj->string_fields.end()); | 407 EXPECT_NE(string_it, sample_obj->string_fields.end()); |
398 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)), | 408 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)), |
399 string_it->second); | 409 string_it->second); |
400 | 410 |
401 const auto& flag_it = sample_obj->flag_fields.find("IsSlow"); | 411 const auto& flag_it = sample_obj->flag_fields.find("IsSlow"); |
402 EXPECT_NE(flag_it, sample_obj->flag_fields.end()); | 412 EXPECT_NE(flag_it, sample_obj->flag_fields.end()); |
403 EXPECT_EQ(0u, flag_it->second); | 413 EXPECT_EQ(0u, flag_it->second); |
404 } | 414 } |
405 | 415 |
406 TEST_F(CorePageLoadMetricsObserverTest, Reload) { | 416 TEST_F(CorePageLoadMetricsObserverTest, Reload) { |
407 page_load_metrics::PageLoadTiming timing; | 417 page_load_metrics::mojom::PageLoadTiming timing; |
| 418 page_load_metrics::InitPageLoadTimingForTest(&timing); |
408 timing.navigation_start = base::Time::FromDoubleT(1); | 419 timing.navigation_start = base::Time::FromDoubleT(1); |
409 timing.parse_timing.parse_start = base::TimeDelta::FromMilliseconds(5); | 420 timing.parse_timing->parse_start = base::TimeDelta::FromMilliseconds(5); |
410 timing.paint_timing.first_contentful_paint = | 421 timing.paint_timing->first_contentful_paint = |
411 base::TimeDelta::FromMilliseconds(10); | 422 base::TimeDelta::FromMilliseconds(10); |
412 PopulateRequiredTimingFields(&timing); | 423 PopulateRequiredTimingFields(&timing); |
413 | 424 |
414 GURL url(kDefaultTestUrl); | 425 GURL url(kDefaultTestUrl); |
415 NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_RELOAD); | 426 NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_RELOAD); |
416 SimulateTimingUpdate(timing); | 427 SimulateTimingUpdate(timing); |
417 | 428 |
418 page_load_metrics::ExtraRequestCompleteInfo resources[] = { | 429 page_load_metrics::ExtraRequestCompleteInfo resources[] = { |
419 // Cached request. | 430 // Cached request. |
420 | 431 |
(...skipping 19 matching lines...) Expand all Loading... |
440 cache_bytes += request.raw_body_bytes; | 451 cache_bytes += request.raw_body_bytes; |
441 } | 452 } |
442 } | 453 } |
443 | 454 |
444 NavigateToUntrackedUrl(); | 455 NavigateToUntrackedUrl(); |
445 | 456 |
446 histogram_tester().ExpectTotalCount( | 457 histogram_tester().ExpectTotalCount( |
447 internal::kHistogramLoadTypeFirstContentfulPaintReload, 1); | 458 internal::kHistogramLoadTypeFirstContentfulPaintReload, 1); |
448 histogram_tester().ExpectBucketCount( | 459 histogram_tester().ExpectBucketCount( |
449 internal::kHistogramLoadTypeFirstContentfulPaintReload, | 460 internal::kHistogramLoadTypeFirstContentfulPaintReload, |
450 timing.paint_timing.first_contentful_paint.value().InMilliseconds(), 1); | 461 timing.paint_timing->first_contentful_paint.value().InMilliseconds(), 1); |
451 histogram_tester().ExpectTotalCount( | 462 histogram_tester().ExpectTotalCount( |
452 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 0); | 463 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 0); |
453 histogram_tester().ExpectTotalCount( | 464 histogram_tester().ExpectTotalCount( |
454 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 0); | 465 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 0); |
455 histogram_tester().ExpectTotalCount( | 466 histogram_tester().ExpectTotalCount( |
456 internal::kHistogramLoadTypeParseStartReload, 1); | 467 internal::kHistogramLoadTypeParseStartReload, 1); |
457 histogram_tester().ExpectBucketCount( | 468 histogram_tester().ExpectBucketCount( |
458 internal::kHistogramLoadTypeParseStartReload, | 469 internal::kHistogramLoadTypeParseStartReload, |
459 timing.parse_timing.parse_start.value().InMilliseconds(), 1); | 470 timing.parse_timing->parse_start.value().InMilliseconds(), 1); |
460 histogram_tester().ExpectTotalCount( | 471 histogram_tester().ExpectTotalCount( |
461 internal::kHistogramLoadTypeParseStartForwardBack, 0); | 472 internal::kHistogramLoadTypeParseStartForwardBack, 0); |
462 histogram_tester().ExpectTotalCount( | 473 histogram_tester().ExpectTotalCount( |
463 internal::kHistogramLoadTypeParseStartNewNavigation, 0); | 474 internal::kHistogramLoadTypeParseStartNewNavigation, 0); |
464 | 475 |
465 histogram_tester().ExpectUniqueSample( | 476 histogram_tester().ExpectUniqueSample( |
466 internal::kHistogramLoadTypeNetworkBytesReload, | 477 internal::kHistogramLoadTypeNetworkBytesReload, |
467 static_cast<int>((network_bytes) / 1024), 1); | 478 static_cast<int>((network_bytes) / 1024), 1); |
468 histogram_tester().ExpectTotalCount( | 479 histogram_tester().ExpectTotalCount( |
469 internal::kHistogramLoadTypeNetworkBytesForwardBack, 0); | 480 internal::kHistogramLoadTypeNetworkBytesForwardBack, 0); |
(...skipping 11 matching lines...) Expand all Loading... |
481 histogram_tester().ExpectUniqueSample( | 492 histogram_tester().ExpectUniqueSample( |
482 internal::kHistogramLoadTypeTotalBytesReload, | 493 internal::kHistogramLoadTypeTotalBytesReload, |
483 static_cast<int>((network_bytes + cache_bytes) / 1024), 1); | 494 static_cast<int>((network_bytes + cache_bytes) / 1024), 1); |
484 histogram_tester().ExpectTotalCount( | 495 histogram_tester().ExpectTotalCount( |
485 internal::kHistogramLoadTypeTotalBytesForwardBack, 0); | 496 internal::kHistogramLoadTypeTotalBytesForwardBack, 0); |
486 histogram_tester().ExpectTotalCount( | 497 histogram_tester().ExpectTotalCount( |
487 internal::kHistogramLoadTypeTotalBytesNewNavigation, 0); | 498 internal::kHistogramLoadTypeTotalBytesNewNavigation, 0); |
488 } | 499 } |
489 | 500 |
490 TEST_F(CorePageLoadMetricsObserverTest, ForwardBack) { | 501 TEST_F(CorePageLoadMetricsObserverTest, ForwardBack) { |
491 page_load_metrics::PageLoadTiming timing; | 502 page_load_metrics::mojom::PageLoadTiming timing; |
| 503 page_load_metrics::InitPageLoadTimingForTest(&timing); |
492 timing.navigation_start = base::Time::FromDoubleT(1); | 504 timing.navigation_start = base::Time::FromDoubleT(1); |
493 timing.parse_timing.parse_start = base::TimeDelta::FromMilliseconds(5); | 505 timing.parse_timing->parse_start = base::TimeDelta::FromMilliseconds(5); |
494 timing.paint_timing.first_contentful_paint = | 506 timing.paint_timing->first_contentful_paint = |
495 base::TimeDelta::FromMilliseconds(10); | 507 base::TimeDelta::FromMilliseconds(10); |
496 PopulateRequiredTimingFields(&timing); | 508 PopulateRequiredTimingFields(&timing); |
497 | 509 |
498 GURL url(kDefaultTestUrl); | 510 GURL url(kDefaultTestUrl); |
499 // Back navigations to a page that was reloaded report a main transition type | 511 // Back navigations to a page that was reloaded report a main transition type |
500 // of PAGE_TRANSITION_RELOAD with a PAGE_TRANSITION_FORWARD_BACK | 512 // of PAGE_TRANSITION_RELOAD with a PAGE_TRANSITION_FORWARD_BACK |
501 // modifier. This test verifies that when we encounter such a page, we log it | 513 // modifier. This test verifies that when we encounter such a page, we log it |
502 // as a forward/back navigation. | 514 // as a forward/back navigation. |
503 NavigateWithPageTransitionAndCommit( | 515 NavigateWithPageTransitionAndCommit( |
504 url, ui::PageTransitionFromInt(ui::PAGE_TRANSITION_RELOAD | | 516 url, ui::PageTransitionFromInt(ui::PAGE_TRANSITION_RELOAD | |
(...skipping 26 matching lines...) Expand all Loading... |
531 } | 543 } |
532 | 544 |
533 NavigateToUntrackedUrl(); | 545 NavigateToUntrackedUrl(); |
534 | 546 |
535 histogram_tester().ExpectTotalCount( | 547 histogram_tester().ExpectTotalCount( |
536 internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); | 548 internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); |
537 histogram_tester().ExpectTotalCount( | 549 histogram_tester().ExpectTotalCount( |
538 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 1); | 550 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 1); |
539 histogram_tester().ExpectBucketCount( | 551 histogram_tester().ExpectBucketCount( |
540 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, | 552 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, |
541 timing.paint_timing.first_contentful_paint.value().InMilliseconds(), 1); | 553 timing.paint_timing->first_contentful_paint.value().InMilliseconds(), 1); |
542 histogram_tester().ExpectTotalCount( | 554 histogram_tester().ExpectTotalCount( |
543 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 0); | 555 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 0); |
544 histogram_tester().ExpectTotalCount( | 556 histogram_tester().ExpectTotalCount( |
545 internal::kHistogramLoadTypeParseStartReload, 0); | 557 internal::kHistogramLoadTypeParseStartReload, 0); |
546 histogram_tester().ExpectTotalCount( | 558 histogram_tester().ExpectTotalCount( |
547 internal::kHistogramLoadTypeParseStartForwardBack, 1); | 559 internal::kHistogramLoadTypeParseStartForwardBack, 1); |
548 histogram_tester().ExpectBucketCount( | 560 histogram_tester().ExpectBucketCount( |
549 internal::kHistogramLoadTypeParseStartForwardBack, | 561 internal::kHistogramLoadTypeParseStartForwardBack, |
550 timing.parse_timing.parse_start.value().InMilliseconds(), 1); | 562 timing.parse_timing->parse_start.value().InMilliseconds(), 1); |
551 histogram_tester().ExpectTotalCount( | 563 histogram_tester().ExpectTotalCount( |
552 internal::kHistogramLoadTypeParseStartNewNavigation, 0); | 564 internal::kHistogramLoadTypeParseStartNewNavigation, 0); |
553 | 565 |
554 histogram_tester().ExpectUniqueSample( | 566 histogram_tester().ExpectUniqueSample( |
555 internal::kHistogramLoadTypeNetworkBytesForwardBack, | 567 internal::kHistogramLoadTypeNetworkBytesForwardBack, |
556 static_cast<int>((network_bytes) / 1024), 1); | 568 static_cast<int>((network_bytes) / 1024), 1); |
557 histogram_tester().ExpectTotalCount( | 569 histogram_tester().ExpectTotalCount( |
558 internal::kHistogramLoadTypeNetworkBytesNewNavigation, 0); | 570 internal::kHistogramLoadTypeNetworkBytesNewNavigation, 0); |
559 histogram_tester().ExpectTotalCount( | 571 histogram_tester().ExpectTotalCount( |
560 internal::kHistogramLoadTypeNetworkBytesReload, 0); | 572 internal::kHistogramLoadTypeNetworkBytesReload, 0); |
561 | 573 |
562 histogram_tester().ExpectUniqueSample( | 574 histogram_tester().ExpectUniqueSample( |
563 internal::kHistogramLoadTypeCacheBytesForwardBack, | 575 internal::kHistogramLoadTypeCacheBytesForwardBack, |
564 static_cast<int>((cache_bytes) / 1024), 1); | 576 static_cast<int>((cache_bytes) / 1024), 1); |
565 histogram_tester().ExpectTotalCount( | 577 histogram_tester().ExpectTotalCount( |
566 internal::kHistogramLoadTypeCacheBytesNewNavigation, 0); | 578 internal::kHistogramLoadTypeCacheBytesNewNavigation, 0); |
567 histogram_tester().ExpectTotalCount( | 579 histogram_tester().ExpectTotalCount( |
568 internal::kHistogramLoadTypeCacheBytesReload, 0); | 580 internal::kHistogramLoadTypeCacheBytesReload, 0); |
569 | 581 |
570 histogram_tester().ExpectUniqueSample( | 582 histogram_tester().ExpectUniqueSample( |
571 internal::kHistogramLoadTypeTotalBytesForwardBack, | 583 internal::kHistogramLoadTypeTotalBytesForwardBack, |
572 static_cast<int>((network_bytes + cache_bytes) / 1024), 1); | 584 static_cast<int>((network_bytes + cache_bytes) / 1024), 1); |
573 histogram_tester().ExpectTotalCount( | 585 histogram_tester().ExpectTotalCount( |
574 internal::kHistogramLoadTypeTotalBytesNewNavigation, 0); | 586 internal::kHistogramLoadTypeTotalBytesNewNavigation, 0); |
575 histogram_tester().ExpectTotalCount( | 587 histogram_tester().ExpectTotalCount( |
576 internal::kHistogramLoadTypeTotalBytesReload, 0); | 588 internal::kHistogramLoadTypeTotalBytesReload, 0); |
577 } | 589 } |
578 | 590 |
579 TEST_F(CorePageLoadMetricsObserverTest, NewNavigation) { | 591 TEST_F(CorePageLoadMetricsObserverTest, NewNavigation) { |
580 page_load_metrics::PageLoadTiming timing; | 592 page_load_metrics::mojom::PageLoadTiming timing; |
| 593 page_load_metrics::InitPageLoadTimingForTest(&timing); |
581 timing.navigation_start = base::Time::FromDoubleT(1); | 594 timing.navigation_start = base::Time::FromDoubleT(1); |
582 timing.parse_timing.parse_start = base::TimeDelta::FromMilliseconds(5); | 595 timing.parse_timing->parse_start = base::TimeDelta::FromMilliseconds(5); |
583 timing.paint_timing.first_contentful_paint = | 596 timing.paint_timing->first_contentful_paint = |
584 base::TimeDelta::FromMilliseconds(10); | 597 base::TimeDelta::FromMilliseconds(10); |
585 PopulateRequiredTimingFields(&timing); | 598 PopulateRequiredTimingFields(&timing); |
586 | 599 |
587 GURL url(kDefaultTestUrl); | 600 GURL url(kDefaultTestUrl); |
588 NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_LINK); | 601 NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_LINK); |
589 SimulateTimingUpdate(timing); | 602 SimulateTimingUpdate(timing); |
590 | 603 |
591 page_load_metrics::ExtraRequestCompleteInfo resources[] = { | 604 page_load_metrics::ExtraRequestCompleteInfo resources[] = { |
592 // Cached request. | 605 // Cached request. |
593 {GURL(), -1 /* frame_tree_node_id */, true /*was_cached*/, | 606 {GURL(), -1 /* frame_tree_node_id */, true /*was_cached*/, |
(...skipping 22 matching lines...) Expand all Loading... |
616 NavigateToUntrackedUrl(); | 629 NavigateToUntrackedUrl(); |
617 | 630 |
618 histogram_tester().ExpectTotalCount( | 631 histogram_tester().ExpectTotalCount( |
619 internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); | 632 internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); |
620 histogram_tester().ExpectTotalCount( | 633 histogram_tester().ExpectTotalCount( |
621 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 0); | 634 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 0); |
622 histogram_tester().ExpectTotalCount( | 635 histogram_tester().ExpectTotalCount( |
623 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 1); | 636 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 1); |
624 histogram_tester().ExpectBucketCount( | 637 histogram_tester().ExpectBucketCount( |
625 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, | 638 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, |
626 timing.paint_timing.first_contentful_paint.value().InMilliseconds(), 1); | 639 timing.paint_timing->first_contentful_paint.value().InMilliseconds(), 1); |
627 histogram_tester().ExpectTotalCount( | 640 histogram_tester().ExpectTotalCount( |
628 internal::kHistogramLoadTypeParseStartReload, 0); | 641 internal::kHistogramLoadTypeParseStartReload, 0); |
629 histogram_tester().ExpectTotalCount( | 642 histogram_tester().ExpectTotalCount( |
630 internal::kHistogramLoadTypeParseStartForwardBack, 0); | 643 internal::kHistogramLoadTypeParseStartForwardBack, 0); |
631 histogram_tester().ExpectTotalCount( | 644 histogram_tester().ExpectTotalCount( |
632 internal::kHistogramLoadTypeParseStartNewNavigation, 1); | 645 internal::kHistogramLoadTypeParseStartNewNavigation, 1); |
633 histogram_tester().ExpectBucketCount( | 646 histogram_tester().ExpectBucketCount( |
634 internal::kHistogramLoadTypeParseStartNewNavigation, | 647 internal::kHistogramLoadTypeParseStartNewNavigation, |
635 timing.parse_timing.parse_start.value().InMilliseconds(), 1); | 648 timing.parse_timing->parse_start.value().InMilliseconds(), 1); |
636 | 649 |
637 histogram_tester().ExpectUniqueSample( | 650 histogram_tester().ExpectUniqueSample( |
638 internal::kHistogramLoadTypeNetworkBytesNewNavigation, | 651 internal::kHistogramLoadTypeNetworkBytesNewNavigation, |
639 static_cast<int>((network_bytes) / 1024), 1); | 652 static_cast<int>((network_bytes) / 1024), 1); |
640 histogram_tester().ExpectTotalCount( | 653 histogram_tester().ExpectTotalCount( |
641 internal::kHistogramLoadTypeNetworkBytesForwardBack, 0); | 654 internal::kHistogramLoadTypeNetworkBytesForwardBack, 0); |
642 histogram_tester().ExpectTotalCount( | 655 histogram_tester().ExpectTotalCount( |
643 internal::kHistogramLoadTypeNetworkBytesReload, 0); | 656 internal::kHistogramLoadTypeNetworkBytesReload, 0); |
644 | 657 |
645 histogram_tester().ExpectUniqueSample( | 658 histogram_tester().ExpectUniqueSample( |
(...skipping 21 matching lines...) Expand all Loading... |
667 histogram_tester().ExpectTotalCount(internal::kHistogramCacheBytes, 1); | 680 histogram_tester().ExpectTotalCount(internal::kHistogramCacheBytes, 1); |
668 histogram_tester().ExpectTotalCount( | 681 histogram_tester().ExpectTotalCount( |
669 internal::kHistogramTotalCompletedResources, 1); | 682 internal::kHistogramTotalCompletedResources, 1); |
670 histogram_tester().ExpectTotalCount( | 683 histogram_tester().ExpectTotalCount( |
671 internal::kHistogramNetworkCompletedResources, 1); | 684 internal::kHistogramNetworkCompletedResources, 1); |
672 histogram_tester().ExpectTotalCount( | 685 histogram_tester().ExpectTotalCount( |
673 internal::kHistogramCacheCompletedResources, 1); | 686 internal::kHistogramCacheCompletedResources, 1); |
674 } | 687 } |
675 | 688 |
676 TEST_F(CorePageLoadMetricsObserverTest, FirstMeaningfulPaint) { | 689 TEST_F(CorePageLoadMetricsObserverTest, FirstMeaningfulPaint) { |
677 page_load_metrics::PageLoadTiming timing; | 690 page_load_metrics::mojom::PageLoadTiming timing; |
| 691 page_load_metrics::InitPageLoadTimingForTest(&timing); |
678 timing.navigation_start = base::Time::FromDoubleT(1); | 692 timing.navigation_start = base::Time::FromDoubleT(1); |
679 timing.parse_timing.parse_start = base::TimeDelta::FromMilliseconds(5); | 693 timing.parse_timing->parse_start = base::TimeDelta::FromMilliseconds(5); |
680 timing.paint_timing.first_meaningful_paint = | 694 timing.paint_timing->first_meaningful_paint = |
681 base::TimeDelta::FromMilliseconds(10); | 695 base::TimeDelta::FromMilliseconds(10); |
682 PopulateRequiredTimingFields(&timing); | 696 PopulateRequiredTimingFields(&timing); |
683 | 697 |
684 NavigateAndCommit(GURL(kDefaultTestUrl)); | 698 NavigateAndCommit(GURL(kDefaultTestUrl)); |
685 SimulateTimingUpdate(timing); | 699 SimulateTimingUpdate(timing); |
686 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 700 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
687 | 701 |
688 histogram_tester().ExpectTotalCount( | 702 histogram_tester().ExpectTotalCount( |
689 internal::kHistogramFirstMeaningfulPaint, 1); | 703 internal::kHistogramFirstMeaningfulPaint, 1); |
690 histogram_tester().ExpectTotalCount( | 704 histogram_tester().ExpectTotalCount( |
691 internal::kHistogramParseStartToFirstMeaningfulPaint, 1); | 705 internal::kHistogramParseStartToFirstMeaningfulPaint, 1); |
692 histogram_tester().ExpectBucketCount( | 706 histogram_tester().ExpectBucketCount( |
693 internal::kHistogramFirstMeaningfulPaintStatus, | 707 internal::kHistogramFirstMeaningfulPaintStatus, |
694 internal::FIRST_MEANINGFUL_PAINT_RECORDED, 1); | 708 internal::FIRST_MEANINGFUL_PAINT_RECORDED, 1); |
695 } | 709 } |
696 | 710 |
697 TEST_F(CorePageLoadMetricsObserverTest, FirstMeaningfulPaintAfterInteraction) { | 711 TEST_F(CorePageLoadMetricsObserverTest, FirstMeaningfulPaintAfterInteraction) { |
698 page_load_metrics::PageLoadTiming timing; | 712 page_load_metrics::mojom::PageLoadTiming timing; |
| 713 page_load_metrics::InitPageLoadTimingForTest(&timing); |
699 timing.navigation_start = base::Time::FromDoubleT(1); | 714 timing.navigation_start = base::Time::FromDoubleT(1); |
700 timing.parse_timing.parse_start = base::TimeDelta::FromMilliseconds(5); | 715 timing.parse_timing->parse_start = base::TimeDelta::FromMilliseconds(5); |
701 timing.paint_timing.first_paint = base::TimeDelta::FromMilliseconds(10); | 716 timing.paint_timing->first_paint = base::TimeDelta::FromMilliseconds(10); |
702 PopulateRequiredTimingFields(&timing); | 717 PopulateRequiredTimingFields(&timing); |
703 | 718 |
704 NavigateAndCommit(GURL(kDefaultTestUrl)); | 719 NavigateAndCommit(GURL(kDefaultTestUrl)); |
705 SimulateTimingUpdate(timing); | 720 SimulateTimingUpdate(timing); |
706 | 721 |
707 blink::WebMouseEvent mouse_event(blink::WebInputEvent::kMouseDown, | 722 blink::WebMouseEvent mouse_event(blink::WebInputEvent::kMouseDown, |
708 blink::WebInputEvent::kNoModifiers, | 723 blink::WebInputEvent::kNoModifiers, |
709 blink::WebInputEvent::kTimeStampForTesting); | 724 blink::WebInputEvent::kTimeStampForTesting); |
710 SimulateInputEvent(mouse_event); | 725 SimulateInputEvent(mouse_event); |
711 | 726 |
712 timing.paint_timing.first_meaningful_paint = | 727 timing.paint_timing->first_meaningful_paint = |
713 base::TimeDelta::FromMilliseconds(1000); | 728 base::TimeDelta::FromMilliseconds(1000); |
714 PopulateRequiredTimingFields(&timing); | 729 PopulateRequiredTimingFields(&timing); |
715 SimulateTimingUpdate(timing); | 730 SimulateTimingUpdate(timing); |
716 | 731 |
717 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 732 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
718 | 733 |
719 histogram_tester().ExpectTotalCount( | 734 histogram_tester().ExpectTotalCount( |
720 internal::kHistogramFirstMeaningfulPaint, 0); | 735 internal::kHistogramFirstMeaningfulPaint, 0); |
721 histogram_tester().ExpectTotalCount( | 736 histogram_tester().ExpectTotalCount( |
722 internal::kHistogramParseStartToFirstMeaningfulPaint, 0); | 737 internal::kHistogramParseStartToFirstMeaningfulPaint, 0); |
723 histogram_tester().ExpectBucketCount( | 738 histogram_tester().ExpectBucketCount( |
724 internal::kHistogramFirstMeaningfulPaintStatus, | 739 internal::kHistogramFirstMeaningfulPaintStatus, |
725 internal::FIRST_MEANINGFUL_PAINT_USER_INTERACTION_BEFORE_FMP, 1); | 740 internal::FIRST_MEANINGFUL_PAINT_USER_INTERACTION_BEFORE_FMP, 1); |
726 } | 741 } |
OLD | NEW |