| 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_inte
rceptor.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_inte
rceptor.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/test/histogram_tester.h" |
| 17 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_test_utils.h" | 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
ig_test_utils.h" |
| 18 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" | 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_conf
igurator.h" |
| 19 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" | 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_io_d
ata.h" |
| 20 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" | 21 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_test
_utils.h" |
| 21 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" | 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s.h" |
| 22 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s_test_utils.h" | 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_param
s_test_utils.h" |
| 23 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" | 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_pref_
names.h" |
| 24 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve
r.h" | 25 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_serve
r.h" |
| 25 #include "components/data_reduction_proxy/proto/client_config.pb.h" | 26 #include "components/data_reduction_proxy/proto/client_config.pb.h" |
| 26 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 CreateAndExecuteRequest(GURL("http://foo.com")); | 393 CreateAndExecuteRequest(GURL("http://foo.com")); |
| 393 | 394 |
| 394 EXPECT_EQ(net::OK, delegate().request_status()); | 395 EXPECT_EQ(net::OK, delegate().request_status()); |
| 395 EXPECT_EQ(200, request->GetResponseCode()); | 396 EXPECT_EQ(200, request->GetResponseCode()); |
| 396 EXPECT_EQ(kBody, delegate().data_received()); | 397 EXPECT_EQ(kBody, delegate().data_received()); |
| 397 EXPECT_EQ(origin(), request->proxy_server()); | 398 EXPECT_EQ(origin(), request->proxy_server()); |
| 398 // The redirect should have been processed and followed normally. | 399 // The redirect should have been processed and followed normally. |
| 399 EXPECT_EQ(1, delegate().received_redirect_count()); | 400 EXPECT_EQ(1, delegate().received_redirect_count()); |
| 400 } | 401 } |
| 401 | 402 |
| 403 // Test that data reduction proxy is byppassed if there is a URL redirect cycle. |
| 404 TEST_F(DataReductionProxyInterceptorEndToEndTest, URLRedirectCycle) { |
| 405 base::HistogramTester histogram_tester; |
| 406 MockRead redirect_mock_reads_1[] = { |
| 407 MockRead("HTTP/1.1 302 Found\r\n" |
| 408 "Via: 1.1 Chrome-Compression-Proxy\r\n" |
| 409 "Location: http://bar.com/\r\n\r\n"), |
| 410 MockRead(""), MockRead(net::SYNCHRONOUS, net::OK), |
| 411 }; |
| 412 net::StaticSocketDataProvider redirect_socket_data_provider_1( |
| 413 redirect_mock_reads_1, arraysize(redirect_mock_reads_1), nullptr, 0); |
| 414 mock_socket_factory()->AddSocketDataProvider( |
| 415 &redirect_socket_data_provider_1); |
| 416 |
| 417 MockRead redirect_mock_reads_2[] = { |
| 418 MockRead("HTTP/1.1 302 Found\r\n" |
| 419 "Via: 1.1 Chrome-Compression-Proxy\r\n" |
| 420 "Location: http://foo.com/\r\n\r\n"), |
| 421 MockRead(""), MockRead(net::SYNCHRONOUS, net::OK), |
| 422 }; |
| 423 net::StaticSocketDataProvider redirect_socket_data_provider_2( |
| 424 redirect_mock_reads_2, arraysize(redirect_mock_reads_2), nullptr, 0); |
| 425 mock_socket_factory()->AddSocketDataProvider( |
| 426 &redirect_socket_data_provider_2); |
| 427 |
| 428 // Redirect cycle. |
| 429 MockRead redirect_mock_reads_3[] = { |
| 430 MockRead("HTTP/1.1 302 Found\r\n" |
| 431 "Via: 1.1 Chrome-Compression-Proxy\r\n" |
| 432 "Location: http://bar.com/\r\n\r\n"), |
| 433 MockRead(""), MockRead(net::SYNCHRONOUS, net::OK), |
| 434 }; |
| 435 net::StaticSocketDataProvider redirect_socket_data_provider_3( |
| 436 redirect_mock_reads_3, arraysize(redirect_mock_reads_3), nullptr, 0); |
| 437 mock_socket_factory()->AddSocketDataProvider( |
| 438 &redirect_socket_data_provider_3); |
| 439 |
| 440 // Data reduction proxy should be bypassed. |
| 441 MockRead redirect_mock_reads_4[] = { |
| 442 MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead(kBody.c_str()), |
| 443 MockRead(net::SYNCHRONOUS, net::OK), |
| 444 }; |
| 445 net::StaticSocketDataProvider redirect_socket_data_provider_4( |
| 446 redirect_mock_reads_4, arraysize(redirect_mock_reads_4), nullptr, 0); |
| 447 mock_socket_factory()->AddSocketDataProvider( |
| 448 &redirect_socket_data_provider_4); |
| 449 |
| 450 std::unique_ptr<net::URLRequest> request = |
| 451 CreateAndExecuteRequest(GURL("http://foo.com")); |
| 452 |
| 453 EXPECT_EQ(net::OK, delegate().request_status()); |
| 454 EXPECT_EQ(200, request->GetResponseCode()); |
| 455 EXPECT_EQ(kBody, delegate().data_received()); |
| 456 EXPECT_FALSE(request->was_fetched_via_proxy()); |
| 457 histogram_tester.ExpectTotalCount( |
| 458 "DataReductionProxy.BypassedBytes.URLRedirectCycle", 1); |
| 459 } |
| 460 |
| 402 TEST_F(DataReductionProxyInterceptorEndToEndTest, ResponseWithBypassAndRetry) { | 461 TEST_F(DataReductionProxyInterceptorEndToEndTest, ResponseWithBypassAndRetry) { |
| 403 // The first try gives a bypass. | 462 // The first try gives a bypass. |
| 404 MockRead initial_mock_reads[] = { | 463 MockRead initial_mock_reads[] = { |
| 405 MockRead("HTTP/1.1 502 Bad Gateway\r\n" | 464 MockRead("HTTP/1.1 502 Bad Gateway\r\n" |
| 406 "Via: 1.1 Chrome-Compression-Proxy\r\n" | 465 "Via: 1.1 Chrome-Compression-Proxy\r\n" |
| 407 "Chrome-Proxy: block-once\r\n\r\n"), | 466 "Chrome-Proxy: block-once\r\n\r\n"), |
| 408 MockRead(""), | 467 MockRead(""), |
| 409 MockRead(net::SYNCHRONOUS, net::OK), | 468 MockRead(net::SYNCHRONOUS, net::OK), |
| 410 }; | 469 }; |
| 411 net::StaticSocketDataProvider initial_socket_data_provider( | 470 net::StaticSocketDataProvider initial_socket_data_provider( |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 std::vector<GURL> expected_url_chain; | 585 std::vector<GURL> expected_url_chain; |
| 527 expected_url_chain.push_back(GURL("http://music.google.com")); | 586 expected_url_chain.push_back(GURL("http://music.google.com")); |
| 528 expected_url_chain.push_back(GURL("http://play.google.com")); | 587 expected_url_chain.push_back(GURL("http://play.google.com")); |
| 529 expected_url_chain.push_back(GURL("https://play.google.com")); | 588 expected_url_chain.push_back(GURL("https://play.google.com")); |
| 530 EXPECT_EQ(expected_url_chain, request->url_chain()); | 589 EXPECT_EQ(expected_url_chain, request->url_chain()); |
| 531 } | 590 } |
| 532 | 591 |
| 533 } // namespace | 592 } // namespace |
| 534 | 593 |
| 535 } // namespace data_reduction_proxy | 594 } // namespace data_reduction_proxy |
| OLD | NEW |