OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 typename map_type::const_iterator it = settings.find(key); | 70 typename map_type::const_iterator it = settings.find(key); |
71 // In case there's a typo or the unittest becomes out of sync. | 71 // In case there's a typo or the unittest becomes out of sync. |
72 CHECK(it != settings.end()) << "key " << key << " not found"; | 72 CHECK(it != settings.end()) << "key " << key << " not found"; |
73 value_type* value_ptr = it->second; | 73 value_type* value_ptr = it->second; |
74 return *value_ptr; | 74 return *value_ptr; |
75 } | 75 } |
76 | 76 |
77 map_type settings; | 77 map_type settings; |
78 }; | 78 }; |
79 | 79 |
80 class MockEnvironmentVariableGetter : public base::EnvironmentVariableGetter { | 80 class MockEnvVarGetter : public base::EnvVarGetter { |
81 public: | 81 public: |
82 MockEnvironmentVariableGetter() { | 82 MockEnvVarGetter() { |
83 #define ENTRY(x) table.settings[#x] = &values.x | 83 #define ENTRY(x) table.settings[#x] = &values.x |
84 ENTRY(DESKTOP_SESSION); | 84 ENTRY(DESKTOP_SESSION); |
85 ENTRY(KDE_HOME); | 85 ENTRY(KDE_HOME); |
86 ENTRY(auto_proxy); | 86 ENTRY(auto_proxy); |
87 ENTRY(all_proxy); | 87 ENTRY(all_proxy); |
88 ENTRY(http_proxy); | 88 ENTRY(http_proxy); |
89 ENTRY(https_proxy); | 89 ENTRY(https_proxy); |
90 ENTRY(ftp_proxy); | 90 ENTRY(ftp_proxy); |
91 ENTRY(no_proxy); | 91 ENTRY(no_proxy); |
92 ENTRY(SOCKS_SERVER); | 92 ENTRY(SOCKS_SERVER); |
93 ENTRY(SOCKS_VERSION); | 93 ENTRY(SOCKS_VERSION); |
94 #undef ENTRY | 94 #undef ENTRY |
95 Reset(); | 95 Reset(); |
96 } | 96 } |
97 | 97 |
98 // Zeros all environment values. | 98 // Zeros all environment values. |
99 void Reset() { | 99 void Reset() { |
100 EnvVarValues zero_values = { 0 }; | 100 EnvVarValues zero_values = { 0 }; |
101 values = zero_values; | 101 values = zero_values; |
102 } | 102 } |
103 | 103 |
104 virtual bool Getenv(const char* variable_name, std::string* result) { | 104 virtual bool GetEnv(const char* variable_name, std::string* result) { |
105 const char* env_value = table.Get(variable_name); | 105 const char* env_value = table.Get(variable_name); |
106 if (env_value) { | 106 if (env_value) { |
107 // Note that the variable may be defined but empty. | 107 // Note that the variable may be defined but empty. |
108 *result = env_value; | 108 *result = env_value; |
109 return true; | 109 return true; |
110 } | 110 } |
111 return false; | 111 return false; |
112 } | 112 } |
113 | 113 |
114 // Intentionally public, for convenience when setting up a test. | 114 // Intentionally public, for convenience when setting up a test. |
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 GURL(), // pac_url | 569 GURL(), // pac_url |
570 ProxyRulesExpectation::Single( | 570 ProxyRulesExpectation::Single( |
571 "www.google.com:80", // single proxy | 571 "www.google.com:80", // single proxy |
572 "*.google.com"), // bypass rules | 572 "*.google.com"), // bypass rules |
573 }, | 573 }, |
574 }; | 574 }; |
575 | 575 |
576 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 576 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
577 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 577 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, |
578 tests[i].description.c_str())); | 578 tests[i].description.c_str())); |
579 MockEnvironmentVariableGetter* env_getter = | 579 MockEnvVarGetter* env_getter = new MockEnvVarGetter; |
580 new MockEnvironmentVariableGetter; | |
581 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | 580 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
582 SynchConfigGetter sync_config_getter( | 581 SynchConfigGetter sync_config_getter( |
583 new ProxyConfigServiceLinux(env_getter, gconf_getter)); | 582 new ProxyConfigServiceLinux(env_getter, gconf_getter)); |
584 ProxyConfig config; | 583 ProxyConfig config; |
585 gconf_getter->values = tests[i].values; | 584 gconf_getter->values = tests[i].values; |
586 sync_config_getter.SetupAndInitialFetch(); | 585 sync_config_getter.SetupAndInitialFetch(); |
587 sync_config_getter.SyncGetProxyConfig(&config); | 586 sync_config_getter.SyncGetProxyConfig(&config); |
588 | 587 |
589 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 588 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
590 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 589 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 ProxyRulesExpectation::Single( | 836 ProxyRulesExpectation::Single( |
838 "www.google.com:80", | 837 "www.google.com:80", |
839 // TODO(eroman): 127.0.0.1/8 is unsupported, so it was dropped | 838 // TODO(eroman): 127.0.0.1/8 is unsupported, so it was dropped |
840 "*.google.com,*foo.com:99,1.2.3.4:22"), | 839 "*.google.com,*foo.com:99,1.2.3.4:22"), |
841 }, | 840 }, |
842 }; | 841 }; |
843 | 842 |
844 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 843 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
845 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 844 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, |
846 tests[i].description.c_str())); | 845 tests[i].description.c_str())); |
847 MockEnvironmentVariableGetter* env_getter = | 846 MockEnvVarGetter* env_getter = new MockEnvVarGetter; |
848 new MockEnvironmentVariableGetter; | |
849 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | 847 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
850 SynchConfigGetter sync_config_getter( | 848 SynchConfigGetter sync_config_getter( |
851 new ProxyConfigServiceLinux(env_getter, gconf_getter)); | 849 new ProxyConfigServiceLinux(env_getter, gconf_getter)); |
852 ProxyConfig config; | 850 ProxyConfig config; |
853 env_getter->values = tests[i].values; | 851 env_getter->values = tests[i].values; |
854 sync_config_getter.SetupAndInitialFetch(); | 852 sync_config_getter.SetupAndInitialFetch(); |
855 sync_config_getter.SyncGetProxyConfig(&config); | 853 sync_config_getter.SyncGetProxyConfig(&config); |
856 | 854 |
857 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 855 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
858 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 856 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
859 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 857 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
860 } | 858 } |
861 } | 859 } |
862 | 860 |
863 TEST_F(ProxyConfigServiceLinuxTest, GconfNotification) { | 861 TEST_F(ProxyConfigServiceLinuxTest, GconfNotification) { |
864 MockEnvironmentVariableGetter* env_getter = | 862 MockEnvVarGetter* env_getter = new MockEnvVarGetter; |
865 new MockEnvironmentVariableGetter; | |
866 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | 863 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
867 ProxyConfigServiceLinux* service = | 864 ProxyConfigServiceLinux* service = |
868 new ProxyConfigServiceLinux(env_getter, gconf_getter); | 865 new ProxyConfigServiceLinux(env_getter, gconf_getter); |
869 SynchConfigGetter sync_config_getter(service); | 866 SynchConfigGetter sync_config_getter(service); |
870 ProxyConfig config; | 867 ProxyConfig config; |
871 | 868 |
872 // Start with no proxy. | 869 // Start with no proxy. |
873 gconf_getter->values.mode = "none"; | 870 gconf_getter->values.mode = "none"; |
874 sync_config_getter.SetupAndInitialFetch(); | 871 sync_config_getter.SetupAndInitialFetch(); |
875 sync_config_getter.SyncGetProxyConfig(&config); | 872 sync_config_getter.SyncGetProxyConfig(&config); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 "www.google.com:80", // http | 1156 "www.google.com:80", // http |
1160 "", // https | 1157 "", // https |
1161 "ftp.foo.com:80", // ftp | 1158 "ftp.foo.com:80", // ftp |
1162 ""), // bypass rules | 1159 ""), // bypass rules |
1163 }, | 1160 }, |
1164 }; | 1161 }; |
1165 | 1162 |
1166 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1163 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
1167 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, | 1164 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "] %s", i, |
1168 tests[i].description.c_str())); | 1165 tests[i].description.c_str())); |
1169 MockEnvironmentVariableGetter* env_getter = | 1166 MockEnvVarGetter* env_getter = new MockEnvVarGetter; |
1170 new MockEnvironmentVariableGetter; | |
1171 // Force the KDE getter to be used and tell it where the test is. | 1167 // Force the KDE getter to be used and tell it where the test is. |
1172 env_getter->values.DESKTOP_SESSION = "kde4"; | 1168 env_getter->values.DESKTOP_SESSION = "kde4"; |
1173 env_getter->values.KDE_HOME = kde_home_.value().c_str(); | 1169 env_getter->values.KDE_HOME = kde_home_.value().c_str(); |
1174 SynchConfigGetter sync_config_getter( | 1170 SynchConfigGetter sync_config_getter( |
1175 new ProxyConfigServiceLinux(env_getter)); | 1171 new ProxyConfigServiceLinux(env_getter)); |
1176 ProxyConfig config; | 1172 ProxyConfig config; |
1177 // Overwrite the kioslaverc file. | 1173 // Overwrite the kioslaverc file. |
1178 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), | 1174 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), |
1179 tests[i].kioslaverc.length()); | 1175 tests[i].kioslaverc.length()); |
1180 sync_config_getter.SetupAndInitialFetch(); | 1176 sync_config_getter.SetupAndInitialFetch(); |
1181 sync_config_getter.SyncGetProxyConfig(&config); | 1177 sync_config_getter.SyncGetProxyConfig(&config); |
1182 | 1178 |
1183 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 1179 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
1184 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 1180 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
1185 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 1181 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
1186 } | 1182 } |
1187 } | 1183 } |
1188 | 1184 |
1189 } // namespace net | 1185 } // namespace net |
OLD | NEW |