• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
TEST(ProxyConfigDictionaryTest,CreateDirect)19 TEST(ProxyConfigDictionaryTest, CreateDirect) {
20   scoped_ptr<DictionaryValue> dict_value(ProxyConfigDictionary::CreateDirect());
21   ProxyConfigDictionary dict(dict_value.get());
22   ProxyConfigHolder h;
23 
24   ASSERT_TRUE(dict.GetMode(&h.mode));
25   EXPECT_EQ(ProxyPrefs::MODE_DIRECT, h.mode);
26   ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
27   ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
28   ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
29 }
30 
TEST(ProxyConfigDictionaryTest,CreateAutoDetect)31 TEST(ProxyConfigDictionaryTest, CreateAutoDetect) {
32   scoped_ptr<DictionaryValue> dict_value(
33       ProxyConfigDictionary::CreateAutoDetect());
34   ProxyConfigDictionary dict(dict_value.get());
35   ProxyConfigHolder h;
36 
37   ASSERT_TRUE(dict.GetMode(&h.mode));
38   EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, h.mode);
39   ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
40   ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
41   ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
42 }
43 
TEST(ProxyConfigDictionaryTest,CreatePacScript)44 TEST(ProxyConfigDictionaryTest, CreatePacScript) {
45   scoped_ptr<DictionaryValue> dict_value(
46       ProxyConfigDictionary::CreatePacScript("pac"));
47   ProxyConfigDictionary dict(dict_value.get());
48   ProxyConfigHolder h;
49 
50   ASSERT_TRUE(dict.GetMode(&h.mode));
51   EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, h.mode);
52   ASSERT_TRUE(dict.GetPacUrl(&h.bypass_list));
53   EXPECT_EQ("pac", h.bypass_list);
54   ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
55   ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
56 }
57 
TEST(ProxyConfigDictionaryTest,CreateFixedServers)58 TEST(ProxyConfigDictionaryTest, CreateFixedServers) {
59   scoped_ptr<DictionaryValue> dict_value(
60       ProxyConfigDictionary::CreateFixedServers("http://1.2.3.4",
61                                                 "http://foo"));
62   ProxyConfigDictionary dict(dict_value.get());
63   ProxyConfigHolder h;
64 
65   ASSERT_TRUE(dict.GetMode(&h.mode));
66   EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, h.mode);
67   ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
68   ASSERT_TRUE(dict.GetProxyServer(&h.proxy_server));
69   EXPECT_EQ("http://1.2.3.4", h.proxy_server);
70   ASSERT_TRUE(dict.GetBypassList(&h.bypass_list));
71   EXPECT_EQ("http://foo", h.bypass_list);
72 }
73 
TEST(ProxyConfigDictionaryTest,CreateSystem)74 TEST(ProxyConfigDictionaryTest, CreateSystem) {
75   scoped_ptr<DictionaryValue> dict_value(ProxyConfigDictionary::CreateSystem());
76   ProxyConfigDictionary dict(dict_value.get());
77   ProxyConfigHolder h;
78 
79   ASSERT_TRUE(dict.GetMode(&h.mode));
80   EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, h.mode);
81   ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
82   ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
83   ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
84 }
85