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