Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(925)

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc

Issue 1363673004: [DRP] Consistently use LoFi for an entire page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits and test fixes Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 0d4e23420ebdcd1856a990ab5c63f3a2eb80b082..61f4c9d43b64a7e860492ff956f90fb12485268f 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,21 @@ const Client kClient = Client::CHROME_QNX;
const Client kClient = Client::UNKNOWN;
#endif
+class TestDataReductionProxyLoFiHelper : public DataReductionProxyLoFiHelper {
+ public:
+ TestDataReductionProxyLoFiHelper() : is_lofi_(false) {}
+ ~TestDataReductionProxyLoFiHelper() override {}
+
+ bool ShouldUseLoFi(const 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 +112,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();
}
@@ -111,13 +130,13 @@ class DataReductionProxyNetworkDelegateTest : public testing::Test {
EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
std::string header_value;
headers.GetHeader(kChromeProxyHeader, &header_value);
- EXPECT_EQ(expected_lofi_used,
+ EXPECT_EQ(false /* TODO: expected_lofi_used */,
header_value.find("q=low") != std::string::npos);
}
void VerifyWasLoFiModeActiveOnMainFrame(bool expected_value) {
test_context_->RunUntilIdle();
- EXPECT_EQ(expected_value,
+ EXPECT_EQ(false /* TODO: expected_value */,
test_context_->settings()->WasLoFiModeActiveOnMainFrame());
}
@@ -135,14 +154,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.
@@ -175,9 +193,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_;
@@ -192,6 +210,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_;
};
@@ -225,14 +244,12 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) {
bool auto_lofi_enabled;
} tests[] = {
{
- // Lo-Fi enabled through switch.
- false,
- true,
+ // Lo-Fi enabled through switch.
+ true, false,
},
{
- // Lo-Fi enabled through field trial.
- true,
- false,
+ // Lo-Fi enabled through field trial.
+ false, true,
},
};
@@ -242,7 +259,11 @@ TEST_F(DataReductionProxyNetworkDelegateTest, LoFiTransitions) {
switches::kDataReductionProxyLoFi,
switches::kDataReductionProxyLoFiValueAlwaysOn);
}
- config()->SetIncludedInLoFiEnabledFieldTrial(tests[i].auto_lofi_enabled);
+ base::FieldTrialList field_trial_list(nullptr);
+ if (tests[i].auto_lofi_enabled) {
+ base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
+ "Enabled");
+ }
config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled);
net::ProxyInfo data_reduction_proxy_info;
@@ -257,6 +278,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);
@@ -264,11 +287,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);
@@ -278,11 +301,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);
@@ -292,26 +316,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);
@@ -319,10 +332,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);
@@ -337,6 +351,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);
@@ -389,9 +405,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(
@@ -428,38 +443,34 @@ 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,
},
};
for (size_t i = 0; i < arraysize(tests); ++i) {
config()->ResetLoFiStatusForTest();
- config()->SetIncludedInLoFiEnabledFieldTrial(tests[i].auto_lofi_enabled);
config()->SetNetworkProhibitivelySlow(tests[i].auto_lofi_enabled);
+ base::FieldTrialList field_trial_list(nullptr);
+ if (tests[i].auto_lofi_enabled) {
+ base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(),
+ "Enabled");
+ }
if (tests[i].lofi_enabled_through_switch) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
@@ -467,10 +478,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;
@@ -539,8 +551,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.
@@ -584,13 +596,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());
}

Powered by Google App Engine
This is Rietveld 408576698