| 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 10ea0f7f6dcb597811b9e23525a699826be361c5..8888a944bd4309a16d211fd76079b81832ce4f60 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
|
| @@ -4,6 +4,9 @@
|
|
|
| #include "chrome/browser/page_load_metrics/observers/data_reduction_proxy_metrics_observer.h"
|
|
|
| +#include <stdint.h>
|
| +
|
| +#include <functional>
|
| #include <memory>
|
| #include <string>
|
|
|
| @@ -14,6 +17,7 @@
|
| #include "base/time/time.h"
|
| #include "chrome/browser/loader/chrome_navigation_data.h"
|
| #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_test_harness.h"
|
| +#include "chrome/browser/page_load_metrics/page_load_metrics_observer.h"
|
| #include "chrome/common/page_load_metrics/page_load_timing.h"
|
| #include "chrome/test/base/testing_browser_process.h"
|
| #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data.h"
|
| @@ -147,13 +151,18 @@ class DataReductionProxyMetricsObserverTest
|
| PopulateRequiredTimingFields(&timing_);
|
| }
|
|
|
| - void RunTest(bool data_reduction_proxy_used, bool is_using_lofi) {
|
| + void RunTest(
|
| + bool data_reduction_proxy_used,
|
| + bool is_using_lofi,
|
| + std::function<void(page_load_metrics::PageLoadTracker*)> extra_steps) {
|
| data_reduction_proxy_used_ = data_reduction_proxy_used;
|
| is_using_lofi_ = is_using_lofi;
|
| NavigateAndCommit(GURL(kDefaultTestUrl));
|
| SimulateTimingUpdate(timing_);
|
| pingback_client_->Reset();
|
|
|
| + extra_steps(recent_tracker_);
|
| +
|
| // Navigate again to force OnComplete, which happens when a new navigation
|
| // occurs.
|
| NavigateAndCommit(GURL(kDefaultTestUrl2));
|
| @@ -243,8 +252,81 @@ class DataReductionProxyMetricsObserverTest
|
| event.value().InMilliseconds(), is_using_lofi_ ? 1 : 0);
|
| }
|
|
|
| + void ValidateDataHistograms(int network_requests,
|
| + int drp_requests,
|
| + int64_t network_bytes,
|
| + int64_t drp_bytes,
|
| + int64_t ocl_bytes) {
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kRequestsPercentProxied),
|
| + 100 * drp_requests / network_requests, 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kBytesPercentProxied),
|
| + static_cast<int>(100 * drp_bytes / network_bytes), 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kNetworkRequests),
|
| + network_requests, 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kRequestsProxied),
|
| + drp_requests, 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kRequestsNotProxied),
|
| + network_requests - drp_requests, 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kNetworkBytes),
|
| + static_cast<int>(network_bytes / 1024), 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kBytesProxied),
|
| + static_cast<int>(drp_bytes / 1024), 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kBytesNotProxied),
|
| + static_cast<int>((network_bytes - drp_bytes) / 1024), 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kBytesOriginal),
|
| + static_cast<int>(ocl_bytes / 1024), 1);
|
| + if (ocl_bytes < network_bytes) {
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kBytesInflationPercent),
|
| + static_cast<int>(100 * network_bytes / ocl_bytes - 100), 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kBytesInflation),
|
| + static_cast<int>((network_bytes - ocl_bytes) / 1024), 1);
|
| + } else {
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kBytesCompressionRatio),
|
| + static_cast<int>(100 * network_bytes / ocl_bytes), 1);
|
| +
|
| + histogram_tester().ExpectUniqueSample(
|
| + std::string(internal::kHistogramDataReductionProxyPrefix)
|
| + .append(internal::kBytesSavings),
|
| + static_cast<int>((ocl_bytes - network_bytes) / 1024), 1);
|
| + }
|
| + }
|
| +
|
| protected:
|
| void RegisterObservers(page_load_metrics::PageLoadTracker* tracker) override {
|
| + recent_tracker_ = tracker;
|
| tracker->AddObserver(
|
| base::MakeUnique<TestDataReductionProxyMetricsObserver>(
|
| web_contents(), pingback_client_.get(), data_reduction_proxy_used_,
|
| @@ -255,6 +337,7 @@ class DataReductionProxyMetricsObserverTest
|
| page_load_metrics::PageLoadTiming timing_;
|
|
|
| private:
|
| + page_load_metrics::PageLoadTracker* recent_tracker_;
|
| bool data_reduction_proxy_used_;
|
| bool is_using_lofi_;
|
|
|
| @@ -264,7 +347,7 @@ class DataReductionProxyMetricsObserverTest
|
| TEST_F(DataReductionProxyMetricsObserverTest, DataReductionProxyOff) {
|
| ResetTest();
|
| // Verify that when the data reduction proxy was not used, no UMA is reported.
|
| - RunTest(false, false);
|
| + RunTest(false, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| ValidateHistograms();
|
| }
|
|
|
| @@ -272,7 +355,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, DataReductionProxyOn) {
|
| ResetTest();
|
| // Verify that when the data reduction proxy was used, but lofi was not used,
|
| // the correpsonding UMA is reported.
|
| - RunTest(true, false);
|
| + RunTest(true, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| ValidateHistograms();
|
| }
|
|
|
| @@ -280,7 +363,7 @@ TEST_F(DataReductionProxyMetricsObserverTest, LofiEnabled) {
|
| ResetTest();
|
| // Verify that when the data reduction proxy was used and lofi was used, both
|
| // histograms are reported.
|
| - RunTest(true, true);
|
| + RunTest(true, true, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| ValidateHistograms();
|
| }
|
|
|
| @@ -288,41 +371,41 @@ TEST_F(DataReductionProxyMetricsObserverTest, OnCompletePingback) {
|
| ResetTest();
|
| // Verify that when data reduction proxy was used the correct timing
|
| // information is sent to SendPingback.
|
| - RunTest(true, false);
|
| + RunTest(true, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| ValidateTimes();
|
|
|
| ResetTest();
|
| // Verify that when data reduction proxy was used but first image paint is
|
| // unset, the correct timing information is sent to SendPingback.
|
| timing_.first_image_paint = base::nullopt;
|
| - RunTest(true, false);
|
| + RunTest(true, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| ValidateTimes();
|
|
|
| ResetTest();
|
| // Verify that when data reduction proxy was used but first contentful paint
|
| // is unset, SendPingback is not called.
|
| timing_.first_contentful_paint = base::nullopt;
|
| - RunTest(true, false);
|
| + RunTest(true, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| ValidateTimes();
|
|
|
| ResetTest();
|
| // Verify that when data reduction proxy was used but first meaningful paint
|
| // is unset, SendPingback is not called.
|
| timing_.first_meaningful_paint = base::nullopt;
|
| - RunTest(true, false);
|
| + RunTest(true, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| ValidateTimes();
|
|
|
| ResetTest();
|
| // Verify that when data reduction proxy was used but load event start is
|
| // unset, SendPingback is not called.
|
| timing_.load_event_start = base::nullopt;
|
| - RunTest(true, false);
|
| + RunTest(true, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| ValidateTimes();
|
|
|
| ResetTest();
|
| // Verify that when data reduction proxy was not used, SendPingback is not
|
| // called.
|
| - RunTest(false, false);
|
| + RunTest(false, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| EXPECT_FALSE(pingback_client_->send_pingback_called());
|
|
|
| ResetTest();
|
| @@ -330,8 +413,116 @@ TEST_F(DataReductionProxyMetricsObserverTest, OnCompletePingback) {
|
| base::FieldTrialList field_trial_list(nullptr);
|
| ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
|
| "DataCompressionProxyHoldback", "Enabled"));
|
| - RunTest(true, false);
|
| + RunTest(true, false, [](page_load_metrics::PageLoadTracker* tracker) {});
|
| EXPECT_FALSE(pingback_client_->send_pingback_called());
|
| }
|
|
|
| +TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationCompression) {
|
| + ResetTest();
|
| +
|
| + int network_requests = 0;
|
| + int drp_requests = 0;
|
| + int64_t network_bytes = 0;
|
| + int64_t drp_bytes = 0;
|
| + int64_t ocl_bytes = 0;
|
| +
|
| + std::function<void(page_load_metrics::PageLoadTracker*)> extra_steps =
|
| + [&network_requests, &drp_requests, &network_bytes, &drp_bytes,
|
| + &ocl_bytes](page_load_metrics::PageLoadTracker* tracker) {
|
| + // Prepare 4 requests of varying size and configurations.
|
| + page_load_metrics::ExtraRequestInfo requests[] = {
|
| + // Cached request.
|
| + {true /*was_cached*/, 1024 * 40 /* 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 */},
|
| + // 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 */},
|
| + // 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 */},
|
| +
|
| + };
|
| +
|
| + for (auto request : requests) {
|
| + tracker->OnLoadedResource(request);
|
| + if (!request.was_cached) {
|
| + network_bytes += request.raw_body_bytes;
|
| + ocl_bytes += request.original_network_content_length;
|
| + ++network_requests;
|
| + }
|
| + if (request.data_reduction_proxy_used) {
|
| + drp_bytes += request.raw_body_bytes;
|
| + ++drp_requests;
|
| + }
|
| + }
|
| + };
|
| +
|
| + RunTest(true, false, extra_steps);
|
| +
|
| + ValidateDataHistograms(network_requests, drp_requests, network_bytes,
|
| + drp_bytes, ocl_bytes);
|
| +}
|
| +
|
| +TEST_F(DataReductionProxyMetricsObserverTest, ByteInformationInflation) {
|
| + ResetTest();
|
| +
|
| + int network_requests = 0;
|
| + int drp_requests = 0;
|
| + int64_t network_bytes = 0;
|
| + int64_t drp_bytes = 0;
|
| + int64_t ocl_bytes = 0;
|
| +
|
| + std::function<void(page_load_metrics::PageLoadTracker*)> extra_steps =
|
| + [&network_requests, &drp_requests, &network_bytes, &drp_bytes,
|
| + &ocl_bytes](page_load_metrics::PageLoadTracker* tracker) {
|
| + // Prepare 4 requests of varying size and configurations.
|
| +
|
| + // Prepare 4 requests of varying size and configurations.
|
| + page_load_metrics::ExtraRequestInfo requests[] = {
|
| + // Cached request.
|
| + {true /*was_cached*/, 1024 * 40 /* 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 */},
|
| + // 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 */},
|
| + // 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 */},
|
| +
|
| + };
|
| +
|
| + for (auto request : requests) {
|
| + tracker->OnLoadedResource(request);
|
| + if (!request.was_cached) {
|
| + network_bytes += request.raw_body_bytes;
|
| + ocl_bytes += request.original_network_content_length;
|
| + ++network_requests;
|
| + }
|
| + if (request.data_reduction_proxy_used) {
|
| + drp_bytes += request.raw_body_bytes;
|
| + ++drp_requests;
|
| + }
|
| + }
|
| + };
|
| +
|
| + RunTest(true, false, extra_steps);
|
| +
|
| + ValidateDataHistograms(network_requests, drp_requests, network_bytes,
|
| + drp_bytes, ocl_bytes);
|
| +}
|
| +
|
| } // namespace data_reduction_proxy
|
|
|