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

Unified Diff: components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc

Issue 1463583003: Move adding Lo-Fi directives from DRPRequestOptions to ContentLoFiDecider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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/content/browser/content_lofi_decider_unittest.cc
diff --git a/components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc b/components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc
index b8d14c05a994f2e594cdc216b400a47e43cf2917..b7273b549e9d9257c291d72d8243b59c532031c5 100644
--- a/components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc
+++ b/components/data_reduction_proxy/content/browser/content_lofi_decider_unittest.cc
@@ -123,7 +123,17 @@ class ContentLoFiDeciderTest : public testing::Test {
std::string header_value;
headers.GetHeader(kChromeProxyHeader, &header_value);
EXPECT_EQ(expected_lofi_used,
- header_value.find("q=low") != std::string::npos);
+ header_value.find(kLoFiHeader) != std::string::npos);
+ }
+
+ static void VerifyLoFiExperimentHeader(
+ bool expected_lofi_experiment_used,
+ const net::HttpRequestHeaders& headers) {
+ EXPECT_TRUE(headers.HasHeader(kChromeProxyHeader));
+ std::string header_value;
+ headers.GetHeader(kChromeProxyHeader, &header_value);
+ EXPECT_EQ(expected_lofi_experiment_used,
+ header_value.find(kLoFiExperimentHeader) != std::string::npos);
}
protected:
@@ -222,4 +232,125 @@ TEST_F(ContentLoFiDeciderTest, LoFiControlFieldTrial) {
}
}
+TEST_F(ContentLoFiDeciderTest, 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;
+
+ 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);
+
+ scoped_ptr<net::URLRequest> request =
+ CreateRequest(tests[i].network_prohibitively_slow);
+ net::HttpRequestHeaders headers;
+ NotifyBeforeSendProxyHeaders(&headers, request.get());
+
+ VerifyLoFiHeader(expect_lofi_header, headers);
+ VerifyLoFiExperimentHeader(expect_lofi_experiment_header, headers);
+ }
+}
+
+TEST_F(ContentLoFiDeciderTest, 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 (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);
+
+ scoped_ptr<net::URLRequest> request =
+ CreateRequest(tests[i].network_prohibitively_slow);
+ net::HttpRequestHeaders headers;
+ NotifyBeforeSendProxyHeaders(&headers, request.get());
+
+ VerifyLoFiHeader(expect_lofi_header, headers);
+ }
+}
+
} // namespace data_reduction_roxy

Powered by Google App Engine
This is Rietveld 408576698