Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / components / proxy_config / proxy_config_dictionary_unittest.cc
blobca73ab0647f068364ebf2b28d199a0aef8167f85
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.
5 #include <string>
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
9 #include "components/proxy_config/proxy_config_dictionary.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 struct ProxyConfigHolder {
13 ProxyPrefs::ProxyMode mode;
14 std::string pac_url;
15 std::string proxy_server;
16 std::string bypass_list;
19 TEST(ProxyConfigDictionaryTest, CreateDirect) {
20 scoped_ptr<base::DictionaryValue> dict_value(
21 ProxyConfigDictionary::CreateDirect());
22 ProxyConfigDictionary dict(dict_value.get());
23 ProxyConfigHolder h;
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));
32 TEST(ProxyConfigDictionaryTest, CreateAutoDetect) {
33 scoped_ptr<base::DictionaryValue> dict_value(
34 ProxyConfigDictionary::CreateAutoDetect());
35 ProxyConfigDictionary dict(dict_value.get());
36 ProxyConfigHolder h;
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));
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;
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));
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;
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);
75 TEST(ProxyConfigDictionaryTest, CreateSystem) {
76 scoped_ptr<base::DictionaryValue> dict_value(
77 ProxyConfigDictionary::CreateSystem());
78 ProxyConfigDictionary dict(dict_value.get());
79 ProxyConfigHolder h;
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));