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" |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 int load_flags = net::LOAD_NORMAL; | 660 int load_flags = net::LOAD_NORMAL; |
661 GURL url("http://www.google.com/"); | 661 GURL url("http://www.google.com/"); |
662 | 662 |
663 TestDataReductionProxyParams test_params( | 663 TestDataReductionProxyParams test_params( |
664 DataReductionProxyParams::kAllowed | | 664 DataReductionProxyParams::kAllowed | |
665 DataReductionProxyParams::kFallbackAllowed | | 665 DataReductionProxyParams::kFallbackAllowed | |
666 DataReductionProxyParams::kPromoAllowed, | 666 DataReductionProxyParams::kPromoAllowed, |
667 TestDataReductionProxyParams::HAS_EVERYTHING & | 667 TestDataReductionProxyParams::HAS_EVERYTHING & |
668 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); | 668 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); |
669 | 669 |
670 // Data reduction proxy | 670 // Data reduction proxy info |
671 net::ProxyInfo info1; | 671 net::ProxyInfo data_reduction_proxy_info; |
672 std::string data_reduction_proxy; | 672 std::string data_reduction_proxy; |
673 base::TrimString(test_params.DefaultOrigin(), "/", &data_reduction_proxy); | 673 base::TrimString(test_params.DefaultOrigin(), "/", &data_reduction_proxy); |
674 info1.UseNamedProxy(data_reduction_proxy); | 674 data_reduction_proxy_info.UseNamedProxy(data_reduction_proxy); |
675 EXPECT_FALSE(info1.is_empty()); | 675 EXPECT_FALSE(data_reduction_proxy_info.is_empty()); |
676 | 676 |
677 // Other proxy | 677 // Data reduction proxy config |
678 net::ProxyInfo info2; | 678 net::ProxyConfig data_reduction_proxy_config; |
679 info2.UseNamedProxy("proxy.com"); | 679 data_reduction_proxy_config.proxy_rules().ParseFromString( |
680 EXPECT_FALSE(info2.is_empty()); | 680 "http=" + data_reduction_proxy + ",direct://;"); |
| 681 data_reduction_proxy_config.set_id(1); |
| 682 |
| 683 // Other proxy info |
| 684 net::ProxyInfo other_proxy_info; |
| 685 other_proxy_info.UseNamedProxy("proxy.com"); |
| 686 EXPECT_FALSE(other_proxy_info.is_empty()); |
| 687 |
| 688 // Direct |
| 689 net::ProxyInfo direct_proxy_info; |
| 690 direct_proxy_info.UseDirect(); |
| 691 EXPECT_TRUE(direct_proxy_info.is_direct()); |
| 692 |
| 693 // Empty retry info map |
| 694 net::ProxyRetryInfoMap empty_proxy_retry_info; |
| 695 |
| 696 // Retry info map with the data reduction proxy; |
| 697 net::ProxyRetryInfoMap data_reduction_proxy_retry_info; |
| 698 net::ProxyRetryInfo retry_info; |
| 699 retry_info.current_delay = base::TimeDelta::FromSeconds(1000); |
| 700 retry_info.bad_until = base::TimeTicks().Now() + retry_info.current_delay; |
| 701 retry_info.try_while_bad = false; |
| 702 data_reduction_proxy_retry_info[ |
| 703 data_reduction_proxy_info.proxy_server().ToURI()] = retry_info; |
| 704 |
| 705 net::ProxyInfo result; |
| 706 |
| 707 // The data reduction proxy is used. It should be used afterwards. |
| 708 result.Use(data_reduction_proxy_info); |
| 709 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
| 710 empty_proxy_retry_info, &test_params, &result); |
| 711 EXPECT_EQ(data_reduction_proxy_info.proxy_server(), result.proxy_server()); |
| 712 |
| 713 // Another proxy is used. It should be used afterwards. |
| 714 result.Use(other_proxy_info); |
| 715 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
| 716 empty_proxy_retry_info, &test_params, &result); |
| 717 EXPECT_EQ(other_proxy_info.proxy_server(), result.proxy_server()); |
| 718 |
| 719 // A direct connection is used. The data reduction proxy should be used |
| 720 // afterwards. |
| 721 // Another proxy is used. It should be used afterwards. |
| 722 result.Use(direct_proxy_info); |
| 723 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
| 724 empty_proxy_retry_info, &test_params, &result); |
| 725 EXPECT_EQ(data_reduction_proxy_info.proxy_server(), result.proxy_server()); |
| 726 |
| 727 // A direct connection is used, but the data reduction proxy is on the retry |
| 728 // list. A direct connection should be used afterwards. |
| 729 result.Use(direct_proxy_info); |
| 730 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
| 731 data_reduction_proxy_retry_info, &test_params, |
| 732 &result); |
| 733 EXPECT_TRUE(result.proxy_server().is_direct()); |
| 734 |
681 | 735 |
682 // Without DataCompressionProxyCriticalBypass Finch trial set, should never | 736 // Without DataCompressionProxyCriticalBypass Finch trial set, should never |
683 // bypass. | 737 // bypass. |
684 OnResolveProxyHandler(url, load_flags, &test_params, &info1); | 738 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
685 EXPECT_FALSE(info1.is_direct()); | 739 empty_proxy_retry_info, &test_params, |
| 740 &data_reduction_proxy_info); |
| 741 EXPECT_FALSE(data_reduction_proxy_info.is_direct()); |
686 | 742 |
687 OnResolveProxyHandler(url, load_flags, &test_params,&info2); | 743 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
688 EXPECT_FALSE(info2.is_direct()); | 744 empty_proxy_retry_info, &test_params, |
| 745 &other_proxy_info); |
| 746 EXPECT_FALSE(other_proxy_info.is_direct()); |
689 | 747 |
690 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | 748 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
691 | 749 |
692 OnResolveProxyHandler(url, load_flags, &test_params, &info1); | 750 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
693 EXPECT_FALSE(info1.is_direct()); | 751 empty_proxy_retry_info, &test_params, |
| 752 &data_reduction_proxy_info); |
| 753 EXPECT_FALSE(data_reduction_proxy_info.is_direct()); |
694 | 754 |
695 OnResolveProxyHandler(url, load_flags, &test_params, &info2); | 755 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
696 EXPECT_FALSE(info2.is_direct()); | 756 empty_proxy_retry_info, &test_params, |
| 757 &other_proxy_info); |
| 758 EXPECT_FALSE(other_proxy_info.is_direct()); |
697 | 759 |
698 // With Finch trial set, should only bypass if LOAD flag is set and the | 760 // With Finch trial set, should only bypass if LOAD flag is set and the |
699 // effective proxy is the data compression proxy. | 761 // effective proxy is the data compression proxy. |
700 base::FieldTrialList field_trial_list(new BadEntropyProvider()); | 762 base::FieldTrialList field_trial_list(new BadEntropyProvider()); |
701 base::FieldTrialList::CreateFieldTrial("DataCompressionProxyRollout", | 763 base::FieldTrialList::CreateFieldTrial("DataCompressionProxyRollout", |
702 "Enabled"); | 764 "Enabled"); |
703 base::FieldTrialList::CreateFieldTrial("DataCompressionProxyCriticalBypass", | 765 base::FieldTrialList::CreateFieldTrial("DataCompressionProxyCriticalBypass", |
704 "Enabled"); | 766 "Enabled"); |
705 EXPECT_TRUE( | 767 EXPECT_TRUE( |
706 DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial()); | 768 DataReductionProxyParams::IsIncludedInCriticalPathBypassFieldTrial()); |
707 | 769 |
708 load_flags = net::LOAD_NORMAL; | 770 load_flags = net::LOAD_NORMAL; |
709 | 771 |
710 OnResolveProxyHandler(url, load_flags, &test_params, &info1); | 772 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
711 EXPECT_FALSE(info1.is_direct()); | 773 empty_proxy_retry_info, &test_params, |
| 774 &data_reduction_proxy_info); |
| 775 EXPECT_FALSE(data_reduction_proxy_info.is_direct()); |
712 | 776 |
713 OnResolveProxyHandler(url, load_flags, &test_params, &info2); | 777 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
714 EXPECT_FALSE(info2.is_direct()); | 778 empty_proxy_retry_info, &test_params, |
| 779 &other_proxy_info); |
| 780 EXPECT_FALSE(other_proxy_info.is_direct()); |
715 | 781 |
716 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | 782 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
717 | 783 |
718 OnResolveProxyHandler(url, load_flags, &test_params, &info2); | 784 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
719 EXPECT_FALSE(info2.is_direct()); | 785 empty_proxy_retry_info, &test_params, |
| 786 &other_proxy_info); |
| 787 EXPECT_FALSE(other_proxy_info.is_direct()); |
720 | 788 |
721 OnResolveProxyHandler(url, load_flags, &test_params, &info1); | 789 OnResolveProxyHandler(url, load_flags, data_reduction_proxy_config, |
722 EXPECT_TRUE(info1.is_direct()); | 790 empty_proxy_retry_info, &test_params, |
| 791 &data_reduction_proxy_info); |
| 792 EXPECT_TRUE(data_reduction_proxy_info.is_direct()); |
723 } | 793 } |
724 | 794 |
725 } // namespace data_reduction_proxy | 795 } // namespace data_reduction_proxy |
OLD | NEW |