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..87f1f87cb3d05fbb0752b7b5d682c594fb85779f 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 |
@@ -62,12 +62,17 @@ class TestPingbackClient |
timing_.reset( |
new data_reduction_proxy::DataReductionProxyPageLoadTiming(timing)); |
send_pingback_called_ = true; |
+ data_ = data.DeepCopy(); |
} |
data_reduction_proxy::DataReductionProxyPageLoadTiming* timing() const { |
return timing_.get(); |
} |
+ const data_reduction_proxy::DataReductionProxyData& data() const { |
+ return *data_; |
+ } |
+ |
bool send_pingback_called() const { return send_pingback_called_; } |
void Reset() { |
@@ -78,6 +83,7 @@ class TestPingbackClient |
private: |
std::unique_ptr<data_reduction_proxy::DataReductionProxyPageLoadTiming> |
timing_; |
+ std::unique_ptr<data_reduction_proxy::DataReductionProxyData> data_; |
bool send_pingback_called_; |
DISALLOW_COPY_AND_ASSIGN(TestPingbackClient); |
@@ -193,6 +199,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 +406,25 @@ TEST_F(DataReductionProxyMetricsObserverTest, OnCompletePingback) { |
timing_.load_event_start = base::nullopt; |
RunTestAndNavigateToUntrackedUrl(true, false); |
ValidateTimes(); |
+ ValidateLoFiInPingback(false); |
+ |
+ ResetTest(); |
+ |
+ std::unique_ptr<DataReductionProxyData> data = |
+ base::MakeUnique<DataReductionProxyData>(); |
+ data->set_used_data_reduction_proxy(true); |
+ data->set_lofi_received(true); |
+ |
+ // Verify LoFi is tracked when a LoFi response is received. |
+ page_load_metrics::ExtraRequestInfo resource = { |
+ true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
+ 0 /* original_network_content_length */, std::move(data)}; |
+ |
+ RunTest(true, false); |
+ SimulateLoadedResource(resource); |
+ NavigateToUntrackedUrl(); |
+ ValidateTimes(); |
+ ValidateLoFiInPingback(true); |
ResetTest(); |
// Verify that when data reduction proxy was not used, SendPingback is not |
@@ -416,24 +446,26 @@ TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { |
RunTest(true, false); |
+ std::unique_ptr<DataReductionProxyData> data = |
+ base::MakeUnique<DataReductionProxyData>(); |
+ data->set_used_data_reduction_proxy(true); |
+ |
// Prepare 4 resources of varying size and configurations. |
page_load_metrics::ExtraRequestInfo resources[] = { |
// Cached request. |
{true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
- false /* data_reduction_proxy_used*/, |
- 0 /* original_network_content_length */}, |
+ 0 /* original_network_content_length */, |
+ nullptr /* data_reduction_proxy_data */}, |
// Uncached non-proxied request. |
{false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
- false /* data_reduction_proxy_used*/, |
- 1024 * 40 /* original_network_content_length */}, |
+ 1024 * 40 /* original_network_content_length */, |
+ nullptr /* data_reduction_proxy_data */}, |
// Uncached proxied request with .1 compression ratio. |
{false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
- true /* data_reduction_proxy_used*/, |
- 1024 * 40 * 10 /* original_network_content_length */}, |
+ 1024 * 40 * 10 /* original_network_content_length */, data->DeepCopy()}, |
// Uncached proxied request with .5 compression ratio. |
{false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
- true /* data_reduction_proxy_used*/, |
- 1024 * 40 * 5 /* original_network_content_length */}, |
+ 1024 * 40 * 5 /* original_network_content_length */, std::move(data)}, |
}; |
int network_resources = 0; |
@@ -441,14 +473,15 @@ TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) { |
int64_t network_bytes = 0; |
int64_t drp_bytes = 0; |
int64_t ocl_bytes = 0; |
- for (auto request : resources) { |
+ for (const auto& request : resources) { |
SimulateLoadedResource(request); |
if (!request.was_cached) { |
network_bytes += request.raw_body_bytes; |
ocl_bytes += request.original_network_content_length; |
++network_resources; |
} |
- if (request.data_reduction_proxy_used) { |
+ if (request.data_reduction_proxy_data && |
+ request.data_reduction_proxy_data->used_data_reduction_proxy()) { |
drp_bytes += request.raw_body_bytes; |
++drp_resources; |
} |
@@ -465,24 +498,26 @@ TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { |
RunTest(true, false); |
+ std::unique_ptr<DataReductionProxyData> data = |
+ base::MakeUnique<DataReductionProxyData>(); |
+ data->set_used_data_reduction_proxy(true); |
+ |
// Prepare 4 resources of varying size and configurations. |
page_load_metrics::ExtraRequestInfo resources[] = { |
// Cached request. |
{true /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
- false /* data_reduction_proxy_used*/, |
- 0 /* original_network_content_length */}, |
+ 0 /* original_network_content_length */, |
+ nullptr /* data_reduction_proxy_data */}, |
// Uncached non-proxied request. |
{false /*was_cached*/, 1024 * 40 /* raw_body_bytes */, |
- false /* data_reduction_proxy_used*/, |
- 1024 * 40 /* original_network_content_length */}, |
+ 1024 * 40 /* original_network_content_length */, |
+ nullptr /* data_reduction_proxy_data */}, |
// Uncached proxied request with .1 compression ratio. |
{false /*was_cached*/, 1024 * 40 * 10 /* raw_body_bytes */, |
- true /* data_reduction_proxy_used*/, |
- 1024 * 40 /* original_network_content_length */}, |
+ 1024 * 40 /* original_network_content_length */, data->DeepCopy()}, |
// Uncached proxied request with .5 compression ratio. |
{false /*was_cached*/, 1024 * 40 * 5 /* raw_body_bytes */, |
- true /* data_reduction_proxy_used*/, |
- 1024 * 40 /* original_network_content_length */}, |
+ 1024 * 40 /* original_network_content_length */, std::move(data)}, |
}; |
int network_resources = 0; |
@@ -490,14 +525,15 @@ TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) { |
int64_t network_bytes = 0; |
int64_t drp_bytes = 0; |
int64_t ocl_bytes = 0; |
- for (auto request : resources) { |
+ for (const auto& request : resources) { |
SimulateLoadedResource(request); |
if (!request.was_cached) { |
network_bytes += request.raw_body_bytes; |
ocl_bytes += request.original_network_content_length; |
++network_resources; |
} |
- if (request.data_reduction_proxy_used) { |
+ if (request.data_reduction_proxy_data && |
+ request.data_reduction_proxy_data->used_data_reduction_proxy()) { |
drp_bytes += request.raw_body_bytes; |
++drp_resources; |
} |