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/browser/data_reduction_proxy_protocol.
h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_protocol.
h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/metrics/field_trial.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te
st_utils.h" | 14 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te
st_utils.h" |
14 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
15 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
| 17 #include "net/base/load_flags.h" |
16 #include "net/base/network_delegate.h" | 18 #include "net/base/network_delegate.h" |
17 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
18 #include "net/http/http_transaction_test_util.h" | 20 #include "net/http/http_transaction_test_util.h" |
| 21 #include "net/proxy/proxy_service.h" |
19 #include "net/socket/socket_test_util.h" | 22 #include "net/socket/socket_test_util.h" |
20 #include "net/url_request/static_http_user_agent_settings.h" | 23 #include "net/url_request/static_http_user_agent_settings.h" |
21 #include "net/url_request/url_request.h" | 24 #include "net/url_request/url_request.h" |
22 #include "net/url_request/url_request_context.h" | 25 #include "net/url_request/url_request_context.h" |
23 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
25 | 28 |
26 using net::HttpResponseHeaders; | 29 using net::HttpResponseHeaders; |
27 using net::HostPortPair; | 30 using net::HostPortPair; |
28 using net::MockRead; | 31 using net::MockRead; |
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 | 607 |
605 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); | 608 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); |
606 EXPECT_EQ(net::OK, r.status().error()); | 609 EXPECT_EQ(net::OK, r.status().error()); |
607 | 610 |
608 EXPECT_EQ("Bypass message", d.data_received()); | 611 EXPECT_EQ("Bypass message", d.data_received()); |
609 | 612 |
610 // We should have no entries in our bad proxy list. | 613 // We should have no entries in our bad proxy list. |
611 TestBadProxies(0, -1, "", ""); | 614 TestBadProxies(0, -1, "", ""); |
612 } | 615 } |
613 | 616 |
| 617 class BadEntropyProvider : public base::FieldTrial::EntropyProvider { |
| 618 public: |
| 619 virtual ~BadEntropyProvider() {} |
| 620 |
| 621 virtual double GetEntropyForTrial(const std::string& trial_name, |
| 622 uint32 randomization_seed) const OVERRIDE { |
| 623 return 0.5; |
| 624 } |
| 625 }; |
| 626 |
| 627 TEST_F(DataReductionProxyProtocolTest, OnResolveProxyHandler) { |
| 628 int load_flags = net::LOAD_NORMAL; |
| 629 GURL url("http://www.google.com/"); |
| 630 |
| 631 TestDataReductionProxyParams test_params( |
| 632 DataReductionProxyParams::kAllowed | |
| 633 DataReductionProxyParams::kFallbackAllowed | |
| 634 DataReductionProxyParams::kPromoAllowed, |
| 635 TestDataReductionProxyParams::HAS_EVERYTHING & |
| 636 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); |
| 637 |
| 638 // Data reduction proxy |
| 639 net::ProxyInfo info1; |
| 640 std::string data_reduction_proxy; |
| 641 base::TrimString(test_params.DefaultOrigin(), "/", &data_reduction_proxy); |
| 642 info1.UseNamedProxy(data_reduction_proxy); |
| 643 EXPECT_FALSE(info1.is_empty()); |
| 644 |
| 645 // Other proxy |
| 646 net::ProxyInfo info2; |
| 647 info2.UseNamedProxy("proxy.com"); |
| 648 EXPECT_FALSE(info2.is_empty()); |
| 649 |
| 650 // Without DataCompressionProxyCriticalBypass Finch trial set, should never |
| 651 // bypass. |
| 652 OnResolveProxyHandler(url, load_flags, &test_params, &info1); |
| 653 EXPECT_FALSE(info1.is_direct()); |
| 654 |
| 655 OnResolveProxyHandler(url, load_flags, &test_params,&info2); |
| 656 EXPECT_FALSE(info2.is_direct()); |
| 657 |
| 658 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
| 659 |
| 660 OnResolveProxyHandler(url, load_flags, &test_params, &info1); |
| 661 EXPECT_FALSE(info1.is_direct()); |
| 662 |
| 663 OnResolveProxyHandler(url, load_flags, &test_params, &info2); |
| 664 EXPECT_FALSE(info2.is_direct()); |
| 665 |
| 666 // With Finch trial set, should only bypass if LOAD flag is set and the |
| 667 // effective proxy is the data compression proxy. |
| 668 base::FieldTrialList field_trial_list(new BadEntropyProvider()); |
| 669 base::FieldTrialList::CreateFieldTrial("DataCompressionProxyRollout", |
| 670 "Enabled"); |
| 671 base::FieldTrialList::CreateFieldTrial("DataCompressionProxyCriticalBypass", |
| 672 "Enabled"); |
| 673 EXPECT_TRUE( |
| 674 DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial()); |
| 675 |
| 676 load_flags = net::LOAD_NORMAL; |
| 677 |
| 678 OnResolveProxyHandler(url, load_flags, &test_params, &info1); |
| 679 EXPECT_FALSE(info1.is_direct()); |
| 680 |
| 681 OnResolveProxyHandler(url, load_flags, &test_params, &info2); |
| 682 EXPECT_FALSE(info2.is_direct()); |
| 683 |
| 684 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
| 685 |
| 686 OnResolveProxyHandler(url, load_flags, &test_params, &info2); |
| 687 EXPECT_FALSE(info2.is_direct()); |
| 688 |
| 689 OnResolveProxyHandler(url, load_flags, &test_params, &info1); |
| 690 EXPECT_TRUE(info1.is_direct()); |
| 691 } |
| 692 |
614 } // namespace data_reduction_proxy | 693 } // namespace data_reduction_proxy |
OLD | NEW |