| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/proxy/proxy_config_service_linux.h" | 5 #include "net/proxy/proxy_config_service_linux.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/format_macros.h" | 13 #include "base/format_macros.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/task.h" | 18 #include "base/task.h" |
| 18 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
| 19 #include "base/synchronization/waitable_event.h" | |
| 20 #include "net/proxy/proxy_config.h" | 20 #include "net/proxy/proxy_config.h" |
| 21 #include "net/proxy/proxy_config_service_common_unittest.h" | 21 #include "net/proxy/proxy_config_service_common_unittest.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
| 24 | 24 |
| 25 namespace net { | 25 namespace net { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Set of values for all environment variables that we might | 28 // Set of values for all environment variables that we might |
| 29 // query. NULL represents an unset variable. | 29 // query. NULL represents an unset variable. |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 // default glib main loop, which is the UI thread). | 283 // default glib main loop, which is the UI thread). |
| 284 void SetupAndInitialFetch() { | 284 void SetupAndInitialFetch() { |
| 285 MessageLoop* file_loop = io_thread_.message_loop(); | 285 MessageLoop* file_loop = io_thread_.message_loop(); |
| 286 DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type()); | 286 DCHECK_EQ(MessageLoop::TYPE_IO, file_loop->type()); |
| 287 // We pass the mock IO thread as both the IO and file threads. | 287 // We pass the mock IO thread as both the IO and file threads. |
| 288 config_service_->SetupAndFetchInitialConfig( | 288 config_service_->SetupAndFetchInitialConfig( |
| 289 MessageLoop::current(), io_thread_.message_loop(), | 289 MessageLoop::current(), io_thread_.message_loop(), |
| 290 static_cast<MessageLoopForIO*>(file_loop)); | 290 static_cast<MessageLoopForIO*>(file_loop)); |
| 291 } | 291 } |
| 292 // Synchronously gets the proxy config. | 292 // Synchronously gets the proxy config. |
| 293 bool SyncGetLatestProxyConfig(net::ProxyConfig* config) { | 293 net::ProxyConfigService::ConfigAvailability SyncGetLatestProxyConfig( |
| 294 net::ProxyConfig* config) { |
| 294 io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 295 io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| 295 this, &SynchConfigGetter::GetLatestConfigOnIOThread)); | 296 this, &SynchConfigGetter::GetLatestConfigOnIOThread)); |
| 296 Wait(); | 297 Wait(); |
| 297 *config = proxy_config_; | 298 *config = proxy_config_; |
| 298 return get_latest_config_result_; | 299 return get_latest_config_result_; |
| 299 } | 300 } |
| 300 | 301 |
| 301 private: | 302 private: |
| 302 // [Runs on |io_thread_|] | 303 // [Runs on |io_thread_|] |
| 303 void Init() { | 304 void Init() { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 324 } | 325 } |
| 325 | 326 |
| 326 base::WaitableEvent event_; | 327 base::WaitableEvent event_; |
| 327 base::Thread io_thread_; | 328 base::Thread io_thread_; |
| 328 | 329 |
| 329 net::ProxyConfigServiceLinux* config_service_; | 330 net::ProxyConfigServiceLinux* config_service_; |
| 330 | 331 |
| 331 // The config obtained by |io_thread_| and read back by the main | 332 // The config obtained by |io_thread_| and read back by the main |
| 332 // thread. | 333 // thread. |
| 333 net::ProxyConfig proxy_config_; | 334 net::ProxyConfig proxy_config_; |
| 334 bool get_latest_config_result_; // Return value from GetLatestProxyConfig(). | 335 |
| 336 // Return value from GetLatestProxyConfig(). |
| 337 net::ProxyConfigService::ConfigAvailability get_latest_config_result_; |
| 335 }; | 338 }; |
| 336 | 339 |
| 337 DISABLE_RUNNABLE_METHOD_REFCOUNT(SynchConfigGetter); | 340 DISABLE_RUNNABLE_METHOD_REFCOUNT(SynchConfigGetter); |
| 338 | 341 |
| 339 namespace net { | 342 namespace net { |
| 340 | 343 |
| 341 // This test fixture is only really needed for the KDEConfigParser test case, | 344 // This test fixture is only really needed for the KDEConfigParser test case, |
| 342 // but all the test cases with the same prefix ("ProxyConfigServiceLinuxTest") | 345 // but all the test cases with the same prefix ("ProxyConfigServiceLinuxTest") |
| 343 // must use the same test fixture class (also "ProxyConfigServiceLinuxTest"). | 346 // must use the same test fixture class (also "ProxyConfigServiceLinuxTest"). |
| 344 class ProxyConfigServiceLinuxTest : public PlatformTest { | 347 class ProxyConfigServiceLinuxTest : public PlatformTest { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 390 |
| 388 // Inspired from proxy_config_service_win_unittest.cc. | 391 // Inspired from proxy_config_service_win_unittest.cc. |
| 389 // Very neat, but harder to track down failures though. | 392 // Very neat, but harder to track down failures though. |
| 390 const struct { | 393 const struct { |
| 391 // Short description to identify the test | 394 // Short description to identify the test |
| 392 std::string description; | 395 std::string description; |
| 393 | 396 |
| 394 // Input. | 397 // Input. |
| 395 GConfValues values; | 398 GConfValues values; |
| 396 | 399 |
| 397 // Expected outputs (fields of the ProxyConfig). | 400 // Expected outputs (availability and fields of ProxyConfig). |
| 401 ProxyConfigService::ConfigAvailability availability; |
| 398 bool auto_detect; | 402 bool auto_detect; |
| 399 GURL pac_url; | 403 GURL pac_url; |
| 400 ProxyRulesExpectation proxy_rules; | 404 ProxyRulesExpectation proxy_rules; |
| 401 } tests[] = { | 405 } tests[] = { |
| 402 { | 406 { |
| 403 TEST_DESC("No proxying"), | 407 TEST_DESC("No proxying"), |
| 404 { // Input. | 408 { // Input. |
| 405 "none", // mode | 409 "none", // mode |
| 406 "", // autoconfig_url | 410 "", // autoconfig_url |
| 407 "", "", "", "", // hosts | 411 "", "", "", "", // hosts |
| 408 0, 0, 0, 0, // ports | 412 0, 0, 0, 0, // ports |
| 409 FALSE, FALSE, FALSE, // use, same, auth | 413 FALSE, FALSE, FALSE, // use, same, auth |
| 410 empty_ignores, // ignore_hosts | 414 empty_ignores, // ignore_hosts |
| 411 }, | 415 }, |
| 412 | 416 |
| 413 // Expected result. | 417 // Expected result. |
| 418 ProxyConfigService::CONFIG_VALID, |
| 414 false, // auto_detect | 419 false, // auto_detect |
| 415 GURL(), // pac_url | 420 GURL(), // pac_url |
| 416 ProxyRulesExpectation::Empty(), | 421 ProxyRulesExpectation::Empty(), |
| 417 }, | 422 }, |
| 418 | 423 |
| 419 { | 424 { |
| 420 TEST_DESC("Auto detect"), | 425 TEST_DESC("Auto detect"), |
| 421 { // Input. | 426 { // Input. |
| 422 "auto", // mode | 427 "auto", // mode |
| 423 "", // autoconfig_url | 428 "", // autoconfig_url |
| 424 "", "", "", "", // hosts | 429 "", "", "", "", // hosts |
| 425 0, 0, 0, 0, // ports | 430 0, 0, 0, 0, // ports |
| 426 FALSE, FALSE, FALSE, // use, same, auth | 431 FALSE, FALSE, FALSE, // use, same, auth |
| 427 empty_ignores, // ignore_hosts | 432 empty_ignores, // ignore_hosts |
| 428 }, | 433 }, |
| 429 | 434 |
| 430 // Expected result. | 435 // Expected result. |
| 436 ProxyConfigService::CONFIG_VALID, |
| 431 true, // auto_detect | 437 true, // auto_detect |
| 432 GURL(), // pac_url | 438 GURL(), // pac_url |
| 433 ProxyRulesExpectation::Empty(), | 439 ProxyRulesExpectation::Empty(), |
| 434 }, | 440 }, |
| 435 | 441 |
| 436 { | 442 { |
| 437 TEST_DESC("Valid PAC URL"), | 443 TEST_DESC("Valid PAC URL"), |
| 438 { // Input. | 444 { // Input. |
| 439 "auto", // mode | 445 "auto", // mode |
| 440 "http://wpad/wpad.dat", // autoconfig_url | 446 "http://wpad/wpad.dat", // autoconfig_url |
| 441 "", "", "", "", // hosts | 447 "", "", "", "", // hosts |
| 442 0, 0, 0, 0, // ports | 448 0, 0, 0, 0, // ports |
| 443 FALSE, FALSE, FALSE, // use, same, auth | 449 FALSE, FALSE, FALSE, // use, same, auth |
| 444 empty_ignores, // ignore_hosts | 450 empty_ignores, // ignore_hosts |
| 445 }, | 451 }, |
| 446 | 452 |
| 447 // Expected result. | 453 // Expected result. |
| 454 ProxyConfigService::CONFIG_VALID, |
| 448 false, // auto_detect | 455 false, // auto_detect |
| 449 GURL("http://wpad/wpad.dat"), // pac_url | 456 GURL("http://wpad/wpad.dat"), // pac_url |
| 450 ProxyRulesExpectation::Empty(), | 457 ProxyRulesExpectation::Empty(), |
| 451 }, | 458 }, |
| 452 | 459 |
| 453 { | 460 { |
| 454 TEST_DESC("Invalid PAC URL"), | 461 TEST_DESC("Invalid PAC URL"), |
| 455 { // Input. | 462 { // Input. |
| 456 "auto", // mode | 463 "auto", // mode |
| 457 "wpad.dat", // autoconfig_url | 464 "wpad.dat", // autoconfig_url |
| 458 "", "", "", "", // hosts | 465 "", "", "", "", // hosts |
| 459 0, 0, 0, 0, // ports | 466 0, 0, 0, 0, // ports |
| 460 FALSE, FALSE, FALSE, // use, same, auth | 467 FALSE, FALSE, FALSE, // use, same, auth |
| 461 empty_ignores, // ignore_hosts | 468 empty_ignores, // ignore_hosts |
| 462 }, | 469 }, |
| 463 | 470 |
| 464 // Expected result. | 471 // Expected result. |
| 465 false, // auto_detect | 472 ProxyConfigService::CONFIG_VALID, |
| 473 false, // auto_detect |
| 466 GURL(), // pac_url | 474 GURL(), // pac_url |
| 467 ProxyRulesExpectation::Empty(), | 475 ProxyRulesExpectation::Empty(), |
| 468 }, | 476 }, |
| 469 | 477 |
| 470 { | 478 { |
| 471 TEST_DESC("Single-host in proxy list"), | 479 TEST_DESC("Single-host in proxy list"), |
| 472 { // Input. | 480 { // Input. |
| 473 "manual", // mode | 481 "manual", // mode |
| 474 "", // autoconfig_url | 482 "", // autoconfig_url |
| 475 "www.google.com", "", "", "", // hosts | 483 "www.google.com", "", "", "", // hosts |
| 476 80, 0, 0, 0, // ports | 484 80, 0, 0, 0, // ports |
| 477 TRUE, TRUE, FALSE, // use, same, auth | 485 TRUE, TRUE, FALSE, // use, same, auth |
| 478 empty_ignores, // ignore_hosts | 486 empty_ignores, // ignore_hosts |
| 479 }, | 487 }, |
| 480 | 488 |
| 481 // Expected result. | 489 // Expected result. |
| 490 ProxyConfigService::CONFIG_VALID, |
| 482 false, // auto_detect | 491 false, // auto_detect |
| 483 GURL(), // pac_url | 492 GURL(), // pac_url |
| 484 ProxyRulesExpectation::Single( | 493 ProxyRulesExpectation::Single( |
| 485 "www.google.com:80", // single proxy | 494 "www.google.com:80", // single proxy |
| 486 ""), // bypass rules | 495 ""), // bypass rules |
| 487 }, | 496 }, |
| 488 | 497 |
| 489 { | 498 { |
| 490 TEST_DESC("use_http_proxy is honored"), | 499 TEST_DESC("use_http_proxy is honored"), |
| 491 { // Input. | 500 { // Input. |
| 492 "manual", // mode | 501 "manual", // mode |
| 493 "", // autoconfig_url | 502 "", // autoconfig_url |
| 494 "www.google.com", "", "", "", // hosts | 503 "www.google.com", "", "", "", // hosts |
| 495 80, 0, 0, 0, // ports | 504 80, 0, 0, 0, // ports |
| 496 FALSE, TRUE, FALSE, // use, same, auth | 505 FALSE, TRUE, FALSE, // use, same, auth |
| 497 empty_ignores, // ignore_hosts | 506 empty_ignores, // ignore_hosts |
| 498 }, | 507 }, |
| 499 | 508 |
| 500 // Expected result. | 509 // Expected result. |
| 510 ProxyConfigService::CONFIG_VALID, |
| 501 false, // auto_detect | 511 false, // auto_detect |
| 502 GURL(), // pac_url | 512 GURL(), // pac_url |
| 503 ProxyRulesExpectation::Empty(), | 513 ProxyRulesExpectation::Empty(), |
| 504 }, | 514 }, |
| 505 | 515 |
| 506 { | 516 { |
| 507 TEST_DESC("use_http_proxy and use_same_proxy are optional"), | 517 TEST_DESC("use_http_proxy and use_same_proxy are optional"), |
| 508 { // Input. | 518 { // Input. |
| 509 "manual", // mode | 519 "manual", // mode |
| 510 "", // autoconfig_url | 520 "", // autoconfig_url |
| 511 "www.google.com", "", "", "", // hosts | 521 "www.google.com", "", "", "", // hosts |
| 512 80, 0, 0, 0, // ports | 522 80, 0, 0, 0, // ports |
| 513 UNSET, UNSET, FALSE, // use, same, auth | 523 UNSET, UNSET, FALSE, // use, same, auth |
| 514 empty_ignores, // ignore_hosts | 524 empty_ignores, // ignore_hosts |
| 515 }, | 525 }, |
| 516 | 526 |
| 517 // Expected result. | 527 // Expected result. |
| 528 ProxyConfigService::CONFIG_VALID, |
| 518 false, // auto_detect | 529 false, // auto_detect |
| 519 GURL(), // pac_url | 530 GURL(), // pac_url |
| 520 ProxyRulesExpectation::PerScheme( | 531 ProxyRulesExpectation::PerScheme( |
| 521 "www.google.com:80", // http | 532 "www.google.com:80", // http |
| 522 "", // https | 533 "", // https |
| 523 "", // ftp | 534 "", // ftp |
| 524 ""), // bypass rules | 535 ""), // bypass rules |
| 525 }, | 536 }, |
| 526 | 537 |
| 527 { | 538 { |
| 528 TEST_DESC("Single-host, different port"), | 539 TEST_DESC("Single-host, different port"), |
| 529 { // Input. | 540 { // Input. |
| 530 "manual", // mode | 541 "manual", // mode |
| 531 "", // autoconfig_url | 542 "", // autoconfig_url |
| 532 "www.google.com", "", "", "", // hosts | 543 "www.google.com", "", "", "", // hosts |
| 533 88, 0, 0, 0, // ports | 544 88, 0, 0, 0, // ports |
| 534 TRUE, TRUE, FALSE, // use, same, auth | 545 TRUE, TRUE, FALSE, // use, same, auth |
| 535 empty_ignores, // ignore_hosts | 546 empty_ignores, // ignore_hosts |
| 536 }, | 547 }, |
| 537 | 548 |
| 538 // Expected result. | 549 // Expected result. |
| 550 ProxyConfigService::CONFIG_VALID, |
| 539 false, // auto_detect | 551 false, // auto_detect |
| 540 GURL(), // pac_url | 552 GURL(), // pac_url |
| 541 ProxyRulesExpectation::Single( | 553 ProxyRulesExpectation::Single( |
| 542 "www.google.com:88", // single proxy | 554 "www.google.com:88", // single proxy |
| 543 ""), // bypass rules | 555 ""), // bypass rules |
| 544 }, | 556 }, |
| 545 | 557 |
| 546 { | 558 { |
| 547 TEST_DESC("Per-scheme proxy rules"), | 559 TEST_DESC("Per-scheme proxy rules"), |
| 548 { // Input. | 560 { // Input. |
| 549 "manual", // mode | 561 "manual", // mode |
| 550 "", // autoconfig_url | 562 "", // autoconfig_url |
| 551 "www.google.com", // http_host | 563 "www.google.com", // http_host |
| 552 "www.foo.com", // secure_host | 564 "www.foo.com", // secure_host |
| 553 "ftp.foo.com", // ftp | 565 "ftp.foo.com", // ftp |
| 554 "", // socks | 566 "", // socks |
| 555 88, 110, 121, 0, // ports | 567 88, 110, 121, 0, // ports |
| 556 TRUE, FALSE, FALSE, // use, same, auth | 568 TRUE, FALSE, FALSE, // use, same, auth |
| 557 empty_ignores, // ignore_hosts | 569 empty_ignores, // ignore_hosts |
| 558 }, | 570 }, |
| 559 | 571 |
| 560 // Expected result. | 572 // Expected result. |
| 573 ProxyConfigService::CONFIG_VALID, |
| 561 false, // auto_detect | 574 false, // auto_detect |
| 562 GURL(), // pac_url | 575 GURL(), // pac_url |
| 563 ProxyRulesExpectation::PerScheme( | 576 ProxyRulesExpectation::PerScheme( |
| 564 "www.google.com:88", // http | 577 "www.google.com:88", // http |
| 565 "www.foo.com:110", // https | 578 "www.foo.com:110", // https |
| 566 "ftp.foo.com:121", // ftp | 579 "ftp.foo.com:121", // ftp |
| 567 ""), // bypass rules | 580 ""), // bypass rules |
| 568 }, | 581 }, |
| 569 | 582 |
| 570 { | 583 { |
| 571 TEST_DESC("socks"), | 584 TEST_DESC("socks"), |
| 572 { // Input. | 585 { // Input. |
| 573 "manual", // mode | 586 "manual", // mode |
| 574 "", // autoconfig_url | 587 "", // autoconfig_url |
| 575 "", "", "", "socks.com", // hosts | 588 "", "", "", "socks.com", // hosts |
| 576 0, 0, 0, 99, // ports | 589 0, 0, 0, 99, // ports |
| 577 TRUE, FALSE, FALSE, // use, same, auth | 590 TRUE, FALSE, FALSE, // use, same, auth |
| 578 empty_ignores, // ignore_hosts | 591 empty_ignores, // ignore_hosts |
| 579 }, | 592 }, |
| 580 | 593 |
| 581 // Expected result. | 594 // Expected result. |
| 595 ProxyConfigService::CONFIG_VALID, |
| 582 false, // auto_detect | 596 false, // auto_detect |
| 583 GURL(), // pac_url | 597 GURL(), // pac_url |
| 584 ProxyRulesExpectation::Single( | 598 ProxyRulesExpectation::Single( |
| 585 "socks5://socks.com:99", // single proxy | 599 "socks5://socks.com:99", // single proxy |
| 586 "") // bypass rules | 600 "") // bypass rules |
| 587 }, | 601 }, |
| 588 | 602 |
| 589 { | 603 { |
| 590 TEST_DESC("Bypass *.google.com"), | 604 TEST_DESC("Bypass *.google.com"), |
| 591 { // Input. | 605 { // Input. |
| 592 "manual", // mode | 606 "manual", // mode |
| 593 "", // autoconfig_url | 607 "", // autoconfig_url |
| 594 "www.google.com", "", "", "", // hosts | 608 "www.google.com", "", "", "", // hosts |
| 595 80, 0, 0, 0, // ports | 609 80, 0, 0, 0, // ports |
| 596 TRUE, TRUE, FALSE, // use, same, auth | 610 TRUE, TRUE, FALSE, // use, same, auth |
| 597 google_ignores, // ignore_hosts | 611 google_ignores, // ignore_hosts |
| 598 }, | 612 }, |
| 599 | 613 |
| 614 ProxyConfigService::CONFIG_VALID, |
| 600 false, // auto_detect | 615 false, // auto_detect |
| 601 GURL(), // pac_url | 616 GURL(), // pac_url |
| 602 ProxyRulesExpectation::Single( | 617 ProxyRulesExpectation::Single( |
| 603 "www.google.com:80", // single proxy | 618 "www.google.com:80", // single proxy |
| 604 "*.google.com"), // bypass rules | 619 "*.google.com"), // bypass rules |
| 605 }, | 620 }, |
| 606 }; | 621 }; |
| 607 | 622 |
| 608 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 623 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 609 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, | 624 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, |
| 610 tests[i].description.c_str())); | 625 tests[i].description.c_str())); |
| 611 MockEnvironment* env = new MockEnvironment; | 626 MockEnvironment* env = new MockEnvironment; |
| 612 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | 627 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 613 SynchConfigGetter sync_config_getter( | 628 SynchConfigGetter sync_config_getter( |
| 614 new ProxyConfigServiceLinux(env, gconf_getter)); | 629 new ProxyConfigServiceLinux(env, gconf_getter)); |
| 615 ProxyConfig config; | 630 ProxyConfig config; |
| 616 gconf_getter->values = tests[i].values; | 631 gconf_getter->values = tests[i].values; |
| 617 sync_config_getter.SetupAndInitialFetch(); | 632 sync_config_getter.SetupAndInitialFetch(); |
| 618 sync_config_getter.SyncGetLatestProxyConfig(&config); | 633 ProxyConfigService::ConfigAvailability availability = |
| 634 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 635 EXPECT_EQ(tests[i].availability, availability); |
| 619 | 636 |
| 620 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 637 if (availability == ProxyConfigService::CONFIG_VALID) { |
| 621 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 638 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
| 622 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 639 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
| 640 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
| 641 } |
| 623 } | 642 } |
| 624 } | 643 } |
| 625 | 644 |
| 626 TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) { | 645 TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) { |
| 627 // Inspired from proxy_config_service_win_unittest.cc. | 646 // Inspired from proxy_config_service_win_unittest.cc. |
| 628 const struct { | 647 const struct { |
| 629 // Short description to identify the test | 648 // Short description to identify the test |
| 630 std::string description; | 649 std::string description; |
| 631 | 650 |
| 632 // Input. | 651 // Input. |
| 633 EnvVarValues values; | 652 EnvVarValues values; |
| 634 | 653 |
| 635 // Expected outputs (fields of the ProxyConfig). | 654 // Expected outputs (availability and fields of ProxyConfig). |
| 655 ProxyConfigService::ConfigAvailability availability; |
| 636 bool auto_detect; | 656 bool auto_detect; |
| 637 GURL pac_url; | 657 GURL pac_url; |
| 638 ProxyRulesExpectation proxy_rules; | 658 ProxyRulesExpectation proxy_rules; |
| 639 } tests[] = { | 659 } tests[] = { |
| 640 { | 660 { |
| 641 TEST_DESC("No proxying"), | 661 TEST_DESC("No proxying"), |
| 642 { // Input. | 662 { // Input. |
| 643 NULL, // DESKTOP_SESSION | 663 NULL, // DESKTOP_SESSION |
| 644 NULL, // HOME | 664 NULL, // HOME |
| 645 NULL, // KDEHOME | 665 NULL, // KDEHOME |
| 646 NULL, // KDE_SESSION_VERSION | 666 NULL, // KDE_SESSION_VERSION |
| 647 NULL, // auto_proxy | 667 NULL, // auto_proxy |
| 648 NULL, // all_proxy | 668 NULL, // all_proxy |
| 649 NULL, NULL, NULL, // per-proto proxies | 669 NULL, NULL, NULL, // per-proto proxies |
| 650 NULL, NULL, // SOCKS | 670 NULL, NULL, // SOCKS |
| 651 "*", // no_proxy | 671 "*", // no_proxy |
| 652 }, | 672 }, |
| 653 | 673 |
| 654 // Expected result. | 674 // Expected result. |
| 675 ProxyConfigService::CONFIG_VALID, |
| 655 false, // auto_detect | 676 false, // auto_detect |
| 656 GURL(), // pac_url | 677 GURL(), // pac_url |
| 657 ProxyRulesExpectation::Empty(), | 678 ProxyRulesExpectation::Empty(), |
| 658 }, | 679 }, |
| 659 | 680 |
| 660 { | 681 { |
| 661 TEST_DESC("Auto detect"), | 682 TEST_DESC("Auto detect"), |
| 662 { // Input. | 683 { // Input. |
| 663 NULL, // DESKTOP_SESSION | 684 NULL, // DESKTOP_SESSION |
| 664 NULL, // HOME | 685 NULL, // HOME |
| 665 NULL, // KDEHOME | 686 NULL, // KDEHOME |
| 666 NULL, // KDE_SESSION_VERSION | 687 NULL, // KDE_SESSION_VERSION |
| 667 "", // auto_proxy | 688 "", // auto_proxy |
| 668 NULL, // all_proxy | 689 NULL, // all_proxy |
| 669 NULL, NULL, NULL, // per-proto proxies | 690 NULL, NULL, NULL, // per-proto proxies |
| 670 NULL, NULL, // SOCKS | 691 NULL, NULL, // SOCKS |
| 671 NULL, // no_proxy | 692 NULL, // no_proxy |
| 672 }, | 693 }, |
| 673 | 694 |
| 674 // Expected result. | 695 // Expected result. |
| 696 ProxyConfigService::CONFIG_VALID, |
| 675 true, // auto_detect | 697 true, // auto_detect |
| 676 GURL(), // pac_url | 698 GURL(), // pac_url |
| 677 ProxyRulesExpectation::Empty(), | 699 ProxyRulesExpectation::Empty(), |
| 678 }, | 700 }, |
| 679 | 701 |
| 680 { | 702 { |
| 681 TEST_DESC("Valid PAC URL"), | 703 TEST_DESC("Valid PAC URL"), |
| 682 { // Input. | 704 { // Input. |
| 683 NULL, // DESKTOP_SESSION | 705 NULL, // DESKTOP_SESSION |
| 684 NULL, // HOME | 706 NULL, // HOME |
| 685 NULL, // KDEHOME | 707 NULL, // KDEHOME |
| 686 NULL, // KDE_SESSION_VERSION | 708 NULL, // KDE_SESSION_VERSION |
| 687 "http://wpad/wpad.dat", // auto_proxy | 709 "http://wpad/wpad.dat", // auto_proxy |
| 688 NULL, // all_proxy | 710 NULL, // all_proxy |
| 689 NULL, NULL, NULL, // per-proto proxies | 711 NULL, NULL, NULL, // per-proto proxies |
| 690 NULL, NULL, // SOCKS | 712 NULL, NULL, // SOCKS |
| 691 NULL, // no_proxy | 713 NULL, // no_proxy |
| 692 }, | 714 }, |
| 693 | 715 |
| 694 // Expected result. | 716 // Expected result. |
| 717 ProxyConfigService::CONFIG_VALID, |
| 695 false, // auto_detect | 718 false, // auto_detect |
| 696 GURL("http://wpad/wpad.dat"), // pac_url | 719 GURL("http://wpad/wpad.dat"), // pac_url |
| 697 ProxyRulesExpectation::Empty(), | 720 ProxyRulesExpectation::Empty(), |
| 698 }, | 721 }, |
| 699 | 722 |
| 700 { | 723 { |
| 701 TEST_DESC("Invalid PAC URL"), | 724 TEST_DESC("Invalid PAC URL"), |
| 702 { // Input. | 725 { // Input. |
| 703 NULL, // DESKTOP_SESSION | 726 NULL, // DESKTOP_SESSION |
| 704 NULL, // HOME | 727 NULL, // HOME |
| 705 NULL, // KDEHOME | 728 NULL, // KDEHOME |
| 706 NULL, // KDE_SESSION_VERSION | 729 NULL, // KDE_SESSION_VERSION |
| 707 "wpad.dat", // auto_proxy | 730 "wpad.dat", // auto_proxy |
| 708 NULL, // all_proxy | 731 NULL, // all_proxy |
| 709 NULL, NULL, NULL, // per-proto proxies | 732 NULL, NULL, NULL, // per-proto proxies |
| 710 NULL, NULL, // SOCKS | 733 NULL, NULL, // SOCKS |
| 711 NULL, // no_proxy | 734 NULL, // no_proxy |
| 712 }, | 735 }, |
| 713 | 736 |
| 714 // Expected result. | 737 // Expected result. |
| 738 ProxyConfigService::CONFIG_VALID, |
| 715 false, // auto_detect | 739 false, // auto_detect |
| 716 GURL(), // pac_url | 740 GURL(), // pac_url |
| 717 ProxyRulesExpectation::Empty(), | 741 ProxyRulesExpectation::Empty(), |
| 718 }, | 742 }, |
| 719 | 743 |
| 720 { | 744 { |
| 721 TEST_DESC("Single-host in proxy list"), | 745 TEST_DESC("Single-host in proxy list"), |
| 722 { // Input. | 746 { // Input. |
| 723 NULL, // DESKTOP_SESSION | 747 NULL, // DESKTOP_SESSION |
| 724 NULL, // HOME | 748 NULL, // HOME |
| 725 NULL, // KDEHOME | 749 NULL, // KDEHOME |
| 726 NULL, // KDE_SESSION_VERSION | 750 NULL, // KDE_SESSION_VERSION |
| 727 NULL, // auto_proxy | 751 NULL, // auto_proxy |
| 728 "www.google.com", // all_proxy | 752 "www.google.com", // all_proxy |
| 729 NULL, NULL, NULL, // per-proto proxies | 753 NULL, NULL, NULL, // per-proto proxies |
| 730 NULL, NULL, // SOCKS | 754 NULL, NULL, // SOCKS |
| 731 NULL, // no_proxy | 755 NULL, // no_proxy |
| 732 }, | 756 }, |
| 733 | 757 |
| 734 // Expected result. | 758 // Expected result. |
| 759 ProxyConfigService::CONFIG_VALID, |
| 735 false, // auto_detect | 760 false, // auto_detect |
| 736 GURL(), // pac_url | 761 GURL(), // pac_url |
| 737 ProxyRulesExpectation::Single( | 762 ProxyRulesExpectation::Single( |
| 738 "www.google.com:80", // single proxy | 763 "www.google.com:80", // single proxy |
| 739 ""), // bypass rules | 764 ""), // bypass rules |
| 740 }, | 765 }, |
| 741 | 766 |
| 742 { | 767 { |
| 743 TEST_DESC("Single-host, different port"), | 768 TEST_DESC("Single-host, different port"), |
| 744 { // Input. | 769 { // Input. |
| 745 NULL, // DESKTOP_SESSION | 770 NULL, // DESKTOP_SESSION |
| 746 NULL, // HOME | 771 NULL, // HOME |
| 747 NULL, // KDEHOME | 772 NULL, // KDEHOME |
| 748 NULL, // KDE_SESSION_VERSION | 773 NULL, // KDE_SESSION_VERSION |
| 749 NULL, // auto_proxy | 774 NULL, // auto_proxy |
| 750 "www.google.com:99", // all_proxy | 775 "www.google.com:99", // all_proxy |
| 751 NULL, NULL, NULL, // per-proto proxies | 776 NULL, NULL, NULL, // per-proto proxies |
| 752 NULL, NULL, // SOCKS | 777 NULL, NULL, // SOCKS |
| 753 NULL, // no_proxy | 778 NULL, // no_proxy |
| 754 }, | 779 }, |
| 755 | 780 |
| 756 // Expected result. | 781 // Expected result. |
| 782 ProxyConfigService::CONFIG_VALID, |
| 757 false, // auto_detect | 783 false, // auto_detect |
| 758 GURL(), // pac_url | 784 GURL(), // pac_url |
| 759 ProxyRulesExpectation::Single( | 785 ProxyRulesExpectation::Single( |
| 760 "www.google.com:99", // single | 786 "www.google.com:99", // single |
| 761 ""), // bypass rules | 787 ""), // bypass rules |
| 762 }, | 788 }, |
| 763 | 789 |
| 764 { | 790 { |
| 765 TEST_DESC("Tolerate a scheme"), | 791 TEST_DESC("Tolerate a scheme"), |
| 766 { // Input. | 792 { // Input. |
| 767 NULL, // DESKTOP_SESSION | 793 NULL, // DESKTOP_SESSION |
| 768 NULL, // HOME | 794 NULL, // HOME |
| 769 NULL, // KDEHOME | 795 NULL, // KDEHOME |
| 770 NULL, // KDE_SESSION_VERSION | 796 NULL, // KDE_SESSION_VERSION |
| 771 NULL, // auto_proxy | 797 NULL, // auto_proxy |
| 772 "http://www.google.com:99", // all_proxy | 798 "http://www.google.com:99", // all_proxy |
| 773 NULL, NULL, NULL, // per-proto proxies | 799 NULL, NULL, NULL, // per-proto proxies |
| 774 NULL, NULL, // SOCKS | 800 NULL, NULL, // SOCKS |
| 775 NULL, // no_proxy | 801 NULL, // no_proxy |
| 776 }, | 802 }, |
| 777 | 803 |
| 778 // Expected result. | 804 // Expected result. |
| 805 ProxyConfigService::CONFIG_VALID, |
| 779 false, // auto_detect | 806 false, // auto_detect |
| 780 GURL(), // pac_url | 807 GURL(), // pac_url |
| 781 ProxyRulesExpectation::Single( | 808 ProxyRulesExpectation::Single( |
| 782 "www.google.com:99", // single proxy | 809 "www.google.com:99", // single proxy |
| 783 ""), // bypass rules | 810 ""), // bypass rules |
| 784 }, | 811 }, |
| 785 | 812 |
| 786 { | 813 { |
| 787 TEST_DESC("Per-scheme proxy rules"), | 814 TEST_DESC("Per-scheme proxy rules"), |
| 788 { // Input. | 815 { // Input. |
| 789 NULL, // DESKTOP_SESSION | 816 NULL, // DESKTOP_SESSION |
| 790 NULL, // HOME | 817 NULL, // HOME |
| 791 NULL, // KDEHOME | 818 NULL, // KDEHOME |
| 792 NULL, // KDE_SESSION_VERSION | 819 NULL, // KDE_SESSION_VERSION |
| 793 NULL, // auto_proxy | 820 NULL, // auto_proxy |
| 794 NULL, // all_proxy | 821 NULL, // all_proxy |
| 795 "www.google.com:80", "www.foo.com:110", "ftp.foo.com:121", // per-proto | 822 "www.google.com:80", "www.foo.com:110", "ftp.foo.com:121", // per-proto |
| 796 NULL, NULL, // SOCKS | 823 NULL, NULL, // SOCKS |
| 797 NULL, // no_proxy | 824 NULL, // no_proxy |
| 798 }, | 825 }, |
| 799 | 826 |
| 800 // Expected result. | 827 // Expected result. |
| 828 ProxyConfigService::CONFIG_VALID, |
| 801 false, // auto_detect | 829 false, // auto_detect |
| 802 GURL(), // pac_url | 830 GURL(), // pac_url |
| 803 ProxyRulesExpectation::PerScheme( | 831 ProxyRulesExpectation::PerScheme( |
| 804 "www.google.com:80", // http | 832 "www.google.com:80", // http |
| 805 "www.foo.com:110", // https | 833 "www.foo.com:110", // https |
| 806 "ftp.foo.com:121", // ftp | 834 "ftp.foo.com:121", // ftp |
| 807 ""), // bypass rules | 835 ""), // bypass rules |
| 808 }, | 836 }, |
| 809 | 837 |
| 810 { | 838 { |
| 811 TEST_DESC("socks"), | 839 TEST_DESC("socks"), |
| 812 { // Input. | 840 { // Input. |
| 813 NULL, // DESKTOP_SESSION | 841 NULL, // DESKTOP_SESSION |
| 814 NULL, // HOME | 842 NULL, // HOME |
| 815 NULL, // KDEHOME | 843 NULL, // KDEHOME |
| 816 NULL, // KDE_SESSION_VERSION | 844 NULL, // KDE_SESSION_VERSION |
| 817 NULL, // auto_proxy | 845 NULL, // auto_proxy |
| 818 "", // all_proxy | 846 "", // all_proxy |
| 819 NULL, NULL, NULL, // per-proto proxies | 847 NULL, NULL, NULL, // per-proto proxies |
| 820 "socks.com:888", NULL, // SOCKS | 848 "socks.com:888", NULL, // SOCKS |
| 821 NULL, // no_proxy | 849 NULL, // no_proxy |
| 822 }, | 850 }, |
| 823 | 851 |
| 824 // Expected result. | 852 // Expected result. |
| 853 ProxyConfigService::CONFIG_VALID, |
| 825 false, // auto_detect | 854 false, // auto_detect |
| 826 GURL(), // pac_url | 855 GURL(), // pac_url |
| 827 ProxyRulesExpectation::Single( | 856 ProxyRulesExpectation::Single( |
| 828 "socks5://socks.com:888", // single proxy | 857 "socks5://socks.com:888", // single proxy |
| 829 ""), // bypass rules | 858 ""), // bypass rules |
| 830 }, | 859 }, |
| 831 | 860 |
| 832 { | 861 { |
| 833 TEST_DESC("socks4"), | 862 TEST_DESC("socks4"), |
| 834 { // Input. | 863 { // Input. |
| 835 NULL, // DESKTOP_SESSION | 864 NULL, // DESKTOP_SESSION |
| 836 NULL, // HOME | 865 NULL, // HOME |
| 837 NULL, // KDEHOME | 866 NULL, // KDEHOME |
| 838 NULL, // KDE_SESSION_VERSION | 867 NULL, // KDE_SESSION_VERSION |
| 839 NULL, // auto_proxy | 868 NULL, // auto_proxy |
| 840 "", // all_proxy | 869 "", // all_proxy |
| 841 NULL, NULL, NULL, // per-proto proxies | 870 NULL, NULL, NULL, // per-proto proxies |
| 842 "socks.com:888", "4", // SOCKS | 871 "socks.com:888", "4", // SOCKS |
| 843 NULL, // no_proxy | 872 NULL, // no_proxy |
| 844 }, | 873 }, |
| 845 | 874 |
| 846 // Expected result. | 875 // Expected result. |
| 876 ProxyConfigService::CONFIG_VALID, |
| 847 false, // auto_detect | 877 false, // auto_detect |
| 848 GURL(), // pac_url | 878 GURL(), // pac_url |
| 849 ProxyRulesExpectation::Single( | 879 ProxyRulesExpectation::Single( |
| 850 "socks4://socks.com:888", // single proxy | 880 "socks4://socks.com:888", // single proxy |
| 851 ""), // bypass rules | 881 ""), // bypass rules |
| 852 }, | 882 }, |
| 853 | 883 |
| 854 { | 884 { |
| 855 TEST_DESC("socks default port"), | 885 TEST_DESC("socks default port"), |
| 856 { // Input. | 886 { // Input. |
| 857 NULL, // DESKTOP_SESSION | 887 NULL, // DESKTOP_SESSION |
| 858 NULL, // HOME | 888 NULL, // HOME |
| 859 NULL, // KDEHOME | 889 NULL, // KDEHOME |
| 860 NULL, // KDE_SESSION_VERSION | 890 NULL, // KDE_SESSION_VERSION |
| 861 NULL, // auto_proxy | 891 NULL, // auto_proxy |
| 862 "", // all_proxy | 892 "", // all_proxy |
| 863 NULL, NULL, NULL, // per-proto proxies | 893 NULL, NULL, NULL, // per-proto proxies |
| 864 "socks.com", NULL, // SOCKS | 894 "socks.com", NULL, // SOCKS |
| 865 NULL, // no_proxy | 895 NULL, // no_proxy |
| 866 }, | 896 }, |
| 867 | 897 |
| 868 // Expected result. | 898 // Expected result. |
| 899 ProxyConfigService::CONFIG_VALID, |
| 869 false, // auto_detect | 900 false, // auto_detect |
| 870 GURL(), // pac_url | 901 GURL(), // pac_url |
| 871 ProxyRulesExpectation::Single( | 902 ProxyRulesExpectation::Single( |
| 872 "socks5://socks.com:1080", // single proxy | 903 "socks5://socks.com:1080", // single proxy |
| 873 ""), // bypass rules | 904 ""), // bypass rules |
| 874 }, | 905 }, |
| 875 | 906 |
| 876 { | 907 { |
| 877 TEST_DESC("bypass"), | 908 TEST_DESC("bypass"), |
| 878 { // Input. | 909 { // Input. |
| 879 NULL, // DESKTOP_SESSION | 910 NULL, // DESKTOP_SESSION |
| 880 NULL, // HOME | 911 NULL, // HOME |
| 881 NULL, // KDEHOME | 912 NULL, // KDEHOME |
| 882 NULL, // KDE_SESSION_VERSION | 913 NULL, // KDE_SESSION_VERSION |
| 883 NULL, // auto_proxy | 914 NULL, // auto_proxy |
| 884 "www.google.com", // all_proxy | 915 "www.google.com", // all_proxy |
| 885 NULL, NULL, NULL, // per-proto | 916 NULL, NULL, NULL, // per-proto |
| 886 NULL, NULL, // SOCKS | 917 NULL, NULL, // SOCKS |
| 887 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy | 918 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy |
| 888 }, | 919 }, |
| 889 | 920 |
| 921 // Expected result. |
| 922 ProxyConfigService::CONFIG_VALID, |
| 890 false, // auto_detect | 923 false, // auto_detect |
| 891 GURL(), // pac_url | 924 GURL(), // pac_url |
| 892 ProxyRulesExpectation::Single( | 925 ProxyRulesExpectation::Single( |
| 893 "www.google.com:80", | 926 "www.google.com:80", |
| 894 "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"), | 927 "*.google.com,*foo.com:99,1.2.3.4:22,127.0.0.1/8"), |
| 895 }, | 928 }, |
| 896 }; | 929 }; |
| 897 | 930 |
| 898 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 931 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 899 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, | 932 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, |
| 900 tests[i].description.c_str())); | 933 tests[i].description.c_str())); |
| 901 MockEnvironment* env = new MockEnvironment; | 934 MockEnvironment* env = new MockEnvironment; |
| 902 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | 935 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 903 SynchConfigGetter sync_config_getter( | 936 SynchConfigGetter sync_config_getter( |
| 904 new ProxyConfigServiceLinux(env, gconf_getter)); | 937 new ProxyConfigServiceLinux(env, gconf_getter)); |
| 905 ProxyConfig config; | 938 ProxyConfig config; |
| 906 env->values = tests[i].values; | 939 env->values = tests[i].values; |
| 907 sync_config_getter.SetupAndInitialFetch(); | 940 sync_config_getter.SetupAndInitialFetch(); |
| 908 sync_config_getter.SyncGetLatestProxyConfig(&config); | 941 ProxyConfigService::ConfigAvailability availability = |
| 942 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 943 EXPECT_EQ(tests[i].availability, availability); |
| 909 | 944 |
| 910 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 945 if (availability == ProxyConfigService::CONFIG_VALID) { |
| 911 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 946 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
| 912 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 947 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
| 948 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
| 949 } |
| 913 } | 950 } |
| 914 } | 951 } |
| 915 | 952 |
| 916 TEST_F(ProxyConfigServiceLinuxTest, GconfNotification) { | 953 TEST_F(ProxyConfigServiceLinuxTest, GconfNotification) { |
| 917 MockEnvironment* env = new MockEnvironment; | 954 MockEnvironment* env = new MockEnvironment; |
| 918 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; | 955 MockGConfSettingGetter* gconf_getter = new MockGConfSettingGetter; |
| 919 ProxyConfigServiceLinux* service = | 956 ProxyConfigServiceLinux* service = |
| 920 new ProxyConfigServiceLinux(env, gconf_getter); | 957 new ProxyConfigServiceLinux(env, gconf_getter); |
| 921 SynchConfigGetter sync_config_getter(service); | 958 SynchConfigGetter sync_config_getter(service); |
| 922 ProxyConfig config; | 959 ProxyConfig config; |
| 923 | 960 |
| 924 // Start with no proxy. | 961 // Start with no proxy. |
| 925 gconf_getter->values.mode = "none"; | 962 gconf_getter->values.mode = "none"; |
| 926 sync_config_getter.SetupAndInitialFetch(); | 963 sync_config_getter.SetupAndInitialFetch(); |
| 927 sync_config_getter.SyncGetLatestProxyConfig(&config); | 964 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 965 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 928 EXPECT_FALSE(config.auto_detect()); | 966 EXPECT_FALSE(config.auto_detect()); |
| 929 | 967 |
| 930 // Now set to auto-detect. | 968 // Now set to auto-detect. |
| 931 gconf_getter->values.mode = "auto"; | 969 gconf_getter->values.mode = "auto"; |
| 932 // Simulate gconf notification callback. | 970 // Simulate gconf notification callback. |
| 933 service->OnCheckProxyConfigSettings(); | 971 service->OnCheckProxyConfigSettings(); |
| 934 sync_config_getter.SyncGetLatestProxyConfig(&config); | 972 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 973 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 935 EXPECT_TRUE(config.auto_detect()); | 974 EXPECT_TRUE(config.auto_detect()); |
| 936 } | 975 } |
| 937 | 976 |
| 938 TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { | 977 TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) { |
| 939 // One of the tests below needs a worst-case long line prefix. We build it | 978 // One of the tests below needs a worst-case long line prefix. We build it |
| 940 // programmatically so that it will always be the right size. | 979 // programmatically so that it will always be the right size. |
| 941 std::string long_line; | 980 std::string long_line; |
| 942 size_t limit = ProxyConfigServiceLinux::GConfSettingGetter::BUFFER_SIZE - 1; | 981 size_t limit = ProxyConfigServiceLinux::GConfSettingGetter::BUFFER_SIZE - 1; |
| 943 for (size_t i = 0; i < limit; ++i) | 982 for (size_t i = 0; i < limit; ++i) |
| 944 long_line += "-"; | 983 long_line += "-"; |
| 945 | 984 |
| 946 // Inspired from proxy_config_service_win_unittest.cc. | 985 // Inspired from proxy_config_service_win_unittest.cc. |
| 947 const struct { | 986 const struct { |
| 948 // Short description to identify the test | 987 // Short description to identify the test |
| 949 std::string description; | 988 std::string description; |
| 950 | 989 |
| 951 // Input. | 990 // Input. |
| 952 std::string kioslaverc; | 991 std::string kioslaverc; |
| 953 EnvVarValues env_values; | 992 EnvVarValues env_values; |
| 954 | 993 |
| 955 // Expected outputs (fields of the ProxyConfig). | 994 // Expected outputs (availability and fields of ProxyConfig). |
| 995 ProxyConfigService::ConfigAvailability availability; |
| 956 bool auto_detect; | 996 bool auto_detect; |
| 957 GURL pac_url; | 997 GURL pac_url; |
| 958 ProxyRulesExpectation proxy_rules; | 998 ProxyRulesExpectation proxy_rules; |
| 959 } tests[] = { | 999 } tests[] = { |
| 960 { | 1000 { |
| 961 TEST_DESC("No proxying"), | 1001 TEST_DESC("No proxying"), |
| 962 | 1002 |
| 963 // Input. | 1003 // Input. |
| 964 "[Proxy Settings]\nProxyType=0\n", | 1004 "[Proxy Settings]\nProxyType=0\n", |
| 965 {}, // env_values | 1005 {}, // env_values |
| 966 | 1006 |
| 967 // Expected result. | 1007 // Expected result. |
| 1008 ProxyConfigService::CONFIG_VALID, |
| 968 false, // auto_detect | 1009 false, // auto_detect |
| 969 GURL(), // pac_url | 1010 GURL(), // pac_url |
| 970 ProxyRulesExpectation::Empty(), | 1011 ProxyRulesExpectation::Empty(), |
| 971 }, | 1012 }, |
| 972 | 1013 |
| 973 { | 1014 { |
| 974 TEST_DESC("Auto detect"), | 1015 TEST_DESC("Auto detect"), |
| 975 | 1016 |
| 976 // Input. | 1017 // Input. |
| 977 "[Proxy Settings]\nProxyType=3\n", | 1018 "[Proxy Settings]\nProxyType=3\n", |
| 978 {}, // env_values | 1019 {}, // env_values |
| 979 | 1020 |
| 980 // Expected result. | 1021 // Expected result. |
| 1022 ProxyConfigService::CONFIG_VALID, |
| 981 true, // auto_detect | 1023 true, // auto_detect |
| 982 GURL(), // pac_url | 1024 GURL(), // pac_url |
| 983 ProxyRulesExpectation::Empty(), | 1025 ProxyRulesExpectation::Empty(), |
| 984 }, | 1026 }, |
| 985 | 1027 |
| 986 { | 1028 { |
| 987 TEST_DESC("Valid PAC URL"), | 1029 TEST_DESC("Valid PAC URL"), |
| 988 | 1030 |
| 989 // Input. | 1031 // Input. |
| 990 "[Proxy Settings]\nProxyType=2\n" | 1032 "[Proxy Settings]\nProxyType=2\n" |
| 991 "Proxy Config Script=http://wpad/wpad.dat\n", | 1033 "Proxy Config Script=http://wpad/wpad.dat\n", |
| 992 {}, // env_values | 1034 {}, // env_values |
| 993 | 1035 |
| 994 // Expected result. | 1036 // Expected result. |
| 1037 ProxyConfigService::CONFIG_VALID, |
| 995 false, // auto_detect | 1038 false, // auto_detect |
| 996 GURL("http://wpad/wpad.dat"), // pac_url | 1039 GURL("http://wpad/wpad.dat"), // pac_url |
| 997 ProxyRulesExpectation::Empty(), | 1040 ProxyRulesExpectation::Empty(), |
| 998 }, | 1041 }, |
| 999 | 1042 |
| 1000 { | 1043 { |
| 1001 TEST_DESC("Per-scheme proxy rules"), | 1044 TEST_DESC("Per-scheme proxy rules"), |
| 1002 | 1045 |
| 1003 // Input. | 1046 // Input. |
| 1004 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1047 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1005 "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n", | 1048 "httpsProxy=www.foo.com\nftpProxy=ftp.foo.com\n", |
| 1006 {}, // env_values | 1049 {}, // env_values |
| 1007 | 1050 |
| 1008 // Expected result. | 1051 // Expected result. |
| 1052 ProxyConfigService::CONFIG_VALID, |
| 1009 false, // auto_detect | 1053 false, // auto_detect |
| 1010 GURL(), // pac_url | 1054 GURL(), // pac_url |
| 1011 ProxyRulesExpectation::PerScheme( | 1055 ProxyRulesExpectation::PerScheme( |
| 1012 "www.google.com:80", // http | 1056 "www.google.com:80", // http |
| 1013 "www.foo.com:80", // https | 1057 "www.foo.com:80", // https |
| 1014 "ftp.foo.com:80", // http | 1058 "ftp.foo.com:80", // http |
| 1015 ""), // bypass rules | 1059 ""), // bypass rules |
| 1016 }, | 1060 }, |
| 1017 | 1061 |
| 1018 { | 1062 { |
| 1019 TEST_DESC("Only HTTP proxy specified"), | 1063 TEST_DESC("Only HTTP proxy specified"), |
| 1020 | 1064 |
| 1021 // Input. | 1065 // Input. |
| 1022 "[Proxy Settings]\nProxyType=1\n" | 1066 "[Proxy Settings]\nProxyType=1\n" |
| 1023 "httpProxy=www.google.com\n", | 1067 "httpProxy=www.google.com\n", |
| 1024 {}, // env_values | 1068 {}, // env_values |
| 1025 | 1069 |
| 1026 // Expected result. | 1070 // Expected result. |
| 1071 ProxyConfigService::CONFIG_VALID, |
| 1027 false, // auto_detect | 1072 false, // auto_detect |
| 1028 GURL(), // pac_url | 1073 GURL(), // pac_url |
| 1029 ProxyRulesExpectation::PerScheme( | 1074 ProxyRulesExpectation::PerScheme( |
| 1030 "www.google.com:80", // http | 1075 "www.google.com:80", // http |
| 1031 "", // https | 1076 "", // https |
| 1032 "", // ftp | 1077 "", // ftp |
| 1033 ""), // bypass rules | 1078 ""), // bypass rules |
| 1034 }, | 1079 }, |
| 1035 | 1080 |
| 1036 { | 1081 { |
| 1037 TEST_DESC("Only HTTP proxy specified, different port"), | 1082 TEST_DESC("Only HTTP proxy specified, different port"), |
| 1038 | 1083 |
| 1039 // Input. | 1084 // Input. |
| 1040 "[Proxy Settings]\nProxyType=1\n" | 1085 "[Proxy Settings]\nProxyType=1\n" |
| 1041 "httpProxy=www.google.com:88\n", | 1086 "httpProxy=www.google.com:88\n", |
| 1042 {}, // env_values | 1087 {}, // env_values |
| 1043 | 1088 |
| 1044 // Expected result. | 1089 // Expected result. |
| 1090 ProxyConfigService::CONFIG_VALID, |
| 1045 false, // auto_detect | 1091 false, // auto_detect |
| 1046 GURL(), // pac_url | 1092 GURL(), // pac_url |
| 1047 ProxyRulesExpectation::PerScheme( | 1093 ProxyRulesExpectation::PerScheme( |
| 1048 "www.google.com:88", // http | 1094 "www.google.com:88", // http |
| 1049 "", // https | 1095 "", // https |
| 1050 "", // ftp | 1096 "", // ftp |
| 1051 ""), // bypass rules | 1097 ""), // bypass rules |
| 1052 }, | 1098 }, |
| 1053 | 1099 |
| 1054 { | 1100 { |
| 1055 TEST_DESC("Bypass *.google.com"), | 1101 TEST_DESC("Bypass *.google.com"), |
| 1056 | 1102 |
| 1057 // Input. | 1103 // Input. |
| 1058 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1104 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1059 "NoProxyFor=.google.com\n", | 1105 "NoProxyFor=.google.com\n", |
| 1060 {}, // env_values | 1106 {}, // env_values |
| 1061 | 1107 |
| 1108 // Expected result. |
| 1109 ProxyConfigService::CONFIG_VALID, |
| 1062 false, // auto_detect | 1110 false, // auto_detect |
| 1063 GURL(), // pac_url | 1111 GURL(), // pac_url |
| 1064 ProxyRulesExpectation::PerScheme( | 1112 ProxyRulesExpectation::PerScheme( |
| 1065 "www.google.com:80", // http | 1113 "www.google.com:80", // http |
| 1066 "", // https | 1114 "", // https |
| 1067 "", // ftp | 1115 "", // ftp |
| 1068 "*.google.com"), // bypass rules | 1116 "*.google.com"), // bypass rules |
| 1069 }, | 1117 }, |
| 1070 | 1118 |
| 1071 { | 1119 { |
| 1072 TEST_DESC("Bypass *.google.com and *.kde.org"), | 1120 TEST_DESC("Bypass *.google.com and *.kde.org"), |
| 1073 | 1121 |
| 1074 // Input. | 1122 // Input. |
| 1075 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1123 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1076 "NoProxyFor=.google.com,.kde.org\n", | 1124 "NoProxyFor=.google.com,.kde.org\n", |
| 1077 {}, // env_values | 1125 {}, // env_values |
| 1078 | 1126 |
| 1127 // Expected result. |
| 1128 ProxyConfigService::CONFIG_VALID, |
| 1079 false, // auto_detect | 1129 false, // auto_detect |
| 1080 GURL(), // pac_url | 1130 GURL(), // pac_url |
| 1081 ProxyRulesExpectation::PerScheme( | 1131 ProxyRulesExpectation::PerScheme( |
| 1082 "www.google.com:80", // http | 1132 "www.google.com:80", // http |
| 1083 "", // https | 1133 "", // https |
| 1084 "", // ftp | 1134 "", // ftp |
| 1085 "*.google.com,*.kde.org"), // bypass rules | 1135 "*.google.com,*.kde.org"), // bypass rules |
| 1086 }, | 1136 }, |
| 1087 | 1137 |
| 1088 { | 1138 { |
| 1089 TEST_DESC("Correctly parse bypass list with ReversedException"), | 1139 TEST_DESC("Correctly parse bypass list with ReversedException"), |
| 1090 | 1140 |
| 1091 // Input. | 1141 // Input. |
| 1092 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1142 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1093 "NoProxyFor=.google.com\nReversedException=true\n", | 1143 "NoProxyFor=.google.com\nReversedException=true\n", |
| 1094 {}, // env_values | 1144 {}, // env_values |
| 1095 | 1145 |
| 1146 // Expected result. |
| 1147 ProxyConfigService::CONFIG_VALID, |
| 1096 false, // auto_detect | 1148 false, // auto_detect |
| 1097 GURL(), // pac_url | 1149 GURL(), // pac_url |
| 1098 ProxyRulesExpectation::PerSchemeWithBypassReversed( | 1150 ProxyRulesExpectation::PerSchemeWithBypassReversed( |
| 1099 "www.google.com:80", // http | 1151 "www.google.com:80", // http |
| 1100 "", // https | 1152 "", // https |
| 1101 "", // ftp | 1153 "", // ftp |
| 1102 "*.google.com"), // bypass rules | 1154 "*.google.com"), // bypass rules |
| 1103 }, | 1155 }, |
| 1104 | 1156 |
| 1105 { | 1157 { |
| 1106 TEST_DESC("Treat all hostname patterns as wildcard patterns"), | 1158 TEST_DESC("Treat all hostname patterns as wildcard patterns"), |
| 1107 | 1159 |
| 1108 // Input. | 1160 // Input. |
| 1109 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1161 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1110 "NoProxyFor=google.com,kde.org,<local>\n", | 1162 "NoProxyFor=google.com,kde.org,<local>\n", |
| 1111 {}, // env_values | 1163 {}, // env_values |
| 1112 | 1164 |
| 1165 // Expected result. |
| 1166 ProxyConfigService::CONFIG_VALID, |
| 1113 false, // auto_detect | 1167 false, // auto_detect |
| 1114 GURL(), // pac_url | 1168 GURL(), // pac_url |
| 1115 ProxyRulesExpectation::PerScheme( | 1169 ProxyRulesExpectation::PerScheme( |
| 1116 "www.google.com:80", // http | 1170 "www.google.com:80", // http |
| 1117 "", // https | 1171 "", // https |
| 1118 "", // ftp | 1172 "", // ftp |
| 1119 "*google.com,*kde.org,<local>"), // bypass rules | 1173 "*google.com,*kde.org,<local>"), // bypass rules |
| 1120 }, | 1174 }, |
| 1121 | 1175 |
| 1122 { | 1176 { |
| 1123 TEST_DESC("Allow trailing whitespace after boolean value"), | 1177 TEST_DESC("Allow trailing whitespace after boolean value"), |
| 1124 | 1178 |
| 1125 // Input. | 1179 // Input. |
| 1126 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1180 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1127 "NoProxyFor=.google.com\nReversedException=true \n", | 1181 "NoProxyFor=.google.com\nReversedException=true \n", |
| 1128 {}, // env_values | 1182 {}, // env_values |
| 1129 | 1183 |
| 1184 // Expected result. |
| 1185 ProxyConfigService::CONFIG_VALID, |
| 1130 false, // auto_detect | 1186 false, // auto_detect |
| 1131 GURL(), // pac_url | 1187 GURL(), // pac_url |
| 1132 ProxyRulesExpectation::PerSchemeWithBypassReversed( | 1188 ProxyRulesExpectation::PerSchemeWithBypassReversed( |
| 1133 "www.google.com:80", // http | 1189 "www.google.com:80", // http |
| 1134 "", // https | 1190 "", // https |
| 1135 "", // ftp | 1191 "", // ftp |
| 1136 "*.google.com"), // bypass rules | 1192 "*.google.com"), // bypass rules |
| 1137 }, | 1193 }, |
| 1138 | 1194 |
| 1139 { | 1195 { |
| 1140 TEST_DESC("Ignore settings outside [Proxy Settings]"), | 1196 TEST_DESC("Ignore settings outside [Proxy Settings]"), |
| 1141 | 1197 |
| 1142 // Input. | 1198 // Input. |
| 1143 "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n" | 1199 "httpsProxy=www.foo.com\n[Proxy Settings]\nProxyType=1\n" |
| 1144 "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n", | 1200 "httpProxy=www.google.com\n[Other Section]\nftpProxy=ftp.foo.com\n", |
| 1145 {}, // env_values | 1201 {}, // env_values |
| 1146 | 1202 |
| 1203 // Expected result. |
| 1204 ProxyConfigService::CONFIG_VALID, |
| 1147 false, // auto_detect | 1205 false, // auto_detect |
| 1148 GURL(), // pac_url | 1206 GURL(), // pac_url |
| 1149 ProxyRulesExpectation::PerScheme( | 1207 ProxyRulesExpectation::PerScheme( |
| 1150 "www.google.com:80", // http | 1208 "www.google.com:80", // http |
| 1151 "", // https | 1209 "", // https |
| 1152 "", // ftp | 1210 "", // ftp |
| 1153 ""), // bypass rules | 1211 ""), // bypass rules |
| 1154 }, | 1212 }, |
| 1155 | 1213 |
| 1156 { | 1214 { |
| 1157 TEST_DESC("Handle CRLF line endings"), | 1215 TEST_DESC("Handle CRLF line endings"), |
| 1158 | 1216 |
| 1159 // Input. | 1217 // Input. |
| 1160 "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n", | 1218 "[Proxy Settings]\r\nProxyType=1\r\nhttpProxy=www.google.com\r\n", |
| 1161 {}, // env_values | 1219 {}, // env_values |
| 1162 | 1220 |
| 1221 // Expected result. |
| 1222 ProxyConfigService::CONFIG_VALID, |
| 1163 false, // auto_detect | 1223 false, // auto_detect |
| 1164 GURL(), // pac_url | 1224 GURL(), // pac_url |
| 1165 ProxyRulesExpectation::PerScheme( | 1225 ProxyRulesExpectation::PerScheme( |
| 1166 "www.google.com:80", // http | 1226 "www.google.com:80", // http |
| 1167 "", // https | 1227 "", // https |
| 1168 "", // ftp | 1228 "", // ftp |
| 1169 ""), // bypass rules | 1229 ""), // bypass rules |
| 1170 }, | 1230 }, |
| 1171 | 1231 |
| 1172 { | 1232 { |
| 1173 TEST_DESC("Handle blank lines and mixed line endings"), | 1233 TEST_DESC("Handle blank lines and mixed line endings"), |
| 1174 | 1234 |
| 1175 // Input. | 1235 // Input. |
| 1176 "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n", | 1236 "[Proxy Settings]\r\n\nProxyType=1\n\r\nhttpProxy=www.google.com\n\n", |
| 1177 {}, // env_values | 1237 {}, // env_values |
| 1178 | 1238 |
| 1239 // Expected result. |
| 1240 ProxyConfigService::CONFIG_VALID, |
| 1179 false, // auto_detect | 1241 false, // auto_detect |
| 1180 GURL(), // pac_url | 1242 GURL(), // pac_url |
| 1181 ProxyRulesExpectation::PerScheme( | 1243 ProxyRulesExpectation::PerScheme( |
| 1182 "www.google.com:80", // http | 1244 "www.google.com:80", // http |
| 1183 "", // https | 1245 "", // https |
| 1184 "", // ftp | 1246 "", // ftp |
| 1185 ""), // bypass rules | 1247 ""), // bypass rules |
| 1186 }, | 1248 }, |
| 1187 | 1249 |
| 1188 { | 1250 { |
| 1189 TEST_DESC("Handle localized settings"), | 1251 TEST_DESC("Handle localized settings"), |
| 1190 | 1252 |
| 1191 // Input. | 1253 // Input. |
| 1192 "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n", | 1254 "[Proxy Settings]\nProxyType[$e]=1\nhttpProxy[$e]=www.google.com\n", |
| 1193 {}, // env_values | 1255 {}, // env_values |
| 1194 | 1256 |
| 1257 // Expected result. |
| 1258 ProxyConfigService::CONFIG_VALID, |
| 1195 false, // auto_detect | 1259 false, // auto_detect |
| 1196 GURL(), // pac_url | 1260 GURL(), // pac_url |
| 1197 ProxyRulesExpectation::PerScheme( | 1261 ProxyRulesExpectation::PerScheme( |
| 1198 "www.google.com:80", // http | 1262 "www.google.com:80", // http |
| 1199 "", // https | 1263 "", // https |
| 1200 "", // ftp | 1264 "", // ftp |
| 1201 ""), // bypass rules | 1265 ""), // bypass rules |
| 1202 }, | 1266 }, |
| 1203 | 1267 |
| 1204 { | 1268 { |
| 1205 TEST_DESC("Ignore malformed localized settings"), | 1269 TEST_DESC("Ignore malformed localized settings"), |
| 1206 | 1270 |
| 1207 // Input. | 1271 // Input. |
| 1208 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" | 1272 "[Proxy Settings]\nProxyType=1\nhttpProxy=www.google.com\n" |
| 1209 "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n", | 1273 "httpsProxy$e]=www.foo.com\nftpProxy=ftp.foo.com\n", |
| 1210 {}, // env_values | 1274 {}, // env_values |
| 1211 | 1275 |
| 1276 // Expected result. |
| 1277 ProxyConfigService::CONFIG_VALID, |
| 1212 false, // auto_detect | 1278 false, // auto_detect |
| 1213 GURL(), // pac_url | 1279 GURL(), // pac_url |
| 1214 ProxyRulesExpectation::PerScheme( | 1280 ProxyRulesExpectation::PerScheme( |
| 1215 "www.google.com:80", // http | 1281 "www.google.com:80", // http |
| 1216 "", // https | 1282 "", // https |
| 1217 "ftp.foo.com:80", // ftp | 1283 "ftp.foo.com:80", // ftp |
| 1218 ""), // bypass rules | 1284 ""), // bypass rules |
| 1219 }, | 1285 }, |
| 1220 | 1286 |
| 1221 { | 1287 { |
| 1222 TEST_DESC("Handle strange whitespace"), | 1288 TEST_DESC("Handle strange whitespace"), |
| 1223 | 1289 |
| 1224 // Input. | 1290 // Input. |
| 1225 "[Proxy Settings]\nProxyType [$e] =2\n" | 1291 "[Proxy Settings]\nProxyType [$e] =2\n" |
| 1226 " Proxy Config Script = http:// foo\n", | 1292 " Proxy Config Script = http:// foo\n", |
| 1227 {}, // env_values | 1293 {}, // env_values |
| 1228 | 1294 |
| 1295 // Expected result. |
| 1296 ProxyConfigService::CONFIG_VALID, |
| 1229 false, // auto_detect | 1297 false, // auto_detect |
| 1230 GURL("http:// foo"), // pac_url | 1298 GURL("http:// foo"), // pac_url |
| 1231 ProxyRulesExpectation::Empty(), | 1299 ProxyRulesExpectation::Empty(), |
| 1232 }, | 1300 }, |
| 1233 | 1301 |
| 1234 { | 1302 { |
| 1235 TEST_DESC("Ignore all of a line which is too long"), | 1303 TEST_DESC("Ignore all of a line which is too long"), |
| 1236 | 1304 |
| 1237 // Input. | 1305 // Input. |
| 1238 std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") + | 1306 std::string("[Proxy Settings]\nProxyType=1\nftpProxy=ftp.foo.com\n") + |
| 1239 long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n", | 1307 long_line + "httpsProxy=www.foo.com\nhttpProxy=www.google.com\n", |
| 1240 {}, // env_values | 1308 {}, // env_values |
| 1241 | 1309 |
| 1310 // Expected result. |
| 1311 ProxyConfigService::CONFIG_VALID, |
| 1242 false, // auto_detect | 1312 false, // auto_detect |
| 1243 GURL(), // pac_url | 1313 GURL(), // pac_url |
| 1244 ProxyRulesExpectation::PerScheme( | 1314 ProxyRulesExpectation::PerScheme( |
| 1245 "www.google.com:80", // http | 1315 "www.google.com:80", // http |
| 1246 "", // https | 1316 "", // https |
| 1247 "ftp.foo.com:80", // ftp | 1317 "ftp.foo.com:80", // ftp |
| 1248 ""), // bypass rules | 1318 ""), // bypass rules |
| 1249 }, | 1319 }, |
| 1250 | 1320 |
| 1251 { | 1321 { |
| 1252 TEST_DESC("Indirect Proxy - no env vars set"), | 1322 TEST_DESC("Indirect Proxy - no env vars set"), |
| 1253 | 1323 |
| 1254 // Input. | 1324 // Input. |
| 1255 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" | 1325 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" |
| 1256 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", | 1326 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", |
| 1257 {}, // env_values | 1327 {}, // env_values |
| 1258 | 1328 |
| 1329 // Expected result. |
| 1330 ProxyConfigService::CONFIG_VALID, |
| 1259 false, // auto_detect | 1331 false, // auto_detect |
| 1260 GURL(), // pac_url | 1332 GURL(), // pac_url |
| 1261 ProxyRulesExpectation::Empty(), | 1333 ProxyRulesExpectation::Empty(), |
| 1262 }, | 1334 }, |
| 1263 | 1335 |
| 1264 { | 1336 { |
| 1265 TEST_DESC("Indirect Proxy - with env vars set"), | 1337 TEST_DESC("Indirect Proxy - with env vars set"), |
| 1266 | 1338 |
| 1267 // Input. | 1339 // Input. |
| 1268 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" | 1340 "[Proxy Settings]\nProxyType=4\nhttpProxy=http_proxy\n" |
| 1269 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", | 1341 "httpsProxy=https_proxy\nftpProxy=ftp_proxy\nNoProxyFor=no_proxy\n", |
| 1270 { // env_values | 1342 { // env_values |
| 1271 NULL, // DESKTOP_SESSION | 1343 NULL, // DESKTOP_SESSION |
| 1272 NULL, // HOME | 1344 NULL, // HOME |
| 1273 NULL, // KDEHOME | 1345 NULL, // KDEHOME |
| 1274 NULL, // KDE_SESSION_VERSION | 1346 NULL, // KDE_SESSION_VERSION |
| 1275 NULL, // auto_proxy | 1347 NULL, // auto_proxy |
| 1276 NULL, // all_proxy | 1348 NULL, // all_proxy |
| 1277 "www.normal.com", // http_proxy | 1349 "www.normal.com", // http_proxy |
| 1278 "www.secure.com", // https_proxy | 1350 "www.secure.com", // https_proxy |
| 1279 "ftp.foo.com", // ftp_proxy | 1351 "ftp.foo.com", // ftp_proxy |
| 1280 NULL, NULL, // SOCKS | 1352 NULL, NULL, // SOCKS |
| 1281 ".google.com, .kde.org", // no_proxy | 1353 ".google.com, .kde.org", // no_proxy |
| 1282 }, | 1354 }, |
| 1283 | 1355 |
| 1356 // Expected result. |
| 1357 ProxyConfigService::CONFIG_VALID, |
| 1284 false, // auto_detect | 1358 false, // auto_detect |
| 1285 GURL(), // pac_url | 1359 GURL(), // pac_url |
| 1286 ProxyRulesExpectation::PerScheme( | 1360 ProxyRulesExpectation::PerScheme( |
| 1287 "www.normal.com:80", // http | 1361 "www.normal.com:80", // http |
| 1288 "www.secure.com:80", // https | 1362 "www.secure.com:80", // https |
| 1289 "ftp.foo.com:80", // ftp | 1363 "ftp.foo.com:80", // ftp |
| 1290 "*.google.com,*.kde.org"), // bypass rules | 1364 "*.google.com,*.kde.org"), // bypass rules |
| 1291 }, | 1365 }, |
| 1292 | 1366 |
| 1293 }; | 1367 }; |
| 1294 | 1368 |
| 1295 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1369 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1296 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, | 1370 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "] %s", i, |
| 1297 tests[i].description.c_str())); | 1371 tests[i].description.c_str())); |
| 1298 MockEnvironment* env = new MockEnvironment; | 1372 MockEnvironment* env = new MockEnvironment; |
| 1299 env->values = tests[i].env_values; | 1373 env->values = tests[i].env_values; |
| 1300 // Force the KDE getter to be used and tell it where the test is. | 1374 // Force the KDE getter to be used and tell it where the test is. |
| 1301 env->values.DESKTOP_SESSION = "kde4"; | 1375 env->values.DESKTOP_SESSION = "kde4"; |
| 1302 env->values.KDEHOME = kde_home_.value().c_str(); | 1376 env->values.KDEHOME = kde_home_.value().c_str(); |
| 1303 SynchConfigGetter sync_config_getter( | 1377 SynchConfigGetter sync_config_getter( |
| 1304 new ProxyConfigServiceLinux(env)); | 1378 new ProxyConfigServiceLinux(env)); |
| 1305 ProxyConfig config; | 1379 ProxyConfig config; |
| 1306 // Overwrite the kioslaverc file. | 1380 // Overwrite the kioslaverc file. |
| 1307 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), | 1381 file_util::WriteFile(kioslaverc_, tests[i].kioslaverc.c_str(), |
| 1308 tests[i].kioslaverc.length()); | 1382 tests[i].kioslaverc.length()); |
| 1309 sync_config_getter.SetupAndInitialFetch(); | 1383 sync_config_getter.SetupAndInitialFetch(); |
| 1310 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1384 ProxyConfigService::ConfigAvailability availability = |
| 1385 sync_config_getter.SyncGetLatestProxyConfig(&config); |
| 1386 EXPECT_EQ(tests[i].availability, availability); |
| 1311 | 1387 |
| 1312 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 1388 if (availability == ProxyConfigService::CONFIG_VALID) { |
| 1313 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 1389 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
| 1314 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 1390 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
| 1391 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
| 1392 } |
| 1315 } | 1393 } |
| 1316 } | 1394 } |
| 1317 | 1395 |
| 1318 TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) { | 1396 TEST_F(ProxyConfigServiceLinuxTest, KDEHomePicker) { |
| 1319 // Auto detect proxy settings. | 1397 // Auto detect proxy settings. |
| 1320 std::string slaverc3 = "[Proxy Settings]\nProxyType=3\n"; | 1398 std::string slaverc3 = "[Proxy Settings]\nProxyType=3\n"; |
| 1321 // Valid PAC URL. | 1399 // Valid PAC URL. |
| 1322 std::string slaverc4 = "[Proxy Settings]\nProxyType=2\n" | 1400 std::string slaverc4 = "[Proxy Settings]\nProxyType=2\n" |
| 1323 "Proxy Config Script=http://wpad/wpad.dat\n"; | 1401 "Proxy Config Script=http://wpad/wpad.dat\n"; |
| 1324 GURL slaverc4_pac_url("http://wpad/wpad.dat"); | 1402 GURL slaverc4_pac_url("http://wpad/wpad.dat"); |
| 1325 | 1403 |
| 1326 // Overwrite the .kde kioslaverc file. | 1404 // Overwrite the .kde kioslaverc file. |
| 1327 file_util::WriteFile(kioslaverc_, slaverc3.c_str(), slaverc3.length()); | 1405 file_util::WriteFile(kioslaverc_, slaverc3.c_str(), slaverc3.length()); |
| 1328 | 1406 |
| 1329 // If .kde4 exists it will mess up the first test. It should not, as | 1407 // If .kde4 exists it will mess up the first test. It should not, as |
| 1330 // we created the directory for $HOME in the test setup. | 1408 // we created the directory for $HOME in the test setup. |
| 1331 CHECK(!file_util::DirectoryExists(kde4_home_)); | 1409 CHECK(!file_util::DirectoryExists(kde4_home_)); |
| 1332 | 1410 |
| 1333 { SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback"); | 1411 { SCOPED_TRACE("KDE4, no .kde4 directory, verify fallback"); |
| 1334 MockEnvironment* env = new MockEnvironment; | 1412 MockEnvironment* env = new MockEnvironment; |
| 1335 env->values.DESKTOP_SESSION = "kde4"; | 1413 env->values.DESKTOP_SESSION = "kde4"; |
| 1336 env->values.HOME = user_home_.value().c_str(); | 1414 env->values.HOME = user_home_.value().c_str(); |
| 1337 SynchConfigGetter sync_config_getter( | 1415 SynchConfigGetter sync_config_getter( |
| 1338 new ProxyConfigServiceLinux(env)); | 1416 new ProxyConfigServiceLinux(env)); |
| 1339 ProxyConfig config; | 1417 ProxyConfig config; |
| 1340 sync_config_getter.SetupAndInitialFetch(); | 1418 sync_config_getter.SetupAndInitialFetch(); |
| 1341 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1419 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1420 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1342 EXPECT_TRUE(config.auto_detect()); | 1421 EXPECT_TRUE(config.auto_detect()); |
| 1343 EXPECT_EQ(GURL(), config.pac_url()); | 1422 EXPECT_EQ(GURL(), config.pac_url()); |
| 1344 } | 1423 } |
| 1345 | 1424 |
| 1346 // Now create .kde4 and put a kioslaverc in the config directory. | 1425 // Now create .kde4 and put a kioslaverc in the config directory. |
| 1347 // Note that its timestamp will be at least as new as the .kde one. | 1426 // Note that its timestamp will be at least as new as the .kde one. |
| 1348 file_util::CreateDirectory(kde4_config_); | 1427 file_util::CreateDirectory(kde4_config_); |
| 1349 file_util::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length()); | 1428 file_util::WriteFile(kioslaverc4_, slaverc4.c_str(), slaverc4.length()); |
| 1350 CHECK(file_util::PathExists(kioslaverc4_)); | 1429 CHECK(file_util::PathExists(kioslaverc4_)); |
| 1351 | 1430 |
| 1352 { SCOPED_TRACE("KDE4, .kde4 directory present, use it"); | 1431 { SCOPED_TRACE("KDE4, .kde4 directory present, use it"); |
| 1353 MockEnvironment* env = new MockEnvironment; | 1432 MockEnvironment* env = new MockEnvironment; |
| 1354 env->values.DESKTOP_SESSION = "kde4"; | 1433 env->values.DESKTOP_SESSION = "kde4"; |
| 1355 env->values.HOME = user_home_.value().c_str(); | 1434 env->values.HOME = user_home_.value().c_str(); |
| 1356 SynchConfigGetter sync_config_getter( | 1435 SynchConfigGetter sync_config_getter( |
| 1357 new ProxyConfigServiceLinux(env)); | 1436 new ProxyConfigServiceLinux(env)); |
| 1358 ProxyConfig config; | 1437 ProxyConfig config; |
| 1359 sync_config_getter.SetupAndInitialFetch(); | 1438 sync_config_getter.SetupAndInitialFetch(); |
| 1360 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1439 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1440 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1361 EXPECT_FALSE(config.auto_detect()); | 1441 EXPECT_FALSE(config.auto_detect()); |
| 1362 EXPECT_EQ(slaverc4_pac_url, config.pac_url()); | 1442 EXPECT_EQ(slaverc4_pac_url, config.pac_url()); |
| 1363 } | 1443 } |
| 1364 | 1444 |
| 1365 { SCOPED_TRACE("KDE3, .kde4 directory present, ignore it"); | 1445 { SCOPED_TRACE("KDE3, .kde4 directory present, ignore it"); |
| 1366 MockEnvironment* env = new MockEnvironment; | 1446 MockEnvironment* env = new MockEnvironment; |
| 1367 env->values.DESKTOP_SESSION = "kde"; | 1447 env->values.DESKTOP_SESSION = "kde"; |
| 1368 env->values.HOME = user_home_.value().c_str(); | 1448 env->values.HOME = user_home_.value().c_str(); |
| 1369 SynchConfigGetter sync_config_getter( | 1449 SynchConfigGetter sync_config_getter( |
| 1370 new ProxyConfigServiceLinux(env)); | 1450 new ProxyConfigServiceLinux(env)); |
| 1371 ProxyConfig config; | 1451 ProxyConfig config; |
| 1372 sync_config_getter.SetupAndInitialFetch(); | 1452 sync_config_getter.SetupAndInitialFetch(); |
| 1373 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1453 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1454 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1374 EXPECT_TRUE(config.auto_detect()); | 1455 EXPECT_TRUE(config.auto_detect()); |
| 1375 EXPECT_EQ(GURL(), config.pac_url()); | 1456 EXPECT_EQ(GURL(), config.pac_url()); |
| 1376 } | 1457 } |
| 1377 | 1458 |
| 1378 { SCOPED_TRACE("KDE4, .kde4 directory present, KDEHOME set to .kde"); | 1459 { SCOPED_TRACE("KDE4, .kde4 directory present, KDEHOME set to .kde"); |
| 1379 MockEnvironment* env = new MockEnvironment; | 1460 MockEnvironment* env = new MockEnvironment; |
| 1380 env->values.DESKTOP_SESSION = "kde4"; | 1461 env->values.DESKTOP_SESSION = "kde4"; |
| 1381 env->values.HOME = user_home_.value().c_str(); | 1462 env->values.HOME = user_home_.value().c_str(); |
| 1382 env->values.KDEHOME = kde_home_.value().c_str(); | 1463 env->values.KDEHOME = kde_home_.value().c_str(); |
| 1383 SynchConfigGetter sync_config_getter( | 1464 SynchConfigGetter sync_config_getter( |
| 1384 new ProxyConfigServiceLinux(env)); | 1465 new ProxyConfigServiceLinux(env)); |
| 1385 ProxyConfig config; | 1466 ProxyConfig config; |
| 1386 sync_config_getter.SetupAndInitialFetch(); | 1467 sync_config_getter.SetupAndInitialFetch(); |
| 1387 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1468 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1469 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1388 EXPECT_TRUE(config.auto_detect()); | 1470 EXPECT_TRUE(config.auto_detect()); |
| 1389 EXPECT_EQ(GURL(), config.pac_url()); | 1471 EXPECT_EQ(GURL(), config.pac_url()); |
| 1390 } | 1472 } |
| 1391 | 1473 |
| 1392 // Finally, make the .kde4 config directory older than the .kde directory | 1474 // Finally, make the .kde4 config directory older than the .kde directory |
| 1393 // and make sure we then use .kde instead of .kde4 since it's newer. | 1475 // and make sure we then use .kde instead of .kde4 since it's newer. |
| 1394 file_util::SetLastModifiedTime(kde4_config_, base::Time()); | 1476 file_util::SetLastModifiedTime(kde4_config_, base::Time()); |
| 1395 | 1477 |
| 1396 { SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde"); | 1478 { SCOPED_TRACE("KDE4, very old .kde4 directory present, use .kde"); |
| 1397 MockEnvironment* env = new MockEnvironment; | 1479 MockEnvironment* env = new MockEnvironment; |
| 1398 env->values.DESKTOP_SESSION = "kde4"; | 1480 env->values.DESKTOP_SESSION = "kde4"; |
| 1399 env->values.HOME = user_home_.value().c_str(); | 1481 env->values.HOME = user_home_.value().c_str(); |
| 1400 SynchConfigGetter sync_config_getter( | 1482 SynchConfigGetter sync_config_getter( |
| 1401 new ProxyConfigServiceLinux(env)); | 1483 new ProxyConfigServiceLinux(env)); |
| 1402 ProxyConfig config; | 1484 ProxyConfig config; |
| 1403 sync_config_getter.SetupAndInitialFetch(); | 1485 sync_config_getter.SetupAndInitialFetch(); |
| 1404 sync_config_getter.SyncGetLatestProxyConfig(&config); | 1486 EXPECT_EQ(ProxyConfigService::CONFIG_VALID, |
| 1487 sync_config_getter.SyncGetLatestProxyConfig(&config)); |
| 1405 EXPECT_TRUE(config.auto_detect()); | 1488 EXPECT_TRUE(config.auto_detect()); |
| 1406 EXPECT_EQ(GURL(), config.pac_url()); | 1489 EXPECT_EQ(GURL(), config.pac_url()); |
| 1407 } | 1490 } |
| 1408 } | 1491 } |
| 1409 | 1492 |
| 1410 } // namespace net | 1493 } // namespace net |
| OLD | NEW |