OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <map> |
| 6 #include <string> |
| 7 #include <vector> |
| 8 |
| 9 #include "net/proxy/proxy_config_service_linux.h" |
| 10 |
| 11 #include "base/logging.h" |
| 12 #include "base/string_util.h" |
| 13 #include "net/proxy/proxy_config.h" |
| 14 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 15 |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace net { |
| 19 |
| 20 namespace { |
| 21 |
| 22 // Set of values for all environment variables that we might |
| 23 // query. NULL represents an unset variable. |
| 24 struct EnvVarValues { |
| 25 // The strange capitalization is so that the field matches the |
| 26 // environment variable name exactly. |
| 27 const char *GNOME_DESKTOP_SESSION_ID, *DESKTOP_SESSION, |
| 28 *auto_proxy, *all_proxy, |
| 29 *http_proxy, *https_proxy, *ftp_proxy, |
| 30 *SOCKS_SERVER, *SOCKS_VERSION, |
| 31 *no_proxy; |
| 32 }; |
| 33 |
| 34 // So as to distinguish between an unset gconf boolean variable and |
| 35 // one that is false. |
| 36 enum BoolSettingValue { |
| 37 UNSET = 0, TRUE, FALSE |
| 38 }; |
| 39 |
| 40 // Set of values for all gconf settings that we might query. |
| 41 struct GConfValues { |
| 42 // strings |
| 43 const char *mode, *autoconfig_url, |
| 44 *http_host, *secure_host, *ftp_host, *socks_host; |
| 45 // integers |
| 46 int http_port, secure_port, ftp_port, socks_port; |
| 47 // booleans |
| 48 BoolSettingValue use_proxy, same_proxy, use_auth; |
| 49 // string list |
| 50 std::vector<std::string> ignore_hosts; |
| 51 }; |
| 52 |
| 53 // Mapping from a setting name to the location of the corresponding |
| 54 // value (inside a EnvVarValues or GConfValues struct). |
| 55 template<typename value_type> |
| 56 struct SettingsTable { |
| 57 typedef std::map<std::string, value_type*> map_type; |
| 58 |
| 59 // Gets the value from its location |
| 60 value_type Get(const std::string& key) { |
| 61 typename map_type::const_iterator it = settings.find(key); |
| 62 // In case there's a typo or the unittest becomes out of sync. |
| 63 CHECK(it != settings.end()) << "key " << key << " not found"; |
| 64 value_type* value_ptr = it->second; |
| 65 return *value_ptr; |
| 66 } |
| 67 |
| 68 map_type settings; |
| 69 }; |
| 70 |
| 71 class MockEnvironmentVariableGetter |
| 72 : public ProxyConfigServiceLinux::EnvironmentVariableGetter { |
| 73 public: |
| 74 MockEnvironmentVariableGetter() { |
| 75 #define ENTRY(x) table.settings[#x] = &values.x |
| 76 ENTRY(GNOME_DESKTOP_SESSION_ID); |
| 77 ENTRY(DESKTOP_SESSION); |
| 78 ENTRY(auto_proxy); |
| 79 ENTRY(all_proxy); |
| 80 ENTRY(http_proxy); |
| 81 ENTRY(https_proxy); |
| 82 ENTRY(ftp_proxy); |
| 83 ENTRY(no_proxy); |
| 84 ENTRY(SOCKS_SERVER); |
| 85 ENTRY(SOCKS_VERSION); |
| 86 #undef ENTRY |
| 87 reset(); |
| 88 } |
| 89 |
| 90 // Zeros all environment values. |
| 91 void reset() { |
| 92 EnvVarValues zero_values = { 0 }; |
| 93 values = zero_values; |
| 94 } |
| 95 |
| 96 virtual bool Getenv(const char* variable_name, std::string* result) { |
| 97 const char* env_value = table.Get(variable_name); |
| 98 if (env_value) { |
| 99 // Note that the variable may be defined but empty. |
| 100 *result = env_value; |
| 101 return true; |
| 102 } |
| 103 return false; |
| 104 } |
| 105 |
| 106 // Intentionally public, for convenience when setting up a test. |
| 107 EnvVarValues values; |
| 108 |
| 109 private: |
| 110 SettingsTable<const char*> table; |
| 111 }; |
| 112 |
| 113 class MockGConfSettingGetter |
| 114 : public ProxyConfigServiceLinux::GConfSettingGetter { |
| 115 public: |
| 116 MockGConfSettingGetter() { |
| 117 #define ENTRY(key, field) \ |
| 118 strings_table.settings["/system/" key] = &values.field |
| 119 ENTRY("proxy/mode", mode); |
| 120 ENTRY("proxy/autoconfig_url", autoconfig_url); |
| 121 ENTRY("http_proxy/host", http_host); |
| 122 ENTRY("proxy/secure_host", secure_host); |
| 123 ENTRY("proxy/ftp_host", ftp_host); |
| 124 ENTRY("proxy/socks_host", socks_host); |
| 125 #undef ENTRY |
| 126 #define ENTRY(key, field) \ |
| 127 ints_table.settings["/system/" key] = &values.field |
| 128 ENTRY("http_proxy/port", http_port); |
| 129 ENTRY("proxy/secure_port", secure_port); |
| 130 ENTRY("proxy/ftp_port", ftp_port); |
| 131 ENTRY("proxy/socks_port", socks_port); |
| 132 #undef ENTRY |
| 133 #define ENTRY(key, field) \ |
| 134 bools_table.settings["/system/" key] = &values.field |
| 135 ENTRY("http_proxy/use_http_proxy", use_proxy); |
| 136 ENTRY("http_proxy/use_same_proxy", same_proxy); |
| 137 ENTRY("http_proxy/use_authentication", use_auth); |
| 138 #undef ENTRY |
| 139 string_lists_table.settings["/system/http_proxy/ignore_hosts"] = |
| 140 &values.ignore_hosts; |
| 141 reset(); |
| 142 } |
| 143 |
| 144 // Zeros all environment values. |
| 145 void reset() { |
| 146 GConfValues zero_values; |
| 147 values = zero_values; |
| 148 } |
| 149 |
| 150 virtual void Enter() {} |
| 151 virtual void Leave() {} |
| 152 |
| 153 virtual bool InitIfNeeded() { |
| 154 return true; |
| 155 } |
| 156 |
| 157 virtual bool GetString(const char* key, std::string* result) { |
| 158 const char* value = strings_table.Get(key); |
| 159 if (value) { |
| 160 *result = value; |
| 161 return true; |
| 162 } |
| 163 return false; |
| 164 } |
| 165 |
| 166 virtual bool GetInt(const char* key, int* result) { |
| 167 // We don't bother to distinguish unset keys from 0 values. |
| 168 *result = ints_table.Get(key); |
| 169 return true; |
| 170 } |
| 171 |
| 172 virtual bool GetBoolean(const char* key, bool* result) { |
| 173 BoolSettingValue value = bools_table.Get(key); |
| 174 switch (value) { |
| 175 case UNSET: |
| 176 return false; |
| 177 case TRUE: |
| 178 *result = true; |
| 179 break; |
| 180 case FALSE: |
| 181 *result = false; |
| 182 } |
| 183 return true; |
| 184 } |
| 185 |
| 186 virtual bool GetStringList(const char* key, |
| 187 std::vector<std::string>* result) { |
| 188 *result = string_lists_table.Get(key); |
| 189 // We don't bother to distinguish unset keys from empty lists. |
| 190 return !result->empty(); |
| 191 } |
| 192 |
| 193 // Intentionally public, for convenience when setting up a test. |
| 194 GConfValues values; |
| 195 |
| 196 private: |
| 197 SettingsTable<const char*> strings_table; |
| 198 SettingsTable<int> ints_table; |
| 199 SettingsTable<BoolSettingValue> bools_table; |
| 200 SettingsTable<std::vector<std::string> > string_lists_table; |
| 201 }; |
| 202 |
| 203 } // namespace |
| 204 |
| 205 // Builds an identifier for each test in an array. |
| 206 #define TEST_DESC(desc) StringPrintf("at line %d <%s>", __LINE__, desc) |
| 207 |
| 208 TEST(ProxyConfigServiceLinuxTest, BasicGConfTest) { |
| 209 MockEnvironmentVariableGetter* env_getter = |
| 210 new MockEnvironmentVariableGetter; |
| 211 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 212 ProxyConfigServiceLinux service(env_getter, gconf_getter); |
| 213 // This env var indicates we are running Gnome and should consult gconf. |
| 214 env_getter->values.GNOME_DESKTOP_SESSION_ID = "defined"; |
| 215 |
| 216 std::vector<std::string> empty_ignores; |
| 217 |
| 218 std::vector<std::string> google_ignores; |
| 219 google_ignores.push_back("*.google.com"); |
| 220 |
| 221 // Inspired from proxy_config_service_win_unittest.cc. |
| 222 // Very neat, but harder to track down failures though. |
| 223 const struct { |
| 224 // Short description to identify the test |
| 225 std::string description; |
| 226 |
| 227 // Input. |
| 228 GConfValues values; |
| 229 |
| 230 // Expected outputs (fields of the ProxyConfig). |
| 231 bool auto_detect; |
| 232 GURL pac_url; |
| 233 ProxyConfig::ProxyRules proxy_rules; |
| 234 const char* proxy_bypass_list; // newline separated |
| 235 bool bypass_local_names; |
| 236 } tests[] = { |
| 237 { |
| 238 TEST_DESC("No proxying"), |
| 239 { // Input. |
| 240 "none", // mode |
| 241 "", // autoconfig_url |
| 242 "", "", "", "", // hosts |
| 243 0, 0, 0, 0, // ports |
| 244 FALSE, FALSE, FALSE, // use, same, auth |
| 245 empty_ignores, // ignore_hosts |
| 246 }, |
| 247 |
| 248 // Expected result. |
| 249 false, // auto_detect |
| 250 GURL(), // pac_url |
| 251 ProxyConfig::ProxyRules(), // proxy_rules |
| 252 "", // proxy_bypass_list |
| 253 false, // bypass_local_names |
| 254 }, |
| 255 |
| 256 { |
| 257 TEST_DESC("Auto detect"), |
| 258 { // Input. |
| 259 "auto", // mode |
| 260 "", // autoconfig_url |
| 261 "", "", "", "", // hosts |
| 262 0, 0, 0, 0, // ports |
| 263 FALSE, FALSE, FALSE, // use, same, auth |
| 264 empty_ignores, // ignore_hosts |
| 265 }, |
| 266 |
| 267 // Expected result. |
| 268 true, // auto_detect |
| 269 GURL(), // pac_url |
| 270 ProxyConfig::ProxyRules(), // proxy_rules |
| 271 "", // proxy_bypass_list |
| 272 false, // bypass_local_names |
| 273 }, |
| 274 |
| 275 { |
| 276 TEST_DESC("Valid PAC url"), |
| 277 { // Input. |
| 278 "auto", // mode |
| 279 "http://wpad/wpad.dat", // autoconfig_url |
| 280 "", "", "", "", // hosts |
| 281 0, 0, 0, 0, // ports |
| 282 FALSE, FALSE, FALSE, // use, same, auth |
| 283 empty_ignores, // ignore_hosts |
| 284 }, |
| 285 |
| 286 // Expected result. |
| 287 false, // auto_detect |
| 288 GURL("http://wpad/wpad.dat"), // pac_url |
| 289 ProxyConfig::ProxyRules(), // proxy_rules |
| 290 "", // proxy_bypass_list |
| 291 false, // bypass_local_names |
| 292 }, |
| 293 |
| 294 { |
| 295 TEST_DESC("Invalid PAC url"), |
| 296 { // Input. |
| 297 "auto", // mode |
| 298 "wpad.dat", // autoconfig_url |
| 299 "", "", "", "", // hosts |
| 300 0, 0, 0, 0, // ports |
| 301 FALSE, FALSE, FALSE, // use, same, auth |
| 302 empty_ignores, // ignore_hosts |
| 303 }, |
| 304 |
| 305 // Expected result. |
| 306 false, // auto_detect |
| 307 GURL(), // pac_url |
| 308 ProxyConfig::ProxyRules(), // proxy_rules |
| 309 "", // proxy_bypass_list |
| 310 false, // bypass_local_names |
| 311 }, |
| 312 |
| 313 { |
| 314 TEST_DESC("Single-host in proxy list"), |
| 315 { // Input. |
| 316 "manual", // mode |
| 317 "", // autoconfig_url |
| 318 "www.google.com", "", "", "", // hosts |
| 319 80, 0, 0, 0, // ports |
| 320 TRUE, TRUE, FALSE, // use, same, auth |
| 321 empty_ignores, // ignore_hosts |
| 322 }, |
| 323 |
| 324 // Expected result. |
| 325 false, // auto_detect |
| 326 GURL(), // pac_url |
| 327 MakeSingleProxyRules("www.google.com"), // proxy_rules |
| 328 "", // proxy_bypass_list |
| 329 false, // bypass_local_names |
| 330 }, |
| 331 |
| 332 { |
| 333 TEST_DESC("use_http_proxy is honored"), |
| 334 { // Input. |
| 335 "manual", // mode |
| 336 "", // autoconfig_url |
| 337 "www.google.com", "", "", "", // hosts |
| 338 80, 0, 0, 0, // ports |
| 339 FALSE, TRUE, FALSE, // use, same, auth |
| 340 empty_ignores, // ignore_hosts |
| 341 }, |
| 342 |
| 343 // Expected result. |
| 344 false, // auto_detect |
| 345 GURL(), // pac_url |
| 346 ProxyConfig::ProxyRules(), // proxy_rules |
| 347 "", // proxy_bypass_list |
| 348 false, // bypass_local_names |
| 349 }, |
| 350 |
| 351 { |
| 352 TEST_DESC("use_http_proxy and use_same_proxy are optional"), |
| 353 { // Input. |
| 354 "manual", // mode |
| 355 "", // autoconfig_url |
| 356 "www.google.com", "", "", "", // hosts |
| 357 80, 0, 0, 0, // ports |
| 358 UNSET, UNSET, FALSE, // use, same, auth |
| 359 empty_ignores, // ignore_hosts |
| 360 }, |
| 361 |
| 362 // Expected result. |
| 363 false, // auto_detect |
| 364 GURL(), // pac_url |
| 365 MakeProxyPerSchemeRules("www.google.com", // proxy_rules |
| 366 "", ""), |
| 367 "", // proxy_bypass_list |
| 368 false, // bypass_local_names |
| 369 }, |
| 370 |
| 371 { |
| 372 TEST_DESC("Single-host, different port"), |
| 373 { // Input. |
| 374 "manual", // mode |
| 375 "", // autoconfig_url |
| 376 "www.google.com", "", "", "", // hosts |
| 377 88, 0, 0, 0, // ports |
| 378 TRUE, TRUE, FALSE, // use, same, auth |
| 379 empty_ignores, // ignore_hosts |
| 380 }, |
| 381 |
| 382 // Expected result. |
| 383 false, // auto_detect |
| 384 GURL(), // pac_aurl |
| 385 MakeSingleProxyRules("www.google.com:88"), // proxy_rules |
| 386 "", // proxy_bypass_list |
| 387 false, // bypass_local_names |
| 388 }, |
| 389 |
| 390 { |
| 391 TEST_DESC("Per-scheme proxy rules"), |
| 392 { // Input. |
| 393 "manual", // mode |
| 394 "", // autoconfig_url |
| 395 "www.google.com", // http_host |
| 396 "www.foo.com", // secure_host |
| 397 "ftpfoo.com", // ftp |
| 398 "", // socks |
| 399 88, 110, 121, 0, // ports |
| 400 TRUE, FALSE, FALSE, // use, same, auth |
| 401 empty_ignores, // ignore_hosts |
| 402 }, |
| 403 |
| 404 // Expected result. |
| 405 false, // auto_detect |
| 406 GURL(), // pac_url |
| 407 MakeProxyPerSchemeRules("www.google.com:88", // proxy_rules |
| 408 "www.foo.com:110", |
| 409 "ftpfoo.com:121"), |
| 410 "", // proxy_bypass_list |
| 411 false, // bypass_local_names |
| 412 }, |
| 413 |
| 414 { |
| 415 TEST_DESC("socks"), |
| 416 { // Input. |
| 417 "manual", // mode |
| 418 "", // autoconfig_url |
| 419 "", "", "", "socks.com", // hosts |
| 420 0, 0, 0, 99, // ports |
| 421 TRUE, FALSE, FALSE, // use, same, auth |
| 422 empty_ignores, // ignore_hosts |
| 423 }, |
| 424 |
| 425 // Expected result. |
| 426 false, // auto_detect |
| 427 GURL(), // pac_url |
| 428 MakeSingleProxyRules("socks4://socks.com:99"), // proxy_rules |
| 429 "", // proxy_bypass_list |
| 430 false, // bypass_local_names |
| 431 }, |
| 432 |
| 433 { |
| 434 TEST_DESC("Bypass *.google.com"), |
| 435 { // Input. |
| 436 "manual", // mode |
| 437 "", // autoconfig_url |
| 438 "www.google.com", "", "", "", // hosts |
| 439 80, 0, 0, 0, // ports |
| 440 TRUE, TRUE, FALSE, // use, same, auth |
| 441 google_ignores, // ignore_hosts |
| 442 }, |
| 443 |
| 444 false, // auto_detect |
| 445 GURL(), // pac_url |
| 446 MakeSingleProxyRules("www.google.com"), // proxy_rules |
| 447 "*.google.com\n", // proxy_bypass_list |
| 448 false, // bypass_local_names |
| 449 }, |
| 450 }; |
| 451 |
| 452 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 453 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str())); |
| 454 ProxyConfig config; |
| 455 gconf_getter->values = tests[i].values; |
| 456 service.GetProxyConfig(&config); |
| 457 |
| 458 // TODO(sdoyon): Add a description field to each test, and a |
| 459 // corresponding message to the EXPECT statements, so that it is |
| 460 // possible to identify which one of the tests failed. |
| 461 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); |
| 462 EXPECT_EQ(tests[i].pac_url, config.pac_url); |
| 463 EXPECT_EQ(tests[i].proxy_bypass_list, |
| 464 FlattenProxyBypass(config.proxy_bypass)); |
| 465 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); |
| 466 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); |
| 467 } |
| 468 } |
| 469 |
| 470 TEST(ProxyConfigServiceLinuxTest, BasicEnvTest) { |
| 471 MockEnvironmentVariableGetter* env_getter = |
| 472 new MockEnvironmentVariableGetter; |
| 473 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 474 ProxyConfigServiceLinux service(env_getter, gconf_getter); |
| 475 |
| 476 // Inspired from proxy_config_service_win_unittest.cc. |
| 477 const struct { |
| 478 // Short description to identify the test |
| 479 std::string description; |
| 480 |
| 481 // Input. |
| 482 EnvVarValues values; |
| 483 |
| 484 // Expected outputs (fields of the ProxyConfig). |
| 485 bool auto_detect; |
| 486 GURL pac_url; |
| 487 ProxyConfig::ProxyRules proxy_rules; |
| 488 const char* proxy_bypass_list; // newline separated |
| 489 bool bypass_local_names; |
| 490 } tests[] = { |
| 491 { |
| 492 TEST_DESC("No proxying"), |
| 493 { // Input. |
| 494 NULL, NULL, // *DESKTOP* |
| 495 NULL, // auto_proxy |
| 496 NULL, // all_proxy |
| 497 NULL, NULL, NULL, // per-proto proxies |
| 498 NULL, NULL, // SOCKS |
| 499 "*", // no_proxy |
| 500 }, |
| 501 |
| 502 // Expected result. |
| 503 false, // auto_detect |
| 504 GURL(), // pac_url |
| 505 ProxyConfig::ProxyRules(), // proxy_rules |
| 506 "", // proxy_bypass_list |
| 507 false, // bypass_local_names |
| 508 }, |
| 509 |
| 510 { |
| 511 TEST_DESC("Auto detect"), |
| 512 { // Input. |
| 513 NULL, NULL, // *DESKTOP* |
| 514 "", // auto_proxy |
| 515 NULL, // all_proxy |
| 516 NULL, NULL, NULL, // per-proto proxies |
| 517 NULL, NULL, // SOCKS |
| 518 NULL, // no_proxy |
| 519 }, |
| 520 |
| 521 // Expected result. |
| 522 true, // auto_detect |
| 523 GURL(), // pac_url |
| 524 ProxyConfig::ProxyRules(), // proxy_rules |
| 525 "", // proxy_bypass_list |
| 526 false, // bypass_local_names |
| 527 }, |
| 528 |
| 529 { |
| 530 TEST_DESC("Valid PAC url"), |
| 531 { // Input. |
| 532 NULL, NULL, // *DESKTOP* |
| 533 "http://wpad/wpad.dat", // auto_proxy |
| 534 NULL, // all_proxy |
| 535 NULL, NULL, NULL, // per-proto proxies |
| 536 NULL, NULL, // SOCKS |
| 537 NULL, // no_proxy |
| 538 }, |
| 539 |
| 540 // Expected result. |
| 541 false, // auto_detect |
| 542 GURL("http://wpad/wpad.dat"), // pac_url |
| 543 ProxyConfig::ProxyRules(), // proxy_rules |
| 544 "", // proxy_bypass_list |
| 545 false, // bypass_local_names |
| 546 }, |
| 547 |
| 548 { |
| 549 TEST_DESC("Invalid PAC url"), |
| 550 { // Input. |
| 551 NULL, NULL, // *DESKTOP* |
| 552 "wpad.dat", // auto_proxy |
| 553 NULL, // all_proxy |
| 554 NULL, NULL, NULL, // per-proto proxies |
| 555 NULL, NULL, // SOCKS |
| 556 NULL, // no_proxy |
| 557 }, |
| 558 |
| 559 // Expected result. |
| 560 false, // auto_detect |
| 561 GURL(), // pac_url |
| 562 ProxyConfig::ProxyRules(), // proxy_rules |
| 563 "", // proxy_bypass_list |
| 564 false, // bypass_local_names |
| 565 }, |
| 566 |
| 567 { |
| 568 TEST_DESC("Single-host in proxy list"), |
| 569 { // Input. |
| 570 NULL, NULL, // *DESKTOP* |
| 571 NULL, // auto_proxy |
| 572 "www.google.com", // all_proxy |
| 573 NULL, NULL, NULL, // per-proto proxies |
| 574 NULL, NULL, // SOCKS |
| 575 NULL, // no_proxy |
| 576 }, |
| 577 |
| 578 // Expected result. |
| 579 false, // auto_detect |
| 580 GURL(), // pac_url |
| 581 MakeSingleProxyRules("www.google.com"), // proxy_rules |
| 582 "", // proxy_bypass_list |
| 583 false, // bypass_local_names |
| 584 }, |
| 585 |
| 586 { |
| 587 TEST_DESC("Single-host, different port"), |
| 588 { // Input. |
| 589 NULL, NULL, // *DESKTOP* |
| 590 NULL, // auto_proxy |
| 591 "www.google.com:99", // all_proxy |
| 592 NULL, NULL, NULL, // per-proto proxies |
| 593 NULL, NULL, // SOCKS |
| 594 NULL, // no_proxy |
| 595 }, |
| 596 |
| 597 // Expected result. |
| 598 false, // auto_detect |
| 599 GURL(), // pac_url |
| 600 MakeSingleProxyRules("www.google.com:99"), // proxy_rules |
| 601 "", // proxy_bypass_list |
| 602 false, // bypass_local_names |
| 603 }, |
| 604 |
| 605 { |
| 606 TEST_DESC("Tolerate a scheme"), |
| 607 { // Input. |
| 608 NULL, NULL, // *DESKTOP* |
| 609 NULL, // auto_proxy |
| 610 "http://www.google.com:99", // all_proxy |
| 611 NULL, NULL, NULL, // per-proto proxies |
| 612 NULL, NULL, // SOCKS |
| 613 NULL, // no_proxy |
| 614 }, |
| 615 |
| 616 // Expected result. |
| 617 false, // auto_detect |
| 618 GURL(), // pac_url |
| 619 MakeSingleProxyRules("www.google.com:99"), // proxy_rules |
| 620 "", // proxy_bypass_list |
| 621 false, // bypass_local_names |
| 622 }, |
| 623 |
| 624 { |
| 625 TEST_DESC("Per-scheme proxy rules"), |
| 626 { // Input. |
| 627 NULL, NULL, // *DESKTOP* |
| 628 NULL, // auto_proxy |
| 629 NULL, // all_proxy |
| 630 "www.google.com:80", "www.foo.com:110", "ftpfoo.com:121", // per-proto |
| 631 NULL, NULL, // SOCKS |
| 632 NULL, // no_proxy |
| 633 }, |
| 634 |
| 635 // Expected result. |
| 636 false, // auto_detect |
| 637 GURL(), // pac_url |
| 638 MakeProxyPerSchemeRules("www.google.com", "www.foo.com:110", |
| 639 "ftpfoo.com:121"), |
| 640 "", // proxy_bypass_list |
| 641 false, // bypass_local_names |
| 642 }, |
| 643 |
| 644 { |
| 645 TEST_DESC("socks"), |
| 646 { // Input. |
| 647 NULL, NULL, // *DESKTOP* |
| 648 NULL, // auto_proxy |
| 649 "", // all_proxy |
| 650 NULL, NULL, NULL, // per-proto proxies |
| 651 "socks.com:888", NULL, // SOCKS |
| 652 NULL, // no_proxy |
| 653 }, |
| 654 |
| 655 // Expected result. |
| 656 false, // auto_detect |
| 657 GURL(), // pac_url |
| 658 MakeSingleProxyRules("socks4://socks.com:888"), // proxy_rules |
| 659 "", // proxy_bypass_list |
| 660 false, // bypass_local_names |
| 661 }, |
| 662 |
| 663 { |
| 664 TEST_DESC("socks5"), |
| 665 { // Input. |
| 666 NULL, NULL, // *DESKTOP* |
| 667 NULL, // auto_proxy |
| 668 "", // all_proxy |
| 669 NULL, NULL, NULL, // per-proto proxies |
| 670 "socks.com:888", "5", // SOCKS |
| 671 NULL, // no_proxy |
| 672 }, |
| 673 |
| 674 // Expected result. |
| 675 false, // auto_detect |
| 676 GURL(), // pac_url |
| 677 MakeSingleProxyRules("socks5://socks.com:888"), // proxy_rules |
| 678 "", // proxy_bypass_list |
| 679 false, // bypass_local_names |
| 680 }, |
| 681 |
| 682 { |
| 683 TEST_DESC("socks default port"), |
| 684 { // Input. |
| 685 NULL, NULL, // *DESKTOP* |
| 686 NULL, // auto_proxy |
| 687 "", // all_proxy |
| 688 NULL, NULL, NULL, // per-proto proxies |
| 689 "socks.com", NULL, // SOCKS |
| 690 NULL, // no_proxy |
| 691 }, |
| 692 |
| 693 // Expected result. |
| 694 false, // auto_detect |
| 695 GURL(), // pac_url |
| 696 MakeSingleProxyRules("socks4://socks.com"), // proxy_rules |
| 697 "", // proxy_bypass_list |
| 698 false, // bypass_local_names |
| 699 }, |
| 700 |
| 701 { |
| 702 TEST_DESC("bypass"), |
| 703 { // Input. |
| 704 NULL, NULL, // *DESKTOP* |
| 705 NULL, // auto_proxy |
| 706 "www.google.com", // all_proxy |
| 707 NULL, NULL, NULL, // per-proto |
| 708 NULL, NULL, // SOCKS |
| 709 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy |
| 710 }, |
| 711 |
| 712 false, // auto_detect |
| 713 GURL(), // pac_url |
| 714 MakeSingleProxyRules("www.google.com"), // proxy_rules |
| 715 // proxy_bypass_list |
| 716 "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n", |
| 717 false, // bypass_local_names |
| 718 }, |
| 719 }; |
| 720 |
| 721 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 722 SCOPED_TRACE(StringPrintf("Test[%d] %s", i, tests[i].description.c_str())); |
| 723 ProxyConfig config; |
| 724 env_getter->values = tests[i].values; |
| 725 service.GetProxyConfig(&config); |
| 726 |
| 727 EXPECT_EQ(tests[i].auto_detect, config.auto_detect); |
| 728 EXPECT_EQ(tests[i].pac_url, config.pac_url); |
| 729 EXPECT_EQ(tests[i].proxy_bypass_list, |
| 730 FlattenProxyBypass(config.proxy_bypass)); |
| 731 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); |
| 732 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); |
| 733 } |
| 734 } |
| 735 |
| 736 } // namespace net |
OLD | NEW |