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 1cf8288bff6518f6b3940f8202cca67bb8d8c294..dc0107c4ddfb43e092c8895b191d4d0e7b1c71ee 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 |
@@ -18,6 +18,7 @@ |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h" |
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test_utils.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h" |
+#include "components/data_reduction_proxy/core/common/data_reduction_proxy_lofi_helper.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params_test_utils.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_names.h" |
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h" |
@@ -65,6 +66,19 @@ const Client kClient = Client::CHROME_QNX; |
const Client kClient = Client::UNKNOWN; |
#endif |
+class TestDataReductionProxyLoFiHelper : public DataReductionProxyLoFiHelper { |
+ public: |
+ TestDataReductionProxyLoFiHelper() : is_lofi_(false) {} |
+ ~TestDataReductionProxyLoFiHelper() override {} |
+ |
+ bool IsLoFi(net::URLRequest* request) const override { return is_lofi_; } |
+ |
+ void SetIsLoFi(bool is_lofi) { is_lofi_ = is_lofi; } |
+ |
+ private: |
+ bool is_lofi_; |
+}; |
+ |
} // namespace |
class DataReductionProxyNetworkDelegateTest : public testing::Test { |
@@ -96,12 +110,15 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
data_reduction_proxy_network_delegate_->InitIODataAndUMA( |
test_context_->io_data(), bypass_stats_.get()); |
- } |
- const net::ProxyConfig& GetProxyConfig() const { |
- return config_; |
+ scoped_ptr<TestDataReductionProxyLoFiHelper> lofi_helper( |
+ new TestDataReductionProxyLoFiHelper()); |
+ lofi_helper_ = lofi_helper.get(); |
+ io_data()->set_lofi_helper(lofi_helper.Pass()); |
} |
+ const net::ProxyConfig& GetProxyConfig() const { return config_; } |
+ |
MockDataReductionProxyConfig* config() const { |
return test_context_->mock_config(); |
} |
@@ -126,14 +143,13 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
const GURL& url, |
const std::string& raw_response_headers, |
int64 response_content_length) { |
- scoped_ptr<net::URLRequest> request = context_.CreateRequest( |
- url, net::IDLE, &delegate_); |
+ scoped_ptr<net::URLRequest> request = |
+ context_.CreateRequest(url, net::IDLE, &delegate_); |
// Create a test job that will fill in the given response headers for the |
// |fake_request|. |
scoped_refptr<net::URLRequestTestJob> test_job( |
- new net::URLRequestTestJob(request.get(), |
- context_.network_delegate(), |
+ new net::URLRequestTestJob(request.get(), context_.network_delegate(), |
raw_response_headers, std::string(), true)); |
// Configure the interceptor to use the test job to handle the next request. |
@@ -166,9 +182,9 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
return test_context_->io_data(); |
} |
- TestDataReductionProxyConfig* config() { |
- return test_context_->config(); |
- } |
+ TestDataReductionProxyConfig* config() { return test_context_->config(); } |
+ |
+ TestDataReductionProxyLoFiHelper* lofi_helper() { return lofi_helper_; } |
scoped_ptr<DataReductionProxyNetworkDelegate> |
data_reduction_proxy_network_delegate_; |
@@ -183,6 +199,7 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test { |
net::ProxyConfig config_; |
net::NetworkDelegate* network_delegate_; |
+ TestDataReductionProxyLoFiHelper* lofi_helper_; |
scoped_ptr<DataReductionProxyTestContext> test_context_; |
scoped_ptr<DataReductionProxyBypassStats> bypass_stats_; |
}; |
@@ -216,14 +233,12 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
bool auto_lofi_enabled; |
} tests[] = { |
{ |
- // Lo-Fi enabled through switch. |
- false, |
- true, |
+ // Lo-Fi enabled through switch. |
+ false, true, |
}, |
{ |
- // Lo-Fi enabled through field trial. |
- true, |
- false, |
+ // Lo-Fi enabled through field trial. |
+ true, false, |
}, |
}; |
@@ -248,6 +263,8 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
scoped_ptr<net::URLRequest> fake_request( |
FetchURLRequest(GURL("http://www.google.com/"), std::string(), 0)); |
fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME); |
+ lofi_helper()->SetIsLoFi( |
+ io_data()->ShouldEnableLoFiMode(fake_request.get())); |
data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders( |
fake_request.get(), data_reduction_proxy_info, &headers); |
VerifyLoFiHeader(true, headers); |
@@ -255,11 +272,11 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
} |
{ |
- // Bypass cache flag used. Lo-Fi should not be used. |
+ // Lo-Fi is already off. Lo-Fi should not be used. |
net::HttpRequestHeaders headers; |
scoped_ptr<net::URLRequest> fake_request( |
FetchURLRequest(GURL("http://www.google.com/"), std::string(), 0)); |
- fake_request->SetLoadFlags(net::LOAD_BYPASS_CACHE); |
+ lofi_helper()->SetIsLoFi(false); |
data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders( |
fake_request.get(), data_reduction_proxy_info, &headers); |
VerifyLoFiHeader(false, headers); |
@@ -269,11 +286,12 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
} |
{ |
- // Bypass cache flag not used. Lo-Fi should be used. |
+ // Lo-Fi is already on. Lo-Fi should be used. |
net::HttpRequestHeaders headers; |
scoped_ptr<net::URLRequest> fake_request( |
FetchURLRequest(GURL("http://www.google.com/"), std::string(), 0)); |
+ lofi_helper()->SetIsLoFi(true); |
data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders( |
fake_request.get(), data_reduction_proxy_info, &headers); |
VerifyLoFiHeader(true, headers); |
@@ -283,26 +301,15 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
} |
{ |
- // Bypass cache flag used. Lo-Fi should not be used. |
- net::HttpRequestHeaders headers; |
- scoped_ptr<net::URLRequest> fake_request( |
- FetchURLRequest(GURL("http://www.google.com/"), std::string(), 0)); |
- fake_request->SetLoadFlags(net::LOAD_BYPASS_CACHE); |
- data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders( |
- fake_request.get(), data_reduction_proxy_info, &headers); |
- VerifyLoFiHeader(false, headers); |
- // Not a mainframe request, WasLoFiModeActiveOnMainFrame should still be |
- // true. |
- VerifyWasLoFiModeActiveOnMainFrame(true); |
- } |
- |
- { |
- // Main frame request with bypass cache flag. Lo-Fi should not be used. |
+ // 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; |
scoped_ptr<net::URLRequest> fake_request( |
FetchURLRequest(GURL("http://www.google.com/"), std::string(), 0)); |
- fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME | net::LOAD_BYPASS_CACHE); |
+ fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME); |
+ lofi_helper()->SetIsLoFi(false); |
data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders( |
fake_request.get(), data_reduction_proxy_info, &headers); |
VerifyLoFiHeader(false, headers); |
@@ -310,10 +317,11 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
} |
{ |
- // Bypass cache flag not used. Lo-Fi is still not used. |
+ // Lo-Fi is off. Lo-Fi is still not used. |
net::HttpRequestHeaders headers; |
scoped_ptr<net::URLRequest> fake_request( |
FetchURLRequest(GURL("http://www.google.com/"), std::string(), 0)); |
+ lofi_helper()->SetIsLoFi(false); |
data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders( |
fake_request.get(), data_reduction_proxy_info, &headers); |
VerifyLoFiHeader(false, headers); |
@@ -328,6 +336,8 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) { |
scoped_ptr<net::URLRequest> fake_request( |
FetchURLRequest(GURL("http://www.google.com/"), std::string(), 0)); |
fake_request->SetLoadFlags(net::LOAD_MAIN_FRAME); |
+ lofi_helper()->SetIsLoFi( |
+ io_data()->ShouldEnableLoFiMode(fake_request.get())); |
data_reduction_proxy_network_delegate_->NotifyBeforeSendProxyHeaders( |
fake_request.get(), data_reduction_proxy_info, &headers); |
VerifyLoFiHeader(true, headers); |
@@ -380,9 +390,8 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
HeadersToRaw(&raw_headers); |
- scoped_ptr<net::URLRequest> fake_request( |
- FetchURLRequest(GURL("http://www.google.com/"), |
- raw_headers, kResponseContentLength)); |
+ scoped_ptr<net::URLRequest> fake_request(FetchURLRequest( |
+ GURL("http://www.google.com/"), raw_headers, kResponseContentLength)); |
base::TimeDelta freshness_lifetime = |
fake_request->response_info().headers->GetFreshnessLifetimes( |
@@ -419,31 +428,23 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
} tests[] = { |
{ |
- // Lo-Fi disabled. |
- false, |
- false, |
- 0, |
+ // Lo-Fi disabled. |
+ false, false, 0, |
}, |
{ |
- // Auto Lo-Fi enabled. |
- // This should populate Lo-Fi content length histogram. |
- false, |
- true, |
- 1, |
+ // Auto Lo-Fi enabled. |
+ // This should populate Lo-Fi content length histogram. |
+ false, true, 1, |
}, |
{ |
- // Lo-Fi enabled through switch. |
- // This should populate Lo-Fi content length histogram. |
- true, |
- false, |
- 1, |
+ // Lo-Fi enabled through switch. |
+ // This should populate Lo-Fi content length histogram. |
+ true, false, 1, |
}, |
{ |
- // Lo-Fi enabled through switch and Auto Lo-Fi also enabled. |
- // This should populate Lo-Fi content length histogram. |
- true, |
- true, |
- 1, |
+ // Lo-Fi enabled through switch and Auto Lo-Fi also enabled. |
+ // This should populate Lo-Fi content length histogram. |
+ true, true, 1, |
}, |
}; |
@@ -458,10 +459,11 @@ TEST_F(DataReductionProxyNetworkDelegateTest, NetHistograms) { |
switches::kDataReductionProxyLoFiValueAlwaysOn); |
} |
- config()->UpdateLoFiStatusOnMainFrameRequest(false, nullptr); |
+ lofi_helper()->SetIsLoFi( |
+ config()->ShouldEnableLoFiMode(fake_request.get())); |
- fake_request = (FetchURLRequest(GURL("http://www.example.com/"), |
- raw_headers, kResponseContentLength)); |
+ fake_request = FetchURLRequest(GURL("http://www.example.com/"), raw_headers, |
+ kResponseContentLength); |
// Histograms are accumulative, so get the sum of all the tests so far. |
int expected_count = 0; |
@@ -530,8 +532,8 @@ TEST_F(DataReductionProxyNetworkDelegateTest, OnResolveProxyHandler) { |
retry_info.current_delay = base::TimeDelta::FromSeconds(1000); |
retry_info.bad_until = base::TimeTicks().Now() + retry_info.current_delay; |
retry_info.try_while_bad = false; |
- data_reduction_proxy_retry_info[ |
- data_reduction_proxy_info.proxy_server().ToURI()] = retry_info; |
+ data_reduction_proxy_retry_info[data_reduction_proxy_info.proxy_server() |
+ .ToURI()] = retry_info; |
net::ProxyInfo result; |
// Another proxy is used. It should be used afterwards. |
@@ -575,13 +577,11 @@ TEST_F(DataReductionProxyNetworkDelegateTest, OnResolveProxyHandler) { |
// Without DataCompressionProxyCriticalBypass Finch trial set, the |
// BYPASS_DATA_REDUCTION_PROXY load flag should be ignored. |
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
- empty_proxy_retry_info, config(), |
- &result); |
+ empty_proxy_retry_info, config(), &result); |
EXPECT_FALSE(result.is_direct()); |
OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
- empty_proxy_retry_info, |
- config(), &other_proxy_info); |
+ empty_proxy_retry_info, config(), &other_proxy_info); |
EXPECT_FALSE(other_proxy_info.is_direct()); |
} |