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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 TEST_F(CorePageLoadMetricsObserverTest, Reload) { | 391 TEST_F(CorePageLoadMetricsObserverTest, Reload) { |
392 page_load_metrics::PageLoadTiming timing; | 392 page_load_metrics::PageLoadTiming timing; |
393 timing.navigation_start = base::Time::FromDoubleT(1); | 393 timing.navigation_start = base::Time::FromDoubleT(1); |
394 timing.parse_start = base::TimeDelta::FromMilliseconds(5); | 394 timing.parse_start = base::TimeDelta::FromMilliseconds(5); |
395 timing.first_contentful_paint = base::TimeDelta::FromMilliseconds(10); | 395 timing.first_contentful_paint = base::TimeDelta::FromMilliseconds(10); |
396 PopulateRequiredTimingFields(&timing); | 396 PopulateRequiredTimingFields(&timing); |
397 | 397 |
398 GURL url(kDefaultTestUrl); | 398 GURL url(kDefaultTestUrl); |
399 NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_RELOAD); | 399 NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_RELOAD); |
400 SimulateTimingUpdate(timing); | 400 SimulateTimingUpdate(timing); |
401 NavigateAndCommit(url); | 401 |
402 page_load_metrics::ExtraRequestInfo resources[] = { | |
403 // Cached request. | |
404 {true /*was_cached*/, 1024 * 20 /* raw_body_bytes */, | |
405 false /* data_reduction_proxy_used*/, | |
406 0 /* original_network_content_length */}, | |
407 // Uncached non-proxied request. | |
408 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | |
409 false /* data_reduction_proxy_used*/, | |
410 1024 * 40 /* original_network_content_length */}, | |
411 }; | |
412 | |
413 int64_t network_bytes = 0; | |
414 int64_t cache_bytes = 0; | |
415 for (auto request : resources) { | |
Alexei Svitkine (slow)
2017/03/06 22:06:08
Nit: const auto&
| |
416 SimulateLoadedResource(request); | |
417 if (!request.was_cached) { | |
418 network_bytes += request.raw_body_bytes; | |
419 } else { | |
420 cache_bytes += request.raw_body_bytes; | |
421 } | |
422 } | |
423 | |
424 NavigateToUntrackedUrl(); | |
402 | 425 |
403 histogram_tester().ExpectTotalCount( | 426 histogram_tester().ExpectTotalCount( |
404 internal::kHistogramLoadTypeFirstContentfulPaintReload, 1); | 427 internal::kHistogramLoadTypeFirstContentfulPaintReload, 1); |
405 histogram_tester().ExpectBucketCount( | 428 histogram_tester().ExpectBucketCount( |
406 internal::kHistogramLoadTypeFirstContentfulPaintReload, | 429 internal::kHistogramLoadTypeFirstContentfulPaintReload, |
407 timing.first_contentful_paint.value().InMilliseconds(), 1); | 430 timing.first_contentful_paint.value().InMilliseconds(), 1); |
408 histogram_tester().ExpectTotalCount( | 431 histogram_tester().ExpectTotalCount( |
409 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 0); | 432 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 0); |
410 histogram_tester().ExpectTotalCount( | 433 histogram_tester().ExpectTotalCount( |
411 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 0); | 434 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 0); |
412 histogram_tester().ExpectTotalCount( | 435 histogram_tester().ExpectTotalCount( |
413 internal::kHistogramLoadTypeParseStartReload, 1); | 436 internal::kHistogramLoadTypeParseStartReload, 1); |
414 histogram_tester().ExpectBucketCount( | 437 histogram_tester().ExpectBucketCount( |
415 internal::kHistogramLoadTypeParseStartReload, | 438 internal::kHistogramLoadTypeParseStartReload, |
416 timing.parse_start.value().InMilliseconds(), 1); | 439 timing.parse_start.value().InMilliseconds(), 1); |
417 histogram_tester().ExpectTotalCount( | 440 histogram_tester().ExpectTotalCount( |
418 internal::kHistogramLoadTypeParseStartForwardBack, 0); | 441 internal::kHistogramLoadTypeParseStartForwardBack, 0); |
419 histogram_tester().ExpectTotalCount( | 442 histogram_tester().ExpectTotalCount( |
420 internal::kHistogramLoadTypeParseStartNewNavigation, 0); | 443 internal::kHistogramLoadTypeParseStartNewNavigation, 0); |
444 | |
445 histogram_tester().ExpectUniqueSample( | |
446 internal::kHistogramLoadTypeNetworkBytesReload, | |
447 static_cast<int>((network_bytes) / 1024), 1); | |
448 histogram_tester().ExpectTotalCount( | |
449 internal::kHistogramLoadTypeNetworkBytesForwardBack, 0); | |
450 histogram_tester().ExpectTotalCount( | |
451 internal::kHistogramLoadTypeNetworkBytesNewNavigation, 0); | |
452 | |
453 histogram_tester().ExpectUniqueSample( | |
454 internal::kHistogramLoadTypeCacheBytesReload, | |
455 static_cast<int>((cache_bytes) / 1024), 1); | |
456 histogram_tester().ExpectTotalCount( | |
457 internal::kHistogramLoadTypeCacheBytesForwardBack, 0); | |
458 histogram_tester().ExpectTotalCount( | |
459 internal::kHistogramLoadTypeCacheBytesNewNavigation, 0); | |
460 | |
461 histogram_tester().ExpectUniqueSample( | |
462 internal::kHistogramLoadTypeTotalBytesReload, | |
463 static_cast<int>((network_bytes + cache_bytes) / 1024), 1); | |
464 histogram_tester().ExpectTotalCount( | |
465 internal::kHistogramLoadTypeTotalBytesForwardBack, 0); | |
466 histogram_tester().ExpectTotalCount( | |
467 internal::kHistogramLoadTypeTotalBytesNewNavigation, 0); | |
421 } | 468 } |
422 | 469 |
423 TEST_F(CorePageLoadMetricsObserverTest, ForwardBack) { | 470 TEST_F(CorePageLoadMetricsObserverTest, ForwardBack) { |
424 page_load_metrics::PageLoadTiming timing; | 471 page_load_metrics::PageLoadTiming timing; |
425 timing.navigation_start = base::Time::FromDoubleT(1); | 472 timing.navigation_start = base::Time::FromDoubleT(1); |
426 timing.parse_start = base::TimeDelta::FromMilliseconds(5); | 473 timing.parse_start = base::TimeDelta::FromMilliseconds(5); |
427 timing.first_contentful_paint = base::TimeDelta::FromMilliseconds(10); | 474 timing.first_contentful_paint = base::TimeDelta::FromMilliseconds(10); |
428 PopulateRequiredTimingFields(&timing); | 475 PopulateRequiredTimingFields(&timing); |
429 | 476 |
430 GURL url(kDefaultTestUrl); | 477 GURL url(kDefaultTestUrl); |
431 // Back navigations to a page that was reloaded report a main transition type | 478 // Back navigations to a page that was reloaded report a main transition type |
432 // of PAGE_TRANSITION_RELOAD with a PAGE_TRANSITION_FORWARD_BACK | 479 // of PAGE_TRANSITION_RELOAD with a PAGE_TRANSITION_FORWARD_BACK |
433 // modifier. This test verifies that when we encounter such a page, we log it | 480 // modifier. This test verifies that when we encounter such a page, we log it |
434 // as a forward/back navigation. | 481 // as a forward/back navigation. |
435 NavigateWithPageTransitionAndCommit( | 482 NavigateWithPageTransitionAndCommit( |
436 url, ui::PageTransitionFromInt(ui::PAGE_TRANSITION_RELOAD | | 483 url, ui::PageTransitionFromInt(ui::PAGE_TRANSITION_RELOAD | |
437 ui::PAGE_TRANSITION_FORWARD_BACK)); | 484 ui::PAGE_TRANSITION_FORWARD_BACK)); |
438 SimulateTimingUpdate(timing); | 485 SimulateTimingUpdate(timing); |
439 NavigateAndCommit(url); | 486 |
487 page_load_metrics::ExtraRequestInfo resources[] = { | |
488 // Cached request. | |
489 {true /*was_cached*/, 1024 * 20 /* raw_body_bytes */, | |
490 false /* data_reduction_proxy_used*/, | |
491 0 /* original_network_content_length */}, | |
492 // Uncached non-proxied request. | |
493 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | |
494 false /* data_reduction_proxy_used*/, | |
495 1024 * 40 /* original_network_content_length */}, | |
496 }; | |
497 | |
498 int64_t network_bytes = 0; | |
499 int64_t cache_bytes = 0; | |
500 for (auto request : resources) { | |
Alexei Svitkine (slow)
2017/03/06 22:06:08
Nit: const auto&
| |
501 SimulateLoadedResource(request); | |
502 if (!request.was_cached) { | |
503 network_bytes += request.raw_body_bytes; | |
504 } else { | |
505 cache_bytes += request.raw_body_bytes; | |
506 } | |
507 } | |
508 | |
509 NavigateToUntrackedUrl(); | |
440 | 510 |
441 histogram_tester().ExpectTotalCount( | 511 histogram_tester().ExpectTotalCount( |
442 internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); | 512 internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); |
443 histogram_tester().ExpectTotalCount( | 513 histogram_tester().ExpectTotalCount( |
444 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 1); | 514 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 1); |
445 histogram_tester().ExpectBucketCount( | 515 histogram_tester().ExpectBucketCount( |
446 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, | 516 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, |
447 timing.first_contentful_paint.value().InMilliseconds(), 1); | 517 timing.first_contentful_paint.value().InMilliseconds(), 1); |
448 histogram_tester().ExpectTotalCount( | 518 histogram_tester().ExpectTotalCount( |
449 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 0); | 519 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 0); |
450 histogram_tester().ExpectTotalCount( | 520 histogram_tester().ExpectTotalCount( |
451 internal::kHistogramLoadTypeParseStartReload, 0); | 521 internal::kHistogramLoadTypeParseStartReload, 0); |
452 histogram_tester().ExpectTotalCount( | 522 histogram_tester().ExpectTotalCount( |
453 internal::kHistogramLoadTypeParseStartForwardBack, 1); | 523 internal::kHistogramLoadTypeParseStartForwardBack, 1); |
454 histogram_tester().ExpectBucketCount( | 524 histogram_tester().ExpectBucketCount( |
455 internal::kHistogramLoadTypeParseStartForwardBack, | 525 internal::kHistogramLoadTypeParseStartForwardBack, |
456 timing.parse_start.value().InMilliseconds(), 1); | 526 timing.parse_start.value().InMilliseconds(), 1); |
457 histogram_tester().ExpectTotalCount( | 527 histogram_tester().ExpectTotalCount( |
458 internal::kHistogramLoadTypeParseStartNewNavigation, 0); | 528 internal::kHistogramLoadTypeParseStartNewNavigation, 0); |
529 | |
530 histogram_tester().ExpectUniqueSample( | |
531 internal::kHistogramLoadTypeNetworkBytesForwardBack, | |
532 static_cast<int>((network_bytes) / 1024), 1); | |
533 histogram_tester().ExpectTotalCount( | |
534 internal::kHistogramLoadTypeNetworkBytesNewNavigation, 0); | |
535 histogram_tester().ExpectTotalCount( | |
536 internal::kHistogramLoadTypeNetworkBytesReload, 0); | |
537 | |
538 histogram_tester().ExpectUniqueSample( | |
539 internal::kHistogramLoadTypeCacheBytesForwardBack, | |
540 static_cast<int>((cache_bytes) / 1024), 1); | |
541 histogram_tester().ExpectTotalCount( | |
542 internal::kHistogramLoadTypeCacheBytesNewNavigation, 0); | |
543 histogram_tester().ExpectTotalCount( | |
544 internal::kHistogramLoadTypeCacheBytesReload, 0); | |
545 | |
546 histogram_tester().ExpectUniqueSample( | |
547 internal::kHistogramLoadTypeTotalBytesForwardBack, | |
548 static_cast<int>((network_bytes + cache_bytes) / 1024), 1); | |
549 histogram_tester().ExpectTotalCount( | |
550 internal::kHistogramLoadTypeTotalBytesNewNavigation, 0); | |
551 histogram_tester().ExpectTotalCount( | |
552 internal::kHistogramLoadTypeTotalBytesReload, 0); | |
459 } | 553 } |
460 | 554 |
461 TEST_F(CorePageLoadMetricsObserverTest, NewNavigation) { | 555 TEST_F(CorePageLoadMetricsObserverTest, NewNavigation) { |
462 page_load_metrics::PageLoadTiming timing; | 556 page_load_metrics::PageLoadTiming timing; |
463 timing.navigation_start = base::Time::FromDoubleT(1); | 557 timing.navigation_start = base::Time::FromDoubleT(1); |
464 timing.parse_start = base::TimeDelta::FromMilliseconds(5); | 558 timing.parse_start = base::TimeDelta::FromMilliseconds(5); |
465 timing.first_contentful_paint = base::TimeDelta::FromMilliseconds(10); | 559 timing.first_contentful_paint = base::TimeDelta::FromMilliseconds(10); |
466 PopulateRequiredTimingFields(&timing); | 560 PopulateRequiredTimingFields(&timing); |
467 | 561 |
468 GURL url(kDefaultTestUrl); | 562 GURL url(kDefaultTestUrl); |
469 NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_LINK); | 563 NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_LINK); |
470 SimulateTimingUpdate(timing); | 564 SimulateTimingUpdate(timing); |
471 NavigateAndCommit(url); | 565 |
566 page_load_metrics::ExtraRequestInfo resources[] = { | |
567 // Cached request. | |
568 {true /*was_cached*/, 1024 * 20 /* raw_body_bytes */, | |
569 false /* data_reduction_proxy_used*/, | |
570 0 /* original_network_content_length */}, | |
571 // Uncached non-proxied request. | |
572 {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, | |
573 false /* data_reduction_proxy_used*/, | |
574 1024 * 40 /* original_network_content_length */}, | |
575 }; | |
576 | |
577 int64_t network_bytes = 0; | |
578 int64_t cache_bytes = 0; | |
579 for (auto request : resources) { | |
580 SimulateLoadedResource(request); | |
581 if (!request.was_cached) { | |
582 network_bytes += request.raw_body_bytes; | |
583 } else { | |
584 cache_bytes += request.raw_body_bytes; | |
585 } | |
586 } | |
587 | |
588 NavigateToUntrackedUrl(); | |
472 | 589 |
473 histogram_tester().ExpectTotalCount( | 590 histogram_tester().ExpectTotalCount( |
474 internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); | 591 internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); |
475 histogram_tester().ExpectTotalCount( | 592 histogram_tester().ExpectTotalCount( |
476 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 0); | 593 internal::kHistogramLoadTypeFirstContentfulPaintForwardBack, 0); |
477 histogram_tester().ExpectTotalCount( | 594 histogram_tester().ExpectTotalCount( |
478 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 1); | 595 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, 1); |
479 histogram_tester().ExpectBucketCount( | 596 histogram_tester().ExpectBucketCount( |
480 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, | 597 internal::kHistogramLoadTypeFirstContentfulPaintNewNavigation, |
481 timing.first_contentful_paint.value().InMilliseconds(), 1); | 598 timing.first_contentful_paint.value().InMilliseconds(), 1); |
482 histogram_tester().ExpectTotalCount( | 599 histogram_tester().ExpectTotalCount( |
483 internal::kHistogramLoadTypeParseStartReload, 0); | 600 internal::kHistogramLoadTypeParseStartReload, 0); |
484 histogram_tester().ExpectTotalCount( | 601 histogram_tester().ExpectTotalCount( |
485 internal::kHistogramLoadTypeParseStartForwardBack, 0); | 602 internal::kHistogramLoadTypeParseStartForwardBack, 0); |
486 histogram_tester().ExpectTotalCount( | 603 histogram_tester().ExpectTotalCount( |
487 internal::kHistogramLoadTypeParseStartNewNavigation, 1); | 604 internal::kHistogramLoadTypeParseStartNewNavigation, 1); |
488 histogram_tester().ExpectBucketCount( | 605 histogram_tester().ExpectBucketCount( |
489 internal::kHistogramLoadTypeParseStartNewNavigation, | 606 internal::kHistogramLoadTypeParseStartNewNavigation, |
490 timing.parse_start.value().InMilliseconds(), 1); | 607 timing.parse_start.value().InMilliseconds(), 1); |
608 | |
609 histogram_tester().ExpectUniqueSample( | |
610 internal::kHistogramLoadTypeNetworkBytesNewNavigation, | |
611 static_cast<int>((network_bytes) / 1024), 1); | |
612 histogram_tester().ExpectTotalCount( | |
613 internal::kHistogramLoadTypeNetworkBytesForwardBack, 0); | |
614 histogram_tester().ExpectTotalCount( | |
615 internal::kHistogramLoadTypeNetworkBytesReload, 0); | |
616 | |
617 histogram_tester().ExpectUniqueSample( | |
618 internal::kHistogramLoadTypeCacheBytesNewNavigation, | |
619 static_cast<int>((cache_bytes) / 1024), 1); | |
620 histogram_tester().ExpectTotalCount( | |
621 internal::kHistogramLoadTypeCacheBytesForwardBack, 0); | |
622 histogram_tester().ExpectTotalCount( | |
623 internal::kHistogramLoadTypeCacheBytesReload, 0); | |
624 | |
625 histogram_tester().ExpectUniqueSample( | |
626 internal::kHistogramLoadTypeTotalBytesNewNavigation, | |
627 static_cast<int>((network_bytes + cache_bytes) / 1024), 1); | |
628 histogram_tester().ExpectTotalCount( | |
629 internal::kHistogramLoadTypeTotalBytesForwardBack, 0); | |
630 histogram_tester().ExpectTotalCount( | |
631 internal::kHistogramLoadTypeTotalBytesReload, 0); | |
491 } | 632 } |
492 | 633 |
493 TEST_F(CorePageLoadMetricsObserverTest, BytesAndResourcesCounted) { | 634 TEST_F(CorePageLoadMetricsObserverTest, BytesAndResourcesCounted) { |
494 NavigateAndCommit(GURL(kDefaultTestUrl)); | 635 NavigateAndCommit(GURL(kDefaultTestUrl)); |
495 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 636 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
496 histogram_tester().ExpectTotalCount(internal::kHistogramTotalBytes, 1); | 637 histogram_tester().ExpectTotalCount(internal::kHistogramTotalBytes, 1); |
497 histogram_tester().ExpectTotalCount(internal::kHistogramNetworkBytes, 1); | 638 histogram_tester().ExpectTotalCount(internal::kHistogramNetworkBytes, 1); |
498 histogram_tester().ExpectTotalCount(internal::kHistogramCacheBytes, 1); | 639 histogram_tester().ExpectTotalCount(internal::kHistogramCacheBytes, 1); |
499 histogram_tester().ExpectTotalCount( | 640 histogram_tester().ExpectTotalCount( |
500 internal::kHistogramTotalCompletedResources, 1); | 641 internal::kHistogramTotalCompletedResources, 1); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
546 NavigateAndCommit(GURL(kDefaultTestUrl2)); | 687 NavigateAndCommit(GURL(kDefaultTestUrl2)); |
547 | 688 |
548 histogram_tester().ExpectTotalCount( | 689 histogram_tester().ExpectTotalCount( |
549 internal::kHistogramFirstMeaningfulPaint, 0); | 690 internal::kHistogramFirstMeaningfulPaint, 0); |
550 histogram_tester().ExpectTotalCount( | 691 histogram_tester().ExpectTotalCount( |
551 internal::kHistogramParseStartToFirstMeaningfulPaint, 0); | 692 internal::kHistogramParseStartToFirstMeaningfulPaint, 0); |
552 histogram_tester().ExpectBucketCount( | 693 histogram_tester().ExpectBucketCount( |
553 internal::kHistogramFirstMeaningfulPaintStatus, | 694 internal::kHistogramFirstMeaningfulPaintStatus, |
554 internal::FIRST_MEANINGFUL_PAINT_USER_INTERACTION_BEFORE_FMP, 1); | 695 internal::FIRST_MEANINGFUL_PAINT_USER_INTERACTION_BEFORE_FMP, 1); |
555 } | 696 } |
OLD | NEW |