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 = 0; |
| 629 GURL url("http://www.google.com/"); |
| 630 |
| 631 // Data reduction proxy |
| 632 ProxyInfo info1; |
| 633 data_reduction_proxy.UseNamedProxy("proxy.googlezip.net:443"); |
| 634 |
| 635 // Other proxy |
| 636 ProxyInfo info2; |
| 637 data_reduction_proxy.UseNamedProxy("proxy.com"); |
| 638 |
| 639 // Without DataCompressionProxyCriticalBypass Finch trial set, should never |
| 640 // bypass. |
| 641 OnResolveProxyHandler(url, load_flags, &info1); |
| 642 EXPECT_FALSE(info1.is_direct()); |
| 643 EXPECT_FALSE(info1.did_bypass_proxy()); |
| 644 |
| 645 OnResolveProxyHandler(url, load_flags, &info2); |
| 646 EXPECT_FALSE(info2.is_direct()); |
| 647 EXPECT_FALSE(info2.did_bypass_proxy()); |
| 648 |
| 649 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
| 650 |
| 651 OnResolveProxyHandler(url, load_flags, &info1); |
| 652 EXPECT_FALSE(info1.is_direct()); |
| 653 EXPECT_FALSE(info1.did_bypass_proxy()); |
| 654 |
| 655 OnResolveProxyHandler(url, load_flags, &info2); |
| 656 EXPECT_FALSE(info2.is_direct()); |
| 657 EXPECT_FALSE(info2.did_bypass_proxy()); |
| 658 |
| 659 // With Finch trial set, should only bypass if LOAD flag is set and the |
| 660 // effective proxy is the data compression proxy. |
| 661 base::FieldTrialList field_trial_list(new BadEntropyProvider()); |
| 662 ASSERT_TRUE(base::FieldTrialList::CreateTrialsFromString( |
| 663 "DataCompressionProxyCriticalBypass/Enabled/", |
| 664 base::FieldTrialList::ACTIVATE_TRIALS, |
| 665 std::set<std::string>())); |
| 666 |
| 667 load_flags = 0; |
| 668 |
| 669 OnResolveProxyHandler(url, load_flags, &info1); |
| 670 EXPECT_FALSE(info1.is_direct()); |
| 671 EXPECT_FALSE(info1.did_bypass_proxy()); |
| 672 |
| 673 OnResolveProxyHandler(url, load_flags, &info2); |
| 674 EXPECT_FALSE(info2.is_direct()); |
| 675 EXPECT_FALSE(info2.did_bypass_proxy()); |
| 676 |
| 677 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
| 678 |
| 679 OnResolveProxyHandler(url, load_flags, &info2); |
| 680 EXPECT_FALSE(info2.is_direct()); |
| 681 EXPECT_FALSE(info2.did_bypass_proxy()); |
| 682 |
| 683 OnResolveProxyHandler(url, load_flags, &info1); |
| 684 EXPECT_TRUE(info1.is_direct()); |
| 685 EXPECT_TRUE(info1.did_bypass_proxy()); |
| 686 } |
| 687 |
614 } // namespace data_reduction_proxy | 688 } // namespace data_reduction_proxy |
OLD | NEW |