Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: components/data_reduction_proxy/browser/data_reduction_proxy_params_unittest.cc

Issue 390533003: Bypassed Bytes UMAs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving #if defined(SPDY_PROXY_AUTH_ORIGIN) Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 flags
576 bool allowed;
577 bool fallback_allowed;
578 bool alt_allowed;
579 // is https request
580 bool is_https;
581 // proxies in retry map
582 bool origin;
583 bool fallback_origin;
584 bool alt_origin;
585 bool alt_fallback_origin;
586 bool ssl_origin;
587
588 bool expected_result;
589 } tests[] = {
590 { // proxy flags
591 false,
592 false,
593 false,
594 // is https request
595 false,
596 // proxies in retry map
597 false,
598 false,
599 false,
600 false,
601 false,
602 // expected result
603 false,
604 },
605 { // proxy flags
606 true,
607 false,
608 false,
609 // is https request
610 false,
611 // proxies in retry map
612 false,
613 false,
614 false,
615 false,
616 false,
617 // expected result
618 false,
619 },
620 { // proxy flags
621 true,
622 true,
623 false,
624 // is https request
625 false,
626 // proxies in retry map
627 false,
628 false,
629 false,
630 false,
631 false,
632 // expected result
633 false,
634 },
635 { // proxy flags
636 true,
637 true,
638 true,
639 // is https request
640 false,
641 // proxies in retry map
642 false,
643 false,
644 false,
645 false,
646 false,
647 // expected result
648 false,
649 },
650 { // proxy flags
651 true,
652 true,
653 true,
654 // is https request
655 true,
656 // proxies in retry map
657 false,
658 false,
659 false,
660 false,
661 false,
662 // expected result
663 false,
664 },
665 { // proxy flags
666 false,
667 false,
668 false,
669 // is https request
670 true,
671 // proxies in retry map
672 false,
673 false,
674 false,
675 false,
676 true,
677 // expected result
678 false,
679 },
680 { // proxy flags
681 false,
682 false,
683 true,
684 // is https request
685 true,
686 // proxies in retry map
687 false,
688 false,
689 false,
690 false,
691 true,
692 // expected result
693 true,
694 },
695 { // proxy flags
696 true,
697 true,
698 true,
699 // is https request
700 true,
701 // proxies in retry map
702 false,
703 false,
704 false,
705 false,
706 true,
707 // expected result
708 true,
709 },
710 { // proxy flags
711 true,
712 false,
713 false,
714 // is https request
715 false,
716 // proxies in retry map
717 true,
718 false,
719 false,
720 false,
721 false,
722 // expected result
723 true,
724 },
725 { // proxy flags
726 true,
727 true,
728 false,
729 // is https request
730 false,
731 // proxies in retry map
732 true,
733 false,
734 false,
735 false,
736 false,
737 // expected result
738 false,
739 },
740 { // proxy flags
741 true,
742 true,
743 false,
744 // is https request
745 false,
746 // proxies in retry map
747 true,
748 true,
749 false,
750 false,
751 false,
752 // expected result
753 true,
754 },
755 { // proxy flags
756 true,
757 true,
758 true,
759 // is https request
760 false,
761 // proxies in retry map
762 true,
763 true,
764 false,
765 false,
766 false,
767 // expected result
768 true,
769 },
770 { // proxy flags
771 true,
772 true,
773 true,
774 // is https request
775 false,
776 // proxies in retry map
777 true,
778 false,
779 true,
780 false,
781 false,
782 // expected result
783 false,
784 },
785 { // proxy flags
786 true,
787 true,
788 true,
789 // is https request
790 false,
791 // proxies in retry map
792 false,
793 false,
794 true,
795 true,
796 false,
797 // expected result
798 true,
799 },
800 { // proxy flags
801 false,
802 true,
803 true,
804 // is https request
805 false,
806 // proxies in retry map
807 false,
808 false,
809 true,
810 true,
811 false,
812 // expected result
813 true,
814 },
815 { // proxy flags
816 false,
817 true,
818 false,
819 // is https request
820 false,
821 // proxies in retry map
822 false,
823 false,
824 true,
825 false,
826 false,
827 // expected result
828 false,
829 },
830 { // proxy flags
831 true,
832 true,
833 true,
834 // is https request
835 false,
836 // proxies in retry map
837 true,
838 false,
839 true,
840 true,
841 false,
842 // expected result
843 true,
844 },
845 { // proxy flags
846 true,
847 true,
848 true,
849 // is https request
850 false,
851 // proxies in retry map
852 true,
853 true,
854 true,
855 true,
856 true,
857 // expected result
858 true,
859 },
860 { // proxy flags
861 true,
862 true,
863 true,
864 // is https request
865 true,
866 // proxies in retry map
867 true,
868 true,
869 true,
870 true,
871 true,
872 // expected result
873 true,
874 },
875 { // proxy flags
876 true,
877 true,
878 true,
879 // is https request
880 true,
881 // proxies in retry map
882 true,
883 true,
884 true,
885 true,
886 false,
887 // expected result
888 false,
889 },
890 };
891
892 // The retry map has the scheme prefix for https but not for http.
893 std::string origin = GetRetryMapKeyFromOrigin(
894 TestDataReductionProxyParams::DefaultOrigin());
895 std::string fallback_origin =GetRetryMapKeyFromOrigin(
896 TestDataReductionProxyParams::DefaultFallbackOrigin());
897 std::string alt_origin = GetRetryMapKeyFromOrigin(
898 TestDataReductionProxyParams::DefaultAltOrigin());
899 std::string alt_fallback_origin = GetRetryMapKeyFromOrigin(
900 TestDataReductionProxyParams::DefaultAltFallbackOrigin());
901 std::string ssl_origin = GetRetryMapKeyFromOrigin(
902 TestDataReductionProxyParams::DefaultSSLOrigin());
903
904 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
905 int flags = 0;
906 if (tests[i].allowed)
907 flags |= DataReductionProxyParams::kAllowed;
908 if (tests[i].alt_allowed)
909 flags |= DataReductionProxyParams::kAlternativeAllowed;
910 if (tests[i].fallback_allowed)
911 flags |= DataReductionProxyParams::kFallbackAllowed;
912 unsigned int has_definitions =
913 TestDataReductionProxyParams::HAS_EVERYTHING &
914 ~TestDataReductionProxyParams::HAS_DEV_ORIGIN;
915 TestDataReductionProxyParams params(flags, has_definitions);
916
917 net::ProxyRetryInfoMap retry_map;
918 net::ProxyRetryInfo retry_info;
919
920 if (tests[i].origin)
921 retry_map[origin] = retry_info;
922 if (tests[i].fallback_origin)
923 retry_map[fallback_origin] = retry_info;
924 if (tests[i].alt_origin)
925 retry_map[alt_origin] = retry_info;
926 if (tests[i].alt_fallback_origin)
927 retry_map[alt_fallback_origin] = retry_info;
928 if (tests[i].ssl_origin)
929 retry_map[ssl_origin] = retry_info;
930
931 bool was_bypassed = params.AreProxiesBypassed(retry_map,
932 tests[i].is_https,
933 NULL);
934
935 EXPECT_EQ(tests[i].expected_result, was_bypassed);
936 }
937 }
561 } // namespace data_reduction_proxy 938 } // namespace data_reduction_proxy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698