| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "components/page_load_metrics/browser/metrics_web_contents_observer.h" | 5 #include "components/page_load_metrics/browser/metrics_web_contents_observer.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
| 9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 | 63 |
| 64 void AttachObserver() { | 64 void AttachObserver() { |
| 65 embedder_interface_ = new TestPageLoadMetricsEmbedderInterface(); | 65 embedder_interface_ = new TestPageLoadMetricsEmbedderInterface(); |
| 66 observer_.reset(new MetricsWebContentsObserver( | 66 observer_.reset(new MetricsWebContentsObserver( |
| 67 web_contents(), make_scoped_ptr(embedder_interface_))); | 67 web_contents(), make_scoped_ptr(embedder_interface_))); |
| 68 observer_->WasShown(); | 68 observer_->WasShown(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void AssertNoHistogramsLogged() { | 71 void AssertNoHistogramsLogged() { |
| 72 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0); | 72 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 0); |
| 73 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0); | 73 histogram_tester_.ExpectTotalCount(kHistogramLoad, 0); |
| 74 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 0); | 74 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 0); |
| 75 histogram_tester_.ExpectTotalCount(kHistogramNameFirstTextPaint, 0); | 75 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 0); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void CheckProvisionalEvent(ProvisionalLoadEvent event, | 78 void CheckProvisionalEvent(ProvisionalLoadEvent event, |
| 79 int count, | 79 int count, |
| 80 bool background) { | 80 bool background) { |
| 81 if (background) { | 81 if (background) { |
| 82 histogram_tester_.ExpectBucketCount(kBGProvisionalEvents, event, count); | 82 histogram_tester_.ExpectBucketCount(kBackgroundProvisionalEvents, event, |
| 83 count); |
| 83 num_provisional_events_bg_ += count; | 84 num_provisional_events_bg_ += count; |
| 84 } else { | 85 } else { |
| 85 histogram_tester_.ExpectBucketCount(kProvisionalEvents, event, count); | 86 histogram_tester_.ExpectBucketCount(kProvisionalEvents, event, count); |
| 86 num_provisional_events_ += count; | 87 num_provisional_events_ += count; |
| 87 } | 88 } |
| 88 } | 89 } |
| 89 | 90 |
| 90 void CheckCommittedEvent(CommittedLoadEvent event, | 91 void CheckCommittedEvent(CommittedLoadEvent event, |
| 91 int count, | 92 int count, |
| 92 bool background) { | 93 bool background) { |
| 93 if (background) { | 94 if (background) { |
| 94 histogram_tester_.ExpectBucketCount(kBGCommittedEvents, event, count); | 95 histogram_tester_.ExpectBucketCount(kBackgroundCommittedEvents, event, |
| 96 count); |
| 95 num_committed_events_bg_ += count; | 97 num_committed_events_bg_ += count; |
| 96 } else { | 98 } else { |
| 97 histogram_tester_.ExpectBucketCount(kCommittedEvents, event, count); | 99 histogram_tester_.ExpectBucketCount(kCommittedEvents, event, count); |
| 98 num_committed_events_ += count; | 100 num_committed_events_ += count; |
| 99 } | 101 } |
| 100 } | 102 } |
| 101 | 103 |
| 102 void CheckErrorEvent(InternalErrorLoadEvent error, int count) { | 104 void CheckErrorEvent(InternalErrorLoadEvent error, int count) { |
| 103 histogram_tester_.ExpectBucketCount(kErrorEvents, error, count); | 105 histogram_tester_.ExpectBucketCount(kErrorEvents, error, count); |
| 104 num_errors_ += count; | 106 num_errors_ += count; |
| 105 } | 107 } |
| 106 | 108 |
| 107 void CheckTotalEvents() { | 109 void CheckTotalEvents() { |
| 108 histogram_tester_.ExpectTotalCount(kProvisionalEvents, | 110 histogram_tester_.ExpectTotalCount(kProvisionalEvents, |
| 109 num_provisional_events_); | 111 num_provisional_events_); |
| 110 histogram_tester_.ExpectTotalCount(kCommittedEvents, num_committed_events_); | 112 histogram_tester_.ExpectTotalCount(kCommittedEvents, num_committed_events_); |
| 111 histogram_tester_.ExpectTotalCount(kBGProvisionalEvents, | 113 histogram_tester_.ExpectTotalCount(kBackgroundProvisionalEvents, |
| 112 num_provisional_events_bg_); | 114 num_provisional_events_bg_); |
| 113 histogram_tester_.ExpectTotalCount(kBGCommittedEvents, | 115 histogram_tester_.ExpectTotalCount(kBackgroundCommittedEvents, |
| 114 num_committed_events_bg_); | 116 num_committed_events_bg_); |
| 115 histogram_tester_.ExpectTotalCount(kErrorEvents, num_errors_); | 117 histogram_tester_.ExpectTotalCount(kErrorEvents, num_errors_); |
| 116 } | 118 } |
| 117 | 119 |
| 118 protected: | 120 protected: |
| 119 base::HistogramTester histogram_tester_; | 121 base::HistogramTester histogram_tester_; |
| 120 TestPageLoadMetricsEmbedderInterface* embedder_interface_; | 122 TestPageLoadMetricsEmbedderInterface* embedder_interface_; |
| 121 scoped_ptr<MetricsWebContentsObserver> observer_; | 123 scoped_ptr<MetricsWebContentsObserver> observer_; |
| 122 | 124 |
| 123 private: | 125 private: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 observer_->OnMessageReceived( | 199 observer_->OnMessageReceived( |
| 198 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), | 200 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), |
| 199 web_contents()->GetMainFrame()); | 201 web_contents()->GetMainFrame()); |
| 200 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); | 202 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrlAnchor)); |
| 201 // A same page navigation shouldn't trigger logging UMA for the original. | 203 // A same page navigation shouldn't trigger logging UMA for the original. |
| 202 AssertNoHistogramsLogged(); | 204 AssertNoHistogramsLogged(); |
| 203 | 205 |
| 204 // But we should keep the timing info and log it when we get another | 206 // But we should keep the timing info and log it when we get another |
| 205 // navigation. | 207 // navigation. |
| 206 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 208 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 207 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0); | 209 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 0); |
| 208 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0); | 210 histogram_tester_.ExpectTotalCount(kHistogramLoad, 0); |
| 209 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 1); | 211 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 1); |
| 210 histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout, | 212 histogram_tester_.ExpectBucketCount(kHistogramFirstLayout, |
| 211 first_layout.InMilliseconds(), 1); | 213 first_layout.InMilliseconds(), 1); |
| 212 histogram_tester_.ExpectTotalCount(kHistogramNameFirstTextPaint, 0); | 214 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 0); |
| 213 } | 215 } |
| 214 | 216 |
| 215 TEST_F(MetricsWebContentsObserverTest, SingleMetricAfterCommit) { | 217 TEST_F(MetricsWebContentsObserverTest, SingleMetricAfterCommit) { |
| 216 base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1); | 218 base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1); |
| 217 | 219 |
| 218 PageLoadTiming timing; | 220 PageLoadTiming timing; |
| 219 timing.navigation_start = base::Time::FromDoubleT(1); | 221 timing.navigation_start = base::Time::FromDoubleT(1); |
| 220 timing.first_layout = first_layout; | 222 timing.first_layout = first_layout; |
| 221 | 223 |
| 222 content::WebContentsTester* web_contents_tester = | 224 content::WebContentsTester* web_contents_tester = |
| 223 content::WebContentsTester::For(web_contents()); | 225 content::WebContentsTester::For(web_contents()); |
| 224 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 226 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 225 | 227 |
| 226 observer_->OnMessageReceived( | 228 observer_->OnMessageReceived( |
| 227 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), | 229 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), |
| 228 web_contents()->GetMainFrame()); | 230 web_contents()->GetMainFrame()); |
| 229 | 231 |
| 230 AssertNoHistogramsLogged(); | 232 AssertNoHistogramsLogged(); |
| 231 | 233 |
| 232 // Navigate again to force histogram recording. | 234 // Navigate again to force histogram recording. |
| 233 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 235 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 234 | 236 |
| 235 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0); | 237 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 0); |
| 236 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0); | 238 histogram_tester_.ExpectTotalCount(kHistogramLoad, 0); |
| 237 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 1); | 239 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 1); |
| 238 histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout, | 240 histogram_tester_.ExpectBucketCount(kHistogramFirstLayout, |
| 239 first_layout.InMilliseconds(), 1); | 241 first_layout.InMilliseconds(), 1); |
| 240 histogram_tester_.ExpectTotalCount(kHistogramNameFirstTextPaint, 0); | 242 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 0); |
| 241 } | 243 } |
| 242 | 244 |
| 243 TEST_F(MetricsWebContentsObserverTest, MultipleMetricsAfterCommits) { | 245 TEST_F(MetricsWebContentsObserverTest, MultipleMetricsAfterCommits) { |
| 244 base::TimeDelta first_layout_1 = base::TimeDelta::FromMilliseconds(1); | 246 base::TimeDelta first_layout_1 = base::TimeDelta::FromMilliseconds(1); |
| 245 base::TimeDelta first_layout_2 = base::TimeDelta::FromMilliseconds(20); | 247 base::TimeDelta first_layout_2 = base::TimeDelta::FromMilliseconds(20); |
| 246 base::TimeDelta response = base::TimeDelta::FromMilliseconds(10); | 248 base::TimeDelta response = base::TimeDelta::FromMilliseconds(10); |
| 247 base::TimeDelta first_text_paint = base::TimeDelta::FromMilliseconds(30); | 249 base::TimeDelta first_text_paint = base::TimeDelta::FromMilliseconds(30); |
| 248 base::TimeDelta dom_content = base::TimeDelta::FromMilliseconds(40); | 250 base::TimeDelta dom_content = base::TimeDelta::FromMilliseconds(40); |
| 249 base::TimeDelta load = base::TimeDelta::FromMilliseconds(100); | 251 base::TimeDelta load = base::TimeDelta::FromMilliseconds(100); |
| 250 | 252 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 269 PageLoadTiming timing2; | 271 PageLoadTiming timing2; |
| 270 timing2.navigation_start = base::Time::FromDoubleT(200); | 272 timing2.navigation_start = base::Time::FromDoubleT(200); |
| 271 timing2.first_layout = first_layout_2; | 273 timing2.first_layout = first_layout_2; |
| 272 | 274 |
| 273 observer_->OnMessageReceived( | 275 observer_->OnMessageReceived( |
| 274 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing2), | 276 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing2), |
| 275 web_contents()->GetMainFrame()); | 277 web_contents()->GetMainFrame()); |
| 276 | 278 |
| 277 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 279 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 278 | 280 |
| 279 histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout, | 281 histogram_tester_.ExpectBucketCount(kHistogramFirstLayout, |
| 280 first_layout_1.InMilliseconds(), 1); | 282 first_layout_1.InMilliseconds(), 1); |
| 281 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 2); | 283 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 2); |
| 282 histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout, | 284 histogram_tester_.ExpectBucketCount(kHistogramFirstLayout, |
| 283 first_layout_1.InMilliseconds(), 1); | 285 first_layout_1.InMilliseconds(), 1); |
| 284 histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout, | 286 histogram_tester_.ExpectBucketCount(kHistogramFirstLayout, |
| 285 first_layout_2.InMilliseconds(), 1); | 287 first_layout_2.InMilliseconds(), 1); |
| 286 | 288 |
| 287 histogram_tester_.ExpectTotalCount(kHistogramNameFirstTextPaint, 1); | 289 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 1); |
| 288 histogram_tester_.ExpectBucketCount(kHistogramNameFirstTextPaint, | 290 histogram_tester_.ExpectBucketCount(kHistogramFirstTextPaint, |
| 289 first_text_paint.InMilliseconds(), 1); | 291 first_text_paint.InMilliseconds(), 1); |
| 290 | 292 |
| 291 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 1); | 293 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 1); |
| 292 histogram_tester_.ExpectBucketCount(kHistogramNameDomContent, | 294 histogram_tester_.ExpectBucketCount(kHistogramDomContentLoaded, |
| 293 dom_content.InMilliseconds(), 1); | 295 dom_content.InMilliseconds(), 1); |
| 294 | 296 |
| 295 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 1); | 297 histogram_tester_.ExpectTotalCount(kHistogramLoad, 1); |
| 296 histogram_tester_.ExpectBucketCount(kHistogramNameLoad, load.InMilliseconds(), | 298 histogram_tester_.ExpectBucketCount(kHistogramLoad, load.InMilliseconds(), 1); |
| 297 1); | |
| 298 } | 299 } |
| 299 | 300 |
| 300 TEST_F(MetricsWebContentsObserverTest, BackgroundDifferentHistogram) { | 301 TEST_F(MetricsWebContentsObserverTest, BackgroundDifferentHistogram) { |
| 301 base::TimeDelta first_layout = base::TimeDelta::FromSeconds(2); | 302 base::TimeDelta first_layout = base::TimeDelta::FromSeconds(2); |
| 302 | 303 |
| 303 PageLoadTiming timing; | 304 PageLoadTiming timing; |
| 304 timing.navigation_start = base::Time::FromDoubleT( | 305 timing.navigation_start = base::Time::FromDoubleT( |
| 305 (base::TimeTicks::Now() - base::TimeTicks::UnixEpoch()).InSecondsF()); | 306 (base::TimeTicks::Now() - base::TimeTicks::UnixEpoch()).InSecondsF()); |
| 306 timing.first_layout = first_layout; | 307 timing.first_layout = first_layout; |
| 307 | 308 |
| 308 content::WebContentsTester* web_contents_tester = | 309 content::WebContentsTester* web_contents_tester = |
| 309 content::WebContentsTester::For(web_contents()); | 310 content::WebContentsTester::For(web_contents()); |
| 310 | 311 |
| 311 // Simulate "Open link in new tab." | 312 // Simulate "Open link in new tab." |
| 312 observer_->WasHidden(); | 313 observer_->WasHidden(); |
| 313 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 314 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 314 | 315 |
| 315 observer_->OnMessageReceived( | 316 observer_->OnMessageReceived( |
| 316 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), | 317 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), |
| 317 web_contents()->GetMainFrame()); | 318 web_contents()->GetMainFrame()); |
| 318 | 319 |
| 319 // Simulate switching to the tab and making another navigation. | 320 // Simulate switching to the tab and making another navigation. |
| 320 observer_->WasShown(); | 321 observer_->WasShown(); |
| 321 AssertNoHistogramsLogged(); | 322 AssertNoHistogramsLogged(); |
| 322 | 323 |
| 323 // Navigate again to force histogram recording. | 324 // Navigate again to force histogram recording. |
| 324 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 325 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 325 | 326 |
| 326 histogram_tester_.ExpectTotalCount(kBGHistogramNameDomContent, 0); | 327 histogram_tester_.ExpectTotalCount(kBackgroundHistogramDomContentLoaded, 0); |
| 327 histogram_tester_.ExpectTotalCount(kBGHistogramNameLoad, 0); | 328 histogram_tester_.ExpectTotalCount(kBackgroundHistogramLoad, 0); |
| 328 histogram_tester_.ExpectTotalCount(kBGHistogramNameFirstLayout, 1); | 329 histogram_tester_.ExpectTotalCount(kBackgroundHistogramFirstLayout, 1); |
| 329 histogram_tester_.ExpectBucketCount(kBGHistogramNameFirstLayout, | 330 histogram_tester_.ExpectBucketCount(kBackgroundHistogramFirstLayout, |
| 330 first_layout.InMilliseconds(), 1); | 331 first_layout.InMilliseconds(), 1); |
| 331 histogram_tester_.ExpectTotalCount(kBGHistogramNameFirstTextPaint, 0); | 332 histogram_tester_.ExpectTotalCount(kBackgroundHistogramFirstTextPaint, 0); |
| 332 | 333 |
| 333 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0); | 334 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 0); |
| 334 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0); | 335 histogram_tester_.ExpectTotalCount(kHistogramLoad, 0); |
| 335 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 0); | 336 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 0); |
| 336 histogram_tester_.ExpectTotalCount(kHistogramNameFirstTextPaint, 0); | 337 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 0); |
| 337 } | 338 } |
| 338 | 339 |
| 339 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) { | 340 TEST_F(MetricsWebContentsObserverTest, DontLogPrerender) { |
| 340 PageLoadTiming timing; | 341 PageLoadTiming timing; |
| 341 timing.navigation_start = base::Time::FromDoubleT(1); | 342 timing.navigation_start = base::Time::FromDoubleT(1); |
| 342 timing.first_layout = base::TimeDelta::FromMilliseconds(10); | 343 timing.first_layout = base::TimeDelta::FromMilliseconds(10); |
| 343 content::WebContentsTester* web_contents_tester = | 344 content::WebContentsTester* web_contents_tester = |
| 344 content::WebContentsTester::For(web_contents()); | 345 content::WebContentsTester::For(web_contents()); |
| 345 embedder_interface_->set_is_prerendering(true); | 346 embedder_interface_->set_is_prerendering(true); |
| 346 | 347 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 374 observer_->WasShown(); | 375 observer_->WasShown(); |
| 375 timing.first_layout = base::TimeDelta::FromSeconds(3); | 376 timing.first_layout = base::TimeDelta::FromSeconds(3); |
| 376 timing.first_text_paint = base::TimeDelta::FromSeconds(4); | 377 timing.first_text_paint = base::TimeDelta::FromSeconds(4); |
| 377 observer_->OnMessageReceived( | 378 observer_->OnMessageReceived( |
| 378 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), | 379 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), |
| 379 web_contents()->GetMainFrame()); | 380 web_contents()->GetMainFrame()); |
| 380 | 381 |
| 381 // Navigate again to force histogram recording. | 382 // Navigate again to force histogram recording. |
| 382 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 383 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
| 383 | 384 |
| 384 histogram_tester_.ExpectTotalCount(kBGHistogramNameDomContent, 0); | 385 histogram_tester_.ExpectTotalCount(kBackgroundHistogramDomContentLoaded, 0); |
| 385 histogram_tester_.ExpectTotalCount(kBGHistogramNameLoad, 0); | 386 histogram_tester_.ExpectTotalCount(kBackgroundHistogramLoad, 0); |
| 386 histogram_tester_.ExpectTotalCount(kBGHistogramNameFirstLayout, 1); | 387 histogram_tester_.ExpectTotalCount(kBackgroundHistogramFirstLayout, 1); |
| 387 histogram_tester_.ExpectBucketCount(kBGHistogramNameFirstLayout, | 388 histogram_tester_.ExpectBucketCount(kBackgroundHistogramFirstLayout, |
| 388 timing.first_layout.InMilliseconds(), 1); | 389 timing.first_layout.InMilliseconds(), 1); |
| 389 histogram_tester_.ExpectTotalCount(kBGHistogramNameFirstTextPaint, 1); | 390 histogram_tester_.ExpectTotalCount(kBackgroundHistogramFirstTextPaint, 1); |
| 390 histogram_tester_.ExpectBucketCount(kBGHistogramNameFirstTextPaint, | 391 histogram_tester_.ExpectBucketCount(kBackgroundHistogramFirstTextPaint, |
| 391 timing.first_text_paint.InMilliseconds(), | 392 timing.first_text_paint.InMilliseconds(), |
| 392 1); | 393 1); |
| 393 | 394 |
| 394 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 1); | 395 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 1); |
| 395 histogram_tester_.ExpectBucketCount( | 396 histogram_tester_.ExpectBucketCount( |
| 396 kHistogramNameDomContent, | 397 kHistogramDomContentLoaded, |
| 397 timing.dom_content_loaded_event_start.InMilliseconds(), 1); | 398 timing.dom_content_loaded_event_start.InMilliseconds(), 1); |
| 398 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0); | 399 histogram_tester_.ExpectTotalCount(kHistogramLoad, 0); |
| 399 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 0); | 400 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 0); |
| 400 histogram_tester_.ExpectTotalCount(kHistogramNameFirstTextPaint, 0); | 401 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 0); |
| 401 } | 402 } |
| 402 | 403 |
| 403 TEST_F(MetricsWebContentsObserverTest, DontBackgroundQuickerLoad) { | 404 TEST_F(MetricsWebContentsObserverTest, DontBackgroundQuickerLoad) { |
| 404 base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1); | 405 base::TimeDelta first_layout = base::TimeDelta::FromMilliseconds(1); |
| 405 | 406 |
| 406 PageLoadTiming timing; | 407 PageLoadTiming timing; |
| 407 timing.navigation_start = base::Time::FromDoubleT(1); | 408 timing.navigation_start = base::Time::FromDoubleT(1); |
| 408 timing.first_layout = first_layout; | 409 timing.first_layout = first_layout; |
| 409 | 410 |
| 410 observer_->WasHidden(); | 411 observer_->WasHidden(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 425 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl2)); | 426 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl2)); |
| 426 rfh_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); | 427 rfh_tester->SimulateNavigationCommit(GURL(kDefaultTestUrl2)); |
| 427 observer_->OnMessageReceived( | 428 observer_->OnMessageReceived( |
| 428 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), | 429 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), |
| 429 main_rfh()); | 430 main_rfh()); |
| 430 rfh_tester->SimulateNavigationStop(); | 431 rfh_tester->SimulateNavigationStop(); |
| 431 | 432 |
| 432 // Navigate again to see if the timing updated for a subframe message. | 433 // Navigate again to see if the timing updated for a subframe message. |
| 433 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 434 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 434 | 435 |
| 435 histogram_tester_.ExpectTotalCount(kHistogramNameDomContent, 0); | 436 histogram_tester_.ExpectTotalCount(kHistogramDomContentLoaded, 0); |
| 436 histogram_tester_.ExpectTotalCount(kHistogramNameLoad, 0); | 437 histogram_tester_.ExpectTotalCount(kHistogramLoad, 0); |
| 437 histogram_tester_.ExpectTotalCount(kHistogramNameFirstLayout, 1); | 438 histogram_tester_.ExpectTotalCount(kHistogramFirstLayout, 1); |
| 438 histogram_tester_.ExpectBucketCount(kHistogramNameFirstLayout, | 439 histogram_tester_.ExpectBucketCount(kHistogramFirstLayout, |
| 439 first_layout.InMilliseconds(), 1); | 440 first_layout.InMilliseconds(), 1); |
| 440 histogram_tester_.ExpectTotalCount(kHistogramNameFirstTextPaint, 0); | 441 histogram_tester_.ExpectTotalCount(kHistogramFirstTextPaint, 0); |
| 441 } | 442 } |
| 442 | 443 |
| 443 TEST_F(MetricsWebContentsObserverTest, FailProvisionalLoad) { | 444 TEST_F(MetricsWebContentsObserverTest, FailProvisionalLoad) { |
| 444 content::WebContentsTester* web_contents_tester = | 445 content::WebContentsTester* web_contents_tester = |
| 445 content::WebContentsTester::For(web_contents()); | 446 content::WebContentsTester::For(web_contents()); |
| 446 | 447 |
| 447 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); | 448 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); |
| 448 content::RenderFrameHostTester* rfh_tester = | 449 content::RenderFrameHostTester* rfh_tester = |
| 449 content::RenderFrameHostTester::For(main_rfh()); | 450 content::RenderFrameHostTester::For(main_rfh()); |
| 450 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), | 451 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 EXPECT_NE(string_it, sample_obj->string_fields.end()); | 711 EXPECT_NE(string_it, sample_obj->string_fields.end()); |
| 711 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)), | 712 EXPECT_EQ(rappor::GetDomainAndRegistrySampleFromGURL(GURL(kDefaultTestUrl)), |
| 712 string_it->second); | 713 string_it->second); |
| 713 | 714 |
| 714 const auto& flag_it = sample_obj->flag_fields.find("IsSlow"); | 715 const auto& flag_it = sample_obj->flag_fields.find("IsSlow"); |
| 715 EXPECT_NE(flag_it, sample_obj->flag_fields.end()); | 716 EXPECT_NE(flag_it, sample_obj->flag_fields.end()); |
| 716 EXPECT_EQ(0u, flag_it->second); | 717 EXPECT_EQ(0u, flag_it->second); |
| 717 } | 718 } |
| 718 | 719 |
| 719 } // namespace page_load_metrics | 720 } // namespace page_load_metrics |
| OLD | NEW |