OLD | NEW |
---|---|
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> |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 lofi_ui_service_ = lofi_ui_service.get(); | 266 lofi_ui_service_ = lofi_ui_service.get(); |
267 test_context_->io_data()->set_lofi_ui_service(std::move(lofi_ui_service)); | 267 test_context_->io_data()->set_lofi_ui_service(std::move(lofi_ui_service)); |
268 | 268 |
269 context_.set_enable_brotli(enable_brotli_globally); | 269 context_.set_enable_brotli(enable_brotli_globally); |
270 context_.set_network_quality_estimator(&test_network_quality_estimator_); | 270 context_.set_network_quality_estimator(&test_network_quality_estimator_); |
271 context_.Init(); | 271 context_.Init(); |
272 | 272 |
273 test_context_->EnableDataReductionProxyWithSecureProxyCheckSuccess(); | 273 test_context_->EnableDataReductionProxyWithSecureProxyCheckSuccess(); |
274 } | 274 } |
275 | 275 |
276 // Build the sockets by adding appropriate mock data for | |
277 // |effective_connection_types.size()| number of requests. Data for | |
278 // chrome-Proxy-ect header is added to the mock data if |expect_ect_header| | |
279 // is true. |reads_list|, |mock_writes| and |writes_list| should be empty, and | |
280 // are owned by the caller. | |
281 void BuildSocket(const std::string& response_headers, | |
282 const std::string& response_body, | |
283 bool expect_ect_header, | |
284 const std::vector<net::EffectiveConnectionType>& | |
285 effective_connection_types, | |
286 std::vector<net::MockRead>* reads_list, | |
287 std::vector<std::string>* mock_writes, | |
288 std::vector<net::MockWrite>* writes_list) { | |
289 EXPECT_LT(0u, effective_connection_types.size()); | |
290 EXPECT_TRUE(reads_list->empty()); | |
291 EXPECT_TRUE(mock_writes->empty()); | |
292 EXPECT_TRUE(writes_list->empty()); | |
293 | |
294 for (size_t i = 0; i < effective_connection_types.size(); ++i) { | |
295 reads_list->push_back(net::MockRead(response_headers.c_str())); | |
296 reads_list->push_back(net::MockRead(response_body.c_str())); | |
297 } | |
298 reads_list->push_back(net::MockRead(net::SYNCHRONOUS, net::OK)); | |
299 | |
300 std::string prefix = std::string("GET ") | |
301 .append(kTestURL) | |
302 .append(" HTTP/1.1\r\n") | |
303 .append("Host: ") | |
304 .append(GURL(kTestURL).host()) | |
305 .append( | |
306 "\r\n" | |
307 "Proxy-Connection: keep-alive\r\n" | |
308 "User-Agent:\r\n" | |
309 "Accept-Encoding: gzip, deflate\r\n" | |
310 "Accept-Language: en-us,fr\r\n"); | |
311 | |
312 if (io_data()->test_request_options()->GetHeaderValueForTesting().empty()) { | |
313 // Force regeneration of Chrome-Proxy header. | |
314 io_data()->test_request_options()->SetSecureSession("123"); | |
315 } | |
316 | |
317 EXPECT_FALSE( | |
318 io_data()->test_request_options()->GetHeaderValueForTesting().empty()); | |
319 | |
320 std::string suffix = | |
321 std::string("Chrome-Proxy: ") + | |
322 io_data()->test_request_options()->GetHeaderValueForTesting() + | |
323 std::string("\r\n\r\n"); | |
324 | |
325 mock_socket_factory_.AddSSLSocketDataProvider(&ssl_socket_data_provider_); | |
326 | |
327 for (net::EffectiveConnectionType effective_connection_type : | |
328 effective_connection_types) { | |
329 std::string ect_header; | |
330 if (expect_ect_header) { | |
331 ect_header = "chrome-proxy-ect: " + | |
332 std::string(net::GetNameForEffectiveConnectionType( | |
333 effective_connection_type)) + | |
334 "\r\n"; | |
335 } | |
336 | |
337 std::string mock_write = prefix + ect_header + suffix; | |
338 mock_writes->push_back(mock_write); | |
339 writes_list->push_back(net::MockWrite(mock_writes->back().c_str())); | |
340 } | |
341 | |
342 EXPECT_FALSE(socket_); | |
343 socket_ = base::MakeUnique<net::StaticSocketDataProvider>( | |
344 reads_list->data(), reads_list->size(), writes_list->data(), | |
345 writes_list->size()); | |
346 mock_socket_factory_.AddSocketDataProvider(socket_.get()); | |
347 } | |
348 | |
276 static void VerifyHeaders(bool expected_data_reduction_proxy_used, | 349 static void VerifyHeaders(bool expected_data_reduction_proxy_used, |
277 bool expected_lofi_used, | 350 bool expected_lofi_used, |
278 const net::HttpRequestHeaders& headers) { | 351 const net::HttpRequestHeaders& headers) { |
279 EXPECT_EQ(expected_data_reduction_proxy_used, | 352 EXPECT_EQ(expected_data_reduction_proxy_used, |
280 headers.HasHeader(chrome_proxy_header())); | 353 headers.HasHeader(chrome_proxy_header())); |
281 std::string header_value; | 354 std::string header_value; |
282 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); | 355 headers.GetHeader(chrome_proxy_accept_transform_header(), &header_value); |
283 EXPECT_EQ(expected_data_reduction_proxy_used && expected_lofi_used, | 356 EXPECT_EQ(expected_data_reduction_proxy_used && expected_lofi_used, |
284 header_value.find("empty-image") != std::string::npos); | 357 header_value.find("empty-image") != std::string::npos); |
285 } | 358 } |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 .append( | 465 .append( |
393 " HTTP/1.1\r\n" | 466 " HTTP/1.1\r\n" |
394 "Host: ") | 467 "Host: ") |
395 .append(host) | 468 .append(host) |
396 .append( | 469 .append( |
397 "\r\n" | 470 "\r\n" |
398 "Proxy-Connection: keep-alive\r\n" | 471 "Proxy-Connection: keep-alive\r\n" |
399 "User-Agent:\r\n"); | 472 "User-Agent:\r\n"); |
400 | 473 |
401 std::string accept_language_header("Accept-Language: en-us,fr\r\n"); | 474 std::string accept_language_header("Accept-Language: en-us,fr\r\n"); |
475 std::string ect_header = "chrome-proxy-ect: " + | |
476 std::string(net::GetNameForEffectiveConnectionType( | |
477 net::EFFECTIVE_CONNECTION_TYPE_UNKNOWN)) + | |
478 "\r\n"; | |
402 | 479 |
403 // Brotli is included in accept-encoding header only if the request went | 480 // Brotli is included in accept-encoding header only if the request went |
404 // to the network (i.e., it was not a cached response), and if data | 481 // to the network (i.e., it was not a cached response), and if data |
405 // reduction ptroxy network delegate added Brotli to the header. | 482 // reduction ptroxy network delegate added Brotli to the header. |
406 std::string accept_encoding_header = | 483 std::string accept_encoding_header = |
407 expect_brotli && !expect_cached | 484 expect_brotli && !expect_cached |
408 ? "Accept-Encoding: gzip, deflate, br\r\n" | 485 ? "Accept-Encoding: gzip, deflate, br\r\n" |
409 : "Accept-Encoding: gzip, deflate\r\n"; | 486 : "Accept-Encoding: gzip, deflate\r\n"; |
410 | 487 |
411 std::string suffix_headers = | 488 std::string suffix_headers = |
412 std::string("Chrome-Proxy: ") + | 489 std::string("Chrome-Proxy: ") + |
413 io_data()->test_request_options()->GetHeaderValueForTesting() + | 490 io_data()->test_request_options()->GetHeaderValueForTesting() + |
414 std::string("\r\n\r\n"); | 491 std::string("\r\n\r\n"); |
415 | 492 |
416 std::string mock_write = prefix_headers + accept_language_header + | 493 std::string mock_write = prefix_headers + accept_language_header + |
417 accept_encoding_header + suffix_headers; | 494 ect_header + accept_encoding_header + |
495 suffix_headers; | |
418 | 496 |
419 if (expect_cached || !expect_brotli) { | 497 if (expect_cached || !expect_brotli) { |
420 // Order of headers is different if the headers were modified by data | 498 // Order of headers is different if the headers were modified by data |
421 // reduction proxy network delegate. | 499 // reduction proxy network delegate. |
422 mock_write = prefix_headers + accept_encoding_header + | 500 mock_write = prefix_headers + accept_encoding_header + |
423 accept_language_header + suffix_headers; | 501 accept_language_header + ect_header + suffix_headers; |
424 } | 502 } |
425 | 503 |
426 net::MockWrite writes[] = {net::MockWrite(mock_write.c_str())}; | 504 net::MockWrite writes[] = {net::MockWrite(mock_write.c_str())}; |
427 net::StaticSocketDataProvider socket(reads, arraysize(reads), writes, | 505 net::StaticSocketDataProvider socket(reads, arraysize(reads), writes, |
428 arraysize(writes)); | 506 arraysize(writes)); |
429 mock_socket_factory_.AddSocketDataProvider(&socket); | 507 mock_socket_factory_.AddSocketDataProvider(&socket); |
430 | 508 |
431 net::TestDelegate delegate; | 509 net::TestDelegate delegate; |
432 std::unique_ptr<net::URLRequest> request = | 510 std::unique_ptr<net::URLRequest> request = |
433 context_.CreateRequest(url, net::IDLE, &delegate); | 511 context_.CreateRequest(url, net::IDLE, &delegate); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
509 net::MockRead(net::SYNCHRONOUS, net::OK)}; | 587 net::MockRead(net::SYNCHRONOUS, net::OK)}; |
510 | 588 |
511 EXPECT_FALSE( | 589 EXPECT_FALSE( |
512 io_data()->test_request_options()->GetHeaderValueForTesting().empty()); | 590 io_data()->test_request_options()->GetHeaderValueForTesting().empty()); |
513 | 591 |
514 std::string mock_write = | 592 std::string mock_write = |
515 "GET http://www.google.com/ HTTP/1.1\r\nHost: " | 593 "GET http://www.google.com/ HTTP/1.1\r\nHost: " |
516 "www.google.com\r\nProxy-Connection: " | 594 "www.google.com\r\nProxy-Connection: " |
517 "keep-alive\r\nUser-Agent:\r\nAccept-Encoding: gzip, " | 595 "keep-alive\r\nUser-Agent:\r\nAccept-Encoding: gzip, " |
518 "deflate\r\nAccept-Language: en-us,fr\r\n" | 596 "deflate\r\nAccept-Language: en-us,fr\r\n" |
597 "chrome-proxy-ect: 4G\r\n" | |
519 "Chrome-Proxy: " + | 598 "Chrome-Proxy: " + |
520 io_data()->test_request_options()->GetHeaderValueForTesting() + | 599 io_data()->test_request_options()->GetHeaderValueForTesting() + |
521 (page_id_value.empty() ? "" : (", " + page_id_value)) + "\r\n\r\n"; | 600 (page_id_value.empty() ? "" : (", " + page_id_value)) + "\r\n\r\n"; |
522 | 601 |
523 net::MockWrite redirect_writes[] = {net::MockWrite(mock_write.c_str()), | 602 net::MockWrite redirect_writes[] = {net::MockWrite(mock_write.c_str()), |
524 net::MockWrite(mock_write.c_str())}; | 603 net::MockWrite(mock_write.c_str())}; |
525 | 604 |
526 net::MockWrite writes[] = {net::MockWrite(mock_write.c_str())}; | 605 net::MockWrite writes[] = {net::MockWrite(mock_write.c_str())}; |
527 | 606 |
528 std::unique_ptr<net::StaticSocketDataProvider> socket; | 607 std::unique_ptr<net::StaticSocketDataProvider> socket; |
(...skipping 13 matching lines...) Expand all Loading... | |
542 context_.CreateRequest(url, net::IDLE, &delegate); | 621 context_.CreateRequest(url, net::IDLE, &delegate); |
543 if (!page_id_value.empty()) { | 622 if (!page_id_value.empty()) { |
544 request->SetLoadFlags(request->load_flags() | | 623 request->SetLoadFlags(request->load_flags() | |
545 net::LOAD_MAIN_FRAME_DEPRECATED); | 624 net::LOAD_MAIN_FRAME_DEPRECATED); |
546 } | 625 } |
547 | 626 |
548 request->Start(); | 627 request->Start(); |
549 base::RunLoop().RunUntilIdle(); | 628 base::RunLoop().RunUntilIdle(); |
550 } | 629 } |
551 | 630 |
631 // Fetches a request while the effective connection type is set to | |
632 // |effective_connection_type|. Verifies that the request headers include the | |
633 // chrome-proxy-ect header only if |expect_ect_header| is true. The response | |
634 // must be served from the cache if |expect_cached| is true. | |
635 void FetchURLRequestAndVerifyECTHeader( | |
636 net::EffectiveConnectionType effective_connection_type, | |
637 bool expect_ect_header, | |
638 bool expect_cached) { | |
639 test_network_quality_estimator()->set_effective_connection_type( | |
640 effective_connection_type); | |
641 | |
642 net::TestDelegate delegate; | |
643 std::unique_ptr<net::URLRequest> request = | |
644 context_.CreateRequest(GURL(kTestURL), net::IDLE, &delegate); | |
645 | |
646 request->Start(); | |
647 base::RunLoop().RunUntilIdle(); | |
648 | |
649 EXPECT_EQ(140, request->received_response_content_length()); | |
650 EXPECT_EQ(expect_cached, request->was_cached()); | |
651 EXPECT_EQ(expect_cached, request->GetTotalSentBytes() == 0); | |
652 EXPECT_EQ(expect_cached, request->GetTotalReceivedBytes() == 0); | |
653 | |
654 net::HttpRequestHeaders sent_request_headers; | |
655 EXPECT_NE(expect_cached, | |
656 request->GetFullRequestHeaders(&sent_request_headers)); | |
657 | |
658 if (expect_cached) { | |
659 // Request headers are missing. Return since there is nothing left to | |
660 // check. | |
661 return; | |
662 } | |
663 | |
664 // Verify that chrome-proxy-ect header is present in the request headers | |
665 // only if |expect_ect_header| is true. | |
666 std::string ect_value; | |
667 EXPECT_EQ(expect_ect_header, sent_request_headers.GetHeader( | |
668 chrome_proxy_ect_header(), &ect_value)); | |
669 | |
670 if (!expect_ect_header) | |
671 return; | |
672 EXPECT_EQ(net::GetNameForEffectiveConnectionType(effective_connection_type), | |
673 ect_value); | |
674 } | |
675 | |
552 void DelegateStageDone(int result) {} | 676 void DelegateStageDone(int result) {} |
553 | 677 |
554 void NotifyNetworkDelegate(net::URLRequest* request, | 678 void NotifyNetworkDelegate(net::URLRequest* request, |
555 const net::ProxyInfo& data_reduction_proxy_info, | 679 const net::ProxyInfo& data_reduction_proxy_info, |
556 const net::ProxyRetryInfoMap& proxy_retry_info, | 680 const net::ProxyRetryInfoMap& proxy_retry_info, |
557 net::HttpRequestHeaders* headers) { | 681 net::HttpRequestHeaders* headers) { |
558 network_delegate()->NotifyBeforeURLRequest( | 682 network_delegate()->NotifyBeforeURLRequest( |
559 request, | 683 request, |
560 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone, | 684 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone, |
561 base::Unretained(this)), | 685 base::Unretained(this)), |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1369 | 1493 |
1370 std::unique_ptr<net::URLRequest> request = context()->CreateRequest( | 1494 std::unique_ptr<net::URLRequest> request = context()->CreateRequest( |
1371 GURL(kTestURL), net::RequestPriority::IDLE, nullptr); | 1495 GURL(kTestURL), net::RequestPriority::IDLE, nullptr); |
1372 request->SetLoadFlags(net::LOAD_MAIN_FRAME_DEPRECATED); | 1496 request->SetLoadFlags(net::LOAD_MAIN_FRAME_DEPRECATED); |
1373 io_data()->request_options()->SetSecureSession("fake-session"); | 1497 io_data()->request_options()->SetSecureSession("fake-session"); |
1374 | 1498 |
1375 net::HttpRequestHeaders headers; | 1499 net::HttpRequestHeaders headers; |
1376 net::ProxyRetryInfoMap proxy_retry_info; | 1500 net::ProxyRetryInfoMap proxy_retry_info; |
1377 | 1501 |
1378 // Send a request and verify the page ID is 1. | 1502 // Send a request and verify the page ID is 1. |
1503 network_delegate()->NotifyBeforeStartTransaction( | |
1504 request.get(), | |
1505 base::Bind(&DataReductionProxyNetworkDelegateTest::DelegateStageDone, | |
1506 base::Unretained(this)), | |
1507 &headers); | |
1379 network_delegate()->NotifyBeforeSendHeaders( | 1508 network_delegate()->NotifyBeforeSendHeaders( |
1380 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); | 1509 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); |
1381 DataReductionProxyData* data = | 1510 DataReductionProxyData* data = |
1382 DataReductionProxyData::GetData(*request.get()); | 1511 DataReductionProxyData::GetData(*request.get()); |
1383 EXPECT_TRUE(data_reduction_proxy_info.is_http()); | 1512 EXPECT_TRUE(data_reduction_proxy_info.is_http()); |
1384 EXPECT_EQ(1u, data->page_id().value()); | 1513 EXPECT_EQ(1u, data->page_id().value()); |
1385 | 1514 |
1386 // Send a second request and verify the page ID incremements. | 1515 // Send a second request and verify the page ID incremements. |
1387 request = context()->CreateRequest(GURL(kTestURL), net::RequestPriority::IDLE, | 1516 request = context()->CreateRequest(GURL(kTestURL), net::RequestPriority::IDLE, |
1388 nullptr); | 1517 nullptr); |
1389 request->SetLoadFlags(net::LOAD_MAIN_FRAME_DEPRECATED); | 1518 request->SetLoadFlags(net::LOAD_MAIN_FRAME_DEPRECATED); |
1390 | 1519 |
1391 network_delegate()->NotifyBeforeSendHeaders( | 1520 network_delegate()->NotifyBeforeSendHeaders( |
RyanSturm
2017/04/19 20:49:18
Call NotifyBeforeStartTransaction again?
dougarnett
2017/04/19 21:20:00
Done.
| |
1392 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); | 1521 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); |
1393 data = DataReductionProxyData::GetData(*request.get()); | 1522 data = DataReductionProxyData::GetData(*request.get()); |
1394 EXPECT_EQ(2u, data->page_id().value()); | 1523 EXPECT_EQ(2u, data->page_id().value()); |
1395 | 1524 |
1396 // Verify that redirects are the same page ID. | 1525 // Verify that redirects are the same page ID. |
1397 network_delegate()->NotifyBeforeRedirect(request.get(), GURL(kTestURL)); | 1526 network_delegate()->NotifyBeforeRedirect(request.get(), GURL(kTestURL)); |
1398 network_delegate()->NotifyBeforeSendHeaders( | 1527 network_delegate()->NotifyBeforeSendHeaders( |
1399 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); | 1528 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); |
1400 data = DataReductionProxyData::GetData(*request.get()); | 1529 data = DataReductionProxyData::GetData(*request.get()); |
1401 EXPECT_EQ(2u, data->page_id().value()); | 1530 EXPECT_EQ(2u, data->page_id().value()); |
1402 | 1531 |
1403 // Verify that redirects into a new session get a new page ID. | 1532 // Verify that redirects into a new session get a new page ID. |
1404 network_delegate()->NotifyBeforeRedirect(request.get(), GURL(kTestURL)); | 1533 network_delegate()->NotifyBeforeRedirect(request.get(), GURL(kTestURL)); |
1405 io_data()->request_options()->SetSecureSession("new-session"); | 1534 io_data()->request_options()->SetSecureSession("new-session"); |
1406 network_delegate()->NotifyBeforeSendHeaders( | 1535 network_delegate()->NotifyBeforeSendHeaders( |
1407 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); | 1536 request.get(), data_reduction_proxy_info, proxy_retry_info, &headers); |
1408 data = DataReductionProxyData::GetData(*request.get()); | 1537 data = DataReductionProxyData::GetData(*request.get()); |
1409 EXPECT_EQ(1u, data->page_id().value()); | 1538 EXPECT_EQ(1u, data->page_id().value()); |
1410 } | 1539 } |
1411 | 1540 |
1541 // Test that effective connection type is correctly added to the request | |
1542 // headers when it is enabled using field trial. The server is varying on the | |
1543 // effective connection type (ECT). | |
1544 TEST_F(DataReductionProxyNetworkDelegateTest, ECTHeaderEnabledWithVary) { | |
1545 Init(USE_SECURE_PROXY, false /* enable_brotli_globally */); | |
1546 | |
1547 std::string response_headers = | |
1548 "HTTP/1.1 200 OK\r\n" | |
1549 "Content-Length: 140\r\n" | |
1550 "Via: 1.1 Chrome-Compression-Proxy\r\n" | |
1551 "Cache-Control: max-age=1200\r\n" | |
1552 "Vary: chrome-proxy-ect\r\n" | |
1553 "x-original-content-length: 200\r\n\r\n"; | |
1554 | |
1555 int response_body_size = 140; | |
1556 std::string response_body(base::checked_cast<size_t>(response_body_size), | |
1557 ' '); | |
1558 | |
1559 std::vector<net::MockRead> reads_list; | |
1560 std::vector<std::string> mock_writes; | |
1561 std::vector<net::MockWrite> writes_list; | |
1562 | |
1563 std::vector<net::EffectiveConnectionType> effective_connection_types; | |
1564 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); | |
1565 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_2G); | |
1566 | |
1567 BuildSocket(response_headers, response_body, true, effective_connection_types, | |
1568 &reads_list, &mock_writes, &writes_list); | |
1569 | |
1570 // Add 2 socket providers since 2 requests in this test are fetched from the | |
1571 // network. | |
1572 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, false); | |
1573 | |
1574 // When the ECT is set to the same value, fetching the same resource should | |
1575 // result in a cache hit. | |
1576 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); | |
1577 | |
1578 // When the ECT is set to a different value, the response should not be | |
1579 // served from the cache. | |
1580 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, false); | |
1581 } | |
1582 | |
1583 // Test that effective connection type is correctly added to the request | |
1584 // headers when it is enabled using field trial. The server is not varying on | |
1585 // the effective connection type (ECT). | |
1586 TEST_F(DataReductionProxyNetworkDelegateTest, ECTHeaderEnabledWithoutVary) { | |
1587 Init(USE_SECURE_PROXY, false /* enable_brotli_globally */); | |
1588 | |
1589 std::string response_headers = | |
1590 "HTTP/1.1 200 OK\r\n" | |
1591 "Content-Length: 140\r\n" | |
1592 "Via: 1.1 Chrome-Compression-Proxy\r\n" | |
1593 "Cache-Control: max-age=1200\r\n" | |
1594 "x-original-content-length: 200\r\n\r\n"; | |
1595 | |
1596 int response_body_size = 140; | |
1597 std::string response_body(base::checked_cast<size_t>(response_body_size), | |
1598 ' '); | |
1599 | |
1600 std::vector<net::MockRead> reads_list; | |
1601 std::vector<std::string> mock_writes; | |
1602 std::vector<net::MockWrite> writes_list; | |
1603 | |
1604 std::vector<net::EffectiveConnectionType> effective_connection_types; | |
1605 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); | |
1606 effective_connection_types.push_back(net::EFFECTIVE_CONNECTION_TYPE_2G); | |
1607 | |
1608 BuildSocket(response_headers, response_body, true, effective_connection_types, | |
1609 &reads_list, &mock_writes, &writes_list); | |
1610 | |
1611 // Add 1 socket provider since 1 request in this test is fetched from the | |
1612 // network. | |
1613 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, false); | |
1614 | |
1615 // When the ECT is set to the same value, fetching the same resource should | |
1616 // result in a cache hit. | |
1617 FetchURLRequestAndVerifyECTHeader(effective_connection_types[0], true, true); | |
1618 | |
1619 // When the ECT is set to a different value, the response should still be | |
1620 // served from the cache. | |
1621 FetchURLRequestAndVerifyECTHeader(effective_connection_types[1], true, true); | |
1622 } | |
1623 | |
1412 } // namespace | 1624 } // namespace |
1413 | 1625 |
1414 } // namespace data_reduction_proxy | 1626 } // namespace data_reduction_proxy |
OLD | NEW |