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 5bc90cc3fc3a48fb6accc768448696b7ab8274c1..bdfebf0e0ae9be724654897564ca2a906ce91b93 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 |
| @@ -51,6 +51,7 @@ namespace { |
| using TestNetworkDelegate = net::NetworkDelegateImpl; |
| const char kChromeProxyHeader[] = "chrome-proxy"; |
| +const char kOtherProxy[] = "testproxy:17"; |
| #if defined(OS_ANDROID) |
| const Client kClient = Client::CHROME_ANDROID; |
| @@ -91,9 +92,7 @@ class TestLoFiDecider : public LoFiDecider { |
| bool MaybeAddLoFiDirectiveToHeaders( |
| const net::URLRequest& request, |
| - net::HttpRequestHeaders* headers, |
| - const net::ProxyServer& proxy_server, |
| - DataReductionProxyConfig* config) const override { |
| + net::HttpRequestHeaders* headers) const override { |
| if (should_request_lofi_resource_) { |
| const char kChromeProxyHeader[] = "Chrome-Proxy"; |
| std::string header_value; |
| @@ -161,12 +160,14 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| test_context_->EnableDataReductionProxyWithSecureProxyCheckSuccess(); |
| } |
| - static void VerifyLoFiHeader(bool expected_lofi_used, |
| + static void VerifyLoFiHeader(bool expected_data_reduction_proxy_used, |
|
tbansal1
2016/05/06 23:36:51
s/verifyLoFiHeader/VerifyHeaders/
megjablon
2016/05/07 00:29:08
Done.
|
| + bool expected_lofi_used, |
| const net::HttpRequestHeaders& headers) { |
| - EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader)); |
| + EXPECT_EQ(expected_data_reduction_proxy_used, |
| + headers.HasHeader(kChromeProxyHeader)); |
|
tbansal1
2016/05/06 23:36:51
#include components/data_reduction_proxy/core/comm
megjablon
2016/05/07 00:29:08
Done.
|
| std::string header_value; |
| headers.GetHeader(kChromeProxyHeader, &header_value); |
| - EXPECT_EQ(expected_lofi_used, |
| + EXPECT_EQ(expected_data_reduction_proxy_used && expected_lofi_used, |
| header_value.find("q=low") != std::string::npos); |
| } |
| @@ -238,6 +239,10 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
| return test_context_->config(); |
| } |
| + TestDataReductionProxyIOData* io_data() const { |
| + return test_context_->io_data(); |
| + } |
| + |
| TestLoFiDecider* lofi_decider() const { return lofi_decider_; } |
| private: |
| @@ -293,14 +298,24 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| const struct { |
| bool lofi_switch_enabled; |
| bool auto_lofi_enabled; |
| + bool is_data_reduction_proxy; |
| } tests[] = { |
| { |
| - // Lo-Fi enabled through switch. |
| - true, false, |
| + // Lo-Fi enabled through switch and not using a Data Reduction Proxy. |
| + true, false, false, |
| + }, |
| + { |
| + // Lo-Fi enabled through switch and using a Data Reduction Proxy. |
| + true, false, true, |
| + }, |
| + { |
| + // Lo-Fi enabled through field trial and not using a Data Reduction |
| + // Proxy. |
| + false, true, false, |
| }, |
| { |
| - // Lo-Fi enabled through field trial. |
| - false, true, |
| + // Lo-Fi enabled through field trial and using a Data Reduction Proxy. |
| + false, true, true, |
| }, |
| }; |
| @@ -316,11 +331,15 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| "Enabled"); |
| } |
| config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled); |
| + io_data()->SetLoFiModeActiveOnMainFrame(false); |
| net::ProxyInfo data_reduction_proxy_info; |
| - std::string data_reduction_proxy; |
| - base::TrimString(params()->DefaultOrigin(), "/", &data_reduction_proxy); |
| - data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); |
| + std::string proxy; |
| + if (tests[i].is_data_reduction_proxy) |
| + base::TrimString(params()->DefaultOrigin(), "/", &proxy); |
| + else |
| + base::TrimString(kOtherProxy, "/", &proxy); |
| + data_reduction_proxy_info.UseNamedProxy(proxy); |
| { |
| // Main frame loaded. Lo-Fi should be used. |
| @@ -333,8 +352,8 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| config()->ShouldEnableLoFiMode(*fake_request.get())); |
| network_delegate()->NotifyBeforeSendProxyHeaders( |
| fake_request.get(), data_reduction_proxy_info, &headers); |
| - VerifyLoFiHeader(true, headers); |
| - VerifyWasLoFiModeActiveOnMainFrame(true); |
| + VerifyLoFiHeader(tests[i].is_data_reduction_proxy, true, headers); |
| + VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy); |
| } |
| { |
| @@ -345,10 +364,10 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| lofi_decider()->SetIsUsingLoFiMode(false); |
| network_delegate()->NotifyBeforeSendProxyHeaders( |
| fake_request.get(), data_reduction_proxy_info, &headers); |
| - VerifyLoFiHeader(false, headers); |
| + VerifyLoFiHeader(tests[i].is_data_reduction_proxy, false, headers); |
| // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be |
| - // true. |
| - VerifyWasLoFiModeActiveOnMainFrame(true); |
| + // true if the proxy is a Data Reduction Proxy. |
| + VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy); |
| } |
| { |
| @@ -360,15 +379,14 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| lofi_decider()->SetIsUsingLoFiMode(true); |
| network_delegate()->NotifyBeforeSendProxyHeaders( |
| fake_request.get(), data_reduction_proxy_info, &headers); |
| - VerifyLoFiHeader(true, headers); |
| + VerifyLoFiHeader(tests[i].is_data_reduction_proxy, |
| + tests[i].is_data_reduction_proxy, headers); |
|
tbansal1
2016/05/06 23:36:51
nit: For the second argument, can you not just pas
megjablon
2016/05/07 00:29:08
Whoops yep, missed switching this one.
|
| // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be |
| - // true. |
| - VerifyWasLoFiModeActiveOnMainFrame(true); |
| + // true if the proxy is a Data Reduction Proxy. |
| + VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy); |
| } |
| { |
| - // TODO(megjablon): Can remove the cases below once |
| - // WasLoFiModeActiveOnMainFrame is fixed to be per-page. |
| // Main frame request with Lo-Fi off. Lo-Fi should not be used. |
| // State of Lo-Fi should persist until next page load. |
| net::HttpRequestHeaders headers; |
| @@ -378,7 +396,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| lofi_decider()->SetIsUsingLoFiMode(false); |
| network_delegate()->NotifyBeforeSendProxyHeaders( |
| fake_request.get(), data_reduction_proxy_info, &headers); |
| - VerifyLoFiHeader(false, headers); |
| + VerifyLoFiHeader(tests[i].is_data_reduction_proxy, false, headers); |
| VerifyWasLoFiModeActiveOnMainFrame(false); |
| } |
| @@ -390,7 +408,7 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| lofi_decider()->SetIsUsingLoFiMode(false); |
| network_delegate()->NotifyBeforeSendProxyHeaders( |
| fake_request.get(), data_reduction_proxy_info, &headers); |
| - VerifyLoFiHeader(false, headers); |
| + VerifyLoFiHeader(tests[i].is_data_reduction_proxy, false, headers); |
| // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be |
| // false. |
| VerifyWasLoFiModeActiveOnMainFrame(false); |
| @@ -406,8 +424,9 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
| config()->ShouldEnableLoFiMode(*fake_request.get())); |
| network_delegate()->NotifyBeforeSendProxyHeaders( |
| fake_request.get(), data_reduction_proxy_info, &headers); |
| - VerifyLoFiHeader(true, headers); |
| - VerifyWasLoFiModeActiveOnMainFrame(true); |
| + VerifyLoFiHeader(tests[i].is_data_reduction_proxy, |
| + tests[i].is_data_reduction_proxy, headers); |
| + VerifyWasLoFiModeActiveOnMainFrame(tests[i].is_data_reduction_proxy); |
| } |
| } |
| } |