Chromium Code Reviews| Index: chrome/browser/page_load_metrics/observers/core_page_load_metrics_observer_unittest.cc |
| diff --git a/chrome/browser/page_load_metrics/observers/core_page_load_metrics_observer_unittest.cc b/chrome/browser/page_load_metrics/observers/core_page_load_metrics_observer_unittest.cc |
| index 721217283885b8fe84e878faa4155183b413a83f..330c417e971b0caa7d66191618e1ad5cd0a57da6 100644 |
| --- a/chrome/browser/page_load_metrics/observers/core_page_load_metrics_observer_unittest.cc |
| +++ b/chrome/browser/page_load_metrics/observers/core_page_load_metrics_observer_unittest.cc |
| @@ -398,7 +398,30 @@ TEST_F(CorePageLoadMetricsObserverTest, Reload) { |
| GURL url(kDefaultTestUrl); |
| NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_RELOAD); |
| SimulateTimingUpdate(timing); |
| - NavigateAndCommit(url); |
| + |
| + page_load_metrics::ExtraRequestInfo resources[] = { |
| + // Cached request. |
| + {true /*was_cached*/, 1024 * 20 /* raw_body_bytes */, |
| + false /* data_reduction_proxy_used*/, |
| + 0 /* original_network_content_length */}, |
| + // Uncached non-proxied request. |
| + {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| + false /* data_reduction_proxy_used*/, |
| + 1024 * 40 /* original_network_content_length */}, |
| + }; |
| + |
| + int64_t network_bytes = 0; |
| + int64_t cache_bytes = 0; |
| + for (auto request : resources) { |
|
Alexei Svitkine (slow)
2017/03/06 22:06:08
Nit: const auto&
|
| + SimulateLoadedResource(request); |
| + if (!request.was_cached) { |
| + network_bytes += request.raw_body_bytes; |
| + } else { |
| + cache_bytes += request.raw_body_bytes; |
| + } |
| + } |
| + |
| + NavigateToUntrackedUrl(); |
| histogram_tester().ExpectTotalCount( |
| internal::kHistogramLoadTypeFirstContentfulPaintReload, 1); |
| @@ -418,6 +441,30 @@ TEST_F(CorePageLoadMetricsObserverTest, Reload) { |
| internal::kHistogramLoadTypeParseStartForwardBack, 0); |
| histogram_tester().ExpectTotalCount( |
| internal::kHistogramLoadTypeParseStartNewNavigation, 0); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeNetworkBytesReload, |
| + static_cast<int>((network_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeNetworkBytesForwardBack, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeNetworkBytesNewNavigation, 0); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeCacheBytesReload, |
| + static_cast<int>((cache_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeCacheBytesForwardBack, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeCacheBytesNewNavigation, 0); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeTotalBytesReload, |
| + static_cast<int>((network_bytes + cache_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeTotalBytesForwardBack, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeTotalBytesNewNavigation, 0); |
| } |
| TEST_F(CorePageLoadMetricsObserverTest, ForwardBack) { |
| @@ -436,7 +483,30 @@ TEST_F(CorePageLoadMetricsObserverTest, ForwardBack) { |
| url, ui::PageTransitionFromInt(ui::PAGE_TRANSITION_RELOAD | |
| ui::PAGE_TRANSITION_FORWARD_BACK)); |
| SimulateTimingUpdate(timing); |
| - NavigateAndCommit(url); |
| + |
| + page_load_metrics::ExtraRequestInfo resources[] = { |
| + // Cached request. |
| + {true /*was_cached*/, 1024 * 20 /* raw_body_bytes */, |
| + false /* data_reduction_proxy_used*/, |
| + 0 /* original_network_content_length */}, |
| + // Uncached non-proxied request. |
| + {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| + false /* data_reduction_proxy_used*/, |
| + 1024 * 40 /* original_network_content_length */}, |
| + }; |
| + |
| + int64_t network_bytes = 0; |
| + int64_t cache_bytes = 0; |
| + for (auto request : resources) { |
|
Alexei Svitkine (slow)
2017/03/06 22:06:08
Nit: const auto&
|
| + SimulateLoadedResource(request); |
| + if (!request.was_cached) { |
| + network_bytes += request.raw_body_bytes; |
| + } else { |
| + cache_bytes += request.raw_body_bytes; |
| + } |
| + } |
| + |
| + NavigateToUntrackedUrl(); |
| histogram_tester().ExpectTotalCount( |
| internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); |
| @@ -456,6 +526,30 @@ TEST_F(CorePageLoadMetricsObserverTest, ForwardBack) { |
| timing.parse_start.value().InMilliseconds(), 1); |
| histogram_tester().ExpectTotalCount( |
| internal::kHistogramLoadTypeParseStartNewNavigation, 0); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeNetworkBytesForwardBack, |
| + static_cast<int>((network_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeNetworkBytesNewNavigation, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeNetworkBytesReload, 0); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeCacheBytesForwardBack, |
| + static_cast<int>((cache_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeCacheBytesNewNavigation, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeCacheBytesReload, 0); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeTotalBytesForwardBack, |
| + static_cast<int>((network_bytes + cache_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeTotalBytesNewNavigation, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeTotalBytesReload, 0); |
| } |
| TEST_F(CorePageLoadMetricsObserverTest, NewNavigation) { |
| @@ -468,7 +562,30 @@ TEST_F(CorePageLoadMetricsObserverTest, NewNavigation) { |
| GURL url(kDefaultTestUrl); |
| NavigateWithPageTransitionAndCommit(url, ui::PAGE_TRANSITION_LINK); |
| SimulateTimingUpdate(timing); |
| - NavigateAndCommit(url); |
| + |
| + page_load_metrics::ExtraRequestInfo resources[] = { |
| + // Cached request. |
| + {true /*was_cached*/, 1024 * 20 /* raw_body_bytes */, |
| + false /* data_reduction_proxy_used*/, |
| + 0 /* original_network_content_length */}, |
| + // Uncached non-proxied request. |
| + {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| + false /* data_reduction_proxy_used*/, |
| + 1024 * 40 /* original_network_content_length */}, |
| + }; |
| + |
| + int64_t network_bytes = 0; |
| + int64_t cache_bytes = 0; |
| + for (auto request : resources) { |
| + SimulateLoadedResource(request); |
| + if (!request.was_cached) { |
| + network_bytes += request.raw_body_bytes; |
| + } else { |
| + cache_bytes += request.raw_body_bytes; |
| + } |
| + } |
| + |
| + NavigateToUntrackedUrl(); |
| histogram_tester().ExpectTotalCount( |
| internal::kHistogramLoadTypeFirstContentfulPaintReload, 0); |
| @@ -488,6 +605,30 @@ TEST_F(CorePageLoadMetricsObserverTest, NewNavigation) { |
| histogram_tester().ExpectBucketCount( |
| internal::kHistogramLoadTypeParseStartNewNavigation, |
| timing.parse_start.value().InMilliseconds(), 1); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeNetworkBytesNewNavigation, |
| + static_cast<int>((network_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeNetworkBytesForwardBack, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeNetworkBytesReload, 0); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeCacheBytesNewNavigation, |
| + static_cast<int>((cache_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeCacheBytesForwardBack, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeCacheBytesReload, 0); |
| + |
| + histogram_tester().ExpectUniqueSample( |
| + internal::kHistogramLoadTypeTotalBytesNewNavigation, |
| + static_cast<int>((network_bytes + cache_bytes) / 1024), 1); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeTotalBytesForwardBack, 0); |
| + histogram_tester().ExpectTotalCount( |
| + internal::kHistogramLoadTypeTotalBytesReload, 0); |
| } |
| TEST_F(CorePageLoadMetricsObserverTest, BytesAndResourcesCounted) { |