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_params.h" | 5 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params.h" |
6 | 6 |
7 #include <map> | |
8 | |
7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te st_utils.h" | 11 #include "components/data_reduction_proxy/browser/data_reduction_proxy_params_te st_utils.h" |
10 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " | 12 #include "components/data_reduction_proxy/common/data_reduction_proxy_switches.h " |
13 #include "net/proxy/proxy_retry_info.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
12 | 15 |
13 namespace data_reduction_proxy { | 16 namespace data_reduction_proxy { |
14 class DataReductionProxyParamsTest : public testing::Test { | 17 class DataReductionProxyParamsTest : public testing::Test { |
15 public: | 18 public: |
16 void CheckParams(const TestDataReductionProxyParams& params, | 19 void CheckParams(const TestDataReductionProxyParams& params, |
17 bool expected_init_result, | 20 bool expected_init_result, |
18 bool expected_allowed, | 21 bool expected_allowed, |
19 bool expected_fallback_allowed, | 22 bool expected_fallback_allowed, |
20 bool expected_alternative_allowed, | 23 bool expected_alternative_allowed, |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
551 std::pair<GURL, GURL> proxy_servers; | 554 std::pair<GURL, GURL> proxy_servers; |
552 EXPECT_EQ(tests[i].expected_result, | 555 EXPECT_EQ(tests[i].expected_result, |
553 params.IsDataReductionProxy( | 556 params.IsDataReductionProxy( |
554 tests[i].host_port_pair, &proxy_servers)); | 557 tests[i].host_port_pair, &proxy_servers)); |
555 EXPECT_TRUE(tests[i].expected_first.Equals( | 558 EXPECT_TRUE(tests[i].expected_first.Equals( |
556 net::HostPortPair::FromURL(proxy_servers.first))); | 559 net::HostPortPair::FromURL(proxy_servers.first))); |
557 EXPECT_TRUE(tests[i].expected_second.Equals( | 560 EXPECT_TRUE(tests[i].expected_second.Equals( |
558 net::HostPortPair::FromURL(proxy_servers.second))); | 561 net::HostPortPair::FromURL(proxy_servers.second))); |
559 } | 562 } |
560 } | 563 } |
564 | |
565 TEST_F(DataReductionProxyParamsTest, WereProxiesBypassed) { | |
566 const struct { | |
567 //proxy rules | |
568 bool allowed; | |
569 bool fallback_allowed; | |
570 bool alt_allowed; | |
571 bool ssl; | |
572 //proxies in retry map | |
573 bool origin; | |
574 bool fallback_origin; | |
575 bool alt_origin; | |
576 bool alt_fallback_origin; | |
577 bool ssl_origin; | |
578 //expected result | |
bengr
2014/07/19 00:13:01
no need for this comment.
megjablon
2014/07/21 19:44:45
Done.
| |
579 bool expected_result; | |
580 } tests[] = { | |
581 { | |
582 //proxy rules | |
583 false, | |
584 false, | |
585 false, | |
586 false, | |
587 //proxies in retry map | |
588 false, | |
589 false, | |
590 false, | |
591 false, | |
592 false, | |
593 //expected result | |
594 false, | |
595 }, | |
596 { | |
597 //proxy rules | |
598 true, | |
599 false, | |
600 false, | |
601 false, | |
602 //proxies in retry map | |
603 false, | |
604 false, | |
605 false, | |
606 false, | |
607 false, | |
608 //expected result | |
609 false, | |
610 }, | |
611 { | |
612 //proxy rules | |
613 true, | |
614 true, | |
615 false, | |
616 false, | |
617 //proxies in retry map | |
618 false, | |
619 false, | |
620 false, | |
621 false, | |
622 false, | |
623 //expected result | |
624 false, | |
625 }, | |
626 { | |
627 //proxy rules | |
bengr
2014/07/19 00:13:01
Always add a space after //
megjablon
2014/07/21 19:44:45
Done.
| |
628 true, | |
629 true, | |
630 true, | |
631 false, | |
632 //proxies in retry map | |
633 false, | |
634 false, | |
635 false, | |
636 false, | |
637 false, | |
638 //expected result | |
639 false, | |
640 }, | |
641 { | |
642 //proxy rules | |
643 true, | |
644 true, | |
645 true, | |
646 true, | |
647 //proxies in retry map | |
648 false, | |
649 false, | |
650 false, | |
651 false, | |
652 false, | |
653 //expected result | |
654 false, | |
655 }, | |
656 { | |
657 false, | |
658 false, | |
659 false, | |
660 true, | |
661 //proxies in retry map | |
662 false, | |
663 false, | |
664 false, | |
665 false, | |
666 true, | |
667 //expected result | |
668 false, | |
669 }, | |
670 { | |
671 //proxy rules | |
672 false, | |
673 false, | |
674 true, | |
675 true, | |
676 //proxies in retry map | |
677 false, | |
678 false, | |
679 false, | |
680 false, | |
681 true, | |
682 //expected result | |
683 true, | |
684 }, | |
685 { | |
686 //proxy rules | |
687 true, | |
688 true, | |
689 true, | |
690 true, | |
691 //proxies in retry map | |
692 false, | |
693 false, | |
694 false, | |
695 false, | |
696 true, | |
697 //expected result | |
698 true, | |
699 }, | |
700 { | |
701 //proxy rules | |
702 true, | |
703 false, | |
704 false, | |
705 false, | |
706 //proxies in retry map | |
707 true, | |
708 false, | |
709 false, | |
710 false, | |
711 false, | |
712 //expected result | |
713 true, | |
714 }, | |
715 { | |
716 //proxy rules | |
717 true, | |
718 true, | |
719 false, | |
720 false, | |
721 //proxies in retry map | |
722 true, | |
723 false, | |
724 false, | |
725 false, | |
726 false, | |
727 //expected result | |
728 false, | |
729 }, | |
730 { | |
731 //proxy rules | |
732 true, | |
733 true, | |
734 false, | |
735 false, | |
736 //proxies in retry map | |
737 true, | |
738 true, | |
739 false, | |
740 false, | |
741 false, | |
742 //expected result | |
743 true, | |
744 }, | |
745 { | |
746 //proxy rules | |
747 true, | |
748 true, | |
749 true, | |
750 false, | |
751 //proxies in retry map | |
752 true, | |
753 true, | |
754 false, | |
755 false, | |
756 false, | |
757 //expected result | |
758 true, | |
759 }, | |
760 { | |
761 //proxy rules | |
762 true, | |
763 true, | |
764 true, | |
765 false, | |
766 //proxies in retry map | |
767 true, | |
768 false, | |
769 true, | |
770 false, | |
771 false, | |
772 //expected result | |
773 false, | |
774 }, | |
775 { | |
776 //proxy rules | |
777 true, | |
778 true, | |
779 true, | |
780 false, | |
781 //proxies in retry map | |
782 false, | |
783 false, | |
784 true, | |
785 true, | |
786 false, | |
787 //expected result | |
788 true, | |
789 }, | |
790 { | |
791 //proxy rules | |
792 false, | |
793 true, | |
794 true, | |
795 false, | |
796 //proxies in retry map | |
797 false, | |
798 false, | |
799 true, | |
800 true, | |
801 false, | |
802 //expected result | |
803 true, | |
804 }, | |
805 { | |
806 //proxy rules | |
807 false, | |
808 true, | |
809 false, | |
810 false, | |
811 //proxies in retry map | |
812 false, | |
813 false, | |
814 true, | |
815 false, | |
816 false, | |
817 //expected result | |
818 false, | |
819 }, | |
820 { | |
821 //proxy rules | |
822 true, | |
823 true, | |
824 true, | |
825 false, | |
826 //proxies in retry map | |
827 true, | |
828 false, | |
829 true, | |
830 true, | |
831 false, | |
832 //expected result | |
833 true, | |
834 }, | |
835 { | |
836 //proxy rules | |
837 true, | |
838 true, | |
839 true, | |
840 false, | |
841 //proxies in retry map | |
842 true, | |
843 true, | |
844 true, | |
845 true, | |
846 true, | |
847 //expected result | |
848 true, | |
849 }, | |
850 { | |
851 //proxy rules | |
852 true, | |
853 true, | |
854 true, | |
855 true, | |
856 //proxies in retry map | |
857 true, | |
858 true, | |
859 true, | |
860 true, | |
861 true, | |
862 //expected result | |
863 true, | |
864 }, | |
865 { | |
866 //proxy rules | |
867 true, | |
868 true, | |
869 true, | |
870 true, | |
871 //proxies in retry map | |
872 true, | |
873 true, | |
874 true, | |
875 true, | |
876 false, | |
877 //expected result | |
878 false, | |
879 }, | |
880 }; | |
881 | |
882 // The retry list has the scheme prefix for https but not for http. | |
883 std::string origin = TestDataReductionProxyParams::DefaultOrigin(); | |
884 if (origin.find("https")==std::string::npos) { | |
bengr
2014/07/19 00:13:01
eek. this is busted for http://https.com
megjablon
2014/07/21 19:44:45
Done.
| |
885 origin = origin.substr(7); | |
886 } | |
887 std::string fallback_origin = | |
888 TestDataReductionProxyParams::DefaultFallbackOrigin(); | |
889 if (fallback_origin.find("https")==std::string::npos) { | |
890 fallback_origin = fallback_origin.substr(7); | |
891 } | |
892 std::string alt_origin = | |
893 TestDataReductionProxyParams::DefaultAltOrigin(); | |
894 if (alt_origin.find("https")==std::string::npos) { | |
895 alt_origin = alt_origin.substr(7); | |
896 } | |
897 std::string alt_fallback_origin = | |
898 TestDataReductionProxyParams::DefaultAltFallbackOrigin(); | |
899 if (alt_fallback_origin.find("https")==std::string::npos) { | |
900 alt_fallback_origin = alt_fallback_origin.substr(7); | |
901 } | |
902 std::string ssl_origin = | |
903 TestDataReductionProxyParams::DefaultSSLOrigin(); | |
904 if (ssl_origin.find("https")==std::string::npos) { | |
905 ssl_origin = ssl_origin.substr(7); | |
906 } | |
907 | |
908 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | |
909 int flags = 0; | |
910 if (tests[i].allowed) | |
911 flags |= DataReductionProxyParams::kAllowed; | |
912 if(tests[i].alt_allowed) | |
913 flags |= DataReductionProxyParams::kAlternativeAllowed; | |
914 if (tests[i].fallback_allowed) | |
915 flags |= DataReductionProxyParams::kFallbackAllowed; | |
916 TestDataReductionProxyParams params( | |
917 flags, TestDataReductionProxyParams::HAS_EVERYTHING & | |
918 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN); | |
919 | |
920 net::ProxyRetryInfoMap retry_map; | |
921 net::ProxyRetryInfo retry_info; | |
922 | |
923 // The retry list has the scheme prefix for https but not for http. | |
924 if (tests[i].origin) { | |
bengr
2014/07/19 00:13:01
Here and below can lose the curly braces.
megjablon
2014/07/21 19:44:45
Done.
| |
925 retry_map[origin] = retry_info; | |
926 } | |
927 if (tests[i].fallback_origin) { | |
928 retry_map[fallback_origin] = retry_info; | |
929 } | |
930 if (tests[i].alt_origin) { | |
931 retry_map[alt_origin] = retry_info; | |
932 } | |
933 if (tests[i].alt_fallback_origin) { | |
934 retry_map[alt_fallback_origin] = retry_info; | |
935 } | |
936 if (tests[i].ssl_origin) { | |
937 retry_map[ssl_origin] = retry_info; | |
938 } | |
939 | |
940 bool was_bypassed = params.WereProxiesBypassed(retry_map, | |
941 tests[i].ssl, | |
942 NULL); | |
943 | |
944 EXPECT_EQ(tests[i].expected_result, was_bypassed); | |
945 } | |
946 } | |
561 } // namespace data_reduction_proxy | 947 } // namespace data_reduction_proxy |
OLD | NEW |