Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc |
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc |
index 511f8d993e53832865d5c97d8a1d40ca636dd02e..7b1196cbe68c0cd5cb730424e558af350cefe4c9 100644 |
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc |
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options_unittest.cc |
@@ -10,6 +10,7 @@ |
#include "base/command_line.h" |
#include "base/md5.h" |
#include "base/memory/scoped_ptr.h" |
+#include "base/metrics/field_trial.h" |
#include "base/strings/string16.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/time/time.h" |
@@ -154,11 +155,10 @@ class DataReductionProxyRequestOptionsTest : public testing::Test { |
request_options_->Init(); |
} |
- void CreateRequest(int load_flags) { |
+ void CreateRequest() { |
net::URLRequestContext* context = |
test_context_->request_context_getter()->GetURLRequestContext(); |
request_ = context->CreateRequest(GURL(), net::DEFAULT_PRIORITY, nullptr); |
- request_->SetLoadFlags(load_flags); |
} |
TestDataReductionProxyParams* params() { |
@@ -170,7 +170,8 @@ class DataReductionProxyRequestOptionsTest : public testing::Test { |
} |
void VerifyExpectedHeader(const std::string& proxy_uri, |
- const std::string& expected_header) { |
+ const std::string& expected_header, |
+ bool is_lofi_on) { |
test_context_->RunUntilIdle(); |
net::HttpRequestHeaders headers; |
request_options_->MaybeAddRequestHeader( |
@@ -178,7 +179,7 @@ class DataReductionProxyRequestOptionsTest : public testing::Test { |
proxy_uri.empty() ? net::ProxyServer() |
: net::ProxyServer::FromURI( |
proxy_uri, net::ProxyServer::SCHEME_HTTP), |
- &headers); |
+ &headers, is_lofi_on); |
if (expected_header.empty()) { |
EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader)); |
return; |
@@ -225,16 +226,16 @@ TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationOnIOThread) { |
request_options()->SetKeyOnIO(kTestKey2); |
// Don't write headers if the proxy is invalid. |
- VerifyExpectedHeader(std::string(), std::string()); |
+ VerifyExpectedHeader(std::string(), std::string(), false); |
// Don't write headers with a valid proxy, that's not a data reduction proxy. |
- VerifyExpectedHeader(kOtherProxy, std::string()); |
+ VerifyExpectedHeader(kOtherProxy, std::string(), false); |
// Don't write headers with a valid data reduction ssl proxy. |
- VerifyExpectedHeader(params()->DefaultSSLOrigin(), std::string()); |
+ VerifyExpectedHeader(params()->DefaultSSLOrigin(), std::string(), false); |
// Write headers with a valid data reduction proxy. |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
// Write headers with a valid data reduction ssl proxy when one is expected. |
net::HttpRequestHeaders ssl_headers; |
@@ -250,11 +251,11 @@ TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationOnIOThread) { |
// Fast forward 24 hours. The header should be the same. |
request_options()->set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60)); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
// Fast forward one more second. The header should be new. |
request_options()->set_offset(base::TimeDelta::FromSeconds(24 * 60 * 60 + 1)); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header2); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header2, false); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationIgnoresEmptyKey) { |
@@ -264,12 +265,12 @@ TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationIgnoresEmptyKey) { |
std::string(), std::vector<std::string>(), |
&expected_header); |
CreateRequestOptions(kVersion); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
// Now set an empty key. The auth handler should ignore that, and the key |
// remains |kTestKey|. |
request_options()->SetKeyOnIO(std::string()); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationBogusVersion) { |
@@ -282,7 +283,7 @@ TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationBogusVersion) { |
// Now set a key. |
request_options()->SetKeyOnIO(kTestKey2); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, LoFiOnThroughCommandLineSwitch) { |
@@ -291,10 +292,11 @@ TEST_F(DataReductionProxyRequestOptionsTest, LoFiOnThroughCommandLineSwitch) { |
SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
kClientStr, std::string(), std::string(), std::string(), |
std::vector<std::string>(), &expected_header); |
- |
- test_context_->config()->UpdateLoFiStatusOnMainFrameRequest(false, nullptr); |
+ CreateRequest(); |
CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader( |
+ params()->DefaultOrigin(), expected_header, |
+ test_context_->config()->ShouldTurnOnLoFiOnMainFrameRequest(nullptr)); |
test_context_->config()->ResetLoFiStatusForTest(); |
// Add the LoFi command line switch. |
@@ -306,9 +308,10 @@ TEST_F(DataReductionProxyRequestOptionsTest, LoFiOnThroughCommandLineSwitch) { |
kClientStr, std::string(), std::string(), "low", |
std::vector<std::string>(), &expected_header); |
- test_context_->config()->UpdateLoFiStatusOnMainFrameRequest(false, nullptr); |
CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader( |
+ params()->DefaultOrigin(), expected_header, |
+ test_context_->config()->ShouldTurnOnLoFiOnMainFrameRequest(nullptr)); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, AutoLoFi) { |
@@ -350,16 +353,20 @@ TEST_F(DataReductionProxyRequestOptionsTest, AutoLoFi) { |
std::string(), "low", std::vector<std::string>(), |
&expected_header); |
} |
- test_context_->config()->SetIncludedInLoFiEnabledFieldTrial( |
- tests[i].auto_lofi_enabled_group); |
+ base::FieldTrialList field_trial_list(nullptr); |
+ if (tests[i].auto_lofi_enabled_group) { |
+ base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
+ "Enabled"); |
+ } |
test_context_->config()->SetNetworkProhibitivelySlow( |
tests[i].network_prohibitively_slow); |
- // Force update Lo-Fi status. |
- test_context_->config()->UpdateLoFiStatusOnMainFrameRequest(false, nullptr); |
+ CreateRequest(); |
CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader( |
+ params()->DefaultOrigin(), expected_header, |
+ test_context_->config()->ShouldTurnOnLoFiOnMainFrameRequest(nullptr)); |
} |
} |
@@ -427,17 +434,21 @@ TEST_F(DataReductionProxyRequestOptionsTest, SlowConnectionsFlag) { |
switches::kDataReductionProxyLoFiValueSlowConnectionsOnly); |
} |
- test_context_->config()->SetIncludedInLoFiEnabledFieldTrial( |
- tests[i].auto_lofi_enabled_group); |
+ base::FieldTrialList field_trial_list(nullptr); |
+ if (tests[i].auto_lofi_enabled_group) { |
+ base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
+ "Enabled"); |
+ } |
test_context_->config()->SetNetworkProhibitivelySlow( |
tests[i].network_prohibitively_slow); |
- // Force update Lo-Fi status. |
- test_context_->config()->UpdateLoFiStatusOnMainFrameRequest(false, nullptr); |
+ CreateRequest(); |
CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader( |
+ params()->DefaultOrigin(), expected_header, |
+ test_context_->config()->ShouldTurnOnLoFiOnMainFrameRequest(nullptr)); |
} |
} |
@@ -449,7 +460,7 @@ TEST_F(DataReductionProxyRequestOptionsTest, SecureSession) { |
CreateRequestOptions(kBogusVersion); |
request_options()->SetSecureSession(kSecureSession); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, ParseExperiments) { |
@@ -465,7 +476,7 @@ TEST_F(DataReductionProxyRequestOptionsTest, ParseExperiments) { |
expected_experiments, &expected_header); |
CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, ParseLocalSessionKey) { |