Chromium Code Reviews| Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc |
| diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc |
| index a02808ce755d11eb4abb0291c9a9ecaca7e6a4e6..fcac62bc15e0ed97631e170926df56e0a357ed24 100644 |
| --- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc |
| +++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc |
| @@ -72,6 +72,7 @@ using TestNetworkDelegate = net::NetworkDelegateImpl; |
| const char kOtherProxy[] = "testproxy:17"; |
| const char kTestURL[] = "http://www.google.com/"; |
| +const char kSecureTestURL[] = "https://www.google.com/"; |
| #if defined(OS_ANDROID) |
| const Client kClient = Client::CHROME_ANDROID; |
| @@ -180,6 +181,8 @@ class TestLoFiUIService : public LoFiUIService { |
| bool on_lofi_response_; |
| }; |
| +enum ProxyConfig { USE_SECURE_PROXY, USE_INSECURE_PROXY, BYPASS_PROXY }; |
| + |
| class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| public: |
| DataReductionProxyNetworkDelegateTest() |
| @@ -191,24 +194,35 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| net::GetTestCertsDirectory(), "unittest.selfsigned.der"); |
| } |
| - void Init(bool use_secure_proxy, bool enable_brotli_globally) { |
| - net::ProxyServer proxy_server = |
| - use_secure_proxy |
| - ? net::ProxyServer::FromURI("https://origin.net:443", |
| - net::ProxyServer::SCHEME_HTTPS) |
| - : net::ProxyServer::FromURI("http://origin.net:80", |
| - net::ProxyServer::SCHEME_HTTP); |
| - |
| + void Init(ProxyConfig proxy_config, bool enable_brotli_globally) { |
|
bengr
2017/04/11 18:51:43
ProxyConfig is already a concept in Chromium. I'd
ajo1
2017/04/11 20:00:25
Done.
|
| + net::ProxyServer proxy_server; |
| + switch (proxy_config) { |
| + case BYPASS_PROXY: |
| + proxy_server = net::ProxyServer::Direct(); |
| + break; |
| + case USE_SECURE_PROXY: |
| + proxy_server = net::ProxyServer::FromURI( |
| + "https://origin.net:443", net::ProxyServer::SCHEME_HTTPS); |
| + break; |
| + case USE_INSECURE_PROXY: |
| + proxy_server = net::ProxyServer::FromURI("http://origin.net:80", |
| + net::ProxyServer::SCHEME_HTTP); |
| + break; |
| + } |
| proxy_service_ = |
| net::ProxyService::CreateFixedFromPacResult(proxy_server.ToPacString()); |
| context_.set_proxy_service(proxy_service_.get()); |
| - test_context_ = (DataReductionProxyTestContext::Builder() |
| - .WithClient(kClient) |
| - .WithMockClientSocketFactory(&mock_socket_factory_) |
| - .WithURLRequestContext(&context_) |
| - .WithProxiesForHttp({DataReductionProxyServer( |
| - proxy_server, ProxyServer::UNSPECIFIED_TYPE)}) |
| - .Build()); |
| + DataReductionProxyTestContext::Builder builder; |
| + builder = builder.WithClient(kClient) |
| + .WithMockClientSocketFactory(&mock_socket_factory_) |
| + .WithURLRequestContext(&context_); |
| + |
| + if (proxy_config != BYPASS_PROXY) { |
| + builder = builder.WithProxiesForHttp({DataReductionProxyServer( |
| + proxy_server, ProxyServer::UNSPECIFIED_TYPE)}); |
| + } |
| + |
| + test_context_ = builder.Build(); |
| context_.set_client_socket_factory(&mock_socket_factory_); |
| test_context_->AttachToURLRequestContext(&context_storage_); |
| @@ -478,6 +492,10 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| return &test_network_quality_estimator_; |
| } |
| + net::SSLSocketDataProvider* ssl_socket_data_provider() { |
| + return &ssl_socket_data_provider_; |
| + } |
| + |
| private: |
| base::MessageLoopForIO message_loop_; |
| net::MockClientSocketFactory mock_socket_factory_; |
| @@ -499,7 +517,7 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| }; |
| TEST_F(DataReductionProxyNetworkDelegateTest, AuthenticationTest) { |
| - Init(false, false); |
| + Init(USE_INSECURE_PROXY, false); |
| std::unique_ptr<net::URLRequest> fake_request( |
| FetchURLRequest(GURL(kTestURL), nullptr, std::string(), 0)); |
| @@ -529,7 +547,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, AuthenticationTest) { |
| } |
| TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| - Init(false, false); |
| + Init(USE_INSECURE_PROXY, false); |
| // Enable Lo-Fi. |
| const struct { |
| bool lofi_switch_enabled; |
| @@ -680,7 +698,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| } |
| TEST_F(DataReductionProxyNetworkDelegateTest, RequestDataConfigurations) { |
| - Init(false, false); |
| + Init(USE_INSECURE_PROXY, false); |
| const struct { |
| bool lofi_on; |
| bool used_data_reduction_proxy; |
| @@ -756,7 +774,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, RequestDataConfigurations) { |
| TEST_F(DataReductionProxyNetworkDelegateTest, |
| RequestDataHoldbackConfigurations) { |
| - Init(false, false); |
| + Init(USE_INSECURE_PROXY, false); |
| const struct { |
| bool data_reduction_proxy_enabled; |
| bool used_direct; |
| @@ -803,7 +821,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, |
| } |
| TEST_F(DataReductionProxyNetworkDelegateTest, RedirectRequestDataCleared) { |
| - Init(false, false); |
| + Init(USE_INSECURE_PROXY, false); |
| net::ProxyInfo data_reduction_proxy_info; |
| std::string data_reduction_proxy; |
| base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); |
| @@ -870,7 +888,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, RedirectRequestDataCleared) { |
| } |
| TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
| - Init(false, false); |
| + Init(USE_INSECURE_PROXY, false); |
| const std::string kReceivedValidOCLHistogramName = |
| "Net.HttpContentLengthWithValidOCL"; |
| const std::string kOriginalValidOCLHistogramName = |
| @@ -887,6 +905,11 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
| "Net.HttpContentLengthDifferenceWithValidOCL.LoFiOn"; |
| const std::string kReceivedHistogramName = "Net.HttpContentLength"; |
| + const std::string kReceivedInsecureHistogramName = |
| + "Net.HttpContentLength.Http"; |
| + const std::string kReceivedSecureHistogramName = |
| + "Net.HttpContentLength.Https"; |
| + const std::string kReceivedVideoHistogramName = "Net.HttpContentLength.Video"; |
| const std::string kOriginalHistogramName = "Net.HttpOriginalContentLength"; |
| const std::string kDifferenceHistogramName = |
| "Net.HttpContentLengthDifference"; |
| @@ -928,6 +951,12 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
| kOriginalContentLength - kResponseContentLength, 1); |
| histogram_tester.ExpectUniqueSample(kReceivedHistogramName, |
| kResponseContentLength, 1); |
| + histogram_tester.ExpectUniqueSample(kReceivedInsecureHistogramName, |
| + kResponseContentLength, 1); |
| + histogram_tester.ExpectTotalCount(kReceivedSecureHistogramName, 0); |
| + histogram_tester.ExpectTotalCount(kReceivedVideoHistogramName, 0); |
| + histogram_tester.ExpectUniqueSample(kReceivedInsecureHistogramName, |
| + kResponseContentLength, 1); |
| histogram_tester.ExpectUniqueSample(kOriginalHistogramName, |
| kOriginalContentLength, 1); |
| histogram_tester.ExpectUniqueSample( |
| @@ -942,6 +971,24 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
| histogram_tester.ExpectUniqueSample(kCacheable24HoursHistogramName, |
| kResponseContentLength, 1); |
| + // Check video |
| + std::string video_response_headers = |
| + "HTTP/1.1 200 OK\r\n" |
| + "Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n" |
| + "Expires: Mon, 24 Nov 2014 12:45:26 GMT\r\n" |
| + "Content-Type: video/mp4\r\n" |
| + "Via: 1.1 Chrome-Compression-Proxy\r\n" |
| + "x-original-content-length: " + |
| + base::Int64ToString(kOriginalContentLength) + "\r\n\r\n"; |
| + |
| + FetchURLRequest(GURL(kTestURL), nullptr, video_response_headers, |
| + kResponseContentLength); |
| + |
| + histogram_tester.ExpectTotalCount(kReceivedInsecureHistogramName, 2); |
| + histogram_tester.ExpectTotalCount(kReceivedSecureHistogramName, 0); |
| + histogram_tester.ExpectUniqueSample(kReceivedVideoHistogramName, |
| + kResponseContentLength, 1); |
| + |
| // Check Lo-Fi histograms. |
| const struct { |
| bool lofi_enabled_through_switch; |
| @@ -1018,8 +1065,40 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
| } |
| } |
| +TEST_F(DataReductionProxyNetworkDelegateTest, NetSSLHistograms) { |
| + Init(BYPASS_PROXY, false); |
| + |
| + const std::string kReceivedInsecureHistogramName = |
| + "Net.HttpContentLength.Http"; |
| + const std::string kReceivedSecureHistogramName = |
| + "Net.HttpContentLength.Https"; |
| + const std::string kReceivedVideoHistogramName = "Net.HttpContentLength.Video"; |
| + const int64_t kResponseContentLength = 100; |
| + const int64_t kOriginalContentLength = 200; |
| + |
| + base::HistogramTester histogram_tester; |
| + |
| + // Check https |
| + std::string secure_response_headers = |
| + "HTTP/1.1 200 OK\r\n" |
| + "Date: Wed, 28 Nov 2007 09:40:09 GMT\r\n" |
| + "Expires: Mon, 24 Nov 2014 12:45:26 GMT\r\n" |
| + "Via: 1.1 Chrome-Compression-Proxy\r\n" |
| + "x-original-content-length: " + |
| + base::Int64ToString(kOriginalContentLength) + "\r\n\r\n"; |
| + |
| + mock_socket_factory()->AddSSLSocketDataProvider(ssl_socket_data_provider()); |
| + FetchURLRequest(GURL(kSecureTestURL), nullptr, secure_response_headers, |
| + kResponseContentLength); |
| + |
| + histogram_tester.ExpectTotalCount(kReceivedInsecureHistogramName, 0); |
| + histogram_tester.ExpectUniqueSample(kReceivedSecureHistogramName, |
| + kResponseContentLength, 1); |
| + histogram_tester.ExpectTotalCount(kReceivedVideoHistogramName, 0); |
| +} |
| + |
| TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternalLoFi) { |
| - Init(false, false); |
| + Init(USE_INSECURE_PROXY, false); |
| // Enable Lo-Fi. |
| const struct { |
| bool lofi_response; |
| @@ -1047,7 +1126,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternalLoFi) { |
| TEST_F(DataReductionProxyNetworkDelegateTest, |
| TestLoFiTransformationTypeHistogram) { |
| - Init(false, false); |
| + Init(USE_INSECURE_PROXY, false); |
| const char kLoFiTransformationTypeHistogram[] = |
| "DataReductionProxy.LoFi.TransformationType"; |
| base::HistogramTester histogram_tester; |
| @@ -1078,7 +1157,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, |
| // disabled globally. |
| TEST_F(DataReductionProxyNetworkDelegateTest, |
| BrotliAdvertisement_BrotliDisabled) { |
| - Init(true /* use_secure_proxy */, false /* enable_brotli_globally */); |
| + Init(USE_SECURE_PROXY, false /* enable_brotli_globally */); |
| ReadBrotliFile(); |
| @@ -1100,7 +1179,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, |
| // is fetched from an insecure proxy. |
| TEST_F(DataReductionProxyNetworkDelegateTest, |
| BrotliAdvertisementInsecureProxy) { |
| - Init(false /* use_secure_proxy */, true /* enable_brotli_globally */); |
| + Init(USE_INSECURE_PROXY, true /* enable_brotli_globally */); |
| std::string response_headers = |
| "HTTP/1.1 200 OK\r\n" |
| "Content-Length: 140\r\n" |
| @@ -1126,7 +1205,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, |
| // disabled via data reduction proxy field trial. |
| TEST_F(DataReductionProxyNetworkDelegateTest, |
| BrotliAdvertisementDisabledViaFieldTrial) { |
| - Init(true /* use_secure_proxy */, true /* enable_brotli_globally */); |
| + Init(USE_SECURE_PROXY, true /* enable_brotli_globally */); |
| base::FieldTrialList field_trial_list(nullptr); |
| ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| @@ -1148,7 +1227,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, |
| // Test that Brotli is correctly added to the accept-encoding header when it is |
| // enabled globally. |
| TEST_F(DataReductionProxyNetworkDelegateTest, BrotliAdvertisement) { |
| - Init(true /* use_secure_proxy */, true /* enable_brotli_globally */); |
| + Init(USE_SECURE_PROXY, true /* enable_brotli_globally */); |
| std::string response_headers = |
| "HTTP/1.1 200 OK\r\n" |