| OLD | NEW |
| 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 13 matching lines...) Expand all Loading... |
| 24 #include "testing/platform_test.h" | 24 #include "testing/platform_test.h" |
| 25 | 25 |
| 26 namespace net { | 26 namespace net { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 // Set of values for all environment variables that we might | 29 // Set of values for all environment variables that we might |
| 30 // query. NULL represents an unset variable. | 30 // query. NULL represents an unset variable. |
| 31 struct EnvVarValues { | 31 struct EnvVarValues { |
| 32 // The strange capitalization is so that the field matches the | 32 // The strange capitalization is so that the field matches the |
| 33 // environment variable name exactly. | 33 // environment variable name exactly. |
| 34 const char *DESKTOP_SESSION, *HOME, | 34 const char* DESKTOP_SESSION, *HOME, *KDEHOME, *KDE_SESSION_VERSION, |
| 35 *KDEHOME, *KDE_SESSION_VERSION, | 35 *auto_proxy, *all_proxy, *http_proxy, *https_proxy, *ftp_proxy, |
| 36 *auto_proxy, *all_proxy, | 36 *SOCKS_SERVER, *SOCKS_VERSION, *no_proxy; |
| 37 *http_proxy, *https_proxy, *ftp_proxy, | |
| 38 *SOCKS_SERVER, *SOCKS_VERSION, | |
| 39 *no_proxy; | |
| 40 }; | 37 }; |
| 41 | 38 |
| 42 // Undo macro pollution from GDK includes (from message_loop.h). | 39 // Undo macro pollution from GDK includes (from message_loop.h). |
| 43 #undef TRUE | 40 #undef TRUE |
| 44 #undef FALSE | 41 #undef FALSE |
| 45 | 42 |
| 46 // So as to distinguish between an unset gconf boolean variable and | 43 // So as to distinguish between an unset gconf boolean variable and |
| 47 // one that is false. | 44 // one that is false. |
| 48 enum BoolSettingValue { | 45 enum BoolSettingValue { UNSET = 0, TRUE, FALSE }; |
| 49 UNSET = 0, TRUE, FALSE | |
| 50 }; | |
| 51 | 46 |
| 52 // Set of values for all gconf settings that we might query. | 47 // Set of values for all gconf settings that we might query. |
| 53 struct GConfValues { | 48 struct GConfValues { |
| 54 // strings | 49 // strings |
| 55 const char *mode, *autoconfig_url, | 50 const char* mode, *autoconfig_url, *http_host, *secure_host, *ftp_host, |
| 56 *http_host, *secure_host, *ftp_host, *socks_host; | 51 *socks_host; |
| 57 // integers | 52 // integers |
| 58 int http_port, secure_port, ftp_port, socks_port; | 53 int http_port, secure_port, ftp_port, socks_port; |
| 59 // booleans | 54 // booleans |
| 60 BoolSettingValue use_proxy, same_proxy, use_auth; | 55 BoolSettingValue use_proxy, same_proxy, use_auth; |
| 61 // string list | 56 // string list |
| 62 std::vector<std::string> ignore_hosts; | 57 std::vector<std::string> ignore_hosts; |
| 63 }; | 58 }; |
| 64 | 59 |
| 65 // Mapping from a setting name to the location of the corresponding | 60 // Mapping from a setting name to the location of the corresponding |
| 66 // value (inside a EnvVarValues or GConfValues struct). | 61 // value (inside a EnvVarValues or GConfValues struct). |
| 67 template<typename key_type, typename value_type> | 62 template <typename key_type, typename value_type> |
| 68 struct SettingsTable { | 63 struct SettingsTable { |
| 69 typedef std::map<key_type, value_type*> map_type; | 64 typedef std::map<key_type, value_type*> map_type; |
| 70 | 65 |
| 71 // Gets the value from its location | 66 // Gets the value from its location |
| 72 value_type Get(key_type key) { | 67 value_type Get(key_type key) { |
| 73 typename map_type::const_iterator it = settings.find(key); | 68 typename map_type::const_iterator it = settings.find(key); |
| 74 // In case there's a typo or the unittest becomes out of sync. | 69 // In case there's a typo or the unittest becomes out of sync. |
| 75 CHECK(it != settings.end()) << "key " << key << " not found"; | 70 CHECK(it != settings.end()) << "key " << key << " not found"; |
| 76 value_type* value_ptr = it->second; | 71 value_type* value_ptr = it->second; |
| 77 return *value_ptr; | 72 return *value_ptr; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 95 ENTRY(ftp_proxy); | 90 ENTRY(ftp_proxy); |
| 96 ENTRY(no_proxy); | 91 ENTRY(no_proxy); |
| 97 ENTRY(SOCKS_SERVER); | 92 ENTRY(SOCKS_SERVER); |
| 98 ENTRY(SOCKS_VERSION); | 93 ENTRY(SOCKS_VERSION); |
| 99 #undef ENTRY | 94 #undef ENTRY |
| 100 Reset(); | 95 Reset(); |
| 101 } | 96 } |
| 102 | 97 |
| 103 // Zeroes all environment values. | 98 // Zeroes all environment values. |
| 104 void Reset() { | 99 void Reset() { |
| 105 EnvVarValues zero_values = { 0 }; | 100 EnvVarValues zero_values = {0}; |
| 106 values = zero_values; | 101 values = zero_values; |
| 107 } | 102 } |
| 108 | 103 |
| 109 // Begin base::Environment implementation. | 104 // Begin base::Environment implementation. |
| 110 virtual bool GetVar(const char* variable_name, std::string* result) OVERRIDE { | 105 virtual bool GetVar(const char* variable_name, std::string* result) OVERRIDE { |
| 111 std::map<std::string, const char**>::iterator it = | 106 std::map<std::string, const char**>::iterator it = |
| 112 table.find(variable_name); | 107 table.find(variable_name); |
| 113 if (it != table.end() && *(it->second) != NULL) { | 108 if (it != table.end() && *(it->second) != NULL) { |
| 114 // Note that the variable may be defined but empty. | 109 // Note that the variable may be defined but empty. |
| 115 *result = *(it->second); | 110 *result = *(it->second); |
| 116 return true; | 111 return true; |
| 117 } | 112 } |
| 118 return false; | 113 return false; |
| 119 } | 114 } |
| 120 | 115 |
| 121 virtual bool SetVar(const char* variable_name, const std::string& new_value) | 116 virtual bool SetVar(const char* variable_name, |
| 122 OVERRIDE { | 117 const std::string& new_value) OVERRIDE { |
| 123 ADD_FAILURE(); | 118 ADD_FAILURE(); |
| 124 return false; | 119 return false; |
| 125 } | 120 } |
| 126 | 121 |
| 127 virtual bool UnSetVar(const char* variable_name) OVERRIDE { | 122 virtual bool UnSetVar(const char* variable_name) OVERRIDE { |
| 128 ADD_FAILURE(); | 123 ADD_FAILURE(); |
| 129 return false; | 124 return false; |
| 130 } | 125 } |
| 131 // End base::Environment implementation. | 126 // End base::Environment implementation. |
| 132 | 127 |
| 133 // Intentionally public, for convenience when setting up a test. | 128 // Intentionally public, for convenience when setting up a test. |
| 134 EnvVarValues values; | 129 EnvVarValues values; |
| 135 | 130 |
| 136 private: | 131 private: |
| 137 std::map<std::string, const char**> table; | 132 std::map<std::string, const char**> table; |
| 138 }; | 133 }; |
| 139 | 134 |
| 140 class MockSettingGetter | 135 class MockSettingGetter : public ProxyConfigServiceLinux::SettingGetter { |
| 141 : public ProxyConfigServiceLinux::SettingGetter { | |
| 142 public: | 136 public: |
| 143 typedef ProxyConfigServiceLinux::SettingGetter SettingGetter; | 137 typedef ProxyConfigServiceLinux::SettingGetter SettingGetter; |
| 144 MockSettingGetter() { | 138 MockSettingGetter() { |
| 145 #define ENTRY(key, field) \ | 139 #define ENTRY(key, field) \ |
| 146 strings_table.settings[SettingGetter::key] = &values.field | 140 strings_table.settings[SettingGetter::key] = &values.field |
| 147 ENTRY(PROXY_MODE, mode); | 141 ENTRY(PROXY_MODE, mode); |
| 148 ENTRY(PROXY_AUTOCONF_URL, autoconfig_url); | 142 ENTRY(PROXY_AUTOCONF_URL, autoconfig_url); |
| 149 ENTRY(PROXY_HTTP_HOST, http_host); | 143 ENTRY(PROXY_HTTP_HOST, http_host); |
| 150 ENTRY(PROXY_HTTPS_HOST, secure_host); | 144 ENTRY(PROXY_HTTPS_HOST, secure_host); |
| 151 ENTRY(PROXY_FTP_HOST, ftp_host); | 145 ENTRY(PROXY_FTP_HOST, ftp_host); |
| 152 ENTRY(PROXY_SOCKS_HOST, socks_host); | 146 ENTRY(PROXY_SOCKS_HOST, socks_host); |
| 153 #undef ENTRY | 147 #undef ENTRY |
| 154 #define ENTRY(key, field) \ | 148 #define ENTRY(key, field) \ |
| 155 ints_table.settings[SettingGetter::key] = &values.field | 149 ints_table.settings[SettingGetter::key] = &values.field |
| 156 ENTRY(PROXY_HTTP_PORT, http_port); | 150 ENTRY(PROXY_HTTP_PORT, http_port); |
| 157 ENTRY(PROXY_HTTPS_PORT, secure_port); | 151 ENTRY(PROXY_HTTPS_PORT, secure_port); |
| 158 ENTRY(PROXY_FTP_PORT, ftp_port); | 152 ENTRY(PROXY_FTP_PORT, ftp_port); |
| 159 ENTRY(PROXY_SOCKS_PORT, socks_port); | 153 ENTRY(PROXY_SOCKS_PORT, socks_port); |
| 160 #undef ENTRY | 154 #undef ENTRY |
| 161 #define ENTRY(key, field) \ | 155 #define ENTRY(key, field) \ |
| 162 bools_table.settings[SettingGetter::key] = &values.field | 156 bools_table.settings[SettingGetter::key] = &values.field |
| 163 ENTRY(PROXY_USE_HTTP_PROXY, use_proxy); | 157 ENTRY(PROXY_USE_HTTP_PROXY, use_proxy); |
| 164 ENTRY(PROXY_USE_SAME_PROXY, same_proxy); | 158 ENTRY(PROXY_USE_SAME_PROXY, same_proxy); |
| 165 ENTRY(PROXY_USE_AUTHENTICATION, use_auth); | 159 ENTRY(PROXY_USE_AUTHENTICATION, use_auth); |
| 166 #undef ENTRY | 160 #undef ENTRY |
| 167 string_lists_table.settings[SettingGetter::PROXY_IGNORE_HOSTS] = | 161 string_lists_table.settings[SettingGetter::PROXY_IGNORE_HOSTS] = |
| 168 &values.ignore_hosts; | 162 &values.ignore_hosts; |
| 169 Reset(); | 163 Reset(); |
| 170 } | 164 } |
| 171 | 165 |
| 172 // Zeros all environment values. | 166 // Zeros all environment values. |
| 173 void Reset() { | 167 void Reset() { |
| 174 GConfValues zero_values = { 0 }; | 168 GConfValues zero_values = {0}; |
| 175 values = zero_values; | 169 values = zero_values; |
| 176 } | 170 } |
| 177 | 171 |
| 178 virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, | 172 virtual bool Init(base::SingleThreadTaskRunner* glib_thread_task_runner, |
| 179 base::MessageLoopForIO* file_loop) OVERRIDE { | 173 base::MessageLoopForIO* file_loop) OVERRIDE { |
| 180 return true; | 174 return true; |
| 181 } | 175 } |
| 182 | 176 |
| 183 virtual void ShutDown() OVERRIDE {} | 177 virtual void ShutDown() OVERRIDE {} |
| 184 | 178 |
| 185 virtual bool SetUpNotifications(ProxyConfigServiceLinux::Delegate* delegate) | 179 virtual bool SetUpNotifications( |
| 186 OVERRIDE { | 180 ProxyConfigServiceLinux::Delegate* delegate) OVERRIDE { |
| 187 return true; | 181 return true; |
| 188 } | 182 } |
| 189 | 183 |
| 190 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { | 184 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { |
| 191 return NULL; | 185 return NULL; |
| 192 } | 186 } |
| 193 | 187 |
| 194 virtual ProxyConfigSource GetConfigSource() OVERRIDE { | 188 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
| 195 return PROXY_CONFIG_SOURCE_TEST; | 189 return PROXY_CONFIG_SOURCE_TEST; |
| 196 } | 190 } |
| 197 | 191 |
| 198 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 192 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
| 199 const char* value = strings_table.Get(key); | 193 const char* value = strings_table.Get(key); |
| 200 if (value) { | 194 if (value) { |
| 201 *result = value; | 195 *result = value; |
| 202 return true; | 196 return true; |
| 203 } | 197 } |
| 204 return false; | 198 return false; |
| 205 } | 199 } |
| 206 | 200 |
| 207 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { | 201 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { |
| 208 BoolSettingValue value = bools_table.Get(key); | 202 BoolSettingValue value = bools_table.Get(key); |
| 209 switch (value) { | 203 switch (value) { |
| 210 case UNSET: | 204 case UNSET: |
| 211 return false; | 205 return false; |
| 212 case TRUE: | 206 case TRUE: |
| 213 *result = true; | 207 *result = true; |
| 214 break; | 208 break; |
| 215 case FALSE: | 209 case FALSE: |
| 216 *result = false; | 210 *result = false; |
| 217 } | 211 } |
| 218 return true; | 212 return true; |
| 219 } | 213 } |
| 220 | 214 |
| 221 virtual bool GetInt(IntSetting key, int* result) OVERRIDE { | 215 virtual bool GetInt(IntSetting key, int* result) OVERRIDE { |
| 222 // We don't bother to distinguish unset keys from 0 values. | 216 // We don't bother to distinguish unset keys from 0 values. |
| 223 *result = ints_table.Get(key); | 217 *result = ints_table.Get(key); |
| 224 return true; | 218 return true; |
| 225 } | 219 } |
| 226 | 220 |
| 227 virtual bool GetStringList(StringListSetting key, | 221 virtual bool GetStringList(StringListSetting key, |
| 228 std::vector<std::string>* result) OVERRIDE { | 222 std::vector<std::string>* result) OVERRIDE { |
| 229 *result = string_lists_table.Get(key); | 223 *result = string_lists_table.Get(key); |
| 230 // We don't bother to distinguish unset keys from empty lists. | 224 // We don't bother to distinguish unset keys from empty lists. |
| 231 return !result->empty(); | 225 return !result->empty(); |
| 232 } | 226 } |
| 233 | 227 |
| 234 virtual bool BypassListIsReversed() OVERRIDE { | 228 virtual bool BypassListIsReversed() OVERRIDE { return false; } |
| 235 return false; | |
| 236 } | |
| 237 | 229 |
| 238 virtual bool MatchHostsUsingSuffixMatching() OVERRIDE { | 230 virtual bool MatchHostsUsingSuffixMatching() OVERRIDE { return false; } |
| 239 return false; | |
| 240 } | |
| 241 | 231 |
| 242 // Intentionally public, for convenience when setting up a test. | 232 // Intentionally public, for convenience when setting up a test. |
| 243 GConfValues values; | 233 GConfValues values; |
| 244 | 234 |
| 245 private: | 235 private: |
| 246 SettingsTable<StringSetting, const char*> strings_table; | 236 SettingsTable<StringSetting, const char*> strings_table; |
| 247 SettingsTable<BoolSetting, BoolSettingValue> bools_table; | 237 SettingsTable<BoolSetting, BoolSettingValue> bools_table; |
| 248 SettingsTable<IntSetting, int> ints_table; | 238 SettingsTable<IntSetting, int> ints_table; |
| 249 SettingsTable<StringListSetting, | 239 SettingsTable<StringListSetting, std::vector<std::string> > |
| 250 std::vector<std::string> > string_lists_table; | 240 string_lists_table; |
| 251 }; | 241 }; |
| 252 | 242 |
| 253 } // namespace | 243 } // namespace |
| 254 } // namespace net | 244 } // namespace net |
| 255 | 245 |
| 256 // This helper class runs ProxyConfigServiceLinux::GetLatestProxyConfig() on | 246 // This helper class runs ProxyConfigServiceLinux::GetLatestProxyConfig() on |
| 257 // the IO thread and synchronously waits for the result. | 247 // the IO thread and synchronously waits for the result. |
| 258 // Some code duplicated from proxy_script_fetcher_unittest.cc. | 248 // Some code duplicated from proxy_script_fetcher_unittest.cc. |
| 259 class SynchConfigGetter { | 249 class SynchConfigGetter { |
| 260 public: | 250 public: |
| 261 // Takes ownership of |config_service|. | 251 // Takes ownership of |config_service|. |
| 262 explicit SynchConfigGetter(net::ProxyConfigServiceLinux* config_service) | 252 explicit SynchConfigGetter(net::ProxyConfigServiceLinux* config_service) |
| 263 : event_(false, false), | 253 : event_(false, false), |
| 264 io_thread_("IO_Thread"), | 254 io_thread_("IO_Thread"), |
| 265 config_service_(config_service) { | 255 config_service_(config_service) { |
| 266 // Start an IO thread. | 256 // Start an IO thread. |
| 267 base::Thread::Options options; | 257 base::Thread::Options options; |
| 268 options.message_loop_type = base::MessageLoop::TYPE_IO; | 258 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 269 io_thread_.StartWithOptions(options); | 259 io_thread_.StartWithOptions(options); |
| 270 | 260 |
| 271 // Make sure the thread started. | 261 // Make sure the thread started. |
| 272 io_thread_.message_loop()->PostTask(FROM_HERE, | 262 io_thread_.message_loop()->PostTask( |
| 263 FROM_HERE, |
| 273 base::Bind(&SynchConfigGetter::Init, base::Unretained(this))); | 264 base::Bind(&SynchConfigGetter::Init, base::Unretained(this))); |
| 274 Wait(); | 265 Wait(); |
| 275 } | 266 } |
| 276 | 267 |
| 277 ~SynchConfigGetter() { | 268 ~SynchConfigGetter() { |
| 278 // Let the config service post a destroy message to the IO thread | 269 // Let the config service post a destroy message to the IO thread |
| 279 // before cleaning up that thread. | 270 // before cleaning up that thread. |
| 280 delete config_service_; | 271 delete config_service_; |
| 281 // Clean up the IO thread. | 272 // Clean up the IO thread. |
| 282 io_thread_.message_loop()->PostTask(FROM_HERE, | 273 io_thread_.message_loop()->PostTask( |
| 274 FROM_HERE, |
| 283 base::Bind(&SynchConfigGetter::CleanUp, base::Unretained(this))); | 275 base::Bind(&SynchConfigGetter::CleanUp, base::Unretained(this))); |
| 284 Wait(); | 276 Wait(); |
| 285 } | 277 } |
| 286 | 278 |
| 287 // Does gconf setup and initial fetch of the proxy config, | 279 // Does gconf setup and initial fetch of the proxy config, |
| 288 // all on the calling thread (meant to be the thread with the | 280 // all on the calling thread (meant to be the thread with the |
| 289 // default glib main loop, which is the UI thread). | 281 // default glib main loop, which is the UI thread). |
| 290 void SetupAndInitialFetch() { | 282 void SetupAndInitialFetch() { |
| 291 base::MessageLoop* file_loop = io_thread_.message_loop(); | 283 base::MessageLoop* file_loop = io_thread_.message_loop(); |
| 292 DCHECK_EQ(base::MessageLoop::TYPE_IO, file_loop->type()); | 284 DCHECK_EQ(base::MessageLoop::TYPE_IO, file_loop->type()); |
| 293 // We pass the mock IO thread as both the IO and file threads. | 285 // We pass the mock IO thread as both the IO and file threads. |
| 294 config_service_->SetupAndFetchInitialConfig( | 286 config_service_->SetupAndFetchInitialConfig( |
| 295 base::MessageLoopProxy::current().get(), | 287 base::MessageLoopProxy::current().get(), |
| 296 io_thread_.message_loop_proxy().get(), | 288 io_thread_.message_loop_proxy().get(), |
| 297 static_cast<base::MessageLoopForIO*>(file_loop)); | 289 static_cast<base::MessageLoopForIO*>(file_loop)); |
| 298 } | 290 } |
| 299 // Synchronously gets the proxy config. | 291 // Synchronously gets the proxy config. |
| 300 net::ProxyConfigService::ConfigAvailability SyncGetLatestProxyConfig( | 292 net::ProxyConfigService::ConfigAvailability SyncGetLatestProxyConfig( |
| 301 net::ProxyConfig* config) { | 293 net::ProxyConfig* config) { |
| 302 io_thread_.message_loop()->PostTask(FROM_HERE, | 294 io_thread_.message_loop()->PostTask( |
| 295 FROM_HERE, |
| 303 base::Bind(&SynchConfigGetter::GetLatestConfigOnIOThread, | 296 base::Bind(&SynchConfigGetter::GetLatestConfigOnIOThread, |
| 304 base::Unretained(this))); | 297 base::Unretained(this))); |
| 305 Wait(); | 298 Wait(); |
| 306 *config = proxy_config_; | 299 *config = proxy_config_; |
| 307 return get_latest_config_result_; | 300 return get_latest_config_result_; |
| 308 } | 301 } |
| 309 | 302 |
| 310 private: | 303 private: |
| 311 // [Runs on |io_thread_|] | 304 // [Runs on |io_thread_|] |
| 312 void Init() { | 305 void Init() { event_.Signal(); } |
| 313 event_.Signal(); | |
| 314 } | |
| 315 | 306 |
| 316 // Calls GetLatestProxyConfig, running on |io_thread_| Signals |event_| | 307 // Calls GetLatestProxyConfig, running on |io_thread_| Signals |event_| |
| 317 // on completion. | 308 // on completion. |
| 318 void GetLatestConfigOnIOThread() { | 309 void GetLatestConfigOnIOThread() { |
| 319 get_latest_config_result_ = | 310 get_latest_config_result_ = |
| 320 config_service_->GetLatestProxyConfig(&proxy_config_); | 311 config_service_->GetLatestProxyConfig(&proxy_config_); |
| 321 event_.Signal(); | 312 event_.Signal(); |
| 322 } | 313 } |
| 323 | 314 |
| 324 // [Runs on |io_thread_|] Signals |event_| on cleanup completion. | 315 // [Runs on |io_thread_|] Signals |event_| on cleanup completion. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 393 |
| 403 // Input. | 394 // Input. |
| 404 GConfValues values; | 395 GConfValues values; |
| 405 | 396 |
| 406 // Expected outputs (availability and fields of ProxyConfig). | 397 // Expected outputs (availability and fields of ProxyConfig). |
| 407 ProxyConfigService::ConfigAvailability availability; | 398 ProxyConfigService::ConfigAvailability availability; |
| 408 bool auto_detect; | 399 bool auto_detect; |
| 409 GURL pac_url; | 400 GURL pac_url; |
| 410 ProxyRulesExpectation proxy_rules; | 401 ProxyRulesExpectation proxy_rules; |
| 411 } tests[] = { | 402 } tests[] = { |
| 412 { | 403 { |
| 413 TEST_DESC("No proxying"), | 404 TEST_DESC("No proxying"), |
| 414 { // Input. | 405 { // Input. |
| 415 "none", // mode | 406 "none", // mode |
| 416 "", // autoconfig_url | 407 "", // autoconfig_url |
| 417 "", "", "", "", // hosts | 408 "", "", "", "", // hosts |
| 418 0, 0, 0, 0, // ports | 409 0, 0, 0, 0, // ports |
| 419 FALSE, FALSE, FALSE, // use, same, auth | 410 FALSE, FALSE, FALSE, // use, same, auth |
| 420 empty_ignores, // ignore_hosts | 411 empty_ignores, // ignore_hosts |
| 421 }, | 412 }, |
| 422 | 413 |
| 423 // Expected result. | 414 // Expected result. |
| 424 ProxyConfigService::CONFIG_VALID, | 415 ProxyConfigService::CONFIG_VALID, |
| 425 false, // auto_detect | 416 false, // auto_detect |
| 426 GURL(), // pac_url | 417 GURL(), // pac_url |
| 427 ProxyRulesExpectation::Empty(), | 418 ProxyRulesExpectation::Empty(), |
| 428 }, | 419 }, |
| 429 | 420 { |
| 430 { | 421 TEST_DESC("Auto detect"), |
| 431 TEST_DESC("Auto detect"), | 422 { // Input. |
| 432 { // Input. | 423 "auto", // mode |
| 433 "auto", // mode | 424 "", // autoconfig_url |
| 434 "", // autoconfig_url | 425 "", "", "", "", // hosts |
| 435 "", "", "", "", // hosts | 426 0, 0, 0, 0, // ports |
| 436 0, 0, 0, 0, // ports | 427 FALSE, FALSE, FALSE, // use, same, auth |
| 437 FALSE, FALSE, FALSE, // use, same, auth | 428 empty_ignores, // ignore_hosts |
| 438 empty_ignores, // ignore_hosts | 429 }, |
| 439 }, | 430 |
| 440 | 431 // Expected result. |
| 441 // Expected result. | 432 ProxyConfigService::CONFIG_VALID, |
| 442 ProxyConfigService::CONFIG_VALID, | 433 true, // auto_detect |
| 443 true, // auto_detect | 434 GURL(), // pac_url |
| 444 GURL(), // pac_url | 435 ProxyRulesExpectation::Empty(), |
| 445 ProxyRulesExpectation::Empty(), | 436 }, |
| 446 }, | 437 { |
| 447 | 438 TEST_DESC("Valid PAC URL"), |
| 448 { | 439 { // Input. |
| 449 TEST_DESC("Valid PAC URL"), | 440 "auto", // mode |
| 450 { // Input. | 441 "http://wpad/wpad.dat", // autoconfig_url |
| 451 "auto", // mode | 442 "", "", "", "", // hosts |
| 452 "http://wpad/wpad.dat", // autoconfig_url | 443 0, 0, 0, 0, // ports |
| 453 "", "", "", "", // hosts | 444 FALSE, FALSE, FALSE, // use, same, auth |
| 454 0, 0, 0, 0, // ports | 445 empty_ignores, // ignore_hosts |
| 455 FALSE, FALSE, FALSE, // use, same, auth | 446 }, |
| 456 empty_ignores, // ignore_hosts | 447 |
| 457 }, | 448 // Expected result. |
| 458 | 449 ProxyConfigService::CONFIG_VALID, |
| 459 // Expected result. | 450 false, // auto_detect |
| 460 ProxyConfigService::CONFIG_VALID, | 451 GURL("http://wpad/wpad.dat"), // pac_url |
| 461 false, // auto_detect | 452 ProxyRulesExpectation::Empty(), |
| 462 GURL("http://wpad/wpad.dat"), // pac_url | 453 }, |
| 463 ProxyRulesExpectation::Empty(), | 454 { |
| 464 }, | 455 TEST_DESC("Invalid PAC URL"), |
| 465 | 456 { // Input. |
| 466 { | 457 "auto", // mode |
| 467 TEST_DESC("Invalid PAC URL"), | 458 "wpad.dat", // autoconfig_url |
| 468 { // Input. | 459 "", "", "", "", // hosts |
| 469 "auto", // mode | 460 0, 0, 0, 0, // ports |
| 470 "wpad.dat", // autoconfig_url | 461 FALSE, FALSE, FALSE, // use, same, auth |
| 471 "", "", "", "", // hosts | 462 empty_ignores, // ignore_hosts |
| 472 0, 0, 0, 0, // ports | 463 }, |
| 473 FALSE, FALSE, FALSE, // use, same, auth | 464 |
| 474 empty_ignores, // ignore_hosts | 465 // Expected result. |
| 475 }, | 466 ProxyConfigService::CONFIG_VALID, |
| 476 | 467 false, // auto_detect |
| 477 // Expected result. | 468 GURL(), // pac_url |
| 478 ProxyConfigService::CONFIG_VALID, | 469 ProxyRulesExpectation::Empty(), |
| 479 false, // auto_detect | 470 }, |
| 480 GURL(), // pac_url | 471 { |
| 481 ProxyRulesExpectation::Empty(), | 472 TEST_DESC("Single-host in proxy list"), |
| 482 }, | 473 { // Input. |
| 483 | 474 "manual", // mode |
| 484 { | 475 "", // autoconfig_url |
| 485 TEST_DESC("Single-host in proxy list"), | 476 "www.google.com", "", "", "", // hosts |
| 486 { // Input. | 477 80, 0, 0, 0, // ports |
| 487 "manual", // mode | 478 TRUE, TRUE, FALSE, // use, same, auth |
| 488 "", // autoconfig_url | 479 empty_ignores, // ignore_hosts |
| 489 "www.google.com", "", "", "", // hosts | 480 }, |
| 490 80, 0, 0, 0, // ports | 481 |
| 491 TRUE, TRUE, FALSE, // use, same, auth | 482 // Expected result. |
| 492 empty_ignores, // ignore_hosts | 483 ProxyConfigService::CONFIG_VALID, |
| 493 }, | 484 false, // auto_detect |
| 494 | 485 GURL(), // pac_url |
| 495 // Expected result. | 486 ProxyRulesExpectation::Single("www.google.com:80", // single proxy |
| 496 ProxyConfigService::CONFIG_VALID, | 487 ""), // bypass rules |
| 497 false, // auto_detect | 488 }, |
| 498 GURL(), // pac_url | 489 { |
| 499 ProxyRulesExpectation::Single( | 490 TEST_DESC("use_http_proxy is honored"), |
| 500 "www.google.com:80", // single proxy | 491 { // Input. |
| 501 ""), // bypass rules | 492 "manual", // mode |
| 502 }, | 493 "", // autoconfig_url |
| 503 | 494 "www.google.com", "", "", "", // hosts |
| 504 { | 495 80, 0, 0, 0, // ports |
| 505 TEST_DESC("use_http_proxy is honored"), | 496 FALSE, TRUE, FALSE, // use, same, auth |
| 506 { // Input. | 497 empty_ignores, // ignore_hosts |
| 507 "manual", // mode | 498 }, |
| 508 "", // autoconfig_url | 499 |
| 509 "www.google.com", "", "", "", // hosts | 500 // Expected result. |
| 510 80, 0, 0, 0, // ports | 501 ProxyConfigService::CONFIG_VALID, |
| 511 FALSE, TRUE, FALSE, // use, same, auth | 502 false, // auto_detect |
| 512 empty_ignores, // ignore_hosts | 503 GURL(), // pac_url |
| 513 }, | 504 ProxyRulesExpectation::Empty(), |
| 514 | 505 }, |
| 515 // Expected result. | 506 { |
| 516 ProxyConfigService::CONFIG_VALID, | 507 TEST_DESC("use_http_proxy and use_same_proxy are optional"), |
| 517 false, // auto_detect | 508 { // Input. |
| 518 GURL(), // pac_url | 509 "manual", // mode |
| 519 ProxyRulesExpectation::Empty(), | 510 "", // autoconfig_url |
| 520 }, | 511 "www.google.com", "", "", "", // hosts |
| 521 | 512 80, 0, 0, 0, // ports |
| 522 { | 513 UNSET, UNSET, FALSE, // use, same, auth |
| 523 TEST_DESC("use_http_proxy and use_same_proxy are optional"), | 514 empty_ignores, // ignore_hosts |
| 524 { // Input. | 515 }, |
| 525 "manual", // mode | 516 |
| 526 "", // autoconfig_url | 517 // Expected result. |
| 527 "www.google.com", "", "", "", // hosts | 518 ProxyConfigService::CONFIG_VALID, |
| 528 80, 0, 0, 0, // ports | 519 false, // auto_detect |
| 529 UNSET, UNSET, FALSE, // use, same, auth | 520 GURL(), // pac_url |
| 530 empty_ignores, // ignore_hosts | 521 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 531 }, | 522 "", // https |
| 532 | 523 "", // ftp |
| 533 // Expected result. | 524 ""), // bypass rules |
| 534 ProxyConfigService::CONFIG_VALID, | 525 }, |
| 535 false, // auto_detect | 526 { |
| 536 GURL(), // pac_url | 527 TEST_DESC("Single-host, different port"), |
| 537 ProxyRulesExpectation::PerScheme( | 528 { // Input. |
| 538 "www.google.com:80", // http | 529 "manual", // mode |
| 539 "", // https | 530 "", // autoconfig_url |
| 540 "", // ftp | 531 "www.google.com", "", "", "", // hosts |
| 541 ""), // bypass rules | 532 88, 0, 0, 0, // ports |
| 542 }, | 533 TRUE, TRUE, FALSE, // use, same, auth |
| 543 | 534 empty_ignores, // ignore_hosts |
| 544 { | 535 }, |
| 545 TEST_DESC("Single-host, different port"), | 536 |
| 546 { // Input. | 537 // Expected result. |
| 547 "manual", // mode | 538 ProxyConfigService::CONFIG_VALID, |
| 548 "", // autoconfig_url | 539 false, // auto_detect |
| 549 "www.google.com", "", "", "", // hosts | 540 GURL(), // pac_url |
| 550 88, 0, 0, 0, // ports | 541 ProxyRulesExpectation::Single("www.google.com:88", // single proxy |
| 551 TRUE, TRUE, FALSE, // use, same, auth | 542 ""), // bypass rules |
| 552 empty_ignores, // ignore_hosts | 543 }, |
| 553 }, | 544 { |
| 554 | 545 TEST_DESC("Per-scheme proxy rules"), |
| 555 // Expected result. | 546 { // Input. |
| 556 ProxyConfigService::CONFIG_VALID, | 547 "manual", // mode |
| 557 false, // auto_detect | 548 "", // autoconfig_url |
| 558 GURL(), // pac_url | 549 "www.google.com", // http_host |
| 559 ProxyRulesExpectation::Single( | 550 "www.foo.com", // secure_host |
| 560 "www.google.com:88", // single proxy | 551 "ftp.foo.com", // ftp |
| 561 ""), // bypass rules | 552 "", // socks |
| 562 }, | 553 88, 110, 121, 0, // ports |
| 563 | 554 TRUE, FALSE, FALSE, // use, same, auth |
| 564 { | 555 empty_ignores, // ignore_hosts |
| 565 TEST_DESC("Per-scheme proxy rules"), | 556 }, |
| 566 { // Input. | 557 |
| 567 "manual", // mode | 558 // Expected result. |
| 568 "", // autoconfig_url | 559 ProxyConfigService::CONFIG_VALID, |
| 569 "www.google.com", // http_host | 560 false, // auto_detect |
| 570 "www.foo.com", // secure_host | 561 GURL(), // pac_url |
| 571 "ftp.foo.com", // ftp | 562 ProxyRulesExpectation::PerScheme("www.google.com:88", // http |
| 572 "", // socks | 563 "www.foo.com:110", // https |
| 573 88, 110, 121, 0, // ports | 564 "ftp.foo.com:121", // ftp |
| 574 TRUE, FALSE, FALSE, // use, same, auth | 565 ""), // bypass rules |
| 575 empty_ignores, // ignore_hosts | 566 }, |
| 576 }, | 567 { |
| 577 | 568 TEST_DESC("socks"), |
| 578 // Expected result. | 569 { // Input. |
| 579 ProxyConfigService::CONFIG_VALID, | 570 "manual", // mode |
| 580 false, // auto_detect | 571 "", // autoconfig_url |
| 581 GURL(), // pac_url | 572 "", "", "", "socks.com", // hosts |
| 582 ProxyRulesExpectation::PerScheme( | 573 0, 0, 0, 99, // ports |
| 583 "www.google.com:88", // http | 574 TRUE, FALSE, FALSE, // use, same, auth |
| 584 "www.foo.com:110", // https | 575 empty_ignores, // ignore_hosts |
| 585 "ftp.foo.com:121", // ftp | 576 }, |
| 586 ""), // bypass rules | 577 |
| 587 }, | 578 // Expected result. |
| 588 | 579 ProxyConfigService::CONFIG_VALID, |
| 589 { | 580 false, // auto_detect |
| 590 TEST_DESC("socks"), | 581 GURL(), // pac_url |
| 591 { // Input. | 582 ProxyRulesExpectation::Single("socks5://socks.com:99", // single proxy |
| 592 "manual", // mode | 583 "") // bypass rules |
| 593 "", // autoconfig_url | 584 }, |
| 594 "", "", "", "socks.com", // hosts | 585 { |
| 595 0, 0, 0, 99, // ports | 586 TEST_DESC("Per-scheme proxy rules with fallback to SOCKS"), |
| 596 TRUE, FALSE, FALSE, // use, same, auth | 587 { // Input. |
| 597 empty_ignores, // ignore_hosts | 588 "manual", // mode |
| 598 }, | 589 "", // autoconfig_url |
| 599 | 590 "www.google.com", // http_host |
| 600 // Expected result. | 591 "www.foo.com", // secure_host |
| 601 ProxyConfigService::CONFIG_VALID, | 592 "ftp.foo.com", // ftp |
| 602 false, // auto_detect | 593 "foobar.net", // socks |
| 603 GURL(), // pac_url | 594 88, 110, 121, 99, // ports |
| 604 ProxyRulesExpectation::Single( | 595 TRUE, FALSE, FALSE, // use, same, auth |
| 605 "socks5://socks.com:99", // single proxy | 596 empty_ignores, // ignore_hosts |
| 606 "") // bypass rules | 597 }, |
| 607 }, | 598 |
| 608 | 599 // Expected result. |
| 609 { | 600 ProxyConfigService::CONFIG_VALID, |
| 610 TEST_DESC("Per-scheme proxy rules with fallback to SOCKS"), | 601 false, // auto_detect |
| 611 { // Input. | 602 GURL(), // pac_url |
| 612 "manual", // mode | 603 ProxyRulesExpectation::PerSchemeWithSocks( |
| 613 "", // autoconfig_url | 604 "www.google.com:88", // http |
| 614 "www.google.com", // http_host | 605 "www.foo.com:110", // https |
| 615 "www.foo.com", // secure_host | 606 "ftp.foo.com:121", // ftp |
| 616 "ftp.foo.com", // ftp | 607 "socks5://foobar.net:99", // socks |
| 617 "foobar.net", // socks | 608 ""), // bypass rules |
| 618 88, 110, 121, 99, // ports | 609 }, |
| 619 TRUE, FALSE, FALSE, // use, same, auth | 610 { |
| 620 empty_ignores, // ignore_hosts | 611 TEST_DESC("Per-scheme proxy rules (just HTTP) with fallback to SOCKS"), |
| 621 }, | 612 { // Input. |
| 622 | 613 "manual", // mode |
| 623 // Expected result. | 614 "", // autoconfig_url |
| 624 ProxyConfigService::CONFIG_VALID, | 615 "www.google.com", // http_host |
| 625 false, // auto_detect | 616 "", // secure_host |
| 626 GURL(), // pac_url | 617 "", // ftp |
| 627 ProxyRulesExpectation::PerSchemeWithSocks( | 618 "foobar.net", // socks |
| 628 "www.google.com:88", // http | 619 88, 0, 0, 99, // ports |
| 629 "www.foo.com:110", // https | 620 TRUE, FALSE, FALSE, // use, same, auth |
| 630 "ftp.foo.com:121", // ftp | 621 empty_ignores, // ignore_hosts |
| 631 "socks5://foobar.net:99", // socks | 622 }, |
| 632 ""), // bypass rules | 623 |
| 633 }, | 624 // Expected result. |
| 634 | 625 ProxyConfigService::CONFIG_VALID, |
| 635 { | 626 false, // auto_detect |
| 636 TEST_DESC("Per-scheme proxy rules (just HTTP) with fallback to SOCKS"), | 627 GURL(), // pac_url |
| 637 { // Input. | 628 ProxyRulesExpectation::PerSchemeWithSocks( |
| 638 "manual", // mode | 629 "www.google.com:88", // http |
| 639 "", // autoconfig_url | 630 "", // https |
| 640 "www.google.com", // http_host | 631 "", // ftp |
| 641 "", // secure_host | 632 "socks5://foobar.net:99", // socks |
| 642 "", // ftp | 633 ""), // bypass rules |
| 643 "foobar.net", // socks | 634 }, |
| 644 88, 0, 0, 99, // ports | 635 { |
| 645 TRUE, FALSE, FALSE, // use, same, auth | 636 TEST_DESC("Bypass *.google.com"), |
| 646 empty_ignores, // ignore_hosts | 637 { // Input. |
| 647 }, | 638 "manual", // mode |
| 648 | 639 "", // autoconfig_url |
| 649 // Expected result. | 640 "www.google.com", "", "", "", // hosts |
| 650 ProxyConfigService::CONFIG_VALID, | 641 80, 0, 0, 0, // ports |
| 651 false, // auto_detect | 642 TRUE, TRUE, FALSE, // use, same, auth |
| 652 GURL(), // pac_url | 643 google_ignores, // ignore_hosts |
| 653 ProxyRulesExpectation::PerSchemeWithSocks( | 644 }, |
| 654 "www.google.com:88", // http | 645 ProxyConfigService::CONFIG_VALID, |
| 655 "", // https | 646 false, // auto_detect |
| 656 "", // ftp | 647 GURL(), // pac_url |
| 657 "socks5://foobar.net:99", // socks | 648 ProxyRulesExpectation::Single("www.google.com:80", // single proxy |
| 658 ""), // bypass rules | 649 "*.google.com"), // bypass rules |
| 659 }, | 650 }, |
| 660 | 651 }; |
| 661 { | |
| 662 TEST_DESC("Bypass *.google.com"), | |
| 663 { // Input. | |
| 664 "manual", // mode | |
| 665 "", // autoconfig_url | |
| 666 "www.google.com", "", "", "", // hosts | |
| 667 80, 0, 0, 0, // ports | |
| 668 TRUE, TRUE, FALSE, // use, same, auth | |
| 669 google_ignores, // ignore_hosts | |
| 670 }, | |
| 671 | |
| 672 ProxyConfigService::CONFIG_VALID, | |
| 673 false, // auto_detect | |
| 674 GURL(), // pac_url | |
| 675 ProxyRulesExpectation::Single( | |
| 676 "www.google.com:80", // single proxy | |
| 677 "*.google.com"), // bypass rules | |
| 678 }, | |
| 679 }; | |
| 680 | 652 |
| 681 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 653 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 682 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, | 654 SCOPED_TRACE(base::StringPrintf( |
| 683 tests[i].description.c_str())); | 655 "Test[%" PRIuS "] %s", i, tests[i].description.c_str())); |
| 684 MockEnvironment* env = new MockEnvironment; | 656 MockEnvironment* env = new MockEnvironment; |
| 685 MockSettingGetter* setting_getter = new MockSettingGetter; | 657 MockSettingGetter* setting_getter = new MockSettingGetter; |
| 686 SynchConfigGetter sync_config_getter( | 658 SynchConfigGetter sync_config_getter( |
| 687 new ProxyConfigServiceLinux(env, setting_getter)); | 659 new ProxyConfigServiceLinux(env, setting_getter)); |
| 688 ProxyConfig config; | 660 ProxyConfig config; |
| 689 setting_getter->values = tests[i].values; | 661 setting_getter->values = tests[i].values; |
| 690 sync_config_getter.SetupAndInitialFetch(); | 662 sync_config_getter.SetupAndInitialFetch(); |
| 691 ProxyConfigService::ConfigAvailability availability = | 663 ProxyConfigService::ConfigAvailability availability = |
| 692 sync_config_getter.SyncGetLatestProxyConfig(&config); | 664 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 693 EXPECT_EQ(tests[i].availability, availability); | 665 EXPECT_EQ(tests[i].availability, availability); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 708 | 680 |
| 709 // Input. | 681 // Input. |
| 710 EnvVarValues values; | 682 EnvVarValues values; |
| 711 | 683 |
| 712 // Expected outputs (availability and fields of ProxyConfig). | 684 // Expected outputs (availability and fields of ProxyConfig). |
| 713 ProxyConfigService::ConfigAvailability availability; | 685 ProxyConfigService::ConfigAvailability availability; |
| 714 bool auto_detect; | 686 bool auto_detect; |
| 715 GURL pac_url; | 687 GURL pac_url; |
| 716 ProxyRulesExpectation proxy_rules; | 688 ProxyRulesExpectation proxy_rules; |
| 717 } tests[] = { | 689 } tests[] = { |
| 718 { | 690 { |
| 719 TEST_DESC("No proxying"), | 691 TEST_DESC("No proxying"), |
| 720 { // Input. | 692 { // Input. |
| 721 NULL, // DESKTOP_SESSION | 693 NULL, // DESKTOP_SESSION |
| 722 NULL, // HOME | 694 NULL, // HOME |
| 723 NULL, // KDEHOME | 695 NULL, // KDEHOME |
| 724 NULL, // KDE_SESSION_VERSION | 696 NULL, // KDE_SESSION_VERSION |
| 725 NULL, // auto_proxy | 697 NULL, // auto_proxy |
| 726 NULL, // all_proxy | 698 NULL, // all_proxy |
| 727 NULL, NULL, NULL, // per-proto proxies | 699 NULL, NULL, NULL, // per-proto proxies |
| 728 NULL, NULL, // SOCKS | 700 NULL, NULL, // SOCKS |
| 729 "*", // no_proxy | 701 "*", // no_proxy |
| 730 }, | 702 }, |
| 731 | 703 |
| 732 // Expected result. | 704 // Expected result. |
| 733 ProxyConfigService::CONFIG_VALID, | 705 ProxyConfigService::CONFIG_VALID, |
| 734 false, // auto_detect | 706 false, // auto_detect |
| 735 GURL(), // pac_url | 707 GURL(), // pac_url |
| 736 ProxyRulesExpectation::Empty(), | 708 ProxyRulesExpectation::Empty(), |
| 737 }, | 709 }, |
| 738 | 710 { |
| 739 { | 711 TEST_DESC("Auto detect"), |
| 740 TEST_DESC("Auto detect"), | 712 { // Input. |
| 741 { // Input. | 713 NULL, // DESKTOP_SESSION |
| 742 NULL, // DESKTOP_SESSION | 714 NULL, // HOME |
| 743 NULL, // HOME | 715 NULL, // KDEHOME |
| 744 NULL, // KDEHOME | 716 NULL, // KDE_SESSION_VERSION |
| 745 NULL, // KDE_SESSION_VERSION | 717 "", // auto_proxy |
| 746 "", // auto_proxy | 718 NULL, // all_proxy |
| 747 NULL, // all_proxy | 719 NULL, NULL, NULL, // per-proto proxies |
| 748 NULL, NULL, NULL, // per-proto proxies | 720 NULL, NULL, // SOCKS |
| 749 NULL, NULL, // SOCKS | 721 NULL, // no_proxy |
| 750 NULL, // no_proxy | 722 }, |
| 751 }, | 723 |
| 752 | 724 // Expected result. |
| 753 // Expected result. | 725 ProxyConfigService::CONFIG_VALID, |
| 754 ProxyConfigService::CONFIG_VALID, | 726 true, // auto_detect |
| 755 true, // auto_detect | 727 GURL(), // pac_url |
| 756 GURL(), // pac_url | 728 ProxyRulesExpectation::Empty(), |
| 757 ProxyRulesExpectation::Empty(), | 729 }, |
| 758 }, | 730 { |
| 759 | 731 TEST_DESC("Valid PAC URL"), |
| 760 { | 732 { // Input. |
| 761 TEST_DESC("Valid PAC URL"), | 733 NULL, // DESKTOP_SESSION |
| 762 { // Input. | 734 NULL, // HOME |
| 763 NULL, // DESKTOP_SESSION | 735 NULL, // KDEHOME |
| 764 NULL, // HOME | 736 NULL, // KDE_SESSION_VERSION |
| 765 NULL, // KDEHOME | 737 "http://wpad/wpad.dat", // auto_proxy |
| 766 NULL, // KDE_SESSION_VERSION | 738 NULL, // all_proxy |
| 767 "http://wpad/wpad.dat", // auto_proxy | 739 NULL, NULL, NULL, // per-proto proxies |
| 768 NULL, // all_proxy | 740 NULL, NULL, // SOCKS |
| 769 NULL, NULL, NULL, // per-proto proxies | 741 NULL, // no_proxy |
| 770 NULL, NULL, // SOCKS | 742 }, |
| 771 NULL, // no_proxy | 743 |
| 772 }, | 744 // Expected result. |
| 773 | 745 ProxyConfigService::CONFIG_VALID, |
| 774 // Expected result. | 746 false, // auto_detect |
| 775 ProxyConfigService::CONFIG_VALID, | 747 GURL("http://wpad/wpad.dat"), // pac_url |
| 776 false, // auto_detect | 748 ProxyRulesExpectation::Empty(), |
| 777 GURL("http://wpad/wpad.dat"), // pac_url | 749 }, |
| 778 ProxyRulesExpectation::Empty(), | 750 { |
| 779 }, | 751 TEST_DESC("Invalid PAC URL"), |
| 780 | 752 { // Input. |
| 781 { | 753 NULL, // DESKTOP_SESSION |
| 782 TEST_DESC("Invalid PAC URL"), | 754 NULL, // HOME |
| 783 { // Input. | 755 NULL, // KDEHOME |
| 784 NULL, // DESKTOP_SESSION | 756 NULL, // KDE_SESSION_VERSION |
| 785 NULL, // HOME | 757 "wpad.dat", // auto_proxy |
| 786 NULL, // KDEHOME | 758 NULL, // all_proxy |
| 787 NULL, // KDE_SESSION_VERSION | 759 NULL, NULL, NULL, // per-proto proxies |
| 788 "wpad.dat", // auto_proxy | 760 NULL, NULL, // SOCKS |
| 789 NULL, // all_proxy | 761 NULL, // no_proxy |
| 790 NULL, NULL, NULL, // per-proto proxies | 762 }, |
| 791 NULL, NULL, // SOCKS | 763 |
| 792 NULL, // no_proxy | 764 // Expected result. |
| 793 }, | 765 ProxyConfigService::CONFIG_VALID, |
| 794 | 766 false, // auto_detect |
| 795 // Expected result. | 767 GURL(), // pac_url |
| 796 ProxyConfigService::CONFIG_VALID, | 768 ProxyRulesExpectation::Empty(), |
| 797 false, // auto_detect | 769 }, |
| 798 GURL(), // pac_url | 770 { |
| 799 ProxyRulesExpectation::Empty(), | 771 TEST_DESC("Single-host in proxy list"), |
| 800 }, | 772 { // Input. |
| 801 | 773 NULL, // DESKTOP_SESSION |
| 802 { | 774 NULL, // HOME |
| 803 TEST_DESC("Single-host in proxy list"), | 775 NULL, // KDEHOME |
| 804 { // Input. | 776 NULL, // KDE_SESSION_VERSION |
| 805 NULL, // DESKTOP_SESSION | 777 NULL, // auto_proxy |
| 806 NULL, // HOME | 778 "www.google.com", // all_proxy |
| 807 NULL, // KDEHOME | 779 NULL, NULL, NULL, // per-proto proxies |
| 808 NULL, // KDE_SESSION_VERSION | 780 NULL, NULL, // SOCKS |
| 809 NULL, // auto_proxy | 781 NULL, // no_proxy |
| 810 "www.google.com", // all_proxy | 782 }, |
| 811 NULL, NULL, NULL, // per-proto proxies | 783 |
| 812 NULL, NULL, // SOCKS | 784 // Expected result. |
| 813 NULL, // no_proxy | 785 ProxyConfigService::CONFIG_VALID, |
| 814 }, | 786 false, // auto_detect |
| 815 | 787 GURL(), // pac_url |
| 816 // Expected result. | 788 ProxyRulesExpectation::Single("www.google.com:80", // single proxy |
| 817 ProxyConfigService::CONFIG_VALID, | 789 ""), // bypass rules |
| 818 false, // auto_detect | 790 }, |
| 819 GURL(), // pac_url | 791 { |
| 820 ProxyRulesExpectation::Single( | 792 TEST_DESC("Single-host, different port"), |
| 821 "www.google.com:80", // single proxy | 793 { // Input. |
| 822 ""), // bypass rules | 794 NULL, // DESKTOP_SESSION |
| 823 }, | 795 NULL, // HOME |
| 824 | 796 NULL, // KDEHOME |
| 825 { | 797 NULL, // KDE_SESSION_VERSION |
| 826 TEST_DESC("Single-host, different port"), | 798 NULL, // auto_proxy |
| 827 { // Input. | 799 "www.google.com:99", // all_proxy |
| 828 NULL, // DESKTOP_SESSION | 800 NULL, NULL, NULL, // per-proto proxies |
| 829 NULL, // HOME | 801 NULL, NULL, // SOCKS |
| 830 NULL, // KDEHOME | 802 NULL, // no_proxy |
| 831 NULL, // KDE_SESSION_VERSION | 803 }, |
| 832 NULL, // auto_proxy | 804 |
| 833 "www.google.com:99", // all_proxy | 805 // Expected result. |
| 834 NULL, NULL, NULL, // per-proto proxies | 806 ProxyConfigService::CONFIG_VALID, |
| 835 NULL, NULL, // SOCKS | 807 false, // auto_detect |
| 836 NULL, // no_proxy | 808 GURL(), // pac_url |
| 837 }, | 809 ProxyRulesExpectation::Single("www.google.com:99", // single |
| 838 | 810 ""), // bypass rules |
| 839 // Expected result. | 811 }, |
| 840 ProxyConfigService::CONFIG_VALID, | 812 { |
| 841 false, // auto_detect | 813 TEST_DESC("Tolerate a scheme"), |
| 842 GURL(), // pac_url | 814 { // Input. |
| 843 ProxyRulesExpectation::Single( | 815 NULL, // DESKTOP_SESSION |
| 844 "www.google.com:99", // single | 816 NULL, // HOME |
| 845 ""), // bypass rules | 817 NULL, // KDEHOME |
| 846 }, | 818 NULL, // KDE_SESSION_VERSION |
| 847 | 819 NULL, // auto_proxy |
| 848 { | 820 "http://www.google.com:99", // all_proxy |
| 849 TEST_DESC("Tolerate a scheme"), | 821 NULL, NULL, NULL, // per-proto proxies |
| 850 { // Input. | 822 NULL, NULL, // SOCKS |
| 851 NULL, // DESKTOP_SESSION | 823 NULL, // no_proxy |
| 852 NULL, // HOME | 824 }, |
| 853 NULL, // KDEHOME | 825 |
| 854 NULL, // KDE_SESSION_VERSION | 826 // Expected result. |
| 855 NULL, // auto_proxy | 827 ProxyConfigService::CONFIG_VALID, |
| 856 "http://www.google.com:99", // all_proxy | 828 false, // auto_detect |
| 857 NULL, NULL, NULL, // per-proto proxies | 829 GURL(), // pac_url |
| 858 NULL, NULL, // SOCKS | 830 ProxyRulesExpectation::Single("www.google.com:99", // single proxy |
| 859 NULL, // no_proxy | 831 ""), // bypass rules |
| 860 }, | 832 }, |
| 861 | 833 { |
| 862 // Expected result. | 834 TEST_DESC("Per-scheme proxy rules"), |
| 863 ProxyConfigService::CONFIG_VALID, | 835 { // Input. |
| 864 false, // auto_detect | 836 NULL, // DESKTOP_SESSION |
| 865 GURL(), // pac_url | 837 NULL, // HOME |
| 866 ProxyRulesExpectation::Single( | 838 NULL, // KDEHOME |
| 867 "www.google.com:99", // single proxy | 839 NULL, // KDE_SESSION_VERSION |
| 868 ""), // bypass rules | 840 NULL, // auto_proxy |
| 869 }, | 841 NULL, // all_proxy |
| 870 | 842 "www.google.com:80", "www.foo.com:110", |
| 871 { | 843 "ftp.foo.com:121", // per-proto |
| 872 TEST_DESC("Per-scheme proxy rules"), | 844 NULL, NULL, // SOCKS |
| 873 { // Input. | 845 NULL, // no_proxy |
| 874 NULL, // DESKTOP_SESSION | 846 }, |
| 875 NULL, // HOME | 847 |
| 876 NULL, // KDEHOME | 848 // Expected result. |
| 877 NULL, // KDE_SESSION_VERSION | 849 ProxyConfigService::CONFIG_VALID, |
| 878 NULL, // auto_proxy | 850 false, // auto_detect |
| 879 NULL, // all_proxy | 851 GURL(), // pac_url |
| 880 "www.google.com:80", "www.foo.com:110", "ftp.foo.com:121", // per-proto | 852 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 881 NULL, NULL, // SOCKS | 853 "www.foo.com:110", // https |
| 882 NULL, // no_proxy | 854 "ftp.foo.com:121", // ftp |
| 883 }, | 855 ""), // bypass rules |
| 884 | 856 }, |
| 885 // Expected result. | 857 { |
| 886 ProxyConfigService::CONFIG_VALID, | 858 TEST_DESC("socks"), |
| 887 false, // auto_detect | 859 { // Input. |
| 888 GURL(), // pac_url | 860 NULL, // DESKTOP_SESSION |
| 889 ProxyRulesExpectation::PerScheme( | 861 NULL, // HOME |
| 890 "www.google.com:80", // http | 862 NULL, // KDEHOME |
| 891 "www.foo.com:110", // https | 863 NULL, // KDE_SESSION_VERSION |
| 892 "ftp.foo.com:121", // ftp | 864 NULL, // auto_proxy |
| 893 ""), // bypass rules | 865 "", // all_proxy |
| 894 }, | 866 NULL, NULL, NULL, // per-proto proxies |
| 895 | 867 "socks.com:888", NULL, // SOCKS |
| 896 { | 868 NULL, // no_proxy |
| 897 TEST_DESC("socks"), | 869 }, |
| 898 { // Input. | 870 |
| 899 NULL, // DESKTOP_SESSION | 871 // Expected result. |
| 900 NULL, // HOME | 872 ProxyConfigService::CONFIG_VALID, |
| 901 NULL, // KDEHOME | 873 false, // auto_detect |
| 902 NULL, // KDE_SESSION_VERSION | 874 GURL(), // pac_url |
| 903 NULL, // auto_proxy | 875 ProxyRulesExpectation::Single( |
| 904 "", // all_proxy | 876 "socks5://socks.com:888", // single proxy |
| 905 NULL, NULL, NULL, // per-proto proxies | 877 ""), // bypass rules |
| 906 "socks.com:888", NULL, // SOCKS | 878 }, |
| 907 NULL, // no_proxy | 879 { |
| 908 }, | 880 TEST_DESC("socks4"), |
| 909 | 881 { // Input. |
| 910 // Expected result. | 882 NULL, // DESKTOP_SESSION |
| 911 ProxyConfigService::CONFIG_VALID, | 883 NULL, // HOME |
| 912 false, // auto_detect | 884 NULL, // KDEHOME |
| 913 GURL(), // pac_url | 885 NULL, // KDE_SESSION_VERSION |
| 914 ProxyRulesExpectation::Single( | 886 NULL, // auto_proxy |
| 915 "socks5://socks.com:888", // single proxy | 887 "", // all_proxy |
| 916 ""), // bypass rules | 888 NULL, NULL, NULL, // per-proto proxies |
| 917 }, | 889 "socks.com:888", "4", // SOCKS |
| 918 | 890 NULL, // no_proxy |
| 919 { | 891 }, |
| 920 TEST_DESC("socks4"), | 892 |
| 921 { // Input. | 893 // Expected result. |
| 922 NULL, // DESKTOP_SESSION | 894 ProxyConfigService::CONFIG_VALID, |
| 923 NULL, // HOME | 895 false, // auto_detect |
| 924 NULL, // KDEHOME | 896 GURL(), // pac_url |
| 925 NULL, // KDE_SESSION_VERSION | 897 ProxyRulesExpectation::Single( |
| 926 NULL, // auto_proxy | 898 "socks4://socks.com:888", // single proxy |
| 927 "", // all_proxy | 899 ""), // bypass rules |
| 928 NULL, NULL, NULL, // per-proto proxies | 900 }, |
| 929 "socks.com:888", "4", // SOCKS | 901 { |
| 930 NULL, // no_proxy | 902 TEST_DESC("socks default port"), |
| 931 }, | 903 { // Input. |
| 932 | 904 NULL, // DESKTOP_SESSION |
| 933 // Expected result. | 905 NULL, // HOME |
| 934 ProxyConfigService::CONFIG_VALID, | 906 NULL, // KDEHOME |
| 935 false, // auto_detect | 907 NULL, // KDE_SESSION_VERSION |
| 936 GURL(), // pac_url | 908 NULL, // auto_proxy |
| 937 ProxyRulesExpectation::Single( | 909 "", // all_proxy |
| 938 "socks4://socks.com:888", // single proxy | 910 NULL, NULL, NULL, // per-proto proxies |
| 939 ""), // bypass rules | 911 "socks.com", NULL, // SOCKS |
| 940 }, | 912 NULL, // no_proxy |
| 941 | 913 }, |
| 942 { | 914 |
| 943 TEST_DESC("socks default port"), | 915 // Expected result. |
| 944 { // Input. | 916 ProxyConfigService::CONFIG_VALID, |
| 945 NULL, // DESKTOP_SESSION | 917 false, // auto_detect |
| 946 NULL, // HOME | 918 GURL(), // pac_url |
| 947 NULL, // KDEHOME | 919 ProxyRulesExpectation::Single( |
| 948 NULL, // KDE_SESSION_VERSION | 920 "socks5://socks.com:1080", // single proxy |
| 949 NULL, // auto_proxy | 921 ""), // bypass rules |
| 950 "", // all_proxy | 922 }, |
| 951 NULL, NULL, NULL, // per-proto proxies | 923 { |
| 952 "socks.com", NULL, // SOCKS | 924 TEST_DESC("bypass"), |
| 953 NULL, // no_proxy | 925 { // Input. |
| 954 }, | 926 NULL, // DESKTOP_SESSION |
| 955 | 927 NULL, // HOME |
| 956 // Expected result. | 928 NULL, // KDEHOME |
| 957 ProxyConfigService::CONFIG_VALID, | 929 NULL, // KDE_SESSION_VERSION |
| 958 false, // auto_detect | 930 NULL, // auto_proxy |
| 959 GURL(), // pac_url | 931 "www.google.com", // all_proxy |
| 960 ProxyRulesExpectation::Single( | 932 NULL, NULL, NULL, // per-proto |
| 961 "socks5://socks.com:1080", // single proxy | 933 NULL, NULL, // SOCKS |
| 962 ""), // bypass rules | 934 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy |
| 963 }, | 935 }, |
| 964 | 936 |
| 965 { | 937 // Expected result. |
| 966 TEST_DESC("bypass"), | 938 ProxyConfigService::CONFIG_VALID, |
| 967 { // Input. | 939 false, // auto_detect |
| 968 NULL, // DESKTOP_SESSION | 940 GURL(), // pac_url |
| 969 NULL, // HOME | 941 ProxyRulesExpectation::Single( |
| 970 NULL, // KDEHOME | 942 "www.google.com:80", |
| 971 NULL, // KDE_SESSION_VERSION | 943 "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"), |
| 972 NULL, // auto_proxy | 944 }, |
| 973 "www.google.com", // all_proxy | 945 }; |
| 974 NULL, NULL, NULL, // per-proto | |
| 975 NULL, NULL, // SOCKS | |
| 976 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy | |
| 977 }, | |
| 978 | |
| 979 // Expected result. | |
| 980 ProxyConfigService::CONFIG_VALID, | |
| 981 false, // auto_detect | |
| 982 GURL(), // pac_url | |
| 983 ProxyRulesExpectation::Single( | |
| 984 "www.google.com:80", | |
| 985 "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"), | |
| 986 }, | |
| 987 }; | |
| 988 | 946 |
| 989 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 947 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 990 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, | 948 SCOPED_TRACE(base::StringPrintf( |
| 991 tests[i].description.c_str())); | 949 "Test[%" PRIuS "] %s", i, tests[i].description.c_str())); |
| 992 MockEnvironment* env = new MockEnvironment; | 950 MockEnvironment* env = new MockEnvironment; |
| 993 MockSettingGetter* setting_getter = new MockSettingGetter; | 951 MockSettingGetter* setting_getter = new MockSettingGetter; |
| 994 SynchConfigGetter sync_config_getter( | 952 SynchConfigGetter sync_config_getter( |
| 995 new ProxyConfigServiceLinux(env, setting_getter)); | 953 new ProxyConfigServiceLinux(env, setting_getter)); |
| 996 ProxyConfig config; | 954 ProxyConfig config; |
| 997 env->values = tests[i].values; | 955 env->values = tests[i].values; |
| 998 sync_config_getter.SetupAndInitialFetch(); | 956 sync_config_getter.SetupAndInitialFetch(); |
| 999 ProxyConfigService::ConfigAvailability availability = | 957 ProxyConfigService::ConfigAvailability availability = |
| 1000 sync_config_getter.SyncGetLatestProxyConfig(&config); | 958 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 1001 EXPECT_EQ(tests[i].availability, availability); | 959 EXPECT_EQ(tests[i].availability, availability); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 // Input. | 1006 // Input. |
| 1049 std::string kioslaverc; | 1007 std::string kioslaverc; |
| 1050 EnvVarValues env_values; | 1008 EnvVarValues env_values; |
| 1051 | 1009 |
| 1052 // Expected outputs (availability and fields of ProxyConfig). | 1010 // Expected outputs (availability and fields of ProxyConfig). |
| 1053 ProxyConfigService::ConfigAvailability availability; | 1011 ProxyConfigService::ConfigAvailability availability; |
| 1054 bool auto_detect; | 1012 bool auto_detect; |
| 1055 GURL pac_url; | 1013 GURL pac_url; |
| 1056 ProxyRulesExpectation proxy_rules; | 1014 ProxyRulesExpectation proxy_rules; |
| 1057 } tests[] = { | 1015 } tests[] = { |
| 1058 { | 1016 { |
| 1059 TEST_DESC("No proxying"), | 1017 TEST_DESC("No proxying"), |
| 1060 | 1018 |
| 1061 // Input. | 1019 // Input. |
| 1062 "[Proxy Settings]\nProxyType=0\n", | 1020 "[Proxy Settings]\nProxyType=0\n", |
| 1063 {}, // env_values | 1021 {}, // env_values |
| 1064 | 1022 |
| 1065 // Expected result. | 1023 // Expected result. |
| 1066 ProxyConfigService::CONFIG_VALID, | 1024 ProxyConfigService::CONFIG_VALID, |
| 1067 false, // auto_detect | 1025 false, // auto_detect |
| 1068 GURL(), // pac_url | 1026 GURL(), // pac_url |
| 1069 ProxyRulesExpectation::Empty(), | 1027 ProxyRulesExpectation::Empty(), |
| 1070 }, | 1028 }, |
| 1071 | 1029 { |
| 1072 { | 1030 TEST_DESC("Auto detect"), |
| 1073 TEST_DESC("Auto detect"), | 1031 |
| 1074 | 1032 // Input. |
| 1075 // Input. | 1033 "[Proxy Settings]\nProxyType=3\n", |
| 1076 "[Proxy Settings]\nProxyType=3\n", | 1034 {}, // env_values |
| 1077 {}, // env_values | 1035 |
| 1078 | 1036 // Expected result. |
| 1079 // Expected result. | 1037 ProxyConfigService::CONFIG_VALID, |
| 1080 ProxyConfigService::CONFIG_VALID, | 1038 true, // auto_detect |
| 1081 true, // auto_detect | 1039 GURL(), // pac_url |
| 1082 GURL(), // pac_url | 1040 ProxyRulesExpectation::Empty(), |
| 1083 ProxyRulesExpectation::Empty(), | 1041 }, |
| 1084 }, | 1042 { |
| 1085 | 1043 TEST_DESC("Valid PAC URL"), |
| 1086 { | 1044 |
| 1087 TEST_DESC("Valid PAC URL"), | 1045 // Input. |
| 1088 | 1046 "[Proxy Settings]\nProxyType=2\n" |
| 1089 // Input. | 1047 "Proxy Config Script=http://wpad/wpad.dat\n", |
| 1090 "[Proxy Settings]\nProxyType=2\n" | 1048 {}, // env_values |
| 1091 "Proxy Config Script=http://wpad/wpad.dat\n", | 1049 |
| 1092 {}, // env_values | 1050 // Expected result. |
| 1093 | 1051 ProxyConfigService::CONFIG_VALID, |
| 1094 // Expected result. | 1052 false, // auto_detect |
| 1095 ProxyConfigService::CONFIG_VALID, | 1053 GURL("http://wpad/wpad.dat"), // pac_url |
| 1096 false, // auto_detect | 1054 ProxyRulesExpectation::Empty(), |
| 1097 GURL("http://wpad/wpad.dat"), // pac_url | 1055 }, |
| 1098 ProxyRulesExpectation::Empty(), | 1056 { |
| 1099 }, | 1057 TEST_DESC("Valid PAC file without file://"), |
| 1100 | 1058 |
| 1101 { | 1059 // Input. |
| 1102 TEST_DESC("Valid PAC file without file://"), | 1060 "[Proxy Settings]\nProxyType=2\n" |
| 1103 | 1061 "Proxy Config Script=/wpad/wpad.dat\n", |
| 1104 // Input. | 1062 {}, // env_values |
| 1105 "[Proxy Settings]\nProxyType=2\n" | 1063 |
| 1106 "Proxy Config Script=/wpad/wpad.dat\n", | 1064 // Expected result. |
| 1107 {}, // env_values | 1065 ProxyConfigService::CONFIG_VALID, |
| 1108 | 1066 false, // auto_detect |
| 1109 // Expected result. | 1067 GURL("file:///wpad/wpad.dat"), // pac_url |
| 1110 ProxyConfigService::CONFIG_VALID, | 1068 ProxyRulesExpectation::Empty(), |
| 1111 false, // auto_detect | 1069 }, |
| 1112 GURL("file:///wpad/wpad.dat"), // pac_url | 1070 { |
| 1113 ProxyRulesExpectation::Empty(), | 1071 TEST_DESC("Per-scheme proxy rules"), |
| 1114 }, | 1072 |
| 1115 | 1073 // Input. |
| 1116 { | 1074 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1117 TEST_DESC("Per-scheme proxy rules"), | 1075 "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n", |
| 1118 | 1076 {}, // env_values |
| 1119 // Input. | 1077 |
| 1120 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1078 // Expected result. |
| 1121 "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n", | 1079 ProxyConfigService::CONFIG_VALID, |
| 1122 {}, // env_values | 1080 false, // auto_detect |
| 1123 | 1081 GURL(), // pac_url |
| 1124 // Expected result. | 1082 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1125 ProxyConfigService::CONFIG_VALID, | 1083 "www.foo.com:80", // https |
| 1126 false, // auto_detect | 1084 "ftp.foo.com:80", // http |
| 1127 GURL(), // pac_url | 1085 ""), // bypass rules |
| 1128 ProxyRulesExpectation::PerScheme( | 1086 }, |
| 1129 "www.google.com:80", // http | 1087 { |
| 1130 "www.foo.com:80", // https | 1088 TEST_DESC("Only HTTP proxy specified"), |
| 1131 "ftp.foo.com:80", // http | 1089 |
| 1132 ""), // bypass rules | 1090 // Input. |
| 1133 }, | 1091 "[Proxy Settings]\nProxyType=1\n" |
| 1134 | 1092 "httpProxy=www.google.com\n", |
| 1135 { | 1093 {}, // env_values |
| 1136 TEST_DESC("Only HTTP proxy specified"), | 1094 |
| 1137 | 1095 // Expected result. |
| 1138 // Input. | 1096 ProxyConfigService::CONFIG_VALID, |
| 1139 "[Proxy Settings]\nProxyType=1\n" | 1097 false, // auto_detect |
| 1140 "httpProxy=www.google.com\n", | 1098 GURL(), // pac_url |
| 1141 {}, // env_values | 1099 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1142 | 1100 "", // https |
| 1143 // Expected result. | 1101 "", // ftp |
| 1144 ProxyConfigService::CONFIG_VALID, | 1102 ""), // bypass rules |
| 1145 false, // auto_detect | 1103 }, |
| 1146 GURL(), // pac_url | 1104 { |
| 1147 ProxyRulesExpectation::PerScheme( | 1105 TEST_DESC("Only HTTP proxy specified, different port"), |
| 1148 "www.google.com:80", // http | 1106 |
| 1149 "", // https | 1107 // Input. |
| 1150 "", // ftp | 1108 "[Proxy Settings]\nProxyType=1\n" |
| 1151 ""), // bypass rules | 1109 "httpProxy=www.google.com:88\n", |
| 1152 }, | 1110 {}, // env_values |
| 1153 | 1111 |
| 1154 { | 1112 // Expected result. |
| 1155 TEST_DESC("Only HTTP proxy specified, different port"), | 1113 ProxyConfigService::CONFIG_VALID, |
| 1156 | 1114 false, // auto_detect |
| 1157 // Input. | 1115 GURL(), // pac_url |
| 1158 "[Proxy Settings]\nProxyType=1\n" | 1116 ProxyRulesExpectation::PerScheme("www.google.com:88", // http |
| 1159 "httpProxy=www.google.com:88\n", | 1117 "", // https |
| 1160 {}, // env_values | 1118 "", // ftp |
| 1161 | 1119 ""), // bypass rules |
| 1162 // Expected result. | 1120 }, |
| 1163 ProxyConfigService::CONFIG_VALID, | 1121 { |
| 1164 false, // auto_detect | 1122 TEST_DESC( |
| 1165 GURL(), // pac_url | 1123 "Only HTTP proxy specified, different port, space-delimited"), |
| 1166 ProxyRulesExpectation::PerScheme( | 1124 |
| 1167 "www.google.com:88", // http | 1125 // Input. |
| 1168 "", // https | 1126 "[Proxy Settings]\nProxyType=1\n" |
| 1169 "", // ftp | 1127 "httpProxy=www.google.com 88\n", |
| 1170 ""), // bypass rules | 1128 {}, // env_values |
| 1171 }, | 1129 |
| 1172 | 1130 // Expected result. |
| 1173 { | 1131 ProxyConfigService::CONFIG_VALID, |
| 1174 TEST_DESC("Only HTTP proxy specified, different port, space-delimited"), | 1132 false, // auto_detect |
| 1175 | 1133 GURL(), // pac_url |
| 1176 // Input. | 1134 ProxyRulesExpectation::PerScheme("www.google.com:88", // http |
| 1177 "[Proxy Settings]\nProxyType=1\n" | 1135 "", // https |
| 1178 "httpProxy=www.google.com 88\n", | 1136 "", // ftp |
| 1179 {}, // env_values | 1137 ""), // bypass rules |
| 1180 | 1138 }, |
| 1181 // Expected result. | 1139 { |
| 1182 ProxyConfigService::CONFIG_VALID, | 1140 TEST_DESC("Bypass *.google.com"), |
| 1183 false, // auto_detect | 1141 |
| 1184 GURL(), // pac_url | 1142 // Input. |
| 1185 ProxyRulesExpectation::PerScheme( | 1143 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1186 "www.google.com:88", // http | 1144 "NoProxyFor=.google.com\n", |
| 1187 "", // https | 1145 {}, // env_values |
| 1188 "", // ftp | 1146 |
| 1189 ""), // bypass rules | 1147 // Expected result. |
| 1190 }, | 1148 ProxyConfigService::CONFIG_VALID, |
| 1191 | 1149 false, // auto_detect |
| 1192 { | 1150 GURL(), // pac_url |
| 1193 TEST_DESC("Bypass *.google.com"), | 1151 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1194 | 1152 "", // https |
| 1195 // Input. | 1153 "", // ftp |
| 1196 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1154 "*.google.com"), // bypass rules |
| 1197 "NoProxyFor=.google.com\n", | 1155 }, |
| 1198 {}, // env_values | 1156 { |
| 1199 | 1157 TEST_DESC("Bypass *.google.com and *.kde.org"), |
| 1200 // Expected result. | 1158 |
| 1201 ProxyConfigService::CONFIG_VALID, | 1159 // Input. |
| 1202 false, // auto_detect | 1160 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1203 GURL(), // pac_url | 1161 "NoProxyFor=.google.com,.kde.org\n", |
| 1204 ProxyRulesExpectation::PerScheme( | 1162 {}, // env_values |
| 1205 "www.google.com:80", // http | 1163 |
| 1206 "", // https | 1164 // Expected result. |
| 1207 "", // ftp | 1165 ProxyConfigService::CONFIG_VALID, |
| 1208 "*.google.com"), // bypass rules | 1166 false, // auto_detect |
| 1209 }, | 1167 GURL(), // pac_url |
| 1210 | 1168 ProxyRulesExpectation::PerScheme( |
| 1211 { | 1169 "www.google.com:80", // http |
| 1212 TEST_DESC("Bypass *.google.com and *.kde.org"), | 1170 "", // https |
| 1213 | 1171 "", // ftp |
| 1214 // Input. | 1172 "*.google.com,*.kde.org"), // bypass rules |
| 1215 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1173 }, |
| 1216 "NoProxyFor=.google.com,.kde.org\n", | 1174 { |
| 1217 {}, // env_values | 1175 TEST_DESC("Correctly parse bypass list with ReversedException"), |
| 1218 | 1176 |
| 1219 // Expected result. | 1177 // Input. |
| 1220 ProxyConfigService::CONFIG_VALID, | 1178 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1221 false, // auto_detect | 1179 "NoProxyFor=.google.com\nReversedException=true\n", |
| 1222 GURL(), // pac_url | 1180 {}, // env_values |
| 1223 ProxyRulesExpectation::PerScheme( | 1181 |
| 1224 "www.google.com:80", // http | 1182 // Expected result. |
| 1225 "", // https | 1183 ProxyConfigService::CONFIG_VALID, |
| 1226 "", // ftp | 1184 false, // auto_detect |
| 1227 "*.google.com,*.kde.org"), // bypass rules | 1185 GURL(), // pac_url |
| 1228 }, | 1186 ProxyRulesExpectation::PerSchemeWithBypassReversed( |
| 1229 | 1187 "www.google.com:80", // http |
| 1230 { | 1188 "", // https |
| 1231 TEST_DESC("Correctly parse bypass list with ReversedException"), | 1189 "", // ftp |
| 1232 | 1190 "*.google.com"), // bypass rules |
| 1233 // Input. | 1191 }, |
| 1234 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1192 { |
| 1235 "NoProxyFor=.google.com\nReversedException=true\n", | 1193 TEST_DESC("socks"), |
| 1236 {}, // env_values | 1194 |
| 1237 | 1195 // Input. |
| 1238 // Expected result. | 1196 "[Proxy Settings]\nProxyType=1\nsocksProxy=socks.com 888\n", |
| 1239 ProxyConfigService::CONFIG_VALID, | 1197 {}, // env_values |
| 1240 false, // auto_detect | 1198 |
| 1241 GURL(), // pac_url | 1199 // Expected result. |
| 1242 ProxyRulesExpectation::PerSchemeWithBypassReversed( | 1200 ProxyConfigService::CONFIG_VALID, |
| 1243 "www.google.com:80", // http | 1201 false, // auto_detect |
| 1244 "", // https | 1202 GURL(), // pac_url |
| 1245 "", // ftp | 1203 ProxyRulesExpectation::Single( |
| 1246 "*.google.com"), // bypass rules | 1204 "socks5://socks.com:888", // single proxy |
| 1247 }, | 1205 ""), // bypass rules |
| 1248 | 1206 }, |
| 1249 { | 1207 { |
| 1250 TEST_DESC("socks"), | 1208 TEST_DESC("socks4"), |
| 1251 | 1209 |
| 1252 // Input. | 1210 // Input. |
| 1253 "[Proxy Settings]\nProxyType=1\nsocksProxy=socks.com 888\n", | 1211 "[Proxy Settings]\nProxyType=1\nsocksProxy=socks4://socks.com 888\n", |
| 1254 {}, // env_values | 1212 {}, // env_values |
| 1255 | 1213 |
| 1256 // Expected result. | 1214 // Expected result. |
| 1257 ProxyConfigService::CONFIG_VALID, | 1215 ProxyConfigService::CONFIG_VALID, |
| 1258 false, // auto_detect | 1216 false, // auto_detect |
| 1259 GURL(), // pac_url | 1217 GURL(), // pac_url |
| 1260 ProxyRulesExpectation::Single( | 1218 ProxyRulesExpectation::Single( |
| 1261 "socks5://socks.com:888", // single proxy | 1219 "socks4://socks.com:888", // single proxy |
| 1262 ""), // bypass rules | 1220 ""), // bypass rules |
| 1263 }, | 1221 }, |
| 1264 | 1222 { |
| 1265 { | 1223 TEST_DESC("Treat all hostname patterns as wildcard patterns"), |
| 1266 TEST_DESC("socks4"), | 1224 |
| 1267 | 1225 // Input. |
| 1268 // Input. | 1226 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1269 "[Proxy Settings]\nProxyType=1\nsocksProxy=socks4://socks.com 888\n", | 1227 "NoProxyFor=google.com,kde.org,<local>\n", |
| 1270 {}, // env_values | 1228 {}, // env_values |
| 1271 | 1229 |
| 1272 // Expected result. | 1230 // Expected result. |
| 1273 ProxyConfigService::CONFIG_VALID, | 1231 ProxyConfigService::CONFIG_VALID, |
| 1274 false, // auto_detect | 1232 false, // auto_detect |
| 1275 GURL(), // pac_url | 1233 GURL(), // pac_url |
| 1276 ProxyRulesExpectation::Single( | 1234 ProxyRulesExpectation::PerScheme( |
| 1277 "socks4://socks.com:888", // single proxy | 1235 "www.google.com:80", // http |
| 1278 ""), // bypass rules | 1236 "", // https |
| 1279 }, | 1237 "", // ftp |
| 1280 | 1238 "*google.com,*kde.org,<local>"), // bypass rules |
| 1281 { | 1239 }, |
| 1282 TEST_DESC("Treat all hostname patterns as wildcard patterns"), | 1240 { |
| 1283 | 1241 TEST_DESC("Allow trailing whitespace after boolean value"), |
| 1284 // Input. | 1242 |
| 1285 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1243 // Input. |
| 1286 "NoProxyFor=google.com,kde.org,<local>\n", | 1244 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1287 {}, // env_values | 1245 "NoProxyFor=.google.com\nReversedException=true \n", |
| 1288 | 1246 {}, // env_values |
| 1289 // Expected result. | 1247 |
| 1290 ProxyConfigService::CONFIG_VALID, | 1248 // Expected result. |
| 1291 false, // auto_detect | 1249 ProxyConfigService::CONFIG_VALID, |
| 1292 GURL(), // pac_url | 1250 false, // auto_detect |
| 1293 ProxyRulesExpectation::PerScheme( | 1251 GURL(), // pac_url |
| 1294 "www.google.com:80", // http | 1252 ProxyRulesExpectation::PerSchemeWithBypassReversed( |
| 1295 "", // https | 1253 "www.google.com:80", // http |
| 1296 "", // ftp | 1254 "", // https |
| 1297 "*google.com,*kde.org,<local>"), // bypass rules | 1255 "", // ftp |
| 1298 }, | 1256 "*.google.com"), // bypass rules |
| 1299 | 1257 }, |
| 1300 { | 1258 { |
| 1301 TEST_DESC("Allow trailing whitespace after boolean value"), | 1259 TEST_DESC("Ignore settings outside [Proxy Settings]"), |
| 1302 | 1260 |
| 1303 // Input. | 1261 // Input. |
| 1304 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1262 "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n" |
| 1305 "NoProxyFor=.google.com\nReversedException=true \n", | 1263 "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n", |
| 1306 {}, // env_values | 1264 {}, // env_values |
| 1307 | 1265 |
| 1308 // Expected result. | 1266 // Expected result. |
| 1309 ProxyConfigService::CONFIG_VALID, | 1267 ProxyConfigService::CONFIG_VALID, |
| 1310 false, // auto_detect | 1268 false, // auto_detect |
| 1311 GURL(), // pac_url | 1269 GURL(), // pac_url |
| 1312 ProxyRulesExpectation::PerSchemeWithBypassReversed( | 1270 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1313 "www.google.com:80", // http | 1271 "", // https |
| 1314 "", // https | 1272 "", // ftp |
| 1315 "", // ftp | 1273 ""), // bypass rules |
| 1316 "*.google.com"), // bypass rules | 1274 }, |
| 1317 }, | 1275 { |
| 1318 | 1276 TEST_DESC("Handle CRLF line endings"), |
| 1319 { | 1277 |
| 1320 TEST_DESC("Ignore settings outside [Proxy Settings]"), | 1278 // Input. |
| 1321 | 1279 "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n", |
| 1322 // Input. | 1280 {}, // env_values |
| 1323 "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n" | 1281 |
| 1324 "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n", | 1282 // Expected result. |
| 1325 {}, // env_values | 1283 ProxyConfigService::CONFIG_VALID, |
| 1326 | 1284 false, // auto_detect |
| 1327 // Expected result. | 1285 GURL(), // pac_url |
| 1328 ProxyConfigService::CONFIG_VALID, | 1286 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1329 false, // auto_detect | 1287 "", // https |
| 1330 GURL(), // pac_url | 1288 "", // ftp |
| 1331 ProxyRulesExpectation::PerScheme( | 1289 ""), // bypass rules |
| 1332 "www.google.com:80", // http | 1290 }, |
| 1333 "", // https | 1291 { |
| 1334 "", // ftp | 1292 TEST_DESC("Handle blank lines and mixed line endings"), |
| 1335 ""), // bypass rules | 1293 |
| 1336 }, | 1294 // Input. |
| 1337 | 1295 "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n", |
| 1338 { | 1296 {}, // env_values |
| 1339 TEST_DESC("Handle CRLF line endings"), | 1297 |
| 1340 | 1298 // Expected result. |
| 1341 // Input. | 1299 ProxyConfigService::CONFIG_VALID, |
| 1342 "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n", | 1300 false, // auto_detect |
| 1343 {}, // env_values | 1301 GURL(), // pac_url |
| 1344 | 1302 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1345 // Expected result. | 1303 "", // https |
| 1346 ProxyConfigService::CONFIG_VALID, | 1304 "", // ftp |
| 1347 false, // auto_detect | 1305 ""), // bypass rules |
| 1348 GURL(), // pac_url | 1306 }, |
| 1349 ProxyRulesExpectation::PerScheme( | 1307 { |
| 1350 "www.google.com:80", // http | 1308 TEST_DESC("Handle localized settings"), |
| 1351 "", // https | 1309 |
| 1352 "", // ftp | 1310 // Input. |
| 1353 ""), // bypass rules | 1311 "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n", |
| 1354 }, | 1312 {}, // env_values |
| 1355 | 1313 |
| 1356 { | 1314 // Expected result. |
| 1357 TEST_DESC("Handle blank lines and mixed line endings"), | 1315 ProxyConfigService::CONFIG_VALID, |
| 1358 | 1316 false, // auto_detect |
| 1359 // Input. | 1317 GURL(), // pac_url |
| 1360 "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n", | 1318 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1361 {}, // env_values | 1319 "", // https |
| 1362 | 1320 "", // ftp |
| 1363 // Expected result. | 1321 ""), // bypass rules |
| 1364 ProxyConfigService::CONFIG_VALID, | 1322 }, |
| 1365 false, // auto_detect | 1323 { |
| 1366 GURL(), // pac_url | 1324 TEST_DESC("Ignore malformed localized settings"), |
| 1367 ProxyRulesExpectation::PerScheme( | 1325 |
| 1368 "www.google.com:80", // http | 1326 // Input. |
| 1369 "", // https | 1327 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1370 "", // ftp | 1328 "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n", |
| 1371 ""), // bypass rules | 1329 {}, // env_values |
| 1372 }, | 1330 |
| 1373 | 1331 // Expected result. |
| 1374 { | 1332 ProxyConfigService::CONFIG_VALID, |
| 1375 TEST_DESC("Handle localized settings"), | 1333 false, // auto_detect |
| 1376 | 1334 GURL(), // pac_url |
| 1377 // Input. | 1335 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1378 "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n", | 1336 "", // https |
| 1379 {}, // env_values | 1337 "ftp.foo.com:80", // ftp |
| 1380 | 1338 ""), // bypass rules |
| 1381 // Expected result. | 1339 }, |
| 1382 ProxyConfigService::CONFIG_VALID, | 1340 { |
| 1383 false, // auto_detect | 1341 TEST_DESC("Handle strange whitespace"), |
| 1384 GURL(), // pac_url | 1342 |
| 1385 ProxyRulesExpectation::PerScheme( | 1343 // Input. |
| 1386 "www.google.com:80", // http | 1344 "[Proxy Settings]\nProxyType [$e] =2\n" |
| 1387 "", // https | 1345 " Proxy Config Script = http:// foo\n", |
| 1388 "", // ftp | 1346 {}, // env_values |
| 1389 ""), // bypass rules | 1347 |
| 1390 }, | 1348 // Expected result. |
| 1391 | 1349 ProxyConfigService::CONFIG_VALID, |
| 1392 { | 1350 false, // auto_detect |
| 1393 TEST_DESC("Ignore malformed localized settings"), | 1351 GURL("http:// foo"), // pac_url |
| 1394 | 1352 ProxyRulesExpectation::Empty(), |
| 1395 // Input. | 1353 }, |
| 1396 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1354 { |
| 1397 "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n", | 1355 TEST_DESC("Ignore all of a line which is too long"), |
| 1398 {}, // env_values | 1356 |
| 1399 | 1357 // Input. |
| 1400 // Expected result. | 1358 std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") + |
| 1401 ProxyConfigService::CONFIG_VALID, | 1359 long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n", |
| 1402 false, // auto_detect | 1360 {}, // env_values |
| 1403 GURL(), // pac_url | 1361 |
| 1404 ProxyRulesExpectation::PerScheme( | 1362 // Expected result. |
| 1405 "www.google.com:80", // http | 1363 ProxyConfigService::CONFIG_VALID, |
| 1406 "", // https | 1364 false, // auto_detect |
| 1407 "ftp.foo.com:80", // ftp | 1365 GURL(), // pac_url |
| 1408 ""), // bypass rules | 1366 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
| 1409 }, | 1367 "", // https |
| 1410 | 1368 "ftp.foo.com:80", // ftp |
| 1411 { | 1369 ""), // bypass rules |
| 1412 TEST_DESC("Handle strange whitespace"), | 1370 }, |
| 1413 | 1371 { |
| 1414 // Input. | 1372 TEST_DESC("Indirect Proxy - no env vars set"), |
| 1415 "[Proxy Settings]\nProxyType [$e] =2\n" | 1373 |
| 1416 " Proxy Config Script = http:// foo\n", | 1374 // Input. |
| 1417 {}, // env_values | 1375 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" |
| 1418 | 1376 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", |
| 1419 // Expected result. | 1377 {}, // env_values |
| 1420 ProxyConfigService::CONFIG_VALID, | 1378 |
| 1421 false, // auto_detect | 1379 // Expected result. |
| 1422 GURL("http:// foo"), // pac_url | 1380 ProxyConfigService::CONFIG_VALID, |
| 1423 ProxyRulesExpectation::Empty(), | 1381 false, // auto_detect |
| 1424 }, | 1382 GURL(), // pac_url |
| 1425 | 1383 ProxyRulesExpectation::Empty(), |
| 1426 { | 1384 }, |
| 1427 TEST_DESC("Ignore all of a line which is too long"), | 1385 { |
| 1428 | 1386 TEST_DESC("Indirect Proxy - with env vars set"), |
| 1429 // Input. | 1387 |
| 1430 std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") + | 1388 // Input. |
| 1431 long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n", | 1389 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" |
| 1432 {}, // env_values | 1390 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", |
| 1433 | 1391 { // env_values |
| 1434 // Expected result. | 1392 NULL, // DESKTOP_SESSION |
| 1435 ProxyConfigService::CONFIG_VALID, | 1393 NULL, // HOME |
| 1436 false, // auto_detect | 1394 NULL, // KDEHOME |
| 1437 GURL(), // pac_url | 1395 NULL, // KDE_SESSION_VERSION |
| 1438 ProxyRulesExpectation::PerScheme( | 1396 NULL, // auto_proxy |
| 1439 "www.google.com:80", // http | 1397 NULL, // all_proxy |
| 1440 "", // https | 1398 "www.normal.com", // http_proxy |
| 1441 "ftp.foo.com:80", // ftp | 1399 "www.secure.com", // https_proxy |
| 1442 ""), // bypass rules | 1400 "ftp.foo.com", // ftp_proxy |
| 1443 }, | 1401 NULL, NULL, // SOCKS |
| 1444 | 1402 ".google.com, .kde.org", // no_proxy |
| 1445 { | 1403 }, |
| 1446 TEST_DESC("Indirect Proxy - no env vars set"), | 1404 |
| 1447 | 1405 // Expected result. |
| 1448 // Input. | 1406 ProxyConfigService::CONFIG_VALID, |
| 1449 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" | 1407 false, // auto_detect |
| 1450 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", | 1408 GURL(), // pac_url |
| 1451 {}, // env_values | 1409 ProxyRulesExpectation::PerScheme( |
| 1452 | 1410 "www.normal.com:80", // http |
| 1453 // Expected result. | 1411 "www.secure.com:80", // https |
| 1454 ProxyConfigService::CONFIG_VALID, | 1412 "ftp.foo.com:80", // ftp |
| 1455 false, // auto_detect | 1413 "*.google.com,*.kde.org"), // bypass rules |
| 1456 GURL(), // pac_url | 1414 }, |
| 1457 ProxyRulesExpectation::Empty(), | 1415 }; |
| 1458 }, | |
| 1459 | |
| 1460 { | |
| 1461 TEST_DESC("Indirect Proxy - with env vars set"), | |
| 1462 | |
| 1463 // Input. | |
| 1464 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" | |
| 1465 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", | |
| 1466 { // env_values | |
| 1467 NULL, // DESKTOP_SESSION | |
| 1468 NULL, // HOME | |
| 1469 NULL, // KDEHOME | |
| 1470 NULL, // KDE_SESSION_VERSION | |
| 1471 NULL, // auto_proxy | |
| 1472 NULL, // all_proxy | |
| 1473 "www.normal.com", // http_proxy | |
| 1474 "www.secure.com", // https_proxy | |
| 1475 "ftp.foo.com", // ftp_proxy | |
| 1476 NULL, NULL, // SOCKS | |
| 1477 ".google.com, .kde.org", // no_proxy | |
| 1478 }, | |
| 1479 | |
| 1480 // Expected result. | |
| 1481 ProxyConfigService::CONFIG_VALID, | |
| 1482 false, // auto_detect | |
| 1483 GURL(), // pac_url | |
| 1484 ProxyRulesExpectation::PerScheme( | |
| 1485 "www.normal.com:80", // http | |
| 1486 "www.secure.com:80", // https | |
| 1487 "ftp.foo.com:80", // ftp | |
| 1488 "*.google.com,*.kde.org"), // bypass rules | |
| 1489 }, | |
| 1490 | |
| 1491 }; | |
| 1492 | 1416 |
| 1493 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1417 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1494 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, | 1418 SCOPED_TRACE(base::StringPrintf( |
| 1495 tests[i].description.c_str())); | 1419 "Test[%" PRIuS "] %s", i, tests[i].description.c_str())); |
| 1496 MockEnvironment* env = new MockEnvironment; | 1420 MockEnvironment* env = new MockEnvironment; |
| 1497 env->values = tests[i].env_values; | 1421 env->values = tests[i].env_values; |
| 1498 // Force the KDE getter to be used and tell it where the test is. | 1422 // Force the KDE getter to be used and tell it where the test is. |
| 1499 env->values.DESKTOP_SESSION = "kde4"; | 1423 env->values.DESKTOP_SESSION = "kde4"; |
| 1500 env->values.KDEHOME = kde_home_.value().c_str(); | 1424 env->values.KDEHOME = kde_home_.value().c_str(); |
| 1501 SynchConfigGetter sync_config_getter( | 1425 SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env)); |
| 1502 new ProxyConfigServiceLinux(env)); | |
| 1503 ProxyConfig config; | 1426 ProxyConfig config; |
| 1504 // Overwrite the kioslaverc file. | 1427 // Overwrite the kioslaverc file. |
| 1505 base::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), | 1428 base::WriteFile( |
| 1506 tests[i].kioslaverc.length()); | 1429 kioslaverc_, tests[i].kioslaverc.c_str(), tests[i].kioslaverc.length()); |
| 1507 sync_config_getter.SetupAndInitialFetch(); | 1430 sync_config_getter.SetupAndInitialFetch(); |
| 1508 ProxyConfigService::ConfigAvailability availability = | 1431 ProxyConfigService::ConfigAvailability availability = |
| 1509 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1432 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 1510 EXPECT_EQ(tests[i].availability, availability); | 1433 EXPECT_EQ(tests[i].availability, availability); |
| 1511 | 1434 |
| 1512 if (availability == ProxyConfigService::CONFIG_VALID) { | 1435 if (availability == ProxyConfigService::CONFIG_VALID) { |
| 1513 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 1436 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
| 1514 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 1437 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
| 1515 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 1438 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
| 1516 } | 1439 } |
| 1517 } | 1440 } |
| 1518 } | 1441 } |
| 1519 | 1442 |
| 1520 TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) { | 1443 TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) { |
| 1521 // Auto detect proxy settings. | 1444 // Auto detect proxy settings. |
| 1522 std::string slaverc3 = "[Proxy Settings]\nProxyType=3\n"; | 1445 std::string slaverc3 = "[Proxy Settings]\nProxyType=3\n"; |
| 1523 // Valid PAC URL. | 1446 // Valid PAC URL. |
| 1524 std::string slaverc4 = "[Proxy Settings]\nProxyType=2\n" | 1447 std::string slaverc4 = |
| 1525 "Proxy Config Script=http://wpad/wpad.dat\n"; | 1448 "[Proxy Settings]\nProxyType=2\n" |
| 1449 "Proxy Config Script=http://wpad/wpad.dat\n"; |
| 1526 GURL slaverc4_pac_url("http://wpad/wpad.dat"); | 1450 GURL slaverc4_pac_url("http://wpad/wpad.dat"); |
| 1527 | 1451 |
| 1528 // Overwrite the .kde kioslaverc file. | 1452 // Overwrite the .kde kioslaverc file. |
| 1529 base::WriteFile(kioslaverc_, slaverc3.c_str(), slaverc3.length()); | 1453 base::WriteFile(kioslaverc_, slaverc3.c_str(), slaverc3.length()); |
| 1530 | 1454 |
| 1531 // If .kde4 exists it will mess up the first test. It should not, as | 1455 // If .kde4 exists it will mess up the first test. It should not, as |
| 1532 // we created the directory for $HOME in the test setup. | 1456 // we created the directory for $HOME in the test setup. |
| 1533 CHECK(!base::DirectoryExists(kde4_home_)); | 1457 CHECK(!base::DirectoryExists(kde4_home_)); |
| 1534 | 1458 |
| 1535 { SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback"); | 1459 { |
| 1460 SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback"); |
| 1536 MockEnvironment* env = new MockEnvironment; | 1461 MockEnvironment* env = new MockEnvironment; |
| 1537 env->values.DESKTOP_SESSION = "kde4"; | 1462 env->values.DESKTOP_SESSION = "kde4"; |
| 1538 env->values.HOME = user_home_.value().c_str(); | 1463 env->values.HOME = user_home_.value().c_str(); |
| 1539 SynchConfigGetter sync_config_getter( | 1464 SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env)); |
| 1540 new ProxyConfigServiceLinux(env)); | |
| 1541 ProxyConfig config; | 1465 ProxyConfig config; |
| 1542 sync_config_getter.SetupAndInitialFetch(); | 1466 sync_config_getter.SetupAndInitialFetch(); |
| 1543 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, | 1467 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1544 sync_config_getter.SyncGetLatestProxyConfig(&config)); | 1468 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1545 EXPECT_TRUE(config.auto_detect()); | 1469 EXPECT_TRUE(config.auto_detect()); |
| 1546 EXPECT_EQ(GURL(), config.pac_url()); | 1470 EXPECT_EQ(GURL(), config.pac_url()); |
| 1547 } | 1471 } |
| 1548 | 1472 |
| 1549 // Now create .kde4 and put a kioslaverc in the config directory. | 1473 // Now create .kde4 and put a kioslaverc in the config directory. |
| 1550 // Note that its timestamp will be at least as new as the .kde one. | 1474 // Note that its timestamp will be at least as new as the .kde one. |
| 1551 base::CreateDirectory(kde4_config_); | 1475 base::CreateDirectory(kde4_config_); |
| 1552 base::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length()); | 1476 base::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length()); |
| 1553 CHECK(base::PathExists(kioslaverc4_)); | 1477 CHECK(base::PathExists(kioslaverc4_)); |
| 1554 | 1478 |
| 1555 { SCOPED_TRACE("KDE4, .kde4 directory present, use it"); | 1479 { |
| 1480 SCOPED_TRACE("KDE4, .kde4 directory present, use it"); |
| 1556 MockEnvironment* env = new MockEnvironment; | 1481 MockEnvironment* env = new MockEnvironment; |
| 1557 env->values.DESKTOP_SESSION = "kde4"; | 1482 env->values.DESKTOP_SESSION = "kde4"; |
| 1558 env->values.HOME = user_home_.value().c_str(); | 1483 env->values.HOME = user_home_.value().c_str(); |
| 1559 SynchConfigGetter sync_config_getter( | 1484 SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env)); |
| 1560 new ProxyConfigServiceLinux(env)); | |
| 1561 ProxyConfig config; | 1485 ProxyConfig config; |
| 1562 sync_config_getter.SetupAndInitialFetch(); | 1486 sync_config_getter.SetupAndInitialFetch(); |
| 1563 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, | 1487 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1564 sync_config_getter.SyncGetLatestProxyConfig(&config)); | 1488 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1565 EXPECT_FALSE(config.auto_detect()); | 1489 EXPECT_FALSE(config.auto_detect()); |
| 1566 EXPECT_EQ(slaverc4_pac_url, config.pac_url()); | 1490 EXPECT_EQ(slaverc4_pac_url, config.pac_url()); |
| 1567 } | 1491 } |
| 1568 | 1492 |
| 1569 { SCOPED_TRACE("KDE3, .kde4 directory present, ignore it"); | 1493 { |
| 1494 SCOPED_TRACE("KDE3, .kde4 directory present, ignore it"); |
| 1570 MockEnvironment* env = new MockEnvironment; | 1495 MockEnvironment* env = new MockEnvironment; |
| 1571 env->values.DESKTOP_SESSION = "kde"; | 1496 env->values.DESKTOP_SESSION = "kde"; |
| 1572 env->values.HOME = user_home_.value().c_str(); | 1497 env->values.HOME = user_home_.value().c_str(); |
| 1573 SynchConfigGetter sync_config_getter( | 1498 SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env)); |
| 1574 new ProxyConfigServiceLinux(env)); | |
| 1575 ProxyConfig config; | 1499 ProxyConfig config; |
| 1576 sync_config_getter.SetupAndInitialFetch(); | 1500 sync_config_getter.SetupAndInitialFetch(); |
| 1577 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, | 1501 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1578 sync_config_getter.SyncGetLatestProxyConfig(&config)); | 1502 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1579 EXPECT_TRUE(config.auto_detect()); | 1503 EXPECT_TRUE(config.auto_detect()); |
| 1580 EXPECT_EQ(GURL(), config.pac_url()); | 1504 EXPECT_EQ(GURL(), config.pac_url()); |
| 1581 } | 1505 } |
| 1582 | 1506 |
| 1583 { SCOPED_TRACE("KDE4, .kde4 directory present, KDEHOME set to .kde"); | 1507 { |
| 1508 SCOPED_TRACE("KDE4, .kde4 directory present, KDEHOME set to .kde"); |
| 1584 MockEnvironment* env = new MockEnvironment; | 1509 MockEnvironment* env = new MockEnvironment; |
| 1585 env->values.DESKTOP_SESSION = "kde4"; | 1510 env->values.DESKTOP_SESSION = "kde4"; |
| 1586 env->values.HOME = user_home_.value().c_str(); | 1511 env->values.HOME = user_home_.value().c_str(); |
| 1587 env->values.KDEHOME = kde_home_.value().c_str(); | 1512 env->values.KDEHOME = kde_home_.value().c_str(); |
| 1588 SynchConfigGetter sync_config_getter( | 1513 SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env)); |
| 1589 new ProxyConfigServiceLinux(env)); | |
| 1590 ProxyConfig config; | 1514 ProxyConfig config; |
| 1591 sync_config_getter.SetupAndInitialFetch(); | 1515 sync_config_getter.SetupAndInitialFetch(); |
| 1592 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, | 1516 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1593 sync_config_getter.SyncGetLatestProxyConfig(&config)); | 1517 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1594 EXPECT_TRUE(config.auto_detect()); | 1518 EXPECT_TRUE(config.auto_detect()); |
| 1595 EXPECT_EQ(GURL(), config.pac_url()); | 1519 EXPECT_EQ(GURL(), config.pac_url()); |
| 1596 } | 1520 } |
| 1597 | 1521 |
| 1598 // Finally, make the .kde4 config directory older than the .kde directory | 1522 // Finally, make the .kde4 config directory older than the .kde directory |
| 1599 // and make sure we then use .kde instead of .kde4 since it's newer. | 1523 // and make sure we then use .kde instead of .kde4 since it's newer. |
| 1600 base::TouchFile(kde4_config_, base::Time(), base::Time()); | 1524 base::TouchFile(kde4_config_, base::Time(), base::Time()); |
| 1601 | 1525 |
| 1602 { SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde"); | 1526 { |
| 1527 SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde"); |
| 1603 MockEnvironment* env = new MockEnvironment; | 1528 MockEnvironment* env = new MockEnvironment; |
| 1604 env->values.DESKTOP_SESSION = "kde4"; | 1529 env->values.DESKTOP_SESSION = "kde4"; |
| 1605 env->values.HOME = user_home_.value().c_str(); | 1530 env->values.HOME = user_home_.value().c_str(); |
| 1606 SynchConfigGetter sync_config_getter( | 1531 SynchConfigGetter sync_config_getter(new ProxyConfigServiceLinux(env)); |
| 1607 new ProxyConfigServiceLinux(env)); | |
| 1608 ProxyConfig config; | 1532 ProxyConfig config; |
| 1609 sync_config_getter.SetupAndInitialFetch(); | 1533 sync_config_getter.SetupAndInitialFetch(); |
| 1610 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, | 1534 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1611 sync_config_getter.SyncGetLatestProxyConfig(&config)); | 1535 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1612 EXPECT_TRUE(config.auto_detect()); | 1536 EXPECT_TRUE(config.auto_detect()); |
| 1613 EXPECT_EQ(GURL(), config.pac_url()); | 1537 EXPECT_EQ(GURL(), config.pac_url()); |
| 1614 } | 1538 } |
| 1615 } | 1539 } |
| 1616 | 1540 |
| 1617 } // namespace net | 1541 } // namespace net |
| OLD | NEW |