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

Side by Side Diff: net/proxy/proxy_config_service_linux_unittest.cc

Issue 2094913002: Make base::Environment::Create() return unique_ptrs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit, rebase Created 4 years, 5 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/proxy/proxy_config_service_linux.h" 5 #include "net/proxy/proxy_config_service_linux.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 17 matching lines...) Expand all
28 #include "testing/platform_test.h" 28 #include "testing/platform_test.h"
29 29
30 namespace net { 30 namespace net {
31 namespace { 31 namespace {
32 32
33 // Set of values for all environment variables that we might 33 // Set of values for all environment variables that we might
34 // query. NULL represents an unset variable. 34 // query. NULL represents an unset variable.
35 struct EnvVarValues { 35 struct EnvVarValues {
36 // The strange capitalization is so that the field matches the 36 // The strange capitalization is so that the field matches the
37 // environment variable name exactly. 37 // environment variable name exactly.
38 const char *DESKTOP_SESSION, *HOME, 38 const char* DESKTOP_SESSION;
39 *KDEHOME, *KDE_SESSION_VERSION, 39 const char* HOME;
40 *XDG_CURRENT_DESKTOP, 40 const char* KDEHOME;
41 *auto_proxy, *all_proxy, 41 const char* KDE_SESSION_VERSION;
42 *http_proxy, *https_proxy, *ftp_proxy, 42 const char* XDG_CURRENT_DESKTOP;
43 *SOCKS_SERVER, *SOCKS_VERSION, 43 const char* auto_proxy;
44 *no_proxy; 44 const char* all_proxy;
45 const char* http_proxy;
46 const char* https_proxy;
47 const char* ftp_proxy;
48 const char* SOCKS_SERVER;
49 const char* SOCKS_VERSION;
50 const char* no_proxy;
45 }; 51 };
46 52
47 // Undo macro pollution from GDK includes (from message_loop.h). 53 // Undo macro pollution from GDK includes (from message_loop.h).
48 #undef TRUE 54 #undef TRUE
49 #undef FALSE 55 #undef FALSE
50 56
51 // So as to distinguish between an unset gconf boolean variable and 57 // So as to distinguish between an unset gconf boolean variable and
52 // one that is false. 58 // one that is false.
53 enum BoolSettingValue { 59 enum BoolSettingValue {
54 UNSET = 0, TRUE, FALSE 60 UNSET = 0, TRUE, FALSE
55 }; 61 };
56 62
57 // Set of values for all gconf settings that we might query. 63 // Set of values for all gconf settings that we might query.
58 struct GConfValues { 64 struct GConfValues {
59 // strings 65 // strings
60 const char *mode, *autoconfig_url, 66 const char* mode;
61 *http_host, *secure_host, *ftp_host, *socks_host; 67 const char* autoconfig_url;
68 const char* http_host;
69 const char* secure_host;
70 const char* ftp_host;
71 const char* socks_host;
62 // integers 72 // integers
63 int http_port, secure_port, ftp_port, socks_port; 73 int http_port;
74 int secure_port;
75 int ftp_port;
76 int socks_port;
64 // booleans 77 // booleans
65 BoolSettingValue use_proxy, same_proxy, use_auth; 78 BoolSettingValue use_proxy;
79 BoolSettingValue same_proxy;
80 BoolSettingValue use_auth;
66 // string list 81 // string list
67 std::vector<std::string> ignore_hosts; 82 std::vector<std::string> ignore_hosts;
68 }; 83 };
69 84
70 // Mapping from a setting name to the location of the corresponding 85 // Mapping from a setting name to the location of the corresponding
71 // value (inside a EnvVarValues or GConfValues struct). 86 // value (inside a EnvVarValues or GConfValues struct).
72 template<typename key_type, typename value_type> 87 template<typename key_type, typename value_type>
73 struct SettingsTable { 88 struct SettingsTable {
74 typedef std::map<key_type, value_type*> map_type; 89 typedef std::map<key_type, value_type*> map_type;
75 90
76 // Gets the value from its location 91 // Gets the value from its location
77 value_type Get(key_type key) { 92 value_type Get(key_type key) {
78 typename map_type::const_iterator it = settings.find(key); 93 auto it = settings.find(key);
79 // In case there's a typo or the unittest becomes out of sync. 94 // In case there's a typo or the unittest becomes out of sync.
80 CHECK(it != settings.end()) << "key " << key << " not found"; 95 CHECK(it != settings.end()) << "key " << key << " not found";
81 value_type* value_ptr = it->second; 96 value_type* value_ptr = it->second;
82 return *value_ptr; 97 return *value_ptr;
83 } 98 }
84 99
85 map_type settings; 100 map_type settings;
86 }; 101 };
87 102
88 class MockEnvironment : public base::Environment { 103 class MockEnvironment : public base::Environment {
89 public: 104 public:
90 MockEnvironment() { 105 MockEnvironment() {
91 #define ENTRY(x) table[#x] = &values.x 106 #define ENTRY(x) table_[#x] = &values.x
92 ENTRY(DESKTOP_SESSION); 107 ENTRY(DESKTOP_SESSION);
93 ENTRY(HOME); 108 ENTRY(HOME);
94 ENTRY(KDEHOME); 109 ENTRY(KDEHOME);
95 ENTRY(KDE_SESSION_VERSION); 110 ENTRY(KDE_SESSION_VERSION);
96 ENTRY(XDG_CURRENT_DESKTOP); 111 ENTRY(XDG_CURRENT_DESKTOP);
97 ENTRY(auto_proxy); 112 ENTRY(auto_proxy);
98 ENTRY(all_proxy); 113 ENTRY(all_proxy);
99 ENTRY(http_proxy); 114 ENTRY(http_proxy);
100 ENTRY(https_proxy); 115 ENTRY(https_proxy);
101 ENTRY(ftp_proxy); 116 ENTRY(ftp_proxy);
102 ENTRY(no_proxy); 117 ENTRY(no_proxy);
103 ENTRY(SOCKS_SERVER); 118 ENTRY(SOCKS_SERVER);
104 ENTRY(SOCKS_VERSION); 119 ENTRY(SOCKS_VERSION);
105 #undef ENTRY 120 #undef ENTRY
106 Reset(); 121 Reset();
107 } 122 }
108 123
109 // Zeroes all environment values. 124 // Zeroes all environment values.
110 void Reset() { 125 void Reset() {
111 EnvVarValues zero_values = { 0 }; 126 EnvVarValues zero_values = { 0 };
112 values = zero_values; 127 values = zero_values;
113 } 128 }
114 129
115 // Begin base::Environment implementation. 130 // Begin base::Environment implementation.
116 bool GetVar(const char* variable_name, std::string* result) override { 131 bool GetVar(base::StringPiece variable_name, std::string* result) override {
117 std::map<std::string, const char**>::iterator it = 132 auto it = table_.find(variable_name);
118 table.find(variable_name); 133 if (it == table_.end() || !*it->second)
119 if (it != table.end() && *(it->second) != NULL) { 134 return false;
120 // Note that the variable may be defined but empty. 135
121 *result = *(it->second); 136 // Note that the variable may be defined but empty.
122 return true; 137 *result = *(it->second);
123 } 138 return true;
124 return false;
125 } 139 }
126 140
127 bool SetVar(const char* variable_name, 141 bool SetVar(base::StringPiece variable_name,
128 const std::string& new_value) override { 142 const std::string& new_value) override {
129 ADD_FAILURE(); 143 ADD_FAILURE();
130 return false; 144 return false;
131 } 145 }
132 146
133 bool UnSetVar(const char* variable_name) override { 147 bool UnSetVar(base::StringPiece variable_name) override {
134 ADD_FAILURE(); 148 ADD_FAILURE();
135 return false; 149 return false;
136 } 150 }
137 // End base::Environment implementation. 151 // End base::Environment implementation.
138 152
139 // Intentionally public, for convenience when setting up a test. 153 // Intentionally public, for convenience when setting up a test.
140 EnvVarValues values; 154 EnvVarValues values;
141 155
142 private: 156 private:
143 std::map<std::string, const char**> table; 157 std::map<base::StringPiece, const char**> table_;
144 }; 158 };
145 159
146 class MockSettingGetter 160 class MockSettingGetter
147 : public ProxyConfigServiceLinux::SettingGetter { 161 : public ProxyConfigServiceLinux::SettingGetter {
148 public: 162 public:
149 typedef ProxyConfigServiceLinux::SettingGetter SettingGetter; 163 typedef ProxyConfigServiceLinux::SettingGetter SettingGetter;
150 MockSettingGetter() { 164 MockSettingGetter() {
151 #define ENTRY(key, field) \ 165 #define ENTRY(key, field) \
152 strings_table.settings[SettingGetter::key] = &values.field 166 strings_table.settings[SettingGetter::key] = &values.field
153 ENTRY(PROXY_MODE, mode); 167 ENTRY(PROXY_MODE, mode);
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 GURL(), // pac_url 695 GURL(), // pac_url
682 ProxyRulesExpectation::Single( 696 ProxyRulesExpectation::Single(
683 "www.google.com:80", // single proxy 697 "www.google.com:80", // single proxy
684 "*.google.com"), // bypass rules 698 "*.google.com"), // bypass rules
685 }, 699 },
686 }; 700 };
687 701
688 for (size_t i = 0; i < arraysize(tests); ++i) { 702 for (size_t i = 0; i < arraysize(tests); ++i) {
689 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, 703 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
690 tests[i].description.c_str())); 704 tests[i].description.c_str()));
691 MockEnvironment* env = new MockEnvironment; 705 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
692 MockSettingGetter* setting_getter = new MockSettingGetter; 706 MockSettingGetter* setting_getter = new MockSettingGetter;
693 SynchConfigGetter sync_config_getter( 707 SynchConfigGetter sync_config_getter(
694 new ProxyConfigServiceLinux(env, setting_getter)); 708 new ProxyConfigServiceLinux(std::move(env), setting_getter));
695 ProxyConfig config; 709 ProxyConfig config;
696 setting_getter->values = tests[i].values; 710 setting_getter->values = tests[i].values;
697 sync_config_getter.SetupAndInitialFetch(); 711 sync_config_getter.SetupAndInitialFetch();
698 ProxyConfigService::ConfigAvailability availability = 712 ProxyConfigService::ConfigAvailability availability =
699 sync_config_getter.SyncGetLatestProxyConfig(&config); 713 sync_config_getter.SyncGetLatestProxyConfig(&config);
700 EXPECT_EQ(tests[i].availability, availability); 714 EXPECT_EQ(tests[i].availability, availability);
701 715
702 if (availability == ProxyConfigService::CONFIG_VALID) { 716 if (availability == ProxyConfigService::CONFIG_VALID) {
703 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); 717 EXPECT_EQ(tests[i].auto_detect, config.auto_detect());
704 EXPECT_EQ(tests[i].pac_url, config.pac_url()); 718 EXPECT_EQ(tests[i].pac_url, config.pac_url());
(...skipping 10 matching lines...) Expand all
715 729
716 // Input. 730 // Input.
717 EnvVarValues values; 731 EnvVarValues values;
718 732
719 // Expected outputs (availability and fields of ProxyConfig). 733 // Expected outputs (availability and fields of ProxyConfig).
720 ProxyConfigService::ConfigAvailability availability; 734 ProxyConfigService::ConfigAvailability availability;
721 bool auto_detect; 735 bool auto_detect;
722 GURL pac_url; 736 GURL pac_url;
723 ProxyRulesExpectation proxy_rules; 737 ProxyRulesExpectation proxy_rules;
724 } tests[] = { 738 } tests[] = {
725 { 739 {
726 TEST_DESC("No proxying"), 740 TEST_DESC("No proxying"),
727 { // Input. 741 {
728 NULL, // DESKTOP_SESSION 742 // Input.
729 NULL, // HOME 743 nullptr, // DESKTOP_SESSION
730 NULL, // KDEHOME 744 nullptr, // HOME
731 NULL, // KDE_SESSION_VERSION 745 nullptr, // KDEHOME
732 NULL, // XDG_CURRENT_DESKTOP 746 nullptr, // KDE_SESSION_VERSION
733 NULL, // auto_proxy 747 nullptr, // XDG_CURRENT_DESKTOP
734 NULL, // all_proxy 748 nullptr, // auto_proxy
735 NULL, NULL, NULL, // per-proto proxies 749 nullptr, // all_proxy
736 NULL, NULL, // SOCKS 750 nullptr, nullptr, nullptr, // per-proto proxies
737 "*", // no_proxy 751 nullptr, nullptr, // SOCKS
738 }, 752 "*", // no_proxy
739 753 },
740 // Expected result. 754
741 ProxyConfigService::CONFIG_VALID, 755 // Expected result.
742 false, // auto_detect 756 ProxyConfigService::CONFIG_VALID,
743 GURL(), // pac_url 757 false, // auto_detect
744 ProxyRulesExpectation::Empty(), 758 GURL(), // pac_url
745 }, 759 ProxyRulesExpectation::Empty(),
746 760 },
747 { 761
748 TEST_DESC("Auto detect"), 762 {
749 { // Input. 763 TEST_DESC("Auto detect"),
750 NULL, // DESKTOP_SESSION 764 {
751 NULL, // HOME 765 // Input.
752 NULL, // KDEHOME 766 nullptr, // DESKTOP_SESSION
753 NULL, // KDE_SESSION_VERSION 767 nullptr, // HOME
754 NULL, // XDG_CURRENT_DESKTOP 768 nullptr, // KDEHOME
755 "", // auto_proxy 769 nullptr, // KDE_SESSION_VERSION
756 NULL, // all_proxy 770 nullptr, // XDG_CURRENT_DESKTOP
757 NULL, NULL, NULL, // per-proto proxies 771 "", // auto_proxy
758 NULL, NULL, // SOCKS 772 nullptr, // all_proxy
759 NULL, // no_proxy 773 nullptr, nullptr, nullptr, // per-proto proxies
760 }, 774 nullptr, nullptr, // SOCKS
761 775 nullptr, // no_proxy
762 // Expected result. 776 },
763 ProxyConfigService::CONFIG_VALID, 777
764 true, // auto_detect 778 // Expected result.
765 GURL(), // pac_url 779 ProxyConfigService::CONFIG_VALID,
766 ProxyRulesExpectation::Empty(), 780 true, // auto_detect
767 }, 781 GURL(), // pac_url
768 782 ProxyRulesExpectation::Empty(),
769 { 783 },
770 TEST_DESC("Valid PAC URL"), 784
771 { // Input. 785 {
772 NULL, // DESKTOP_SESSION 786 TEST_DESC("Valid PAC URL"),
773 NULL, // HOME 787 {
774 NULL, // KDEHOME 788 // Input.
775 NULL, // KDE_SESSION_VERSION 789 nullptr, // DESKTOP_SESSION
776 NULL, // XDG_CURRENT_DESKTOP 790 nullptr, // HOME
777 "http://wpad/wpad.dat", // auto_proxy 791 nullptr, // KDEHOME
778 NULL, // all_proxy 792 nullptr, // KDE_SESSION_VERSION
779 NULL, NULL, NULL, // per-proto proxies 793 nullptr, // XDG_CURRENT_DESKTOP
780 NULL, NULL, // SOCKS 794 "http://wpad/wpad.dat", // auto_proxy
781 NULL, // no_proxy 795 nullptr, // all_proxy
782 }, 796 nullptr, nullptr, nullptr, // per-proto proxies
783 797 nullptr, nullptr, // SOCKS
784 // Expected result. 798 nullptr, // no_proxy
785 ProxyConfigService::CONFIG_VALID, 799 },
786 false, // auto_detect 800
787 GURL("http://wpad/wpad.dat"), // pac_url 801 // Expected result.
788 ProxyRulesExpectation::Empty(), 802 ProxyConfigService::CONFIG_VALID,
789 }, 803 false, // auto_detect
790 804 GURL("http://wpad/wpad.dat"), // pac_url
791 { 805 ProxyRulesExpectation::Empty(),
792 TEST_DESC("Invalid PAC URL"), 806 },
793 { // Input. 807
794 NULL, // DESKTOP_SESSION 808 {
795 NULL, // HOME 809 TEST_DESC("Invalid PAC URL"),
796 NULL, // KDEHOME 810 {
797 NULL, // KDE_SESSION_VERSION 811 // Input.
798 NULL, // XDG_CURRENT_DESKTOP 812 nullptr, // DESKTOP_SESSION
799 "wpad.dat", // auto_proxy 813 nullptr, // HOME
800 NULL, // all_proxy 814 nullptr, // KDEHOME
801 NULL, NULL, NULL, // per-proto proxies 815 nullptr, // KDE_SESSION_VERSION
802 NULL, NULL, // SOCKS 816 nullptr, // XDG_CURRENT_DESKTOP
803 NULL, // no_proxy 817 "wpad.dat", // auto_proxy
804 }, 818 nullptr, // all_proxy
805 819 nullptr, nullptr, nullptr, // per-proto proxies
806 // Expected result. 820 nullptr, nullptr, // SOCKS
807 ProxyConfigService::CONFIG_VALID, 821 nullptr, // no_proxy
808 false, // auto_detect 822 },
809 GURL(), // pac_url 823
810 ProxyRulesExpectation::Empty(), 824 // Expected result.
811 }, 825 ProxyConfigService::CONFIG_VALID,
812 826 false, // auto_detect
813 { 827 GURL(), // pac_url
814 TEST_DESC("Single-host in proxy list"), 828 ProxyRulesExpectation::Empty(),
815 { // Input. 829 },
816 NULL, // DESKTOP_SESSION 830
817 NULL, // HOME 831 {
818 NULL, // KDEHOME 832 TEST_DESC("Single-host in proxy list"),
819 NULL, // KDE_SESSION_VERSION 833 {
820 NULL, // XDG_CURRENT_DESKTOP 834 // Input.
821 NULL, // auto_proxy 835 nullptr, // DESKTOP_SESSION
822 "www.google.com", // all_proxy 836 nullptr, // HOME
823 NULL, NULL, NULL, // per-proto proxies 837 nullptr, // KDEHOME
824 NULL, NULL, // SOCKS 838 nullptr, // KDE_SESSION_VERSION
825 NULL, // no_proxy 839 nullptr, // XDG_CURRENT_DESKTOP
826 }, 840 nullptr, // auto_proxy
827 841 "www.google.com", // all_proxy
828 // Expected result. 842 nullptr, nullptr, nullptr, // per-proto proxies
829 ProxyConfigService::CONFIG_VALID, 843 nullptr, nullptr, // SOCKS
830 false, // auto_detect 844 nullptr, // no_proxy
831 GURL(), // pac_url 845 },
832 ProxyRulesExpectation::Single( 846
833 "www.google.com:80", // single proxy 847 // Expected result.
834 ""), // bypass rules 848 ProxyConfigService::CONFIG_VALID,
835 }, 849 false, // auto_detect
836 850 GURL(), // pac_url
837 { 851 ProxyRulesExpectation::Single("www.google.com:80", // single proxy
838 TEST_DESC("Single-host, different port"), 852 ""), // bypass rules
839 { // Input. 853 },
840 NULL, // DESKTOP_SESSION 854
841 NULL, // HOME 855 {
842 NULL, // KDEHOME 856 TEST_DESC("Single-host, different port"),
843 NULL, // KDE_SESSION_VERSION 857 {
844 NULL, // XDG_CURRENT_DESKTOP 858 // Input.
845 NULL, // auto_proxy 859 nullptr, // DESKTOP_SESSION
846 "www.google.com:99", // all_proxy 860 nullptr, // HOME
847 NULL, NULL, NULL, // per-proto proxies 861 nullptr, // KDEHOME
848 NULL, NULL, // SOCKS 862 nullptr, // KDE_SESSION_VERSION
849 NULL, // no_proxy 863 nullptr, // XDG_CURRENT_DESKTOP
850 }, 864 nullptr, // auto_proxy
851 865 "www.google.com:99", // all_proxy
852 // Expected result. 866 nullptr, nullptr, nullptr, // per-proto proxies
853 ProxyConfigService::CONFIG_VALID, 867 nullptr, nullptr, // SOCKS
854 false, // auto_detect 868 nullptr, // no_proxy
855 GURL(), // pac_url 869 },
856 ProxyRulesExpectation::Single( 870
857 "www.google.com:99", // single 871 // Expected result.
858 ""), // bypass rules 872 ProxyConfigService::CONFIG_VALID,
859 }, 873 false, // auto_detect
860 874 GURL(), // pac_url
861 { 875 ProxyRulesExpectation::Single("www.google.com:99", // single
862 TEST_DESC("Tolerate a scheme"), 876 ""), // bypass rules
863 { // Input. 877 },
864 NULL, // DESKTOP_SESSION 878
865 NULL, // HOME 879 {
866 NULL, // KDEHOME 880 TEST_DESC("Tolerate a scheme"),
867 NULL, // KDE_SESSION_VERSION 881 {
868 NULL, // XDG_CURRENT_DESKTOP 882 // Input.
869 NULL, // auto_proxy 883 nullptr, // DESKTOP_SESSION
870 "http://www.google.com:99", // all_proxy 884 nullptr, // HOME
871 NULL, NULL, NULL, // per-proto proxies 885 nullptr, // KDEHOME
872 NULL, NULL, // SOCKS 886 nullptr, // KDE_SESSION_VERSION
873 NULL, // no_proxy 887 nullptr, // XDG_CURRENT_DESKTOP
874 }, 888 nullptr, // auto_proxy
875 889 "http://www.google.com:99", // all_proxy
876 // Expected result. 890 nullptr, nullptr, nullptr, // per-proto proxies
877 ProxyConfigService::CONFIG_VALID, 891 nullptr, nullptr, // SOCKS
878 false, // auto_detect 892 nullptr, // no_proxy
879 GURL(), // pac_url 893 },
880 ProxyRulesExpectation::Single( 894
881 "www.google.com:99", // single proxy 895 // Expected result.
882 ""), // bypass rules 896 ProxyConfigService::CONFIG_VALID,
883 }, 897 false, // auto_detect
884 898 GURL(), // pac_url
885 { 899 ProxyRulesExpectation::Single("www.google.com:99", // single proxy
886 TEST_DESC("Per-scheme proxy rules"), 900 ""), // bypass rules
887 { // Input. 901 },
888 NULL, // DESKTOP_SESSION 902
889 NULL, // HOME 903 {
890 NULL, // KDEHOME 904 TEST_DESC("Per-scheme proxy rules"),
891 NULL, // KDE_SESSION_VERSION 905 {
892 NULL, // XDG_CURRENT_DESKTOP 906 // Input.
893 NULL, // auto_proxy 907 nullptr, // DESKTOP_SESSION
894 NULL, // all_proxy 908 nullptr, // HOME
895 "www.google.com:80", "www.foo.com:110", "ftp.foo.com:121", // per-proto 909 nullptr, // KDEHOME
896 NULL, NULL, // SOCKS 910 nullptr, // KDE_SESSION_VERSION
897 NULL, // no_proxy 911 nullptr, // XDG_CURRENT_DESKTOP
898 }, 912 nullptr, // auto_proxy
899 913 nullptr, // all_proxy
900 // Expected result. 914 "www.google.com:80", "www.foo.com:110",
901 ProxyConfigService::CONFIG_VALID, 915 "ftp.foo.com:121", // per-proto
902 false, // auto_detect 916 nullptr, nullptr, // SOCKS
903 GURL(), // pac_url 917 nullptr, // no_proxy
904 ProxyRulesExpectation::PerScheme( 918 },
905 "www.google.com:80", // http 919
906 "www.foo.com:110", // https 920 // Expected result.
907 "ftp.foo.com:121", // ftp 921 ProxyConfigService::CONFIG_VALID,
908 ""), // bypass rules 922 false, // auto_detect
909 }, 923 GURL(), // pac_url
910 924 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
911 { 925 "www.foo.com:110", // https
912 TEST_DESC("socks"), 926 "ftp.foo.com:121", // ftp
913 { // Input. 927 ""), // bypass rules
914 NULL, // DESKTOP_SESSION 928 },
915 NULL, // HOME 929
916 NULL, // KDEHOME 930 {
917 NULL, // KDE_SESSION_VERSION 931 TEST_DESC("socks"),
918 NULL, // XDG_CURRENT_DESKTOP 932 {
919 NULL, // auto_proxy 933 // Input.
920 "", // all_proxy 934 nullptr, // DESKTOP_SESSION
921 NULL, NULL, NULL, // per-proto proxies 935 nullptr, // HOME
922 "socks.com:888", NULL, // SOCKS 936 nullptr, // KDEHOME
923 NULL, // no_proxy 937 nullptr, // KDE_SESSION_VERSION
924 }, 938 nullptr, // XDG_CURRENT_DESKTOP
925 939 nullptr, // auto_proxy
926 // Expected result. 940 "", // all_proxy
927 ProxyConfigService::CONFIG_VALID, 941 nullptr, nullptr, nullptr, // per-proto proxies
928 false, // auto_detect 942 "socks.com:888", nullptr, // SOCKS
929 GURL(), // pac_url 943 nullptr, // no_proxy
930 ProxyRulesExpectation::Single( 944 },
931 "socks5://socks.com:888", // single proxy 945
932 ""), // bypass rules 946 // Expected result.
933 }, 947 ProxyConfigService::CONFIG_VALID,
934 948 false, // auto_detect
935 { 949 GURL(), // pac_url
936 TEST_DESC("socks4"), 950 ProxyRulesExpectation::Single(
937 { // Input. 951 "socks5://socks.com:888", // single proxy
938 NULL, // DESKTOP_SESSION 952 ""), // bypass rules
939 NULL, // HOME 953 },
940 NULL, // KDEHOME 954
941 NULL, // KDE_SESSION_VERSION 955 {
942 NULL, // XDG_CURRENT_DESKTOP 956 TEST_DESC("socks4"),
943 NULL, // auto_proxy 957 {
944 "", // all_proxy 958 // Input.
945 NULL, NULL, NULL, // per-proto proxies 959 nullptr, // DESKTOP_SESSION
946 "socks.com:888", "4", // SOCKS 960 nullptr, // HOME
947 NULL, // no_proxy 961 nullptr, // KDEHOME
948 }, 962 nullptr, // KDE_SESSION_VERSION
949 963 nullptr, // XDG_CURRENT_DESKTOP
950 // Expected result. 964 nullptr, // auto_proxy
951 ProxyConfigService::CONFIG_VALID, 965 "", // all_proxy
952 false, // auto_detect 966 nullptr, nullptr, nullptr, // per-proto proxies
953 GURL(), // pac_url 967 "socks.com:888", "4", // SOCKS
954 ProxyRulesExpectation::Single( 968 nullptr, // no_proxy
955 "socks4://socks.com:888", // single proxy 969 },
956 ""), // bypass rules 970
957 }, 971 // Expected result.
958 972 ProxyConfigService::CONFIG_VALID,
959 { 973 false, // auto_detect
960 TEST_DESC("socks default port"), 974 GURL(), // pac_url
961 { // Input. 975 ProxyRulesExpectation::Single(
962 NULL, // DESKTOP_SESSION 976 "socks4://socks.com:888", // single proxy
963 NULL, // HOME 977 ""), // bypass rules
964 NULL, // KDEHOME 978 },
965 NULL, // KDE_SESSION_VERSION 979
966 NULL, // XDG_CURRENT_DESKTOP 980 {
967 NULL, // auto_proxy 981 TEST_DESC("socks default port"),
968 "", // all_proxy 982 {
969 NULL, NULL, NULL, // per-proto proxies 983 // Input.
970 "socks.com", NULL, // SOCKS 984 nullptr, // DESKTOP_SESSION
971 NULL, // no_proxy 985 nullptr, // HOME
972 }, 986 nullptr, // KDEHOME
973 987 nullptr, // KDE_SESSION_VERSION
974 // Expected result. 988 nullptr, // XDG_CURRENT_DESKTOP
975 ProxyConfigService::CONFIG_VALID, 989 nullptr, // auto_proxy
976 false, // auto_detect 990 "", // all_proxy
977 GURL(), // pac_url 991 nullptr, nullptr, nullptr, // per-proto proxies
978 ProxyRulesExpectation::Single( 992 "socks.com", nullptr, // SOCKS
979 "socks5://socks.com:1080", // single proxy 993 nullptr, // no_proxy
980 ""), // bypass rules 994 },
981 }, 995
982 996 // Expected result.
983 { 997 ProxyConfigService::CONFIG_VALID,
984 TEST_DESC("bypass"), 998 false, // auto_detect
985 { // Input. 999 GURL(), // pac_url
986 NULL, // DESKTOP_SESSION 1000 ProxyRulesExpectation::Single(
987 NULL, // HOME 1001 "socks5://socks.com:1080", // single proxy
988 NULL, // KDEHOME 1002 ""), // bypass rules
989 NULL, // KDE_SESSION_VERSION 1003 },
990 NULL, // XDG_CURRENT_DESKTOP 1004
991 NULL, // auto_proxy 1005 {
992 "www.google.com", // all_proxy 1006 TEST_DESC("bypass"),
993 NULL, NULL, NULL, // per-proto 1007 {
994 NULL, NULL, // SOCKS 1008 // Input.
995 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy 1009 nullptr, // DESKTOP_SESSION
996 }, 1010 nullptr, // HOME
997 1011 nullptr, // KDEHOME
998 // Expected result. 1012 nullptr, // KDE_SESSION_VERSION
999 ProxyConfigService::CONFIG_VALID, 1013 nullptr, // XDG_CURRENT_DESKTOP
1000 false, // auto_detect 1014 nullptr, // auto_proxy
1001 GURL(), // pac_url 1015 "www.google.com", // all_proxy
1002 ProxyRulesExpectation::Single( 1016 nullptr, nullptr, nullptr, // per-proto
1003 "www.google.com:80", 1017 nullptr, nullptr, // SOCKS
1004 "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"), 1018 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy
1005 }, 1019 },
1020
1021 // Expected result.
1022 ProxyConfigService::CONFIG_VALID,
1023 false, // auto_detect
1024 GURL(), // pac_url
1025 ProxyRulesExpectation::Single(
1026 "www.google.com:80",
1027 "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"),
1028 },
1006 }; 1029 };
1007 1030
1008 for (size_t i = 0; i < arraysize(tests); ++i) { 1031 for (size_t i = 0; i < arraysize(tests); ++i) {
1009 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, 1032 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
1010 tests[i].description.c_str())); 1033 tests[i].description.c_str()));
1011 MockEnvironment* env = new MockEnvironment; 1034 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1035 env->values = tests[i].values;
1012 MockSettingGetter* setting_getter = new MockSettingGetter; 1036 MockSettingGetter* setting_getter = new MockSettingGetter;
1013 SynchConfigGetter sync_config_getter( 1037 SynchConfigGetter sync_config_getter(
1014 new ProxyConfigServiceLinux(env, setting_getter)); 1038 new ProxyConfigServiceLinux(std::move(env), setting_getter));
1015 ProxyConfig config; 1039 ProxyConfig config;
1016 env->values = tests[i].values;
1017 sync_config_getter.SetupAndInitialFetch(); 1040 sync_config_getter.SetupAndInitialFetch();
1018 ProxyConfigService::ConfigAvailability availability = 1041 ProxyConfigService::ConfigAvailability availability =
1019 sync_config_getter.SyncGetLatestProxyConfig(&config); 1042 sync_config_getter.SyncGetLatestProxyConfig(&config);
1020 EXPECT_EQ(tests[i].availability, availability); 1043 EXPECT_EQ(tests[i].availability, availability);
1021 1044
1022 if (availability == ProxyConfigService::CONFIG_VALID) { 1045 if (availability == ProxyConfigService::CONFIG_VALID) {
1023 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); 1046 EXPECT_EQ(tests[i].auto_detect, config.auto_detect());
1024 EXPECT_EQ(tests[i].pac_url, config.pac_url()); 1047 EXPECT_EQ(tests[i].pac_url, config.pac_url());
1025 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); 1048 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules()));
1026 } 1049 }
1027 } 1050 }
1028 } 1051 }
1029 1052
1030 TEST_F(ProxyConfigServiceLinuxTest, GconfNotification) { 1053 TEST_F(ProxyConfigServiceLinuxTest, GconfNotification) {
1031 MockEnvironment* env = new MockEnvironment; 1054 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1032 MockSettingGetter* setting_getter = new MockSettingGetter; 1055 MockSettingGetter* setting_getter = new MockSettingGetter;
1033 ProxyConfigServiceLinux* service = 1056 ProxyConfigServiceLinux* service =
1034 new ProxyConfigServiceLinux(env, setting_getter); 1057 new ProxyConfigServiceLinux(std::move(env), setting_getter);
1035 SynchConfigGetter sync_config_getter(service); 1058 SynchConfigGetter sync_config_getter(service);
1036 ProxyConfig config; 1059 ProxyConfig config;
1037 1060
1038 // Start with no proxy. 1061 // Start with no proxy.
1039 setting_getter->values.mode = "none"; 1062 setting_getter->values.mode = "none";
1040 sync_config_getter.SetupAndInitialFetch(); 1063 sync_config_getter.SetupAndInitialFetch();
1041 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1064 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1042 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1065 sync_config_getter.SyncGetLatestProxyConfig(&config));
1043 EXPECT_FALSE(config.auto_detect()); 1066 EXPECT_FALSE(config.auto_detect());
1044 1067
(...skipping 22 matching lines...) Expand all
1067 // Input. 1090 // Input.
1068 std::string kioslaverc; 1091 std::string kioslaverc;
1069 EnvVarValues env_values; 1092 EnvVarValues env_values;
1070 1093
1071 // Expected outputs (availability and fields of ProxyConfig). 1094 // Expected outputs (availability and fields of ProxyConfig).
1072 ProxyConfigService::ConfigAvailability availability; 1095 ProxyConfigService::ConfigAvailability availability;
1073 bool auto_detect; 1096 bool auto_detect;
1074 GURL pac_url; 1097 GURL pac_url;
1075 ProxyRulesExpectation proxy_rules; 1098 ProxyRulesExpectation proxy_rules;
1076 } tests[] = { 1099 } tests[] = {
1077 { 1100 {
1078 TEST_DESC("No proxying"), 1101 TEST_DESC("No proxying"),
1079 1102
1080 // Input. 1103 // Input.
1081 "[Proxy Settings]\nProxyType=0\n", 1104 "[Proxy Settings]\nProxyType=0\n",
1082 {}, // env_values 1105 {}, // env_values
1083 1106
1084 // Expected result. 1107 // Expected result.
1085 ProxyConfigService::CONFIG_VALID, 1108 ProxyConfigService::CONFIG_VALID,
1086 false, // auto_detect 1109 false, // auto_detect
1087 GURL(), // pac_url 1110 GURL(), // pac_url
1088 ProxyRulesExpectation::Empty(), 1111 ProxyRulesExpectation::Empty(),
1089 }, 1112 },
1090 1113
1091 { 1114 {
1092 TEST_DESC("Auto detect"), 1115 TEST_DESC("Auto detect"),
1093 1116
1094 // Input. 1117 // Input.
1095 "[Proxy Settings]\nProxyType=3\n", 1118 "[Proxy Settings]\nProxyType=3\n",
1096 {}, // env_values 1119 {}, // env_values
1097 1120
1098 // Expected result. 1121 // Expected result.
1099 ProxyConfigService::CONFIG_VALID, 1122 ProxyConfigService::CONFIG_VALID,
1100 true, // auto_detect 1123 true, // auto_detect
1101 GURL(), // pac_url 1124 GURL(), // pac_url
1102 ProxyRulesExpectation::Empty(), 1125 ProxyRulesExpectation::Empty(),
1103 }, 1126 },
1104 1127
1105 { 1128 {
1106 TEST_DESC("Valid PAC URL"), 1129 TEST_DESC("Valid PAC URL"),
1107 1130
1108 // Input. 1131 // Input.
1109 "[Proxy Settings]\nProxyType=2\n" 1132 "[Proxy Settings]\nProxyType=2\n"
1110 "Proxy Config Script=http://wpad/wpad.dat\n", 1133 "Proxy Config Script=http://wpad/wpad.dat\n",
1111 {}, // env_values 1134 {}, // env_values
1112 1135
1113 // Expected result. 1136 // Expected result.
1114 ProxyConfigService::CONFIG_VALID, 1137 ProxyConfigService::CONFIG_VALID,
1115 false, // auto_detect 1138 false, // auto_detect
1116 GURL("http://wpad/wpad.dat"), // pac_url 1139 GURL("http://wpad/wpad.dat"), // pac_url
1117 ProxyRulesExpectation::Empty(), 1140 ProxyRulesExpectation::Empty(),
1118 }, 1141 },
1119 1142
1120 { 1143 {
1121 TEST_DESC("Valid PAC file without file://"), 1144 TEST_DESC("Valid PAC file without file://"),
1122 1145
1123 // Input. 1146 // Input.
1124 "[Proxy Settings]\nProxyType=2\n" 1147 "[Proxy Settings]\nProxyType=2\n"
1125 "Proxy Config Script=/wpad/wpad.dat\n", 1148 "Proxy Config Script=/wpad/wpad.dat\n",
1126 {}, // env_values 1149 {}, // env_values
1127 1150
1128 // Expected result. 1151 // Expected result.
1129 ProxyConfigService::CONFIG_VALID, 1152 ProxyConfigService::CONFIG_VALID,
1130 false, // auto_detect 1153 false, // auto_detect
1131 GURL("file:///wpad/wpad.dat"), // pac_url 1154 GURL("file:///wpad/wpad.dat"), // pac_url
1132 ProxyRulesExpectation::Empty(), 1155 ProxyRulesExpectation::Empty(),
1133 }, 1156 },
1134 1157
1135 { 1158 {
1136 TEST_DESC("Per-scheme proxy rules"), 1159 TEST_DESC("Per-scheme proxy rules"),
1137 1160
1138 // Input. 1161 // Input.
1139 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" 1162 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1140 "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n", 1163 "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n",
1141 {}, // env_values 1164 {}, // env_values
1142 1165
1143 // Expected result. 1166 // Expected result.
1144 ProxyConfigService::CONFIG_VALID, 1167 ProxyConfigService::CONFIG_VALID,
1145 false, // auto_detect 1168 false, // auto_detect
1146 GURL(), // pac_url 1169 GURL(), // pac_url
1147 ProxyRulesExpectation::PerScheme( 1170 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1148 "www.google.com:80", // http 1171 "www.foo.com:80", // https
1149 "www.foo.com:80", // https 1172 "ftp.foo.com:80", // http
1150 "ftp.foo.com:80", // http 1173 ""), // bypass rules
1151 ""), // bypass rules 1174 },
1152 }, 1175
1153 1176 {
1154 { 1177 TEST_DESC("Only HTTP proxy specified"),
1155 TEST_DESC("Only HTTP proxy specified"), 1178
1156 1179 // Input.
1157 // Input. 1180 "[Proxy Settings]\nProxyType=1\n"
1158 "[Proxy Settings]\nProxyType=1\n"
1159 "httpProxy=www.google.com\n", 1181 "httpProxy=www.google.com\n",
1160 {}, // env_values 1182 {}, // env_values
1161 1183
1162 // Expected result. 1184 // Expected result.
1163 ProxyConfigService::CONFIG_VALID, 1185 ProxyConfigService::CONFIG_VALID,
1164 false, // auto_detect 1186 false, // auto_detect
1165 GURL(), // pac_url 1187 GURL(), // pac_url
1166 ProxyRulesExpectation::PerScheme( 1188 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1167 "www.google.com:80", // http 1189 "", // https
1168 "", // https 1190 "", // ftp
1169 "", // ftp 1191 ""), // bypass rules
1170 ""), // bypass rules 1192 },
1171 }, 1193
1172 1194 {
1173 { 1195 TEST_DESC("Only HTTP proxy specified, different port"),
1174 TEST_DESC("Only HTTP proxy specified, different port"), 1196
1175 1197 // Input.
1176 // Input. 1198 "[Proxy Settings]\nProxyType=1\n"
1177 "[Proxy Settings]\nProxyType=1\n"
1178 "httpProxy=www.google.com:88\n", 1199 "httpProxy=www.google.com:88\n",
1179 {}, // env_values 1200 {}, // env_values
1180 1201
1181 // Expected result. 1202 // Expected result.
1182 ProxyConfigService::CONFIG_VALID, 1203 ProxyConfigService::CONFIG_VALID,
1183 false, // auto_detect 1204 false, // auto_detect
1184 GURL(), // pac_url 1205 GURL(), // pac_url
1185 ProxyRulesExpectation::PerScheme( 1206 ProxyRulesExpectation::PerScheme("www.google.com:88", // http
1186 "www.google.com:88", // http 1207 "", // https
1187 "", // https 1208 "", // ftp
1188 "", // ftp 1209 ""), // bypass rules
1189 ""), // bypass rules 1210 },
1190 }, 1211
1191 1212 {
1192 { 1213 TEST_DESC(
1193 TEST_DESC("Only HTTP proxy specified, different port, space-delimited"), 1214 "Only HTTP proxy specified, different port, space-delimited"),
1194 1215
1195 // Input. 1216 // Input.
1196 "[Proxy Settings]\nProxyType=1\n" 1217 "[Proxy Settings]\nProxyType=1\n"
1197 "httpProxy=www.google.com 88\n", 1218 "httpProxy=www.google.com 88\n",
1198 {}, // env_values 1219 {}, // env_values
1199 1220
1200 // Expected result. 1221 // Expected result.
1201 ProxyConfigService::CONFIG_VALID, 1222 ProxyConfigService::CONFIG_VALID,
1202 false, // auto_detect 1223 false, // auto_detect
1203 GURL(), // pac_url 1224 GURL(), // pac_url
1204 ProxyRulesExpectation::PerScheme( 1225 ProxyRulesExpectation::PerScheme("www.google.com:88", // http
1205 "www.google.com:88", // http 1226 "", // https
1206 "", // https 1227 "", // ftp
1207 "", // ftp 1228 ""), // bypass rules
1208 ""), // bypass rules 1229 },
1209 }, 1230
1210 1231 {
1211 { 1232 TEST_DESC("Bypass *.google.com"),
1212 TEST_DESC("Bypass *.google.com"), 1233
1213 1234 // Input.
1214 // Input. 1235 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1215 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1216 "NoProxyFor=.google.com\n", 1236 "NoProxyFor=.google.com\n",
1217 {}, // env_values 1237 {}, // env_values
1218 1238
1219 // Expected result. 1239 // Expected result.
1220 ProxyConfigService::CONFIG_VALID, 1240 ProxyConfigService::CONFIG_VALID,
1221 false, // auto_detect 1241 false, // auto_detect
1222 GURL(), // pac_url 1242 GURL(), // pac_url
1223 ProxyRulesExpectation::PerScheme( 1243 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1224 "www.google.com:80", // http 1244 "", // https
1225 "", // https 1245 "", // ftp
1226 "", // ftp 1246 "*.google.com"), // bypass rules
1227 "*.google.com"), // bypass rules 1247 },
1228 }, 1248
1229 1249 {
1230 { 1250 TEST_DESC("Bypass *.google.com and *.kde.org"),
1231 TEST_DESC("Bypass *.google.com and *.kde.org"), 1251
1232 1252 // Input.
1233 // Input. 1253 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1234 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1235 "NoProxyFor=.google.com,.kde.org\n", 1254 "NoProxyFor=.google.com,.kde.org\n",
1236 {}, // env_values 1255 {}, // env_values
1237 1256
1238 // Expected result. 1257 // Expected result.
1239 ProxyConfigService::CONFIG_VALID, 1258 ProxyConfigService::CONFIG_VALID,
1240 false, // auto_detect 1259 false, // auto_detect
1241 GURL(), // pac_url 1260 GURL(), // pac_url
1242 ProxyRulesExpectation::PerScheme( 1261 ProxyRulesExpectation::PerScheme(
1243 "www.google.com:80", // http 1262 "www.google.com:80", // http
1244 "", // https 1263 "", // https
1245 "", // ftp 1264 "", // ftp
1246 "*.google.com,*.kde.org"), // bypass rules 1265 "*.google.com,*.kde.org"), // bypass rules
1247 }, 1266 },
1248 1267
1249 { 1268 {
1250 TEST_DESC("Correctly parse bypass list with ReversedException"), 1269 TEST_DESC("Correctly parse bypass list with ReversedException"),
1251 1270
1252 // Input. 1271 // Input.
1253 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" 1272 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1254 "NoProxyFor=.google.com\nReversedException=true\n", 1273 "NoProxyFor=.google.com\nReversedException=true\n",
1255 {}, // env_values 1274 {}, // env_values
1256 1275
1257 // Expected result. 1276 // Expected result.
1258 ProxyConfigService::CONFIG_VALID, 1277 ProxyConfigService::CONFIG_VALID,
1259 false, // auto_detect 1278 false, // auto_detect
1260 GURL(), // pac_url 1279 GURL(), // pac_url
1261 ProxyRulesExpectation::PerSchemeWithBypassReversed( 1280 ProxyRulesExpectation::PerSchemeWithBypassReversed(
1262 "www.google.com:80", // http 1281 "www.google.com:80", // http
1263 "", // https 1282 "", // https
1264 "", // ftp 1283 "", // ftp
1265 "*.google.com"), // bypass rules 1284 "*.google.com"), // bypass rules
1266 }, 1285 },
1267 1286
1268 { 1287 {
1269 TEST_DESC("socks"), 1288 TEST_DESC("socks"),
1270 1289
1271 // Input. 1290 // Input.
1272 "[Proxy Settings]\nProxyType=1\nsocksProxy=socks.com 888\n", 1291 "[Proxy Settings]\nProxyType=1\nsocksProxy=socks.com 888\n",
1273 {}, // env_values 1292 {}, // env_values
1274 1293
1275 // Expected result. 1294 // Expected result.
1276 ProxyConfigService::CONFIG_VALID, 1295 ProxyConfigService::CONFIG_VALID,
1277 false, // auto_detect 1296 false, // auto_detect
1278 GURL(), // pac_url 1297 GURL(), // pac_url
1279 ProxyRulesExpectation::Single( 1298 ProxyRulesExpectation::Single(
1280 "socks5://socks.com:888", // single proxy 1299 "socks5://socks.com:888", // single proxy
1281 ""), // bypass rules 1300 ""), // bypass rules
1282 }, 1301 },
1283 1302
1284 { 1303 {
1285 TEST_DESC("socks4"), 1304 TEST_DESC("socks4"),
1286 1305
1287 // Input. 1306 // Input.
1288 "[Proxy Settings]\nProxyType=1\nsocksProxy=socks4://socks.com 888\n", 1307 "[Proxy Settings]\nProxyType=1\nsocksProxy=socks4://socks.com 888\n",
1289 {}, // env_values 1308 {}, // env_values
1290 1309
1291 // Expected result. 1310 // Expected result.
1292 ProxyConfigService::CONFIG_VALID, 1311 ProxyConfigService::CONFIG_VALID,
1293 false, // auto_detect 1312 false, // auto_detect
1294 GURL(), // pac_url 1313 GURL(), // pac_url
1295 ProxyRulesExpectation::Single( 1314 ProxyRulesExpectation::Single(
1296 "socks4://socks.com:888", // single proxy 1315 "socks4://socks.com:888", // single proxy
1297 ""), // bypass rules 1316 ""), // bypass rules
1298 }, 1317 },
1299 1318
1300 { 1319 {
1301 TEST_DESC("Treat all hostname patterns as wildcard patterns"), 1320 TEST_DESC("Treat all hostname patterns as wildcard patterns"),
1302 1321
1303 // Input. 1322 // Input.
1304 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" 1323 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1305 "NoProxyFor=google.com,kde.org,<local>\n", 1324 "NoProxyFor=google.com,kde.org,<local>\n",
1306 {}, // env_values 1325 {}, // env_values
1307 1326
1308 // Expected result. 1327 // Expected result.
1309 ProxyConfigService::CONFIG_VALID, 1328 ProxyConfigService::CONFIG_VALID,
1310 false, // auto_detect 1329 false, // auto_detect
1311 GURL(), // pac_url 1330 GURL(), // pac_url
1312 ProxyRulesExpectation::PerScheme( 1331 ProxyRulesExpectation::PerScheme(
1313 "www.google.com:80", // http 1332 "www.google.com:80", // http
1314 "", // https 1333 "", // https
1315 "", // ftp 1334 "", // ftp
1316 "*google.com,*kde.org,<local>"), // bypass rules 1335 "*google.com,*kde.org,<local>"), // bypass rules
1317 }, 1336 },
1318 1337
1319 { 1338 {
1320 TEST_DESC("Allow trailing whitespace after boolean value"), 1339 TEST_DESC("Allow trailing whitespace after boolean value"),
1321 1340
1322 // Input. 1341 // Input.
1323 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" 1342 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1324 "NoProxyFor=.google.com\nReversedException=true \n", 1343 "NoProxyFor=.google.com\nReversedException=true \n",
1325 {}, // env_values 1344 {}, // env_values
1326 1345
1327 // Expected result. 1346 // Expected result.
1328 ProxyConfigService::CONFIG_VALID, 1347 ProxyConfigService::CONFIG_VALID,
1329 false, // auto_detect 1348 false, // auto_detect
1330 GURL(), // pac_url 1349 GURL(), // pac_url
1331 ProxyRulesExpectation::PerSchemeWithBypassReversed( 1350 ProxyRulesExpectation::PerSchemeWithBypassReversed(
1332 "www.google.com:80", // http 1351 "www.google.com:80", // http
1333 "", // https 1352 "", // https
1334 "", // ftp 1353 "", // ftp
1335 "*.google.com"), // bypass rules 1354 "*.google.com"), // bypass rules
1336 }, 1355 },
1337 1356
1338 { 1357 {
1339 TEST_DESC("Ignore settings outside [Proxy Settings]"), 1358 TEST_DESC("Ignore settings outside [Proxy Settings]"),
1340 1359
1341 // Input. 1360 // Input.
1342 "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n" 1361 "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n"
1343 "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n", 1362 "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n",
1344 {}, // env_values 1363 {}, // env_values
1345 1364
1346 // Expected result. 1365 // Expected result.
1347 ProxyConfigService::CONFIG_VALID, 1366 ProxyConfigService::CONFIG_VALID,
1348 false, // auto_detect 1367 false, // auto_detect
1349 GURL(), // pac_url 1368 GURL(), // pac_url
1350 ProxyRulesExpectation::PerScheme( 1369 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1351 "www.google.com:80", // http 1370 "", // https
1352 "", // https 1371 "", // ftp
1353 "", // ftp 1372 ""), // bypass rules
1354 ""), // bypass rules 1373 },
1355 }, 1374
1356 1375 {
1357 { 1376 TEST_DESC("Handle CRLF line endings"),
1358 TEST_DESC("Handle CRLF line endings"), 1377
1359 1378 // Input.
1360 // Input. 1379 "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n",
1361 "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n", 1380 {}, // env_values
1362 {}, // env_values 1381
1363 1382 // Expected result.
1364 // Expected result. 1383 ProxyConfigService::CONFIG_VALID,
1365 ProxyConfigService::CONFIG_VALID, 1384 false, // auto_detect
1366 false, // auto_detect 1385 GURL(), // pac_url
1367 GURL(), // pac_url 1386 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1368 ProxyRulesExpectation::PerScheme( 1387 "", // https
1369 "www.google.com:80", // http 1388 "", // ftp
1370 "", // https 1389 ""), // bypass rules
1371 "", // ftp 1390 },
1372 ""), // bypass rules 1391
1373 }, 1392 {
1374 1393 TEST_DESC("Handle blank lines and mixed line endings"),
1375 { 1394
1376 TEST_DESC("Handle blank lines and mixed line endings"), 1395 // Input.
1377 1396 "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n",
1378 // Input. 1397 {}, // env_values
1379 "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n", 1398
1380 {}, // env_values 1399 // Expected result.
1381 1400 ProxyConfigService::CONFIG_VALID,
1382 // Expected result. 1401 false, // auto_detect
1383 ProxyConfigService::CONFIG_VALID, 1402 GURL(), // pac_url
1384 false, // auto_detect 1403 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1385 GURL(), // pac_url 1404 "", // https
1386 ProxyRulesExpectation::PerScheme( 1405 "", // ftp
1387 "www.google.com:80", // http 1406 ""), // bypass rules
1388 "", // https 1407 },
1389 "", // ftp 1408
1390 ""), // bypass rules 1409 {
1391 }, 1410 TEST_DESC("Handle localized settings"),
1392 1411
1393 { 1412 // Input.
1394 TEST_DESC("Handle localized settings"), 1413 "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n",
1395 1414 {}, // env_values
1396 // Input. 1415
1397 "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n", 1416 // Expected result.
1398 {}, // env_values 1417 ProxyConfigService::CONFIG_VALID,
1399 1418 false, // auto_detect
1400 // Expected result. 1419 GURL(), // pac_url
1401 ProxyConfigService::CONFIG_VALID, 1420 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1402 false, // auto_detect 1421 "", // https
1403 GURL(), // pac_url 1422 "", // ftp
1404 ProxyRulesExpectation::PerScheme( 1423 ""), // bypass rules
1405 "www.google.com:80", // http 1424 },
1406 "", // https 1425
1407 "", // ftp 1426 {
1408 ""), // bypass rules 1427 TEST_DESC("Ignore malformed localized settings"),
1409 }, 1428
1410 1429 // Input.
1411 { 1430 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1412 TEST_DESC("Ignore malformed localized settings"),
1413
1414 // Input.
1415 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n"
1416 "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n", 1431 "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n",
1417 {}, // env_values 1432 {}, // env_values
1418 1433
1419 // Expected result. 1434 // Expected result.
1420 ProxyConfigService::CONFIG_VALID, 1435 ProxyConfigService::CONFIG_VALID,
1421 false, // auto_detect 1436 false, // auto_detect
1422 GURL(), // pac_url 1437 GURL(), // pac_url
1423 ProxyRulesExpectation::PerScheme( 1438 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1424 "www.google.com:80", // http 1439 "", // https
1425 "", // https 1440 "ftp.foo.com:80", // ftp
1426 "ftp.foo.com:80", // ftp 1441 ""), // bypass rules
1427 ""), // bypass rules 1442 },
1428 }, 1443
1429 1444 {
1430 { 1445 TEST_DESC("Handle strange whitespace"),
1431 TEST_DESC("Handle strange whitespace"), 1446
1432 1447 // Input.
1433 // Input. 1448 "[Proxy Settings]\nProxyType [$e] =2\n"
1434 "[Proxy Settings]\nProxyType [$e] =2\n"
1435 " Proxy Config Script = http:// foo\n", 1449 " Proxy Config Script = http:// foo\n",
1436 {}, // env_values 1450 {}, // env_values
1437 1451
1438 // Expected result. 1452 // Expected result.
1439 ProxyConfigService::CONFIG_VALID, 1453 ProxyConfigService::CONFIG_VALID,
1440 false, // auto_detect 1454 false, // auto_detect
1441 GURL("http:// foo"), // pac_url 1455 GURL("http:// foo"), // pac_url
1442 ProxyRulesExpectation::Empty(), 1456 ProxyRulesExpectation::Empty(),
1443 }, 1457 },
1444 1458
1445 { 1459 {
1446 TEST_DESC("Ignore all of a line which is too long"), 1460 TEST_DESC("Ignore all of a line which is too long"),
1447 1461
1448 // Input. 1462 // Input.
1449 std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") + 1463 std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") +
1450 long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n", 1464 long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n",
1451 {}, // env_values 1465 {}, // env_values
1452 1466
1453 // Expected result. 1467 // Expected result.
1454 ProxyConfigService::CONFIG_VALID, 1468 ProxyConfigService::CONFIG_VALID,
1455 false, // auto_detect 1469 false, // auto_detect
1456 GURL(), // pac_url 1470 GURL(), // pac_url
1457 ProxyRulesExpectation::PerScheme( 1471 ProxyRulesExpectation::PerScheme("www.google.com:80", // http
1458 "www.google.com:80", // http 1472 "", // https
1459 "", // https 1473 "ftp.foo.com:80", // ftp
1460 "ftp.foo.com:80", // ftp 1474 ""), // bypass rules
1461 ""), // bypass rules 1475 },
1462 }, 1476
1463 1477 {
1464 { 1478 TEST_DESC("Indirect Proxy - no env vars set"),
1465 TEST_DESC("Indirect Proxy - no env vars set"), 1479
1466 1480 // Input.
1467 // Input. 1481 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
1468 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
1469 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", 1482 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n",
1470 {}, // env_values 1483 {}, // env_values
1471 1484
1472 // Expected result. 1485 // Expected result.
1473 ProxyConfigService::CONFIG_VALID, 1486 ProxyConfigService::CONFIG_VALID,
1474 false, // auto_detect 1487 false, // auto_detect
1475 GURL(), // pac_url 1488 GURL(), // pac_url
1476 ProxyRulesExpectation::Empty(), 1489 ProxyRulesExpectation::Empty(),
1477 }, 1490 },
1478 1491
1479 { 1492 {
1480 TEST_DESC("Indirect Proxy - with env vars set"), 1493 TEST_DESC("Indirect Proxy - with env vars set"),
1481 1494
1482 // Input. 1495 // Input.
1483 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" 1496 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n"
1484 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", 1497 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n",
1485 { // env_values 1498 {
1486 NULL, // DESKTOP_SESSION 1499 // env_values
1487 NULL, // HOME 1500 nullptr, // DESKTOP_SESSION
1488 NULL, // KDEHOME 1501 nullptr, // HOME
1489 NULL, // KDE_SESSION_VERSION 1502 nullptr, // KDEHOME
1490 NULL, // XDG_CURRENT_DESKTOP 1503 nullptr, // KDE_SESSION_VERSION
1491 NULL, // auto_proxy 1504 nullptr, // XDG_CURRENT_DESKTOP
1492 NULL, // all_proxy 1505 nullptr, // auto_proxy
1493 "www.normal.com", // http_proxy 1506 nullptr, // all_proxy
1494 "www.secure.com", // https_proxy 1507 "www.normal.com", // http_proxy
1495 "ftp.foo.com", // ftp_proxy 1508 "www.secure.com", // https_proxy
1496 NULL, NULL, // SOCKS 1509 "ftp.foo.com", // ftp_proxy
1497 ".google.com, .kde.org", // no_proxy 1510 nullptr, nullptr, // SOCKS
1498 }, 1511 ".google.com, .kde.org", // no_proxy
1499 1512 },
1500 // Expected result. 1513
1501 ProxyConfigService::CONFIG_VALID, 1514 // Expected result.
1502 false, // auto_detect 1515 ProxyConfigService::CONFIG_VALID,
1503 GURL(), // pac_url 1516 false, // auto_detect
1504 ProxyRulesExpectation::PerScheme( 1517 GURL(), // pac_url
1505 "www.normal.com:80", // http 1518 ProxyRulesExpectation::PerScheme(
1506 "www.secure.com:80", // https 1519 "www.normal.com:80", // http
1507 "ftp.foo.com:80", // ftp 1520 "www.secure.com:80", // https
1508 "*.google.com,*.kde.org"), // bypass rules 1521 "ftp.foo.com:80", // ftp
1509 }, 1522 "*.google.com,*.kde.org"), // bypass rules
1510 1523 },
1511 }; 1524 };
1512 1525
1513 for (size_t i = 0; i < arraysize(tests); ++i) { 1526 for (size_t i = 0; i < arraysize(tests); ++i) {
1514 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, 1527 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i,
1515 tests[i].description.c_str())); 1528 tests[i].description.c_str()));
1516 MockEnvironment* env = new MockEnvironment; 1529 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1517 env->values = tests[i].env_values; 1530 env->values = tests[i].env_values;
1518 // Force the KDE getter to be used and tell it where the test is. 1531 // Force the KDE getter to be used and tell it where the test is.
1519 env->values.DESKTOP_SESSION = "kde4"; 1532 env->values.DESKTOP_SESSION = "kde4";
1520 env->values.KDEHOME = kde_home_.value().c_str(); 1533 env->values.KDEHOME = kde_home_.value().c_str();
1521 SynchConfigGetter sync_config_getter( 1534 SynchConfigGetter sync_config_getter(
1522 new ProxyConfigServiceLinux(env)); 1535 new ProxyConfigServiceLinux(std::move(env)));
1523 ProxyConfig config; 1536 ProxyConfig config;
1524 // Overwrite the kioslaverc file. 1537 // Overwrite the kioslaverc file.
1525 base::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), 1538 base::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(),
1526 tests[i].kioslaverc.length()); 1539 tests[i].kioslaverc.length());
1527 sync_config_getter.SetupAndInitialFetch(); 1540 sync_config_getter.SetupAndInitialFetch();
1528 ProxyConfigService::ConfigAvailability availability = 1541 ProxyConfigService::ConfigAvailability availability =
1529 sync_config_getter.SyncGetLatestProxyConfig(&config); 1542 sync_config_getter.SyncGetLatestProxyConfig(&config);
1530 EXPECT_EQ(tests[i].availability, availability); 1543 EXPECT_EQ(tests[i].availability, availability);
1531 1544
1532 if (availability == ProxyConfigService::CONFIG_VALID) { 1545 if (availability == ProxyConfigService::CONFIG_VALID) {
(...skipping 21 matching lines...) Expand all
1554 ""); // bypass rules 1567 ""); // bypass rules
1555 1568
1556 // Overwrite the .kde kioslaverc file. 1569 // Overwrite the .kde kioslaverc file.
1557 base::WriteFile(kioslaverc_, slaverc3.c_str(), slaverc3.length()); 1570 base::WriteFile(kioslaverc_, slaverc3.c_str(), slaverc3.length());
1558 1571
1559 // If .kde4 exists it will mess up the first test. It should not, as 1572 // If .kde4 exists it will mess up the first test. It should not, as
1560 // we created the directory for $HOME in the test setup. 1573 // we created the directory for $HOME in the test setup.
1561 CHECK(!base::DirectoryExists(kde4_home_)); 1574 CHECK(!base::DirectoryExists(kde4_home_));
1562 1575
1563 { SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback"); 1576 { SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback");
1564 MockEnvironment* env = new MockEnvironment; 1577 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1565 env->values.DESKTOP_SESSION = "kde4"; 1578 env->values.DESKTOP_SESSION = "kde4";
1566 env->values.HOME = user_home_.value().c_str(); 1579 env->values.HOME = user_home_.value().c_str();
1567 SynchConfigGetter sync_config_getter( 1580 SynchConfigGetter sync_config_getter(
1568 new ProxyConfigServiceLinux(env)); 1581 new ProxyConfigServiceLinux(std::move(env)));
1569 ProxyConfig config; 1582 ProxyConfig config;
1570 sync_config_getter.SetupAndInitialFetch(); 1583 sync_config_getter.SetupAndInitialFetch();
1571 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1584 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1572 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1585 sync_config_getter.SyncGetLatestProxyConfig(&config));
1573 EXPECT_TRUE(config.auto_detect()); 1586 EXPECT_TRUE(config.auto_detect());
1574 EXPECT_EQ(GURL(), config.pac_url()); 1587 EXPECT_EQ(GURL(), config.pac_url());
1575 } 1588 }
1576 1589
1577 // Now create .kde4 and put a kioslaverc in the config directory. 1590 // Now create .kde4 and put a kioslaverc in the config directory.
1578 // Note that its timestamp will be at least as new as the .kde one. 1591 // Note that its timestamp will be at least as new as the .kde one.
1579 base::CreateDirectory(kde4_config_); 1592 base::CreateDirectory(kde4_config_);
1580 base::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length()); 1593 base::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length());
1581 CHECK(base::PathExists(kioslaverc4_)); 1594 CHECK(base::PathExists(kioslaverc4_));
1582 1595
1583 { SCOPED_TRACE("KDE4, .kde4 directory present, use it"); 1596 { SCOPED_TRACE("KDE4, .kde4 directory present, use it");
1584 MockEnvironment* env = new MockEnvironment; 1597 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1585 env->values.DESKTOP_SESSION = "kde4"; 1598 env->values.DESKTOP_SESSION = "kde4";
1586 env->values.HOME = user_home_.value().c_str(); 1599 env->values.HOME = user_home_.value().c_str();
1587 SynchConfigGetter sync_config_getter( 1600 SynchConfigGetter sync_config_getter(
1588 new ProxyConfigServiceLinux(env)); 1601 new ProxyConfigServiceLinux(std::move(env)));
1589 ProxyConfig config; 1602 ProxyConfig config;
1590 sync_config_getter.SetupAndInitialFetch(); 1603 sync_config_getter.SetupAndInitialFetch();
1591 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1604 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1592 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1605 sync_config_getter.SyncGetLatestProxyConfig(&config));
1593 EXPECT_FALSE(config.auto_detect()); 1606 EXPECT_FALSE(config.auto_detect());
1594 EXPECT_EQ(slaverc4_pac_url, config.pac_url()); 1607 EXPECT_EQ(slaverc4_pac_url, config.pac_url());
1595 } 1608 }
1596 1609
1597 { SCOPED_TRACE("KDE3, .kde4 directory present, ignore it"); 1610 { SCOPED_TRACE("KDE3, .kde4 directory present, ignore it");
1598 MockEnvironment* env = new MockEnvironment; 1611 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1599 env->values.DESKTOP_SESSION = "kde"; 1612 env->values.DESKTOP_SESSION = "kde";
1600 env->values.HOME = user_home_.value().c_str(); 1613 env->values.HOME = user_home_.value().c_str();
1601 SynchConfigGetter sync_config_getter( 1614 SynchConfigGetter sync_config_getter(
1602 new ProxyConfigServiceLinux(env)); 1615 new ProxyConfigServiceLinux(std::move(env)));
1603 ProxyConfig config; 1616 ProxyConfig config;
1604 sync_config_getter.SetupAndInitialFetch(); 1617 sync_config_getter.SetupAndInitialFetch();
1605 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1618 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1606 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1619 sync_config_getter.SyncGetLatestProxyConfig(&config));
1607 EXPECT_TRUE(config.auto_detect()); 1620 EXPECT_TRUE(config.auto_detect());
1608 EXPECT_EQ(GURL(), config.pac_url()); 1621 EXPECT_EQ(GURL(), config.pac_url());
1609 } 1622 }
1610 1623
1611 { SCOPED_TRACE("KDE4, .kde4 directory present, KDEHOME set to .kde"); 1624 { SCOPED_TRACE("KDE4, .kde4 directory present, KDEHOME set to .kde");
1612 MockEnvironment* env = new MockEnvironment; 1625 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1613 env->values.DESKTOP_SESSION = "kde4"; 1626 env->values.DESKTOP_SESSION = "kde4";
1614 env->values.HOME = user_home_.value().c_str(); 1627 env->values.HOME = user_home_.value().c_str();
1615 env->values.KDEHOME = kde_home_.value().c_str(); 1628 env->values.KDEHOME = kde_home_.value().c_str();
1616 SynchConfigGetter sync_config_getter( 1629 SynchConfigGetter sync_config_getter(
1617 new ProxyConfigServiceLinux(env)); 1630 new ProxyConfigServiceLinux(std::move(env)));
1618 ProxyConfig config; 1631 ProxyConfig config;
1619 sync_config_getter.SetupAndInitialFetch(); 1632 sync_config_getter.SetupAndInitialFetch();
1620 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1633 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1621 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1634 sync_config_getter.SyncGetLatestProxyConfig(&config));
1622 EXPECT_TRUE(config.auto_detect()); 1635 EXPECT_TRUE(config.auto_detect());
1623 EXPECT_EQ(GURL(), config.pac_url()); 1636 EXPECT_EQ(GURL(), config.pac_url());
1624 } 1637 }
1625 1638
1626 // Finally, make the .kde4 config directory older than the .kde directory 1639 // Finally, make the .kde4 config directory older than the .kde directory
1627 // and make sure we then use .kde instead of .kde4 since it's newer. 1640 // and make sure we then use .kde instead of .kde4 since it's newer.
1628 base::TouchFile(kde4_config_, base::Time(), base::Time()); 1641 base::TouchFile(kde4_config_, base::Time(), base::Time());
1629 1642
1630 { SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde"); 1643 { SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde");
1631 MockEnvironment* env = new MockEnvironment; 1644 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1632 env->values.DESKTOP_SESSION = "kde4"; 1645 env->values.DESKTOP_SESSION = "kde4";
1633 env->values.HOME = user_home_.value().c_str(); 1646 env->values.HOME = user_home_.value().c_str();
1634 SynchConfigGetter sync_config_getter( 1647 SynchConfigGetter sync_config_getter(
1635 new ProxyConfigServiceLinux(env)); 1648 new ProxyConfigServiceLinux(std::move(env)));
1636 ProxyConfig config; 1649 ProxyConfig config;
1637 sync_config_getter.SetupAndInitialFetch(); 1650 sync_config_getter.SetupAndInitialFetch();
1638 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1651 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1639 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1652 sync_config_getter.SyncGetLatestProxyConfig(&config));
1640 EXPECT_TRUE(config.auto_detect()); 1653 EXPECT_TRUE(config.auto_detect());
1641 EXPECT_EQ(GURL(), config.pac_url()); 1654 EXPECT_EQ(GURL(), config.pac_url());
1642 } 1655 }
1643 1656
1644 // For KDE 5 create ${HOME}/.config and put a kioslaverc in the directory. 1657 // For KDE 5 create ${HOME}/.config and put a kioslaverc in the directory.
1645 base::CreateDirectory(config_home_); 1658 base::CreateDirectory(config_home_);
1646 base::WriteFile(kioslaverc5_, slaverc5.c_str(), slaverc5.length()); 1659 base::WriteFile(kioslaverc5_, slaverc5.c_str(), slaverc5.length());
1647 CHECK(base::PathExists(kioslaverc5_)); 1660 CHECK(base::PathExists(kioslaverc5_));
1648 1661
1649 { 1662 {
1650 SCOPED_TRACE("KDE5, .kde and .kde4 present, use .config"); 1663 SCOPED_TRACE("KDE5, .kde and .kde4 present, use .config");
1651 MockEnvironment* env = new MockEnvironment; 1664 std::unique_ptr<MockEnvironment> env(new MockEnvironment);
1652 env->values.XDG_CURRENT_DESKTOP = "KDE"; 1665 env->values.XDG_CURRENT_DESKTOP = "KDE";
1653 env->values.KDE_SESSION_VERSION = "5"; 1666 env->values.KDE_SESSION_VERSION = "5";
1654 env->values.HOME = user_home_.value().c_str(); 1667 env->values.HOME = user_home_.value().c_str();
1655 SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env)); 1668 SynchConfigGetter sync_config_getter(
1669 new ProxyConfigServiceLinux(std::move(env)));
1656 ProxyConfig config; 1670 ProxyConfig config;
1657 sync_config_getter.SetupAndInitialFetch(); 1671 sync_config_getter.SetupAndInitialFetch();
1658 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, 1672 EXPECT_EQ(ProxyConfigService::CONFIG_VALID,
1659 sync_config_getter.SyncGetLatestProxyConfig(&config)); 1673 sync_config_getter.SyncGetLatestProxyConfig(&config));
1660 EXPECT_FALSE(config.auto_detect()); 1674 EXPECT_FALSE(config.auto_detect());
1661 EXPECT_TRUE(slaverc5_rules.Matches(config.proxy_rules())); 1675 EXPECT_TRUE(slaverc5_rules.Matches(config.proxy_rules()));
1662 } 1676 }
1663 } 1677 }
1664 1678
1665 } // namespace 1679 } // namespace
1666 1680
1667 } // namespace net 1681 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_linux.cc ('k') | sandbox/linux/suid/client/setuid_sandbox_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698