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 cbc3b44faf91b175d1374c30b45d707b71ddaa6a..3b0cd6c318a7bdbb131fc9cc9fb93b1579add20a 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 |
@@ -93,7 +93,6 @@ void SetHeaderExpectations(const std::string& session, |
const std::string& client, |
const std::string& build, |
const std::string& patch, |
- const std::string& lofi, |
const std::vector<std::string> experiments, |
std::string* expected_header) { |
std::vector<std::string> expected_options; |
@@ -121,10 +120,6 @@ void SetHeaderExpectations(const std::string& session, |
expected_options.push_back( |
std::string(kPatchNumberHeaderOption) + "=" + patch); |
} |
- if (!lofi.empty()) { |
- expected_options.push_back( |
- std::string(kLoFiHeaderOption) + "=" + lofi); |
- } |
for (const auto& experiment : experiments) { |
expected_options.push_back( |
std::string(kExperimentsOption) + "=" + experiment); |
@@ -172,8 +167,7 @@ class DataReductionProxyRequestOptionsTest : public testing::Test { |
} |
void VerifyExpectedHeader(const std::string& proxy_uri, |
- const std::string& expected_header, |
- bool should_request_lofi_resource) { |
+ const std::string& expected_header) { |
test_context_->RunUntilIdle(); |
net::HttpRequestHeaders headers; |
request_options_->MaybeAddRequestHeader( |
@@ -181,7 +175,7 @@ class DataReductionProxyRequestOptionsTest : public testing::Test { |
proxy_uri.empty() ? net::ProxyServer() |
: net::ProxyServer::FromURI( |
proxy_uri, net::ProxyServer::SCHEME_HTTP), |
- &headers, should_request_lofi_resource); |
+ &headers); |
if (expected_header.empty()) { |
EXPECT_FALSE(headers.HasHeader(kChromeProxyHeader)); |
return; |
@@ -211,15 +205,13 @@ TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationOnIOThread) { |
std::string expected_header; |
SetHeaderExpectations(kExpectedSession2, kExpectedCredentials2, std::string(), |
kClientStr, kExpectedBuild, kExpectedPatch, |
- std::string(), std::vector<std::string>(), |
- &expected_header); |
+ std::vector<std::string>(), &expected_header); |
std::string expected_header2; |
SetHeaderExpectations("86401-1633771873-1633771873-1633771873", |
"d7c1c34ef6b90303b01c48a6c1db6419", std::string(), |
kClientStr, kExpectedBuild, kExpectedPatch, |
- std::string(), std::vector<std::string>(), |
- &expected_header2); |
+ std::vector<std::string>(), &expected_header2); |
CreateRequestOptions(kVersion); |
test_context_->RunUntilIdle(); |
@@ -228,16 +220,16 @@ TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationOnIOThread) { |
request_options()->SetKeyOnIO(kTestKey2); |
// Don't write headers if the proxy is invalid. |
- VerifyExpectedHeader(std::string(), std::string(), false); |
+ VerifyExpectedHeader(std::string(), std::string()); |
// Don't write headers with a valid proxy, that's not a data reduction proxy. |
- VerifyExpectedHeader(kOtherProxy, std::string(), false); |
+ VerifyExpectedHeader(kOtherProxy, std::string()); |
// Don't write headers with a valid data reduction ssl proxy. |
- VerifyExpectedHeader(params()->DefaultSSLOrigin(), std::string(), false); |
+ VerifyExpectedHeader(params()->DefaultSSLOrigin(), std::string()); |
// Write headers with a valid data reduction proxy. |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
// Write headers with a valid data reduction ssl proxy when one is expected. |
net::HttpRequestHeaders ssl_headers; |
@@ -253,227 +245,49 @@ 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, false); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
// 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, false); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header2); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationIgnoresEmptyKey) { |
std::string expected_header; |
SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
kClientStr, kExpectedBuild, kExpectedPatch, |
- std::string(), std::vector<std::string>(), |
- &expected_header); |
+ std::vector<std::string>(), &expected_header); |
CreateRequestOptions(kVersion); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
// 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, false); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, AuthorizationBogusVersion) { |
std::string expected_header; |
SetHeaderExpectations(kExpectedSession2, kExpectedCredentials2, std::string(), |
- kClientStr, std::string(), std::string(), std::string(), |
+ kClientStr, std::string(), std::string(), |
std::vector<std::string>(), &expected_header); |
CreateRequestOptions(kBogusVersion); |
// Now set a key. |
request_options()->SetKeyOnIO(kTestKey2); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
-} |
- |
-TEST_F(DataReductionProxyRequestOptionsTest, LoFiOnThroughCommandLineSwitch) { |
- test_context_->config()->ResetLoFiStatusForTest(); |
- std::string expected_header; |
- SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
- kClientStr, std::string(), std::string(), std::string(), |
- std::vector<std::string>(), &expected_header); |
- CreateRequest(); |
- CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader( |
- params()->DefaultOrigin(), expected_header, |
- test_context_->config()->ShouldEnableLoFiMode(request())); |
- |
- test_context_->config()->ResetLoFiStatusForTest(); |
- // Add the LoFi command line switch. |
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
- switches::kDataReductionProxyLoFi, |
- switches::kDataReductionProxyLoFiValueAlwaysOn); |
- |
- SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
- kClientStr, std::string(), std::string(), "low", |
- std::vector<std::string>(), &expected_header); |
- |
- CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader( |
- params()->DefaultOrigin(), expected_header, |
- test_context_->config()->ShouldEnableLoFiMode(request())); |
-} |
- |
-TEST_F(DataReductionProxyRequestOptionsTest, AutoLoFi) { |
- const struct { |
- bool auto_lofi_enabled_group; |
- bool auto_lofi_control_group; |
- bool network_prohibitively_slow; |
- } tests[] = { |
- {false, false, false}, |
- {false, false, true}, |
- {true, false, false}, |
- {true, false, true}, |
- {false, true, false}, |
- {false, true, true}, |
- // Repeat this test data to simulate user moving out of Lo-Fi control |
- // experiment. |
- {false, true, false}, |
- }; |
- |
- for (size_t i = 0; i < arraysize(tests); ++i) { |
- test_context_->config()->ResetLoFiStatusForTest(); |
- // Lo-Fi header is expected only if session is part of Lo-Fi enabled field |
- // trial and network is prohibitively slow. |
- bool expect_lofi_header = |
- tests[i].auto_lofi_enabled_group && tests[i].network_prohibitively_slow; |
- bool expect_lofi_experiment_header = |
- tests[i].auto_lofi_control_group && tests[i].network_prohibitively_slow; |
- |
- std::string expected_header; |
- if (!expect_lofi_header) { |
- SetHeaderExpectations(kExpectedSession, kExpectedCredentials, |
- std::string(), kClientStr, std::string(), |
- std::string(), std::string(), |
- std::vector<std::string>(), &expected_header); |
- } else { |
- SetHeaderExpectations(kExpectedSession, kExpectedCredentials, |
- std::string(), kClientStr, std::string(), |
- std::string(), "low", std::vector<std::string>(), |
- &expected_header); |
- } |
- |
- if (expect_lofi_experiment_header) { |
- expected_header = expected_header.append(", exp="); |
- expected_header = expected_header.append(kLoFiExperimentID); |
- } |
- |
- base::FieldTrialList field_trial_list(nullptr); |
- if (tests[i].auto_lofi_enabled_group) { |
- base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
- "Enabled"); |
- } |
- |
- if (tests[i].auto_lofi_control_group) { |
- base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
- "Control"); |
- } |
- |
- test_context_->config()->SetNetworkProhibitivelySlow( |
- tests[i].network_prohibitively_slow); |
- |
- CreateRequest(); |
- |
- CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader( |
- params()->DefaultOrigin(), expected_header, |
- test_context_->config()->ShouldEnableLoFiMode(request())); |
- } |
-} |
- |
-TEST_F(DataReductionProxyRequestOptionsTest, SlowConnectionsFlag) { |
- const struct { |
- bool slow_connections_flag_enabled; |
- bool network_prohibitively_slow; |
- bool auto_lofi_enabled_group; |
- |
- } tests[] = { |
- { |
- false, false, false, |
- }, |
- { |
- false, true, false, |
- }, |
- { |
- true, false, false, |
- }, |
- { |
- true, true, false, |
- }, |
- { |
- false, false, true, |
- }, |
- { |
- false, true, true, |
- }, |
- { |
- true, false, true, |
- }, |
- { |
- true, true, true, |
- }, |
- }; |
- |
- for (size_t i = 0; i < arraysize(tests); ++i) { |
- test_context_->config()->ResetLoFiStatusForTest(); |
- // For the purpose of this test, Lo-Fi header is expected only if LoFi Slow |
- // Connection Flag is enabled or session is part of Lo-Fi enabled field |
- // trial. For both cases, an additional condition is that network must be |
- // prohibitively slow. |
- bool expect_lofi_header = (tests[i].slow_connections_flag_enabled && |
- tests[i].network_prohibitively_slow) || |
- (!tests[i].slow_connections_flag_enabled && |
- tests[i].auto_lofi_enabled_group && |
- tests[i].network_prohibitively_slow); |
- |
- std::string expected_header; |
- if (!expect_lofi_header) { |
- SetHeaderExpectations(kExpectedSession, kExpectedCredentials, |
- std::string(), kClientStr, std::string(), |
- std::string(), std::string(), |
- std::vector<std::string>(), &expected_header); |
- } else { |
- SetHeaderExpectations(kExpectedSession, kExpectedCredentials, |
- std::string(), kClientStr, std::string(), |
- std::string(), "low", std::vector<std::string>(), |
- &expected_header); |
- } |
- |
- if (tests[i].slow_connections_flag_enabled) { |
- base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
- switches::kDataReductionProxyLoFi, |
- switches::kDataReductionProxyLoFiValueSlowConnectionsOnly); |
- } |
- |
- 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); |
- |
- CreateRequest(); |
- |
- CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader( |
- params()->DefaultOrigin(), expected_header, |
- test_context_->config()->ShouldEnableLoFiMode(request())); |
- } |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, SecureSession) { |
std::string expected_header; |
SetHeaderExpectations(std::string(), std::string(), kSecureSession, |
- kClientStr, std::string(), std::string(), std::string(), |
+ kClientStr, std::string(), std::string(), |
std::vector<std::string>(), &expected_header); |
CreateRequestOptions(kBogusVersion); |
request_options()->SetSecureSession(kSecureSession); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, ParseExperiments) { |
@@ -485,11 +299,11 @@ TEST_F(DataReductionProxyRequestOptionsTest, ParseExperiments) { |
expected_experiments.push_back("\"foo,bar\""); |
std::string expected_header; |
SetHeaderExpectations(kExpectedSession, kExpectedCredentials, std::string(), |
- kClientStr, std::string(), std::string(), std::string(), |
+ kClientStr, std::string(), std::string(), |
expected_experiments, &expected_header); |
CreateRequestOptions(kBogusVersion); |
- VerifyExpectedHeader(params()->DefaultOrigin(), expected_header, false); |
+ VerifyExpectedHeader(params()->DefaultOrigin(), expected_header); |
} |
TEST_F(DataReductionProxyRequestOptionsTest, ParseLocalSessionKey) { |