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

Side by Side Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_network_delegate_unittest.cc

Issue 2802463002: Adds feature flag for chrome-proxy-ect header (default off) (Closed)
Patch Set: Tweaked the name of the Feature to be more Feature like than Switch like. Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/core/browser/data_reduction_proxy_netw ork_delegate.h" 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_netw ork_delegate.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector>
13 14
14 #include "base/command_line.h" 15 #include "base/command_line.h"
15 #include "base/files/file_util.h" 16 #include "base/files/file_util.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
19 #include "base/metrics/field_trial.h" 20 #include "base/metrics/field_trial.h"
20 #include "base/numerics/safe_conversions.h" 21 #include "base/numerics/safe_conversions.h"
21 #include "base/path_service.h" 22 #include "base/path_service.h"
22 #include "base/run_loop.h" 23 #include "base/run_loop.h"
23 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
25 #include "base/test/histogram_tester.h" 26 #include "base/test/histogram_tester.h"
26 #include "base/test/mock_entropy_provider.h" 27 #include "base/test/mock_entropy_provider.h"
28 #include "base/test/scoped_feature_list.h"
27 #include "base/time/time.h" 29 #include "base/time/time.h"
28 #include "base/values.h" 30 #include "base/values.h"
29 #include "build/build_config.h" 31 #include "build/build_config.h"
30 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h" 32 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf ig_test_utils.h"
31 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h" 33 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_data .h"
32 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.h" 34 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_metr ics.h"
33 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h" 35 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_requ est_options.h"
34 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h" 36 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test _utils.h"
37 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_featu res.h"
35 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h" 38 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs.h"
36 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h" 39 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade rs_test_utils.h"
37 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h" 40 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param s_test_utils.h"
38 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h" 41 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_ names.h"
39 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve r.h" 42 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve r.h"
40 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h" 43 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc hes.h"
41 #include "components/data_reduction_proxy/core/common/lofi_decider.h" 44 #include "components/data_reduction_proxy/core/common/lofi_decider.h"
42 #include "components/data_reduction_proxy/proto/client_config.pb.h" 45 #include "components/data_reduction_proxy/proto/client_config.pb.h"
43 #include "net/base/host_port_pair.h" 46 #include "net/base/host_port_pair.h"
44 #include "net/base/load_flags.h" 47 #include "net/base/load_flags.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 lofi_ui_service_ = lofi_ui_service.get(); 224 lofi_ui_service_ = lofi_ui_service.get();
222 test_context_->io_data()->set_lofi_ui_service(std::move(lofi_ui_service)); 225 test_context_->io_data()->set_lofi_ui_service(std::move(lofi_ui_service));
223 226
224 context_.set_enable_brotli(enable_brotli_globally); 227 context_.set_enable_brotli(enable_brotli_globally);
225 context_.set_network_quality_estimator(&test_network_quality_estimator_); 228 context_.set_network_quality_estimator(&test_network_quality_estimator_);
226 context_.Init(); 229 context_.Init();
227 230
228 test_context_->EnableDataReductionProxyWithSecureProxyCheckSuccess(); 231 test_context_->EnableDataReductionProxyWithSecureProxyCheckSuccess();
229 } 232 }
230 233
234 void EnableECTHeader() {
235 feature_list_.InitWithFeatures(
236 {data_reduction_proxy::features::kDataReductionProxyECTHeader}, {});
237 }
238
231 // Build the sockets by adding appropriate mock data for 239 // Build the sockets by adding appropriate mock data for
232 // |effective_connection_types.size()| number of requests. Data for 240 // |effective_connection_types.size()| number of requests. Data for
233 // chrome-Proxy-ect header is added to the mock data if |expect_ect_header| 241 // chrome-Proxy-ect header is added to the mock data if |expect_ect_header|
234 // is true. |reads_list|, |mock_writes| and |writes_list| should be empty, and 242 // is true. |reads_list|, |mock_writes| and |writes_list| should be empty, and
235 // are owned by the caller. 243 // are owned by the caller.
236 void BuildSocket(const std::string& response_headers, 244 void BuildSocket(const std::string& response_headers,
237 const std::string& response_body, 245 const std::string& response_body,
238 bool expect_ect_header, 246 bool expect_ect_header,
239 const std::vector<net::EffectiveConnectionType>& 247 const std::vector<net::EffectiveConnectionType>&
240 effective_connection_types, 248 effective_connection_types,
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 .append( 426 .append(
419 " HTTP/1.1\r\n" 427 " HTTP/1.1\r\n"
420 "Host: ") 428 "Host: ")
421 .append(host) 429 .append(host)
422 .append( 430 .append(
423 "\r\n" 431 "\r\n"
424 "Proxy-Connection: keep-alive\r\n" 432 "Proxy-Connection: keep-alive\r\n"
425 "User-Agent:\r\n"); 433 "User-Agent:\r\n");
426 434
427 std::string accept_language_header("Accept-Language: en-us,fr\r\n"); 435 std::string accept_language_header("Accept-Language: en-us,fr\r\n");
428 std::string ect_header = "chrome-proxy-ect: " + 436
429 std::string(net::GetNameForEffectiveConnectionType( 437 std::string ect_header;
430 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN)) + 438 if (data_reduction_proxy::features::
431 "\r\n"; 439 IsDataReductionProxyECTHeaderEnabled()) {
440 ect_header = "chrome-proxy-ect: " +
441 std::string(net::GetNameForEffectiveConnectionType(
442 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN)) +
443 "\r\n";
444 }
432 445
433 // Brotli is included in accept-encoding header only if the request went 446 // Brotli is included in accept-encoding header only if the request went
434 // to the network (i.e., it was not a cached response), and if data 447 // to the network (i.e., it was not a cached response), and if data
435 // reduction ptroxy network delegate added Brotli to the header. 448 // reduction ptroxy network delegate added Brotli to the header.
436 std::string accept_encoding_header = 449 std::string accept_encoding_header =
437 expect_brotli && !expect_cached 450 expect_brotli && !expect_cached
438 ? "Accept-Encoding: gzip, deflate, br\r\n" 451 ? "Accept-Encoding: gzip, deflate, br\r\n"
439 : "Accept-Encoding: gzip, deflate\r\n"; 452 : "Accept-Encoding: gzip, deflate\r\n";
440 453
441 std::string suffix_headers = 454 std::string suffix_headers =
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 net::TestNetworkQualityEstimator* test_network_quality_estimator() { 613 net::TestNetworkQualityEstimator* test_network_quality_estimator() {
601 return &test_network_quality_estimator_; 614 return &test_network_quality_estimator_;
602 } 615 }
603 616
604 private: 617 private:
605 base::MessageLoopForIO message_loop_; 618 base::MessageLoopForIO message_loop_;
606 net::MockClientSocketFactory mock_socket_factory_; 619 net::MockClientSocketFactory mock_socket_factory_;
607 std::unique_ptr<net::ProxyService> proxy_service_; 620 std::unique_ptr<net::ProxyService> proxy_service_;
608 net::TestURLRequestContext context_; 621 net::TestURLRequestContext context_;
609 net::URLRequestContextStorage context_storage_; 622 net::URLRequestContextStorage context_storage_;
623 base::test::ScopedFeatureList feature_list_;
610 624
611 TestLoFiDecider* lofi_decider_; 625 TestLoFiDecider* lofi_decider_;
612 TestLoFiUIService* lofi_ui_service_; 626 TestLoFiUIService* lofi_ui_service_;
613 std::unique_ptr<DataReductionProxyTestContext> test_context_; 627 std::unique_ptr<DataReductionProxyTestContext> test_context_;
614 net::TestNetworkQualityEstimator test_network_quality_estimator_; 628 net::TestNetworkQualityEstimator test_network_quality_estimator_;
615 629
616 net::SSLSocketDataProvider ssl_socket_data_provider_; 630 net::SSLSocketDataProvider ssl_socket_data_provider_;
617 631
618 std::unique_ptr<net::StaticSocketDataProvider> socket_; 632 std::unique_ptr<net::StaticSocketDataProvider> socket_;
619 633
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 1298
1285 FetchURLRequestAndVerifyBrotli(nullptr, response_headers, false, true); 1299 FetchURLRequestAndVerifyBrotli(nullptr, response_headers, false, true);
1286 FetchURLRequestAndVerifyBrotli(nullptr, response_headers, true, true); 1300 FetchURLRequestAndVerifyBrotli(nullptr, response_headers, true, true);
1287 } 1301 }
1288 1302
1289 // Test that effective connection type is correctly added to the request 1303 // Test that effective connection type is correctly added to the request
1290 // headers when it is enabled using field trial. The server is varying on the 1304 // headers when it is enabled using field trial. The server is varying on the
1291 // effective connection type (ECT). 1305 // effective connection type (ECT).
1292 TEST_F(DataReductionProxyNetworkDelegateTest, ECTHeaderEnabledWithVary) { 1306 TEST_F(DataReductionProxyNetworkDelegateTest, ECTHeaderEnabledWithVary) {
1293 Init(true /* use_secure_proxy */, false /* enable_brotli_globally */); 1307 Init(true /* use_secure_proxy */, false /* enable_brotli_globally */);
1308 EnableECTHeader();
1294 1309
1295 std::string response_headers = 1310 std::string response_headers =
1296 "HTTP/1.1 200 OK\r\n" 1311 "HTTP/1.1 200 OK\r\n"
1297 "Content-Length: 140\r\n" 1312 "Content-Length: 140\r\n"
1298 "Via: 1.1 Chrome-Compression-Proxy\r\n" 1313 "Via: 1.1 Chrome-Compression-Proxy\r\n"
1299 "Cache-Control: max-age=1200\r\n" 1314 "Cache-Control: max-age=1200\r\n"
1300 "Vary: chrome-proxy-ect\r\n" 1315 "Vary: chrome-proxy-ect\r\n"
1301 "x-original-content-length: 200\r\n\r\n"; 1316 "x-original-content-length: 200\r\n\r\n";
1302 1317
1303 int response_body_size = 140; 1318 int response_body_size = 140;
1304 std::string response_body(base::checked_cast<size_t>(response_body_size), 1319 std::string response_body(base::checked_cast<size_t>(response_body_size),
1305 ' '); 1320 ' ');
1306 1321
1307 std::vector<net::MockRead> reads_list; 1322 std::vector<net::MockRead> reads_list;
1308 std::vector<std::string> mock_writes; 1323 std::vector<std::string> mock_writes;
1309 std::vector<net::MockWrite> writes_list; 1324 std::vector<net::MockWrite> writes_list;
1310 1325
1311 std::vector<net::EffectiveConnectionType> effective_connection_types; 1326 std::vector<net::EffectiveConnectionType> effective_connection_types;
1312 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); 1327 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1313 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_2G); 1328 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_2G);
1314 1329
1315 BuildSocket(response_headers, response_body, true, effective_connection_types, 1330 BuildSocket(response_headers, response_body, true /* expect_ect_header */,
1316 &reads_list, &mock_writes, &writes_list); 1331 effective_connection_types, &reads_list, &mock_writes,
1332 &writes_list);
1317 1333
1318 // Add 2 socket providers since 2 requests in this test are fetched from the 1334 // Add 2 socket providers since 2 requests in this test are fetched from the
1319 // network. 1335 // network.
1320 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, false); 1336 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, false);
1321 1337
1322 // When the ECT is set to the same value, fetching the same resource should 1338 // When the ECT is set to the same value, fetching the same resource should
1323 // result in a cache hit. 1339 // result in a cache hit.
1324 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); 1340 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true);
1325 1341
1326 // When the ECT is set to a different value, the response should not be 1342 // When the ECT is set to a different value, the response should not be
1327 // served from the cache. 1343 // served from the cache.
1328 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, false); 1344 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, false);
1329 } 1345 }
1330 1346
1331 // Test that effective connection type is correctly added to the request 1347 // Test that effective connection type is correctly added to the request
1332 // headers when it is enabled using field trial. The server is not varying on 1348 // headers when it is enabled using field trial. The server is not varying on
1333 // the effective connection type (ECT). 1349 // the effective connection type (ECT).
1334 TEST_F(DataReductionProxyNetworkDelegateTest, ECTHeaderEnabledWithoutVary) { 1350 TEST_F(DataReductionProxyNetworkDelegateTest, ECTHeaderEnabledWithoutVary) {
1335 Init(true /* use_secure_proxy */, false /* enable_brotli_globally */); 1351 Init(true /* use_secure_proxy */, false /* enable_brotli_globally */);
1352 EnableECTHeader();
1336 1353
1337 std::string response_headers = 1354 std::string response_headers =
1338 "HTTP/1.1 200 OK\r\n" 1355 "HTTP/1.1 200 OK\r\n"
1339 "Content-Length: 140\r\n" 1356 "Content-Length: 140\r\n"
1340 "Via: 1.1 Chrome-Compression-Proxy\r\n" 1357 "Via: 1.1 Chrome-Compression-Proxy\r\n"
1341 "Cache-Control: max-age=1200\r\n" 1358 "Cache-Control: max-age=1200\r\n"
1342 "x-original-content-length: 200\r\n\r\n"; 1359 "x-original-content-length: 200\r\n\r\n";
1343 1360
1344 int response_body_size = 140; 1361 int response_body_size = 140;
1345 std::string response_body(base::checked_cast<size_t>(response_body_size), 1362 std::string response_body(base::checked_cast<size_t>(response_body_size),
1346 ' '); 1363 ' ');
1347 1364
1348 std::vector<net::MockRead> reads_list; 1365 std::vector<net::MockRead> reads_list;
1349 std::vector<std::string> mock_writes; 1366 std::vector<std::string> mock_writes;
1350 std::vector<net::MockWrite> writes_list; 1367 std::vector<net::MockWrite> writes_list;
1351 1368
1352 std::vector<net::EffectiveConnectionType> effective_connection_types; 1369 std::vector<net::EffectiveConnectionType> effective_connection_types;
1353 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); 1370 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G);
1354 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_2G); 1371 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_2G);
1355 1372
1356 BuildSocket(response_headers, response_body, true, effective_connection_types, 1373 BuildSocket(response_headers, response_body, true /* expect_ect_header */,
1357 &reads_list, &mock_writes, &writes_list); 1374 effective_connection_types, &reads_list, &mock_writes,
1375 &writes_list);
1358 1376
1359 // Add 1 socket provider since 1 request in this test is fetched from the 1377 // Add 1 socket provider since 1 request in this test is fetched from the
1360 // network. 1378 // network.
1361 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, false); 1379 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, false);
1362 1380
1363 // When the ECT is set to the same value, fetching the same resource should 1381 // When the ECT is set to the same value, fetching the same resource should
1364 // result in a cache hit. 1382 // result in a cache hit.
1365 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); 1383 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true);
1366 1384
1367 // When the ECT is set to a different value, the response should still be 1385 // When the ECT is set to a different value, the response should still be
1368 // served from the cache. 1386 // served from the cache.
1369 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true); 1387 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true);
1370 } 1388 }
1371 1389
1372 } // namespace 1390 } // namespace
1373 1391
1374 } // namespace data_reduction_proxy 1392 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698