Chromium Code Reviews| Index: chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_unittest.cc |
| diff --git a/chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_unittest.cc b/chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_unittest.cc |
| index 81203cf40337ed57832837d3ae11a22398f300fb..10de8f5e5715023ff32232c4bc9e81f0dfd90eff 100644 |
| --- a/chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_unittest.cc |
| +++ b/chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer_unittest.cc |
| @@ -52,22 +52,31 @@ class TestPingbackClient |
| public: |
| TestPingbackClient() |
| : data_reduction_proxy::DataReductionProxyPingbackClient(nullptr), |
| + tab_identifier_key_(nullptr), |
| send_pingback_called_(false) {} |
| ~TestPingbackClient() override {} |
| void SendPingback( |
| const data_reduction_proxy::DataReductionProxyData& data, |
| - const data_reduction_proxy::DataReductionProxyPageLoadTiming& timing) |
| - override { |
| + const data_reduction_proxy::DataReductionProxyPageLoadTiming& timing, |
| + const void* tab_identifier_key) override { |
| timing_.reset( |
| new data_reduction_proxy::DataReductionProxyPageLoadTiming(timing)); |
| send_pingback_called_ = true; |
| + data_ = data.DeepCopy(); |
| + tab_identifier_key_ = tab_identifier_key; |
|
bengr
2017/04/20 17:36:18
Which cases will have no tab identifier key? Docum
RyanSturm
2017/04/20 20:25:44
Acknowledged.
|
| } |
| data_reduction_proxy::DataReductionProxyPageLoadTiming* timing() const { |
| return timing_.get(); |
| } |
| + const data_reduction_proxy::DataReductionProxyData& data() const { |
| + return *data_; |
| + } |
| + |
| + const void* tab_identifier_key() const { return tab_identifier_key_; } |
| + |
| bool send_pingback_called() const { return send_pingback_called_; } |
| void Reset() { |
| @@ -78,6 +87,8 @@ class TestPingbackClient |
| private: |
| std::unique_ptr<data_reduction_proxy::DataReductionProxyPageLoadTiming> |
| timing_; |
| + std::unique_ptr<data_reduction_proxy::DataReductionProxyData> data_; |
| + const void* tab_identifier_key_; |
| bool send_pingback_called_; |
| DISALLOW_COPY_AND_ASSIGN(TestPingbackClient); |
| @@ -178,6 +189,8 @@ class DataReductionProxyMetricsObserverTest |
| void ValidateTimes() { |
| EXPECT_TRUE(pingback_client_->send_pingback_called()); |
| + EXPECT_EQ(static_cast<void*>(web_contents()), |
| + pingback_client_->tab_identifier_key()); |
| EXPECT_EQ(timing_.navigation_start, |
| pingback_client_->timing()->navigation_start); |
| ExpectEqualOrUnset(timing_.first_contentful_paint, |
| @@ -193,6 +206,11 @@ class DataReductionProxyMetricsObserverTest |
| pingback_client_->timing()->first_image_paint); |
| } |
| + void ValidateLoFiInPingback(bool lofi_expected) { |
| + EXPECT_TRUE(pingback_client_->send_pingback_called()); |
| + EXPECT_EQ(lofi_expected, pingback_client_->data().lofi_received()); |
| + } |
| + |
| void ValidateHistograms() { |
| ValidateHistogramsForSuffix( |
| internal::kHistogramDOMContentLoadedEventFiredSuffix, |
| @@ -395,6 +413,21 @@ TEST_F(DataReductionProxyMetricsObserverTest, OnCompletePingback) { |
| timing_.load_event_start = base::nullopt; |
| RunTestAndNavigateToUntrackedUrl(true, false); |
| ValidateTimes(); |
| + ValidateLoFiInPingback(false); |
| + |
| + ResetTest(); |
| + |
| + // Verify LoFi is tracked when a LoFi response is received. |
| + page_load_metrics::ExtraRequestInfo resource = { |
| + true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| + false /* data_reduction_proxy_used*/, true /* was_lofi_response */, |
| + 0 /* original_network_content_length */}; |
| + |
| + RunTest(true, false); |
| + SimulateLoadedResource(resource); |
| + NavigateToUntrackedUrl(); |
| + ValidateTimes(); |
| + ValidateLoFiInPingback(true); |
| ResetTest(); |
| // Verify that when data reduction proxy was not used, SendPingback is not |
| @@ -420,19 +453,19 @@ TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { |
| page_load_metrics::ExtraRequestInfo resources[] = { |
| // Cached request. |
| {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| - false /* data_reduction_proxy_used*/, |
| + false /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
|
bengr
2017/04/20 17:36:18
you have two spaces after /*
RyanSturm
2017/04/20 20:25:44
Acknowledged.
|
| 0 /* original_network_content_length */}, |
| // Uncached non-proxied request. |
| {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| - false /* data_reduction_proxy_used*/, |
| + false /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 1024 * 40 /* original_network_content_length */}, |
| // Uncached proxied request with .1 compression ratio. |
| {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| - true /* data_reduction_proxy_used*/, |
| + true /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 1024 * 40 * 10 /* original_network_content_length */}, |
| // Uncached proxied request with .5 compression ratio. |
| {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| - true /* data_reduction_proxy_used*/, |
| + true /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 1024 * 40 * 5 /* original_network_content_length */}, |
| }; |
| @@ -469,19 +502,19 @@ TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { |
| page_load_metrics::ExtraRequestInfo resources[] = { |
| // Cached request. |
| {true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| - false /* data_reduction_proxy_used*/, |
| + false /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 0 /* original_network_content_length */}, |
| // Uncached non-proxied request. |
| {false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
| - false /* data_reduction_proxy_used*/, |
| + false /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 1024 * 40 /* original_network_content_length */}, |
| // Uncached proxied request with .1 compression ratio. |
| {false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, |
| - true /* data_reduction_proxy_used*/, |
| + true /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 1024 * 40 /* original_network_content_length */}, |
| // Uncached proxied request with .5 compression ratio. |
| {false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, |
| - true /* data_reduction_proxy_used*/, |
| + true /* data_reduction_proxy_used*/, false /* was_lofi_response */, |
| 1024 * 40 /* original_network_content_length */}, |
| }; |