OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 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 <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "net/proxy/proxy_config_service_linux.h" | 9 #include "net/proxy/proxy_config_service_linux.h" |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "base/thread.h" | 14 #include "base/thread.h" |
15 #include "base/waitable_event.h" | 15 #include "base/waitable_event.h" |
16 #include "net/proxy/proxy_config.h" | 16 #include "net/proxy/proxy_config.h" |
17 #include "net/proxy/proxy_config_service_common_unittest.h" | 17 #include "net/proxy/proxy_config_service_common_unittest.h" |
18 | 18 |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 namespace { | 22 namespace { |
23 | 23 |
24 // Set of values for all environment variables that we might | 24 // Set of values for all environment variables that we might |
25 // query. NULL represents an unset variable. | 25 // query. NULL represents an unset variable. |
26 struct EnvVarValues { | 26 struct EnvVarValues { |
27 // The strange capitalization is so that the field matches the | 27 // The strange capitalization is so that the field matches the |
28 // environment variable name exactly. | 28 // environment variable name exactly. |
29 const char *GNOME_DESKTOP_SESSION_ID, *DESKTOP_SESSION, | 29 const char *DESKTOP_SESSION, *GNOME_DESKTOP_SESSION_ID, *KDE_FULL_SESSION, |
30 *auto_proxy, *all_proxy, | 30 *auto_proxy, *all_proxy, |
31 *http_proxy, *https_proxy, *ftp_proxy, | 31 *http_proxy, *https_proxy, *ftp_proxy, |
32 *SOCKS_SERVER, *SOCKS_VERSION, | 32 *SOCKS_SERVER, *SOCKS_VERSION, |
33 *no_proxy; | 33 *no_proxy; |
34 }; | 34 }; |
35 | 35 |
36 // Undo macro pollution from GDK includes (from message_loop.h). | 36 // Undo macro pollution from GDK includes (from message_loop.h). |
37 #undef TRUE | 37 #undef TRUE |
38 #undef FALSE | 38 #undef FALSE |
39 | 39 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 return *value_ptr; | 71 return *value_ptr; |
72 } | 72 } |
73 | 73 |
74 map_type settings; | 74 map_type settings; |
75 }; | 75 }; |
76 | 76 |
77 class MockEnvironmentVariableGetter : public base::EnvironmentVariableGetter { | 77 class MockEnvironmentVariableGetter : public base::EnvironmentVariableGetter { |
78 public: | 78 public: |
79 MockEnvironmentVariableGetter() { | 79 MockEnvironmentVariableGetter() { |
80 #define ENTRY(x) table.settings[#x] = &values.x | 80 #define ENTRY(x) table.settings[#x] = &values.x |
| 81 ENTRY(DESKTOP_SESSION); |
81 ENTRY(GNOME_DESKTOP_SESSION_ID); | 82 ENTRY(GNOME_DESKTOP_SESSION_ID); |
82 ENTRY(DESKTOP_SESSION); | 83 ENTRY(KDE_FULL_SESSION); |
83 ENTRY(auto_proxy); | 84 ENTRY(auto_proxy); |
84 ENTRY(all_proxy); | 85 ENTRY(all_proxy); |
85 ENTRY(http_proxy); | 86 ENTRY(http_proxy); |
86 ENTRY(https_proxy); | 87 ENTRY(https_proxy); |
87 ENTRY(ftp_proxy); | 88 ENTRY(ftp_proxy); |
88 ENTRY(no_proxy); | 89 ENTRY(no_proxy); |
89 ENTRY(SOCKS_SERVER); | 90 ENTRY(SOCKS_SERVER); |
90 ENTRY(SOCKS_VERSION); | 91 ENTRY(SOCKS_VERSION); |
91 #undef ENTRY | 92 #undef ENTRY |
92 Reset(); | 93 Reset(); |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 // Expected outputs (fields of the ProxyConfig). | 582 // Expected outputs (fields of the ProxyConfig). |
582 bool auto_detect; | 583 bool auto_detect; |
583 GURL pac_url; | 584 GURL pac_url; |
584 ProxyConfig::ProxyRules proxy_rules; | 585 ProxyConfig::ProxyRules proxy_rules; |
585 const char* proxy_bypass_list; // newline separated | 586 const char* proxy_bypass_list; // newline separated |
586 bool bypass_local_names; | 587 bool bypass_local_names; |
587 } tests[] = { | 588 } tests[] = { |
588 { | 589 { |
589 TEST_DESC("No proxying"), | 590 TEST_DESC("No proxying"), |
590 { // Input. | 591 { // Input. |
591 NULL, NULL, // *DESKTOP* | 592 NULL, NULL, NULL, // *DESKTOP* |
592 NULL, // auto_proxy | 593 NULL, // auto_proxy |
593 NULL, // all_proxy | 594 NULL, // all_proxy |
594 NULL, NULL, NULL, // per-proto proxies | 595 NULL, NULL, NULL, // per-proto proxies |
595 NULL, NULL, // SOCKS | 596 NULL, NULL, // SOCKS |
596 "*", // no_proxy | 597 "*", // no_proxy |
597 }, | 598 }, |
598 | 599 |
599 // Expected result. | 600 // Expected result. |
600 false, // auto_detect | 601 false, // auto_detect |
601 GURL(), // pac_url | 602 GURL(), // pac_url |
602 ProxyConfig::ProxyRules(), // proxy_rules | 603 ProxyConfig::ProxyRules(), // proxy_rules |
603 "", // proxy_bypass_list | 604 "", // proxy_bypass_list |
604 false, // bypass_local_names | 605 false, // bypass_local_names |
605 }, | 606 }, |
606 | 607 |
607 { | 608 { |
608 TEST_DESC("Auto detect"), | 609 TEST_DESC("Auto detect"), |
609 { // Input. | 610 { // Input. |
610 NULL, NULL, // *DESKTOP* | 611 NULL, NULL, NULL, // *DESKTOP* |
611 "", // auto_proxy | 612 "", // auto_proxy |
612 NULL, // all_proxy | 613 NULL, // all_proxy |
613 NULL, NULL, NULL, // per-proto proxies | 614 NULL, NULL, NULL, // per-proto proxies |
614 NULL, NULL, // SOCKS | 615 NULL, NULL, // SOCKS |
615 NULL, // no_proxy | 616 NULL, // no_proxy |
616 }, | 617 }, |
617 | 618 |
618 // Expected result. | 619 // Expected result. |
619 true, // auto_detect | 620 true, // auto_detect |
620 GURL(), // pac_url | 621 GURL(), // pac_url |
621 ProxyConfig::ProxyRules(), // proxy_rules | 622 ProxyConfig::ProxyRules(), // proxy_rules |
622 "", // proxy_bypass_list | 623 "", // proxy_bypass_list |
623 false, // bypass_local_names | 624 false, // bypass_local_names |
624 }, | 625 }, |
625 | 626 |
626 { | 627 { |
627 TEST_DESC("Valid PAC url"), | 628 TEST_DESC("Valid PAC url"), |
628 { // Input. | 629 { // Input. |
629 NULL, NULL, // *DESKTOP* | 630 NULL, NULL, NULL, // *DESKTOP* |
630 "http://wpad/wpad.dat", // auto_proxy | 631 "http://wpad/wpad.dat", // auto_proxy |
631 NULL, // all_proxy | 632 NULL, // all_proxy |
632 NULL, NULL, NULL, // per-proto proxies | 633 NULL, NULL, NULL, // per-proto proxies |
633 NULL, NULL, // SOCKS | 634 NULL, NULL, // SOCKS |
634 NULL, // no_proxy | 635 NULL, // no_proxy |
635 }, | 636 }, |
636 | 637 |
637 // Expected result. | 638 // Expected result. |
638 false, // auto_detect | 639 false, // auto_detect |
639 GURL("http://wpad/wpad.dat"), // pac_url | 640 GURL("http://wpad/wpad.dat"), // pac_url |
640 ProxyConfig::ProxyRules(), // proxy_rules | 641 ProxyConfig::ProxyRules(), // proxy_rules |
641 "", // proxy_bypass_list | 642 "", // proxy_bypass_list |
642 false, // bypass_local_names | 643 false, // bypass_local_names |
643 }, | 644 }, |
644 | 645 |
645 { | 646 { |
646 TEST_DESC("Invalid PAC url"), | 647 TEST_DESC("Invalid PAC url"), |
647 { // Input. | 648 { // Input. |
648 NULL, NULL, // *DESKTOP* | 649 NULL, NULL, NULL, // *DESKTOP* |
649 "wpad.dat", // auto_proxy | 650 "wpad.dat", // auto_proxy |
650 NULL, // all_proxy | 651 NULL, // all_proxy |
651 NULL, NULL, NULL, // per-proto proxies | 652 NULL, NULL, NULL, // per-proto proxies |
652 NULL, NULL, // SOCKS | 653 NULL, NULL, // SOCKS |
653 NULL, // no_proxy | 654 NULL, // no_proxy |
654 }, | 655 }, |
655 | 656 |
656 // Expected result. | 657 // Expected result. |
657 false, // auto_detect | 658 false, // auto_detect |
658 GURL(), // pac_url | 659 GURL(), // pac_url |
659 ProxyConfig::ProxyRules(), // proxy_rules | 660 ProxyConfig::ProxyRules(), // proxy_rules |
660 "", // proxy_bypass_list | 661 "", // proxy_bypass_list |
661 false, // bypass_local_names | 662 false, // bypass_local_names |
662 }, | 663 }, |
663 | 664 |
664 { | 665 { |
665 TEST_DESC("Single-host in proxy list"), | 666 TEST_DESC("Single-host in proxy list"), |
666 { // Input. | 667 { // Input. |
667 NULL, NULL, // *DESKTOP* | 668 NULL, NULL, NULL, // *DESKTOP* |
668 NULL, // auto_proxy | 669 NULL, // auto_proxy |
669 "www.google.com", // all_proxy | 670 "www.google.com", // all_proxy |
670 NULL, NULL, NULL, // per-proto proxies | 671 NULL, NULL, NULL, // per-proto proxies |
671 NULL, NULL, // SOCKS | 672 NULL, NULL, // SOCKS |
672 NULL, // no_proxy | 673 NULL, // no_proxy |
673 }, | 674 }, |
674 | 675 |
675 // Expected result. | 676 // Expected result. |
676 false, // auto_detect | 677 false, // auto_detect |
677 GURL(), // pac_url | 678 GURL(), // pac_url |
678 MakeSingleProxyRules("www.google.com"), // proxy_rules | 679 MakeSingleProxyRules("www.google.com"), // proxy_rules |
679 "", // proxy_bypass_list | 680 "", // proxy_bypass_list |
680 false, // bypass_local_names | 681 false, // bypass_local_names |
681 }, | 682 }, |
682 | 683 |
683 { | 684 { |
684 TEST_DESC("Single-host, different port"), | 685 TEST_DESC("Single-host, different port"), |
685 { // Input. | 686 { // Input. |
686 NULL, NULL, // *DESKTOP* | 687 NULL, NULL, NULL, // *DESKTOP* |
687 NULL, // auto_proxy | 688 NULL, // auto_proxy |
688 "www.google.com:99", // all_proxy | 689 "www.google.com:99", // all_proxy |
689 NULL, NULL, NULL, // per-proto proxies | 690 NULL, NULL, NULL, // per-proto proxies |
690 NULL, NULL, // SOCKS | 691 NULL, NULL, // SOCKS |
691 NULL, // no_proxy | 692 NULL, // no_proxy |
692 }, | 693 }, |
693 | 694 |
694 // Expected result. | 695 // Expected result. |
695 false, // auto_detect | 696 false, // auto_detect |
696 GURL(), // pac_url | 697 GURL(), // pac_url |
697 MakeSingleProxyRules("www.google.com:99"), // proxy_rules | 698 MakeSingleProxyRules("www.google.com:99"), // proxy_rules |
698 "", // proxy_bypass_list | 699 "", // proxy_bypass_list |
699 false, // bypass_local_names | 700 false, // bypass_local_names |
700 }, | 701 }, |
701 | 702 |
702 { | 703 { |
703 TEST_DESC("Tolerate a scheme"), | 704 TEST_DESC("Tolerate a scheme"), |
704 { // Input. | 705 { // Input. |
705 NULL, NULL, // *DESKTOP* | 706 NULL, NULL, NULL, // *DESKTOP* |
706 NULL, // auto_proxy | 707 NULL, // auto_proxy |
707 "http://www.google.com:99", // all_proxy | 708 "http://www.google.com:99", // all_proxy |
708 NULL, NULL, NULL, // per-proto proxies | 709 NULL, NULL, NULL, // per-proto proxies |
709 NULL, NULL, // SOCKS | 710 NULL, NULL, // SOCKS |
710 NULL, // no_proxy | 711 NULL, // no_proxy |
711 }, | 712 }, |
712 | 713 |
713 // Expected result. | 714 // Expected result. |
714 false, // auto_detect | 715 false, // auto_detect |
715 GURL(), // pac_url | 716 GURL(), // pac_url |
716 MakeSingleProxyRules("www.google.com:99"), // proxy_rules | 717 MakeSingleProxyRules("www.google.com:99"), // proxy_rules |
717 "", // proxy_bypass_list | 718 "", // proxy_bypass_list |
718 false, // bypass_local_names | 719 false, // bypass_local_names |
719 }, | 720 }, |
720 | 721 |
721 { | 722 { |
722 TEST_DESC("Per-scheme proxy rules"), | 723 TEST_DESC("Per-scheme proxy rules"), |
723 { // Input. | 724 { // Input. |
724 NULL, NULL, // *DESKTOP* | 725 NULL, NULL, NULL, // *DESKTOP* |
725 NULL, // auto_proxy | 726 NULL, // auto_proxy |
726 NULL, // all_proxy | 727 NULL, // all_proxy |
727 "www.google.com:80", "www.foo.com:110", "ftpfoo.com:121", // per-proto | 728 "www.google.com:80", "www.foo.com:110", "ftpfoo.com:121", // per-proto |
728 NULL, NULL, // SOCKS | 729 NULL, NULL, // SOCKS |
729 NULL, // no_proxy | 730 NULL, // no_proxy |
730 }, | 731 }, |
731 | 732 |
732 // Expected result. | 733 // Expected result. |
733 false, // auto_detect | 734 false, // auto_detect |
734 GURL(), // pac_url | 735 GURL(), // pac_url |
735 MakeProxyPerSchemeRules("www.google.com", "www.foo.com:110", | 736 MakeProxyPerSchemeRules("www.google.com", "www.foo.com:110", |
736 "ftpfoo.com:121"), | 737 "ftpfoo.com:121"), |
737 "", // proxy_bypass_list | 738 "", // proxy_bypass_list |
738 false, // bypass_local_names | 739 false, // bypass_local_names |
739 }, | 740 }, |
740 | 741 |
741 { | 742 { |
742 TEST_DESC("socks"), | 743 TEST_DESC("socks"), |
743 { // Input. | 744 { // Input. |
744 NULL, NULL, // *DESKTOP* | 745 NULL, NULL, NULL, // *DESKTOP* |
745 NULL, // auto_proxy | 746 NULL, // auto_proxy |
746 "", // all_proxy | 747 "", // all_proxy |
747 NULL, NULL, NULL, // per-proto proxies | 748 NULL, NULL, NULL, // per-proto proxies |
748 "socks.com:888", NULL, // SOCKS | 749 "socks.com:888", NULL, // SOCKS |
749 NULL, // no_proxy | 750 NULL, // no_proxy |
750 }, | 751 }, |
751 | 752 |
752 // Expected result. | 753 // Expected result. |
753 false, // auto_detect | 754 false, // auto_detect |
754 GURL(), // pac_url | 755 GURL(), // pac_url |
755 MakeSingleProxyRules("socks4://socks.com:888"), // proxy_rules | 756 MakeSingleProxyRules("socks4://socks.com:888"), // proxy_rules |
756 "", // proxy_bypass_list | 757 "", // proxy_bypass_list |
757 false, // bypass_local_names | 758 false, // bypass_local_names |
758 }, | 759 }, |
759 | 760 |
760 { | 761 { |
761 TEST_DESC("socks5"), | 762 TEST_DESC("socks5"), |
762 { // Input. | 763 { // Input. |
763 NULL, NULL, // *DESKTOP* | 764 NULL, NULL, NULL, // *DESKTOP* |
764 NULL, // auto_proxy | 765 NULL, // auto_proxy |
765 "", // all_proxy | 766 "", // all_proxy |
766 NULL, NULL, NULL, // per-proto proxies | 767 NULL, NULL, NULL, // per-proto proxies |
767 "socks.com:888", "5", // SOCKS | 768 "socks.com:888", "5", // SOCKS |
768 NULL, // no_proxy | 769 NULL, // no_proxy |
769 }, | 770 }, |
770 | 771 |
771 // Expected result. | 772 // Expected result. |
772 false, // auto_detect | 773 false, // auto_detect |
773 GURL(), // pac_url | 774 GURL(), // pac_url |
774 MakeSingleProxyRules("socks5://socks.com:888"), // proxy_rules | 775 MakeSingleProxyRules("socks5://socks.com:888"), // proxy_rules |
775 "", // proxy_bypass_list | 776 "", // proxy_bypass_list |
776 false, // bypass_local_names | 777 false, // bypass_local_names |
777 }, | 778 }, |
778 | 779 |
779 { | 780 { |
780 TEST_DESC("socks default port"), | 781 TEST_DESC("socks default port"), |
781 { // Input. | 782 { // Input. |
782 NULL, NULL, // *DESKTOP* | 783 NULL, NULL, NULL, // *DESKTOP* |
783 NULL, // auto_proxy | 784 NULL, // auto_proxy |
784 "", // all_proxy | 785 "", // all_proxy |
785 NULL, NULL, NULL, // per-proto proxies | 786 NULL, NULL, NULL, // per-proto proxies |
786 "socks.com", NULL, // SOCKS | 787 "socks.com", NULL, // SOCKS |
787 NULL, // no_proxy | 788 NULL, // no_proxy |
788 }, | 789 }, |
789 | 790 |
790 // Expected result. | 791 // Expected result. |
791 false, // auto_detect | 792 false, // auto_detect |
792 GURL(), // pac_url | 793 GURL(), // pac_url |
793 MakeSingleProxyRules("socks4://socks.com"), // proxy_rules | 794 MakeSingleProxyRules("socks4://socks.com"), // proxy_rules |
794 "", // proxy_bypass_list | 795 "", // proxy_bypass_list |
795 false, // bypass_local_names | 796 false, // bypass_local_names |
796 }, | 797 }, |
797 | 798 |
798 { | 799 { |
799 TEST_DESC("bypass"), | 800 TEST_DESC("bypass"), |
800 { // Input. | 801 { // Input. |
801 NULL, NULL, // *DESKTOP* | 802 NULL, NULL, NULL, // *DESKTOP* |
802 NULL, // auto_proxy | 803 NULL, // auto_proxy |
803 "www.google.com", // all_proxy | 804 "www.google.com", // all_proxy |
804 NULL, NULL, NULL, // per-proto | 805 NULL, NULL, NULL, // per-proto |
805 NULL, NULL, // SOCKS | 806 NULL, NULL, // SOCKS |
806 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy | 807 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", // no_proxy |
807 }, | 808 }, |
808 | 809 |
809 false, // auto_detect | 810 false, // auto_detect |
810 GURL(), // pac_url | 811 GURL(), // pac_url |
811 MakeSingleProxyRules("www.google.com"), // proxy_rules | 812 MakeSingleProxyRules("www.google.com"), // proxy_rules |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 | 880 |
880 // Now set to auto-detect. | 881 // Now set to auto-detect. |
881 gconf_getter->values.mode = "auto"; | 882 gconf_getter->values.mode = "auto"; |
882 // Simulate gconf notification callback. | 883 // Simulate gconf notification callback. |
883 service.OnCheckProxyConfigSettings(); | 884 service.OnCheckProxyConfigSettings(); |
884 sync_config_getter.SyncGetProxyConfig(&config); | 885 sync_config_getter.SyncGetProxyConfig(&config); |
885 EXPECT_TRUE(config.auto_detect); | 886 EXPECT_TRUE(config.auto_detect); |
886 } | 887 } |
887 | 888 |
888 } // namespace net | 889 } // namespace net |
OLD | NEW |