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