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