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_bypa ss_stats.h" | 5 #include "components/data_reduction_proxy/core/browser/data_reduction_proxy_bypa ss_stats.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 | 328 |
329 std::unique_ptr<net::URLRequest> request( | 329 std::unique_ptr<net::URLRequest> request( |
330 context_.CreateRequest(url, net::IDLE, &delegate_)); | 330 context_.CreateRequest(url, net::IDLE, &delegate_)); |
331 request->set_method("GET"); | 331 request->set_method("GET"); |
332 request->SetLoadFlags(load_flags); | 332 request->SetLoadFlags(load_flags); |
333 request->Start(); | 333 request->Start(); |
334 drp_test_context_->RunUntilIdle(); | 334 drp_test_context_->RunUntilIdle(); |
335 return request; | 335 return request; |
336 } | 336 } |
337 | 337 |
338 // Create and execute a fake request that goes through a redirect loop using | |
339 // the data reduction proxy stack. | |
340 std::unique_ptr<net::URLRequest> CreateAndExecuteURLRedirectCycleRequest() { | |
RyanSturm
2017/03/28 18:03:19
This is a really good test.
tbansal1
2017/03/28 19:59:48
Acknowledged.
| |
341 MockRead redirect_mock_reads_1[] = { | |
342 MockRead("HTTP/1.1 302 Found\r\n" | |
343 "Via: 1.1 Chrome-Compression-Proxy\r\n" | |
344 "Location: http://bar.com/\r\n\r\n"), | |
345 MockRead(""), MockRead(net::SYNCHRONOUS, net::OK), | |
346 }; | |
347 net::StaticSocketDataProvider redirect_socket_data_provider_1( | |
348 redirect_mock_reads_1, arraysize(redirect_mock_reads_1), nullptr, 0); | |
349 mock_socket_factory_.AddSocketDataProvider( | |
350 &redirect_socket_data_provider_1); | |
351 | |
352 // The response after the redirect comes through proxy. | |
353 MockRead redirect_mock_reads_2[] = { | |
354 MockRead("HTTP/1.1 302 Found\r\n" | |
355 "Via: 1.1 Chrome-Compression-Proxy\r\n" | |
356 "Location: http://foo.com/\r\n\r\n"), | |
357 MockRead(""), MockRead(net::SYNCHRONOUS, net::OK), | |
358 }; | |
359 net::StaticSocketDataProvider redirect_socket_data_provider_2( | |
360 redirect_mock_reads_2, arraysize(redirect_mock_reads_2), nullptr, 0); | |
361 mock_socket_factory_.AddSocketDataProvider( | |
362 &redirect_socket_data_provider_2); | |
363 | |
364 // The response after the redirect comes through proxy and there is a | |
365 // redirect cycle. | |
366 MockRead redirect_mock_reads_3[] = { | |
367 MockRead("HTTP/1.1 302 Found\r\n" | |
368 "Via: 1.1 Chrome-Compression-Proxy\r\n" | |
369 "Location: http://bar.com/\r\n\r\n"), | |
370 MockRead(""), MockRead(net::SYNCHRONOUS, net::OK), | |
371 }; | |
372 net::StaticSocketDataProvider redirect_socket_data_provider_3( | |
373 redirect_mock_reads_3, arraysize(redirect_mock_reads_3), nullptr, 0); | |
374 mock_socket_factory_.AddSocketDataProvider( | |
375 &redirect_socket_data_provider_3); | |
376 | |
377 // Data reduction proxy should be bypassed, and the response should come | |
378 // directly. | |
379 MockRead response_mock_reads[] = { | |
380 MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead(kBody.c_str()), | |
381 MockRead(net::SYNCHRONOUS, net::OK), | |
382 }; | |
383 net::StaticSocketDataProvider response_socket_data_provider( | |
384 response_mock_reads, arraysize(response_mock_reads), nullptr, 0); | |
385 mock_socket_factory_.AddSocketDataProvider(&response_socket_data_provider); | |
386 | |
387 std::unique_ptr<net::URLRequest> request( | |
388 context_.CreateRequest(GURL("http://foo.com"), net::IDLE, &delegate_)); | |
389 request->set_method("GET"); | |
390 request->Start(); | |
391 drp_test_context_->RunUntilIdle(); | |
392 return request; | |
393 } | |
394 | |
338 void set_proxy_service(net::ProxyService* proxy_service) { | 395 void set_proxy_service(net::ProxyService* proxy_service) { |
339 context_.set_proxy_service(proxy_service); | 396 context_.set_proxy_service(proxy_service); |
340 } | 397 } |
341 | 398 |
342 void set_host_resolver(net::HostResolver* host_resolver) { | 399 void set_host_resolver(net::HostResolver* host_resolver) { |
343 context_.set_host_resolver(host_resolver); | 400 context_.set_host_resolver(host_resolver); |
344 } | 401 } |
345 | 402 |
346 const DataReductionProxySettings* settings() const { | 403 const DataReductionProxySettings* settings() const { |
347 return drp_test_context_->settings(); | 404 return drp_test_context_->settings(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 "DataReductionProxy.BypassedBytes.MediumTriggeringRequest", | 447 "DataReductionProxy.BypassedBytes.MediumTriggeringRequest", |
391 "DataReductionProxy.BypassedBytes.LongAll", | 448 "DataReductionProxy.BypassedBytes.LongAll", |
392 "DataReductionProxy.BypassedBytes.LongTriggeringRequest", | 449 "DataReductionProxy.BypassedBytes.LongTriggeringRequest", |
393 "DataReductionProxy.BypassedBytes.MissingViaHeader4xx", | 450 "DataReductionProxy.BypassedBytes.MissingViaHeader4xx", |
394 "DataReductionProxy.BypassedBytes.MissingViaHeaderOther", | 451 "DataReductionProxy.BypassedBytes.MissingViaHeaderOther", |
395 "DataReductionProxy.BypassedBytes.Malformed407", | 452 "DataReductionProxy.BypassedBytes.Malformed407", |
396 "DataReductionProxy.BypassedBytes.Status500HttpInternalServerError", | 453 "DataReductionProxy.BypassedBytes.Status500HttpInternalServerError", |
397 "DataReductionProxy.BypassedBytes.Status502HttpBadGateway", | 454 "DataReductionProxy.BypassedBytes.Status502HttpBadGateway", |
398 "DataReductionProxy.BypassedBytes.Status503HttpServiceUnavailable", | 455 "DataReductionProxy.BypassedBytes.Status503HttpServiceUnavailable", |
399 "DataReductionProxy.BypassedBytes.NetworkErrorOther", | 456 "DataReductionProxy.BypassedBytes.NetworkErrorOther", |
457 "DataReductionProxy.BypassedBytes.RedirectCycle", | |
400 }; | 458 }; |
401 | 459 |
402 for (const std::string& histogram : kHistograms) { | 460 for (const std::string& histogram : kHistograms) { |
403 if (excluded_histograms.find(histogram) == | 461 if (excluded_histograms.find(histogram) == |
404 excluded_histograms.end()) { | 462 excluded_histograms.end()) { |
405 histogram_tester.ExpectTotalCount(histogram, 0); | 463 histogram_tester.ExpectTotalCount(histogram, 0); |
406 } | 464 } |
407 } | 465 } |
408 } | 466 } |
409 | 467 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
501 test_case.initial_response_headers, kBody.c_str(), | 559 test_case.initial_response_headers, kBody.c_str(), |
502 nullptr, nullptr); | 560 nullptr, nullptr); |
503 | 561 |
504 histogram_tester.ExpectUniqueSample(test_case.histogram_name, kBody.size(), | 562 histogram_tester.ExpectUniqueSample(test_case.histogram_name, kBody.size(), |
505 1); | 563 1); |
506 ExpectOtherBypassedBytesHistogramsEmpty(histogram_tester, | 564 ExpectOtherBypassedBytesHistogramsEmpty(histogram_tester, |
507 test_case.histogram_name); | 565 test_case.histogram_name); |
508 } | 566 } |
509 } | 567 } |
510 | 568 |
569 // Verify that when there is a URL redirect cycle, data reduction proxy is | |
570 // bypassed for a single request. | |
571 TEST_F(DataReductionProxyBypassStatsEndToEndTest, URLRedirectCycle) { | |
572 InitializeContext(); | |
573 ClearBadProxies(); | |
574 base::HistogramTester histogram_tester_1; | |
575 CreateAndExecuteURLRedirectCycleRequest(); | |
576 | |
577 histogram_tester_1.ExpectUniqueSample( | |
578 "DataReductionProxy.BypassedBytes.URLRedirectCycle", kBody.size(), 1); | |
579 ExpectOtherBypassedBytesHistogramsEmpty( | |
580 histogram_tester_1, "DataReductionProxy.BypassedBytes.URLRedirectCycle"); | |
581 | |
582 // The second request should be sent via the proxy. | |
583 base::HistogramTester histogram_tester_2; | |
584 CreateAndExecuteRequest(GURL("http://bar.com"), net::LOAD_NORMAL, net::OK, | |
585 "HTTP/1.1 200 OK\r\n" | |
586 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n", | |
587 kNextBody.c_str(), nullptr, nullptr); | |
588 histogram_tester_2.ExpectUniqueSample( | |
589 "DataReductionProxy.BypassedBytes.NotBypassed", kNextBody.size(), 1); | |
590 ExpectOtherBypassedBytesHistogramsEmpty( | |
591 histogram_tester_2, "DataReductionProxy.BypassedBytes.NotBypassed"); | |
592 } | |
593 | |
511 TEST_F(DataReductionProxyBypassStatsEndToEndTest, | 594 TEST_F(DataReductionProxyBypassStatsEndToEndTest, |
512 BypassedBytesProxyOverridden) { | 595 BypassedBytesProxyOverridden) { |
513 std::unique_ptr<net::ProxyService> proxy_service( | 596 std::unique_ptr<net::ProxyService> proxy_service( |
514 net::ProxyService::CreateFixed("http://test.com:80")); | 597 net::ProxyService::CreateFixed("http://test.com:80")); |
515 set_proxy_service(proxy_service.get()); | 598 set_proxy_service(proxy_service.get()); |
516 InitializeContext(); | 599 InitializeContext(); |
517 | 600 |
518 base::HistogramTester histogram_tester; | 601 base::HistogramTester histogram_tester; |
519 CreateAndExecuteRequest(GURL("http://foo.com"), net::LOAD_NORMAL, net::OK, | 602 CreateAndExecuteRequest(GURL("http://foo.com"), net::LOAD_NORMAL, net::OK, |
520 "HTTP/1.1 200 OK\r\n\r\n", kBody.c_str(), nullptr, | 603 "HTTP/1.1 200 OK\r\n\r\n", kBody.c_str(), nullptr, |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
990 base::HistogramTester histogram_tester; | 1073 base::HistogramTester histogram_tester; |
991 CreateAndExecuteRequest(GURL("http://bar.com"), net::LOAD_NORMAL, net::OK, | 1074 CreateAndExecuteRequest(GURL("http://bar.com"), net::LOAD_NORMAL, net::OK, |
992 "HTTP/1.1 200 OK\r\n" | 1075 "HTTP/1.1 200 OK\r\n" |
993 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n", | 1076 "Via: 1.1 Chrome-Compression-Proxy\r\n\r\n", |
994 kNextBody.c_str(), nullptr, nullptr); | 1077 kNextBody.c_str(), nullptr, nullptr); |
995 histogram_tester.ExpectUniqueSample("DataReductionProxy.ProxySchemeUsed", | 1078 histogram_tester.ExpectUniqueSample("DataReductionProxy.ProxySchemeUsed", |
996 2 /*PROXY_SCHEME_HTTPS */, 1); | 1079 2 /*PROXY_SCHEME_HTTPS */, 1); |
997 } | 1080 } |
998 | 1081 |
999 } // namespace data_reduction_proxy | 1082 } // namespace data_reduction_proxy |
OLD | NEW |