| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h
" | 5 #include "components/data_reduction_proxy/content/browser/content_lofi_decider.h
" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 static void VerifyLoFiPreviewHeader(bool expected_lofi_preview_used, | 132 static void VerifyLoFiPreviewHeader(bool expected_lofi_preview_used, |
| 133 const net::HttpRequestHeaders& headers) { | 133 const net::HttpRequestHeaders& headers) { |
| 134 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); | 134 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); |
| 135 std::string header_value; | 135 std::string header_value; |
| 136 headers.GetHeader(chrome_proxy_header(), &header_value); | 136 headers.GetHeader(chrome_proxy_header(), &header_value); |
| 137 EXPECT_EQ(expected_lofi_preview_used, | 137 EXPECT_EQ(expected_lofi_preview_used, |
| 138 header_value.find(chrome_proxy_lo_fi_preview_directive()) != | 138 header_value.find(chrome_proxy_lo_fi_preview_directive()) != |
| 139 std::string::npos); | 139 std::string::npos); |
| 140 } | 140 } |
| 141 | 141 |
| 142 static void VerifyLoFiExperimentHeader( | |
| 143 bool expected_lofi_experiment_used, | |
| 144 const net::HttpRequestHeaders& headers) { | |
| 145 EXPECT_TRUE(headers.HasHeader(chrome_proxy_header())); | |
| 146 std::string header_value; | |
| 147 headers.GetHeader(chrome_proxy_header(), &header_value); | |
| 148 EXPECT_EQ(expected_lofi_experiment_used, | |
| 149 header_value.find(chrome_proxy_lo_fi_experiment_directive()) != | |
| 150 std::string::npos); | |
| 151 } | |
| 152 | |
| 153 protected: | 142 protected: |
| 154 base::MessageLoopForIO message_loop_; | 143 base::MessageLoopForIO message_loop_; |
| 155 net::MockClientSocketFactory mock_socket_factory_; | 144 net::MockClientSocketFactory mock_socket_factory_; |
| 156 net::TestURLRequestContext context_; | 145 net::TestURLRequestContext context_; |
| 157 net::TestDelegate delegate_; | 146 net::TestDelegate delegate_; |
| 158 scoped_ptr<DataReductionProxyTestContext> test_context_; | 147 scoped_ptr<DataReductionProxyTestContext> test_context_; |
| 159 scoped_ptr<DataReductionProxyNetworkDelegate> | 148 scoped_ptr<DataReductionProxyNetworkDelegate> |
| 160 data_reduction_proxy_network_delegate_; | 149 data_reduction_proxy_network_delegate_; |
| 161 }; | 150 }; |
| 162 | 151 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // experiment. | 299 // experiment. |
| 311 {false, true, false}, | 300 {false, true, false}, |
| 312 }; | 301 }; |
| 313 | 302 |
| 314 for (size_t i = 0; i < arraysize(tests); ++i) { | 303 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 315 test_context_->config()->ResetLoFiStatusForTest(); | 304 test_context_->config()->ResetLoFiStatusForTest(); |
| 316 // Lo-Fi header is expected only if session is part of Lo-Fi enabled field | 305 // Lo-Fi header is expected only if session is part of Lo-Fi enabled field |
| 317 // trial and network is prohibitively slow. | 306 // trial and network is prohibitively slow. |
| 318 bool expect_lofi_header = | 307 bool expect_lofi_header = |
| 319 tests[i].auto_lofi_enabled_group && tests[i].network_prohibitively_slow; | 308 tests[i].auto_lofi_enabled_group && tests[i].network_prohibitively_slow; |
| 320 bool expect_lofi_experiment_header = | |
| 321 tests[i].auto_lofi_control_group && tests[i].network_prohibitively_slow; | |
| 322 | 309 |
| 323 base::FieldTrialList field_trial_list(nullptr); | 310 base::FieldTrialList field_trial_list(nullptr); |
| 324 if (tests[i].auto_lofi_enabled_group) { | 311 if (tests[i].auto_lofi_enabled_group) { |
| 325 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 312 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 326 "Enabled"); | 313 "Enabled"); |
| 327 } | 314 } |
| 328 | 315 |
| 329 if (tests[i].auto_lofi_control_group) { | 316 if (tests[i].auto_lofi_control_group) { |
| 330 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), | 317 base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
| 331 "Control"); | 318 "Control"); |
| 332 } | 319 } |
| 333 | 320 |
| 334 test_context_->config()->SetNetworkProhibitivelySlow( | 321 test_context_->config()->SetNetworkProhibitivelySlow( |
| 335 tests[i].network_prohibitively_slow); | 322 tests[i].network_prohibitively_slow); |
| 336 | 323 |
| 337 scoped_ptr<net::URLRequest> request = | 324 scoped_ptr<net::URLRequest> request = |
| 338 CreateRequest(tests[i].network_prohibitively_slow); | 325 CreateRequest(tests[i].network_prohibitively_slow); |
| 339 net::HttpRequestHeaders headers; | 326 net::HttpRequestHeaders headers; |
| 340 NotifyBeforeSendProxyHeaders(&headers, request.get()); | 327 NotifyBeforeSendProxyHeaders(&headers, request.get()); |
| 341 | 328 |
| 342 VerifyLoFiHeader(expect_lofi_header, headers); | 329 VerifyLoFiHeader(expect_lofi_header, headers); |
| 343 VerifyLoFiExperimentHeader(expect_lofi_experiment_header, headers); | |
| 344 } | 330 } |
| 345 } | 331 } |
| 346 | 332 |
| 347 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) { | 333 TEST_F(ContentLoFiDeciderTest, SlowConnectionsFlag) { |
| 348 const struct { | 334 const struct { |
| 349 bool slow_connections_flag_enabled; | 335 bool slow_connections_flag_enabled; |
| 350 bool network_prohibitively_slow; | 336 bool network_prohibitively_slow; |
| 351 bool auto_lofi_enabled_group; | 337 bool auto_lofi_enabled_group; |
| 352 | 338 |
| 353 } tests[] = { | 339 } tests[] = { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 scoped_ptr<net::URLRequest> request = | 374 scoped_ptr<net::URLRequest> request = |
| 389 CreateRequest(tests[i].network_prohibitively_slow); | 375 CreateRequest(tests[i].network_prohibitively_slow); |
| 390 net::HttpRequestHeaders headers; | 376 net::HttpRequestHeaders headers; |
| 391 NotifyBeforeSendProxyHeaders(&headers, request.get()); | 377 NotifyBeforeSendProxyHeaders(&headers, request.get()); |
| 392 | 378 |
| 393 VerifyLoFiHeader(expect_lofi_header, headers); | 379 VerifyLoFiHeader(expect_lofi_header, headers); |
| 394 } | 380 } |
| 395 } | 381 } |
| 396 | 382 |
| 397 } // namespace data_reduction_roxy | 383 } // namespace data_reduction_roxy |
| OLD | NEW |