| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc
|
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc
|
| index d3ddd1944d0d8d52f7138998938be9299770e22a..c19584ec22dadb5ece5f15f4559b33911abe10c8 100644
|
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc
|
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_delegate_unittest.cc
|
| @@ -86,7 +86,7 @@ TEST(DataReductionProxyDelegate, IsTrustedSpdyProxy) {
|
| net::ProxyServer::Scheme first_proxy_scheme;
|
| net::ProxyServer::Scheme second_proxy_scheme;
|
| bool expect_proxy_is_trusted;
|
| - } tests[] = {
|
| + } test_cases[] = {
|
| {false, net::ProxyServer::SCHEME_HTTP, net::ProxyServer::SCHEME_INVALID,
|
| false},
|
| {true, net::ProxyServer::SCHEME_HTTP, net::ProxyServer::SCHEME_INVALID,
|
| @@ -116,23 +116,22 @@ TEST(DataReductionProxyDelegate, IsTrustedSpdyProxy) {
|
| {true, net::ProxyServer::SCHEME_QUIC, net::ProxyServer::SCHEME_HTTPS,
|
| true},
|
| };
|
| - for (size_t i = 0; i < arraysize(tests); ++i) {
|
| - ASSERT_EQ(
|
| - tests[i].expect_proxy_is_trusted,
|
| - tests[i].is_in_trusted_spdy_proxy_field_trial &&
|
| - (tests[i].first_proxy_scheme == net::ProxyServer::SCHEME_HTTPS ||
|
| - tests[i].second_proxy_scheme == net::ProxyServer::SCHEME_HTTPS))
|
| - << i;
|
| + for (const auto& test : test_cases) {
|
| + ASSERT_EQ(test.expect_proxy_is_trusted,
|
| + test.is_in_trusted_spdy_proxy_field_trial &&
|
| + (test.first_proxy_scheme == net::ProxyServer::SCHEME_HTTPS ||
|
| + test.second_proxy_scheme == net::ProxyServer::SCHEME_HTTPS))
|
| + << (&test - test_cases);
|
|
|
| std::vector<net::ProxyServer> proxies_for_http;
|
| net::ProxyServer first_proxy;
|
| net::ProxyServer second_proxy;
|
| - if (tests[i].first_proxy_scheme != net::ProxyServer::SCHEME_INVALID) {
|
| - first_proxy = GetProxyWithScheme(tests[i].first_proxy_scheme);
|
| + if (test.first_proxy_scheme != net::ProxyServer::SCHEME_INVALID) {
|
| + first_proxy = GetProxyWithScheme(test.first_proxy_scheme);
|
| proxies_for_http.push_back(first_proxy);
|
| }
|
| - if (tests[i].second_proxy_scheme != net::ProxyServer::SCHEME_INVALID) {
|
| - second_proxy = GetProxyWithScheme(tests[i].second_proxy_scheme);
|
| + if (test.second_proxy_scheme != net::ProxyServer::SCHEME_INVALID) {
|
| + second_proxy = GetProxyWithScheme(test.second_proxy_scheme);
|
| proxies_for_http.push_back(second_proxy);
|
| }
|
|
|
| @@ -156,12 +155,12 @@ TEST(DataReductionProxyDelegate, IsTrustedSpdyProxy) {
|
| base::FieldTrialList field_trial_list(nullptr);
|
| base::FieldTrialList::CreateFieldTrial(
|
| params::GetTrustedSpdyProxyFieldTrialName(),
|
| - tests[i].is_in_trusted_spdy_proxy_field_trial ? "Enabled" : "Control");
|
| + test.is_in_trusted_spdy_proxy_field_trial ? "Enabled" : "Control");
|
|
|
| - EXPECT_EQ(tests[i].expect_proxy_is_trusted,
|
| + EXPECT_EQ(test.expect_proxy_is_trusted,
|
| delegate.IsTrustedSpdyProxy(first_proxy) ||
|
| delegate.IsTrustedSpdyProxy(second_proxy))
|
| - << i;
|
| + << (&test - test_cases);
|
| }
|
| }
|
|
|
| @@ -408,11 +407,11 @@ TEST_F(DataReductionProxyDelegateTest, OnResolveProxyHandler) {
|
| // missing config are recorded properly.
|
| TEST_F(DataReductionProxyDelegateTest, HTTPRequests) {
|
| const struct {
|
| - std::string url;
|
| + const char* url;
|
| bool enabled_by_user;
|
| bool use_direct_proxy;
|
| bool expect_histogram;
|
| - } tests[] = {
|
| + } test_cases[] = {
|
| {
|
| // Request should not be logged because data saver is disabled.
|
| "http://www.example.com/", false, true, false,
|
| @@ -440,16 +439,16 @@ TEST_F(DataReductionProxyDelegateTest, HTTPRequests) {
|
| },
|
| };
|
|
|
| - for (size_t i = 0; i < arraysize(tests); ++i) {
|
| - ASSERT_TRUE(tests[i].use_direct_proxy || tests[i].enabled_by_user);
|
| - ASSERT_TRUE(tests[i].enabled_by_user || !tests[i].expect_histogram);
|
| + for (const auto& test : test_cases) {
|
| + ASSERT_TRUE(test.use_direct_proxy || test.enabled_by_user);
|
| + ASSERT_TRUE(test.enabled_by_user || !test.expect_histogram);
|
| base::HistogramTester histogram_tester;
|
| - GURL url(tests[i].url);
|
| + GURL url(test.url);
|
|
|
| net::ProxyInfo data_reduction_proxy_info;
|
|
|
| std::string data_reduction_proxy;
|
| - if (!tests[i].use_direct_proxy) {
|
| + if (!test.use_direct_proxy) {
|
| base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy);
|
| data_reduction_proxy_info.UsePacString(
|
| "PROXY " +
|
| @@ -459,10 +458,10 @@ TEST_F(DataReductionProxyDelegateTest, HTTPRequests) {
|
| .ToString() +
|
| "; DIRECT");
|
| }
|
| - EXPECT_EQ(tests[i].use_direct_proxy, data_reduction_proxy_info.is_empty());
|
| + EXPECT_EQ(test.use_direct_proxy, data_reduction_proxy_info.is_empty());
|
|
|
| net::ProxyConfig data_reduction_proxy_config;
|
| - if (tests[i].use_direct_proxy) {
|
| + if (test.use_direct_proxy) {
|
| data_reduction_proxy_config = net::ProxyConfig::CreateDirect();
|
|
|
| } else {
|
| @@ -470,7 +469,7 @@ TEST_F(DataReductionProxyDelegateTest, HTTPRequests) {
|
| "http=" + data_reduction_proxy + ",direct://;");
|
| data_reduction_proxy_config.set_id(1);
|
| }
|
| - config()->SetStateForTest(tests[i].enabled_by_user /* enabled */,
|
| + config()->SetStateForTest(test.enabled_by_user /* enabled */,
|
| false /* at_startup */);
|
|
|
| net::ProxyRetryInfoMap empty_proxy_retry_info;
|
| @@ -485,29 +484,16 @@ TEST_F(DataReductionProxyDelegateTest, HTTPRequests) {
|
| empty_proxy_retry_info, config(), &result);
|
| histogram_tester.ExpectTotalCount(
|
| "DataReductionProxy.ConfigService.HTTPRequests",
|
| - tests[i].expect_histogram ? 1 : 0);
|
| + test.expect_histogram ? 1 : 0);
|
|
|
| - if (tests[i].expect_histogram) {
|
| + if (test.expect_histogram) {
|
| histogram_tester.ExpectUniqueSample(
|
| "DataReductionProxy.ConfigService.HTTPRequests",
|
| - tests[i].use_direct_proxy ? 0 : 1, 1);
|
| + test.use_direct_proxy ? 0 : 1, 1);
|
| }
|
| }
|
| }
|
|
|
| -#if defined(OS_ANDROID)
|
| -#define MAYBE_OnCompletedInternalLoFi DISABLED_OnCompletedInternalLoFi
|
| -#else
|
| -#define MAYBE_OnCompletedInternalLoFi OnCompletedInternalLoFi
|
| -#endif
|
| -
|
| -#if defined(OS_ANDROID)
|
| -#define MAYBE_OnCompletedInternalLoFiPreview \
|
| - DISABLED_OnCompletedInternalLoFiPreview
|
| -#else
|
| -#define MAYBE_OnCompletedInternalLoFiPreview OnCompletedInternalLoFiPreview
|
| -#endif
|
| -
|
| TEST_F(DataReductionProxyDelegateTest, OnCompletedSizeFor200) {
|
| int64_t baseline_received_bytes = total_received_bytes();
|
| int64_t baseline_original_received_bytes = total_original_received_bytes();
|
| @@ -586,10 +572,7 @@ TEST_F(DataReductionProxyDelegateTest, OnCompletedSizeForReadError) {
|
| int64_t baseline_received_bytes = total_received_bytes();
|
| int64_t baseline_original_received_bytes = total_original_received_bytes();
|
|
|
| - net::MockRead reads[] = {net::MockRead("HTTP/1.1 200 OK\r\n"
|
| - "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| - "X-Original-Content-Length: 10000\r\n"
|
| - "Content-Length: 1000\r\n\r\n"),
|
| + net::MockRead reads[] = {net::MockRead("HTTP/1.1 "),
|
| net::MockRead(net::ASYNC, net::ERR_ABORTED)};
|
| net::StaticSocketDataProvider socket(reads, arraysize(reads), nullptr, 0);
|
| mock_socket_factory()->AddSocketDataProvider(&socket);
|
| @@ -606,6 +589,107 @@ TEST_F(DataReductionProxyDelegateTest, OnCompletedSizeForReadError) {
|
| total_original_received_bytes() - baseline_original_received_bytes);
|
| }
|
|
|
| +TEST_F(DataReductionProxyDelegateTest, PartialRangeSavings) {
|
| + const struct {
|
| + std::string response_headers;
|
| + size_t received_content_length;
|
| + int64_t expected_original_content_length;
|
| + } test_cases[] = {
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: 1000\r\n"
|
| + "X-Original-Content-Length: 3000\r\n\r\n",
|
| + 100, 300},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: 1000\r\n"
|
| + "X-Original-Content-Length: 1000\r\n\r\n",
|
| + 100, 100},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: 3000\r\n"
|
| + "X-Original-Content-Length: 1000\r\n\r\n",
|
| + 300, 100},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: 1000\r\n\r\n",
|
| + 100, 100},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: 1000\r\n"
|
| + "X-Original-Content-Length: nonsense\r\n\r\n",
|
| + 100, 100},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: 0\r\n"
|
| + "X-Original-Content-Length: 1000\r\n\r\n",
|
| + 0, 1000},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "X-Original-Content-Length: 1000\r\n\r\n",
|
| + 100, 100},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: nonsense\r\n"
|
| + "X-Original-Content-Length: 3000\r\n\r\n",
|
| + 100, 100},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: 1000\r\n"
|
| + "X-Original-Content-Length: 0\r\n\r\n",
|
| + 100, 0},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: 1000\r\n"
|
| + "X-Original-Content-Length: 0\r\n\r\n",
|
| + 0, 0},
|
| + {"HTTP/1.1 200 OK\r\n"
|
| + "Via: 1.1 Chrome-Compression-Proxy\r\n"
|
| + "Content-Length: " +
|
| + base::Int64ToString(static_cast<int64_t>(1) << 60) +
|
| + "\r\n"
|
| + "X-Original-Content-Length: " +
|
| + base::Int64ToString((static_cast<int64_t>(1) << 60) * 3) +
|
| + "\r\n\r\n",
|
| + 100, 300},
|
| + };
|
| +
|
| + for (const auto& test : test_cases) {
|
| + int64_t baseline_received_bytes = total_received_bytes();
|
| + int64_t baseline_original_received_bytes = total_original_received_bytes();
|
| +
|
| + std::string response_body(test.received_content_length, 'a');
|
| +
|
| + net::MockRead reads[] = {
|
| + net::MockRead(net::ASYNC, test.response_headers.data(),
|
| + test.response_headers.size()),
|
| + net::MockRead(net::ASYNC, response_body.data(), response_body.size()),
|
| + net::MockRead(net::SYNCHRONOUS, net::ERR_ABORTED)};
|
| + net::StaticSocketDataProvider socket(reads, arraysize(reads), nullptr, 0);
|
| + mock_socket_factory()->AddSocketDataProvider(&socket);
|
| +
|
| + net::TestDelegate test_delegate;
|
| + std::unique_ptr<net::URLRequest> request = context()->CreateRequest(
|
| + GURL("http://example.com"), net::IDLE, &test_delegate);
|
| + request->Start();
|
| +
|
| + base::RunLoop().RunUntilIdle();
|
| +
|
| + int64_t expected_original_size =
|
| + net::HttpUtil::AssembleRawHeaders(test.response_headers.data(),
|
| + test.response_headers.size())
|
| + .size() +
|
| + test.expected_original_content_length;
|
| +
|
| + EXPECT_EQ(request->GetTotalReceivedBytes(),
|
| + total_received_bytes() - baseline_received_bytes)
|
| + << (&test - test_cases);
|
| + EXPECT_EQ(expected_original_size, total_original_received_bytes() -
|
| + baseline_original_received_bytes)
|
| + << (&test - test_cases);
|
| + }
|
| +}
|
| +
|
| } // namespace
|
|
|
| } // namespace data_reduction_proxy
|
|
|