| 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 f48c7959bb3ae9a6bafa6131e1d49825878782b3..b656f0f1d58caf11a8fc0e7f28d5ef36c8102e7f 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
|
| @@ -179,7 +179,9 @@
|
| DataReductionProxyNetworkDelegateTest()
|
| : context_(true), context_storage_(&context_) {}
|
|
|
| - void Init(bool use_secure_proxy, bool enable_brotli_globally) {
|
| + void Init(bool use_secure_proxy,
|
| + bool enable_brotli_globally,
|
| + bool exclude_chrome_proxy_header_for_testing) {
|
| net::ProxyServer proxy_server =
|
| use_secure_proxy
|
| ? net::ProxyServer::FromURI("https://origin.net:443",
|
| @@ -198,7 +200,8 @@
|
| .Build());
|
|
|
| context_.set_client_socket_factory(&mock_socket_factory_);
|
| - test_context_->AttachToURLRequestContext(&context_storage_);
|
| + test_context_->AttachToURLRequestContext(
|
| + &context_storage_, exclude_chrome_proxy_header_for_testing);
|
|
|
| std::unique_ptr<TestLoFiDecider> lofi_decider(new TestLoFiDecider());
|
| lofi_decider_ = lofi_decider.get();
|
| @@ -301,46 +304,26 @@
|
| net::MockRead reads[] = {net::MockRead(response_headers.c_str()),
|
| net::MockRead(response_body.c_str()),
|
| net::MockRead(net::SYNCHRONOUS, net::OK)};
|
| -
|
| - if (io_data()->test_request_options()->GetHeaderValueForTesting().empty()) {
|
| - // Force regeneration of Chrome-Proxy header.
|
| - io_data()->test_request_options()->SetSecureSession("123");
|
| - }
|
| - EXPECT_FALSE(
|
| - io_data()->test_request_options()->GetHeaderValueForTesting().empty());
|
| -
|
| - std::string prefix_headers(
|
| - "GET http://www.example.com/a.html HTTP/1.1\r\n"
|
| - "Host: www.example.com\r\n"
|
| - "Proxy-Connection: keep-alive\r\n"
|
| - "User-Agent:\r\n");
|
| -
|
| - std::string accept_language_header("Accept-Language: en-us,fr\r\n");
|
| -
|
| - // Brotli is included in accept-encoding header only if the request went
|
| - // to the network (i.e., it was not a cached response), and if data
|
| - // reduction ptroxy network delegate added Brotli to the header.
|
| - std::string accept_encoding_header =
|
| - expect_brotli && !expect_cached
|
| - ? "Accept-Encoding: gzip, deflate, br\r\n"
|
| - : "Accept-Encoding: gzip, deflate\r\n";
|
| -
|
| - std::string suffix_headers =
|
| - std::string("Chrome-Proxy: ") +
|
| - io_data()->test_request_options()->GetHeaderValueForTesting() +
|
| - std::string("\r\n\r\n");
|
| -
|
| - std::string mock_write = prefix_headers + accept_language_header +
|
| - accept_encoding_header + suffix_headers;
|
| -
|
| - if (expect_cached || !expect_brotli) {
|
| - // Order of headers is different if the headers were modified by data
|
| - // reduction proxy network delegate.
|
| - mock_write = prefix_headers + accept_encoding_header +
|
| - accept_language_header + suffix_headers;
|
| - }
|
| -
|
| - net::MockWrite writes[] = {net::MockWrite(mock_write.c_str())};
|
| + net::MockWrite writes[1];
|
| +
|
| + if (expect_brotli) {
|
| + writes[0] = net::MockWrite(
|
| + "GET http://www.example.com/a.html HTTP/1.1\r\n"
|
| + "Host: www.example.com\r\n"
|
| + "Proxy-Connection: keep-alive\r\n"
|
| + "User-Agent:\r\n"
|
| + "Accept-Language: en-us,fr\r\n"
|
| + "Accept-Encoding: gzip, deflate, br\r\n\r\n");
|
| + } else {
|
| + writes[0] = net::MockWrite(
|
| + "GET http://www.example.com/a.html HTTP/1.1\r\n"
|
| + "Host: www.example.com\r\n"
|
| + "Proxy-Connection: keep-alive\r\n"
|
| + "User-Agent:\r\n"
|
| + "Accept-Encoding: gzip, deflate\r\n"
|
| + "Accept-Language: en-us,fr\r\n\r\n");
|
| + }
|
| +
|
| net::StaticSocketDataProvider socket(reads, arraysize(reads), writes,
|
| arraysize(writes));
|
| mock_socket_factory_.AddSocketDataProvider(&socket);
|
| @@ -464,7 +447,7 @@
|
| };
|
|
|
| TEST_F(DataReductionProxyNetworkDelegateTest, AuthenticationTest) {
|
| - Init(false, false);
|
| + Init(false, false, false);
|
| std::unique_ptr<net::URLRequest> fake_request(FetchURLRequest(
|
| GURL("http://www.google.com/"), nullptr, std::string(), 0));
|
|
|
| @@ -487,7 +470,7 @@
|
| }
|
|
|
| TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) {
|
| - Init(false, false);
|
| + Init(false, false, false);
|
| // Enable Lo-Fi.
|
| const struct {
|
| bool lofi_switch_enabled;
|
| @@ -651,7 +634,7 @@
|
| }
|
|
|
| TEST_F(DataReductionProxyNetworkDelegateTest, RequestDataConfigurations) {
|
| - Init(false, false);
|
| + Init(false, false, false);
|
| const struct {
|
| bool lofi_on;
|
| bool used_data_reduction_proxy;
|
| @@ -723,7 +706,7 @@
|
|
|
| TEST_F(DataReductionProxyNetworkDelegateTest,
|
| RequestDataHoldbackConfigurations) {
|
| - Init(false, false);
|
| + Init(false, false, false);
|
| const struct {
|
| bool data_reduction_proxy_enabled;
|
| bool used_direct;
|
| @@ -770,7 +753,7 @@
|
| }
|
|
|
| TEST_F(DataReductionProxyNetworkDelegateTest, RedirectRequestDataCleared) {
|
| - Init(false, false);
|
| + Init(false, false, false);
|
| net::ProxyInfo data_reduction_proxy_info;
|
| std::string data_reduction_proxy;
|
| base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy);
|
| @@ -816,7 +799,7 @@
|
| }
|
|
|
| TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) {
|
| - Init(false, false);
|
| + Init(false, false, false);
|
| const std::string kReceivedValidOCLHistogramName =
|
| "Net.HttpContentLengthWithValidOCL";
|
| const std::string kOriginalValidOCLHistogramName =
|
| @@ -966,7 +949,7 @@
|
| }
|
|
|
| TEST_F(DataReductionProxyNetworkDelegateTest, OnCompletedInternalLoFi) {
|
| - Init(false, false);
|
| + Init(false, false, false);
|
| // Enable Lo-Fi.
|
| const struct {
|
| bool lofi_response;
|
| @@ -995,7 +978,7 @@
|
|
|
| TEST_F(DataReductionProxyNetworkDelegateTest,
|
| TestLoFiTransformationTypeHistogram) {
|
| - Init(false, false);
|
| + Init(false, false, false);
|
| const char kLoFiTransformationTypeHistogram[] =
|
| "DataReductionProxy.LoFi.TransformationType";
|
| base::HistogramTester histogram_tester;
|
| @@ -1028,7 +1011,9 @@
|
| // disabled globally.
|
| TEST_F(DataReductionProxyNetworkDelegateTest,
|
| BrotliAdvertisement_BrotliDisabled) {
|
| - Init(true /* use_secure_proxy */, false /* enable_brotli_globally */);
|
| + Init(true /* use_secure_proxy */, false /* enable_brotli_globally */,
|
| + true /* exclude_chrome_proxy_header_for_testing */);
|
| + base::FieldTrialList field_trial_list(nullptr);
|
|
|
| std::string response_headers =
|
| "HTTP/1.1 200 OK\r\n"
|
| @@ -1047,7 +1032,8 @@
|
| // is fetched from an insecure proxy.
|
| TEST_F(DataReductionProxyNetworkDelegateTest,
|
| BrotliAdvertisementInsecureProxy) {
|
| - Init(false /* use_secure_proxy */, true /* enable_brotli_globally */);
|
| + Init(false /* use_secure_proxy */, true /* enable_brotli_globally */,
|
| + false /* exclude_chrome_proxy_header_for_testing */);
|
| std::string response_headers =
|
| "HTTP/1.1 200 OK\r\n"
|
| "Content-Length: 140\r\n"
|
| @@ -1072,7 +1058,8 @@
|
| // disabled via data reduction proxy field trial.
|
| TEST_F(DataReductionProxyNetworkDelegateTest,
|
| BrotliAdvertisementDisabledViaFieldTrial) {
|
| - Init(true /* use_secure_proxy */, true /* enable_brotli_globally */);
|
| + Init(true /* use_secure_proxy */, true /* enable_brotli_globally */,
|
| + true /* exclude_chrome_proxy_header_for_testing */);
|
|
|
| base::FieldTrialList field_trial_list(nullptr);
|
| ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial(
|
| @@ -1093,7 +1080,8 @@
|
| // 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(true /* use_secure_proxy */, true /* enable_brotli_globally */,
|
| + true /* exclude_chrome_proxy_header_for_testing */);
|
|
|
| std::string response_headers =
|
| "HTTP/1.1 200 OK\r\n"
|
|
|