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