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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 content::WebContentsTester* web_contents_tester = | 342 content::WebContentsTester* web_contents_tester = |
343 content::WebContentsTester::For(web_contents()); | 343 content::WebContentsTester::For(web_contents()); |
344 | 344 |
345 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); | 345 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); |
346 content::RenderFrameHostTester* rfh_tester = | 346 content::RenderFrameHostTester* rfh_tester = |
347 content::RenderFrameHostTester::For(main_rfh()); | 347 content::RenderFrameHostTester::For(main_rfh()); |
348 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), | 348 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), |
349 net::ERR_TIMED_OUT); | 349 net::ERR_TIMED_OUT); |
350 rfh_tester->SimulateNavigationStop(); | 350 rfh_tester->SimulateNavigationStop(); |
351 | 351 |
352 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 3); | 352 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 2); |
353 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 353 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
354 PAGE_LOAD_STARTED, 1); | 354 PAGE_LOAD_STARTED, 1); |
355 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 355 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
356 PAGE_LOAD_FAILED_BEFORE_COMMIT, 1); | 356 PAGE_LOAD_FAILED_BEFORE_COMMIT, 1); |
357 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 357 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
358 PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, 1); | |
359 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | |
360 PAGE_LOAD_ABORTED_BEFORE_COMMIT, 0); | 358 PAGE_LOAD_ABORTED_BEFORE_COMMIT, 0); |
361 } | 359 } |
362 | 360 |
363 TEST_F(MetricsWebContentsObserverTest, AbortProvisionalLoad) { | 361 TEST_F(MetricsWebContentsObserverTest, AbortProvisionalLoad) { |
364 content::WebContentsTester* web_contents_tester = | 362 content::WebContentsTester* web_contents_tester = |
365 content::WebContentsTester::For(web_contents()); | 363 content::WebContentsTester::For(web_contents()); |
366 | 364 |
367 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); | 365 web_contents_tester->StartNavigation(GURL(kDefaultTestUrl)); |
368 content::RenderFrameHostTester* rfh_tester = | 366 content::RenderFrameHostTester* rfh_tester = |
369 content::RenderFrameHostTester::For(main_rfh()); | 367 content::RenderFrameHostTester::For(main_rfh()); |
370 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), net::ERR_ABORTED); | 368 rfh_tester->SimulateNavigationError(GURL(kDefaultTestUrl), net::ERR_ABORTED); |
371 rfh_tester->SimulateNavigationStop(); | 369 rfh_tester->SimulateNavigationStop(); |
372 | 370 |
373 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 4); | 371 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 4); |
374 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 372 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
375 PAGE_LOAD_STARTED, 1); | 373 PAGE_LOAD_STARTED, 1); |
376 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 374 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
377 PAGE_LOAD_FAILED_BEFORE_COMMIT, 1); | 375 PAGE_LOAD_FAILED_BEFORE_COMMIT, 1); |
378 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 376 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
379 PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, 1); | 377 PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, 1); |
380 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 378 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
381 PAGE_LOAD_ABORTED_BEFORE_COMMIT, 1); | 379 PAGE_LOAD_ABORTED_BEFORE_COMMIT, 1); |
382 } | 380 } |
383 | 381 |
| 382 TEST_F(MetricsWebContentsObserverTest, DontLogIrrelevantNavigation) { |
| 383 PageLoadTiming timing; |
| 384 timing.navigation_start = base::Time::FromDoubleT(10); |
| 385 |
| 386 content::WebContentsTester* web_contents_tester = |
| 387 content::WebContentsTester::For(web_contents()); |
| 388 |
| 389 GURL about_blank_url = GURL("about:blank"); |
| 390 web_contents_tester->NavigateAndCommit(about_blank_url); |
| 391 |
| 392 observer_->OnMessageReceived( |
| 393 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), |
| 394 main_rfh()); |
| 395 |
| 396 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
| 397 |
| 398 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 2); |
| 399 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
| 400 PAGE_LOAD_STARTED, 2); |
| 401 } |
| 402 |
384 TEST_F(MetricsWebContentsObserverTest, AbortCommittedLoadBeforeFirstLayout) { | 403 TEST_F(MetricsWebContentsObserverTest, AbortCommittedLoadBeforeFirstLayout) { |
385 PageLoadTiming timing; | 404 PageLoadTiming timing; |
386 timing.navigation_start = base::Time::FromDoubleT(10); | 405 timing.navigation_start = base::Time::FromDoubleT(10); |
387 | 406 |
388 content::WebContentsTester* web_contents_tester = | 407 content::WebContentsTester* web_contents_tester = |
389 content::WebContentsTester::For(web_contents()); | 408 content::WebContentsTester::For(web_contents()); |
390 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); | 409 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl)); |
391 | 410 |
392 observer_->OnMessageReceived( | 411 observer_->OnMessageReceived( |
393 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), | 412 PageLoadMetricsMsg_TimingUpdated(observer_->routing_id(), timing), |
394 main_rfh()); | 413 main_rfh()); |
395 // Navigate again to force histogram logging. | 414 // Navigate again to force histogram logging. |
396 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 415 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
397 | 416 |
398 // 3 events: 2 starts and one abort before first layout. | 417 // 3 events: 2 starts and one abort before first layout. |
399 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 3); | 418 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 4); |
400 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 419 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
401 PAGE_LOAD_STARTED, 2); | 420 PAGE_LOAD_STARTED, 2); |
402 histogram_tester_.ExpectBucketCount( | 421 histogram_tester_.ExpectBucketCount( |
403 kHistogramNameEvents, PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, 1); | 422 kHistogramNameEvents, PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT, 1); |
| 423 histogram_tester_.ExpectBucketCount( |
| 424 kHistogramNameEvents, PAGE_LOAD_ABORTED_BEFORE_FIRST_LAYOUT_RELEVANT, 1); |
404 } | 425 } |
405 | 426 |
406 TEST_F(MetricsWebContentsObserverTest, | 427 TEST_F(MetricsWebContentsObserverTest, |
407 SuccessfulFirstLayoutInForeGroundEvent) { | 428 SuccessfulFirstLayoutInForeGroundEvent) { |
408 PageLoadTiming timing; | 429 PageLoadTiming timing; |
409 timing.navigation_start = base::Time::FromDoubleT(10); | 430 timing.navigation_start = base::Time::FromDoubleT(10); |
410 timing.first_layout = base::TimeDelta::FromMilliseconds(100); | 431 timing.first_layout = base::TimeDelta::FromMilliseconds(100); |
411 | 432 |
412 content::WebContentsTester* web_contents_tester = | 433 content::WebContentsTester* web_contents_tester = |
413 content::WebContentsTester::For(web_contents()); | 434 content::WebContentsTester::For(web_contents()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); | 471 web_contents_tester->NavigateAndCommit(GURL(kDefaultTestUrl2)); |
451 | 472 |
452 // 3 events: 2 starts and one successful first layout. | 473 // 3 events: 2 starts and one successful first layout. |
453 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 3); | 474 histogram_tester_.ExpectTotalCount(kHistogramNameEvents, 3); |
454 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, | 475 histogram_tester_.ExpectBucketCount(kHistogramNameEvents, |
455 PAGE_LOAD_STARTED, 2); | 476 PAGE_LOAD_STARTED, 2); |
456 histogram_tester_.ExpectBucketCount( | 477 histogram_tester_.ExpectBucketCount( |
457 kHistogramNameEvents, PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_BACKGROUND, 1); | 478 kHistogramNameEvents, PAGE_LOAD_SUCCESSFUL_FIRST_LAYOUT_BACKGROUND, 1); |
458 } | 479 } |
459 } // namespace page_load_metrics | 480 } // namespace page_load_metrics |
OLD | NEW |