OLD | NEW |
1 // Copyright (c) 2011 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 "components/proxy_config/proxy_config_dictionary.h" | 5 #include "components/proxy_config/proxy_config_dictionary.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 struct ProxyConfigHolder { | 13 struct ProxyConfigHolder { |
14 ProxyPrefs::ProxyMode mode; | 14 ProxyPrefs::ProxyMode mode; |
15 std::string pac_url; | 15 std::string pac_url; |
16 std::string proxy_server; | 16 std::string proxy_server; |
17 std::string bypass_list; | 17 std::string bypass_list; |
18 }; | 18 }; |
19 | 19 |
20 TEST(ProxyConfigDictionaryTest, CreateDirect) { | 20 TEST(ProxyConfigDictionaryTest, CreateDirect) { |
21 std::unique_ptr<base::DictionaryValue> dict_value( | 21 std::unique_ptr<base::DictionaryValue> dict_value = |
22 ProxyConfigDictionary::CreateDirect()); | 22 ProxyConfigDictionary::CreateDirect(); |
23 ProxyConfigDictionary dict(dict_value.get()); | 23 ProxyConfigDictionary dict(dict_value.get()); |
24 ProxyConfigHolder h; | 24 ProxyConfigHolder h; |
25 | 25 |
26 ASSERT_TRUE(dict.GetMode(&h.mode)); | 26 ASSERT_TRUE(dict.GetMode(&h.mode)); |
27 EXPECT_EQ(ProxyPrefs::MODE_DIRECT, h.mode); | 27 EXPECT_EQ(ProxyPrefs::MODE_DIRECT, h.mode); |
28 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); | 28 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); |
29 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); | 29 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); |
30 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); | 30 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); |
31 } | 31 } |
32 | 32 |
33 TEST(ProxyConfigDictionaryTest, CreateAutoDetect) { | 33 TEST(ProxyConfigDictionaryTest, CreateAutoDetect) { |
34 std::unique_ptr<base::DictionaryValue> dict_value( | 34 std::unique_ptr<base::DictionaryValue> dict_value = |
35 ProxyConfigDictionary::CreateAutoDetect()); | 35 ProxyConfigDictionary::CreateAutoDetect(); |
36 ProxyConfigDictionary dict(dict_value.get()); | 36 ProxyConfigDictionary dict(dict_value.get()); |
37 ProxyConfigHolder h; | 37 ProxyConfigHolder h; |
38 | 38 |
39 ASSERT_TRUE(dict.GetMode(&h.mode)); | 39 ASSERT_TRUE(dict.GetMode(&h.mode)); |
40 EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, h.mode); | 40 EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, h.mode); |
41 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); | 41 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); |
42 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); | 42 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); |
43 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); | 43 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); |
44 } | 44 } |
45 | 45 |
46 TEST(ProxyConfigDictionaryTest, CreatePacScript) { | 46 TEST(ProxyConfigDictionaryTest, CreatePacScript) { |
47 std::unique_ptr<base::DictionaryValue> dict_value( | 47 std::unique_ptr<base::DictionaryValue> dict_value = |
48 ProxyConfigDictionary::CreatePacScript("pac", false)); | 48 ProxyConfigDictionary::CreatePacScript("pac", false); |
49 ProxyConfigDictionary dict(dict_value.get()); | 49 ProxyConfigDictionary dict(dict_value.get()); |
50 ProxyConfigHolder h; | 50 ProxyConfigHolder h; |
51 | 51 |
52 ASSERT_TRUE(dict.GetMode(&h.mode)); | 52 ASSERT_TRUE(dict.GetMode(&h.mode)); |
53 EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, h.mode); | 53 EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, h.mode); |
54 ASSERT_TRUE(dict.GetPacUrl(&h.bypass_list)); | 54 ASSERT_TRUE(dict.GetPacUrl(&h.bypass_list)); |
55 EXPECT_EQ("pac", h.bypass_list); | 55 EXPECT_EQ("pac", h.bypass_list); |
56 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); | 56 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); |
57 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); | 57 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); |
58 } | 58 } |
59 | 59 |
60 TEST(ProxyConfigDictionaryTest, CreateFixedServers) { | 60 TEST(ProxyConfigDictionaryTest, CreateFixedServers) { |
61 std::unique_ptr<base::DictionaryValue> dict_value( | 61 std::unique_ptr<base::DictionaryValue> dict_value = |
62 ProxyConfigDictionary::CreateFixedServers("http://1.2.3.4", | 62 ProxyConfigDictionary::CreateFixedServers("http://1.2.3.4", "http://foo"); |
63 "http://foo")); | |
64 ProxyConfigDictionary dict(dict_value.get()); | 63 ProxyConfigDictionary dict(dict_value.get()); |
65 ProxyConfigHolder h; | 64 ProxyConfigHolder h; |
66 | 65 |
67 ASSERT_TRUE(dict.GetMode(&h.mode)); | 66 ASSERT_TRUE(dict.GetMode(&h.mode)); |
68 EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, h.mode); | 67 EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, h.mode); |
69 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); | 68 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); |
70 ASSERT_TRUE(dict.GetProxyServer(&h.proxy_server)); | 69 ASSERT_TRUE(dict.GetProxyServer(&h.proxy_server)); |
71 EXPECT_EQ("http://1.2.3.4", h.proxy_server); | 70 EXPECT_EQ("http://1.2.3.4", h.proxy_server); |
72 ASSERT_TRUE(dict.GetBypassList(&h.bypass_list)); | 71 ASSERT_TRUE(dict.GetBypassList(&h.bypass_list)); |
73 EXPECT_EQ("http://foo", h.bypass_list); | 72 EXPECT_EQ("http://foo", h.bypass_list); |
74 } | 73 } |
75 | 74 |
76 TEST(ProxyConfigDictionaryTest, CreateSystem) { | 75 TEST(ProxyConfigDictionaryTest, CreateSystem) { |
77 std::unique_ptr<base::DictionaryValue> dict_value( | 76 std::unique_ptr<base::DictionaryValue> dict_value = |
78 ProxyConfigDictionary::CreateSystem()); | 77 ProxyConfigDictionary::CreateSystem(); |
79 ProxyConfigDictionary dict(dict_value.get()); | 78 ProxyConfigDictionary dict(dict_value.get()); |
80 ProxyConfigHolder h; | 79 ProxyConfigHolder h; |
81 | 80 |
82 ASSERT_TRUE(dict.GetMode(&h.mode)); | 81 ASSERT_TRUE(dict.GetMode(&h.mode)); |
83 EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, h.mode); | 82 EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, h.mode); |
84 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); | 83 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list)); |
85 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); | 84 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server)); |
86 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); | 85 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list)); |
87 } | 86 } |
OLD | NEW |