blob: c1c311d60b09935406e20867f7869eace2a20e1b [file] [log] [blame]
[email protected]c2f23d012011-02-09 14:52:171// 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
dcheng82beb4f2016-04-26 00:35:025#include "components/proxy_config/proxy_config_dictionary.h"
6
7#include <memory>
[email protected]c2f23d012011-02-09 14:52:178#include <string>
vabr6f6e2662017-03-31 08:08:339#include <utility>
[email protected]c2f23d012011-02-09 14:52:1710
[email protected]c2f23d012011-02-09 14:52:1711#include "base/values.h"
[email protected]c2f23d012011-02-09 14:52:1712#include "testing/gtest/include/gtest/gtest.h"
13
14struct ProxyConfigHolder {
15 ProxyPrefs::ProxyMode mode;
16 std::string pac_url;
17 std::string proxy_server;
18 std::string bypass_list;
19};
20
21TEST(ProxyConfigDictionaryTest, CreateDirect) {
Steven Bennetts3e470ac2018-07-27 18:29:2722 ProxyConfigDictionary dict(ProxyConfigDictionary::CreateDirect());
[email protected]c2f23d012011-02-09 14:52:1723 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
32TEST(ProxyConfigDictionaryTest, CreateAutoDetect) {
Steven Bennetts3e470ac2018-07-27 18:29:2733 ProxyConfigDictionary dict(ProxyConfigDictionary::CreateAutoDetect());
[email protected]c2f23d012011-02-09 14:52:1734 ProxyConfigHolder h;
35
36 ASSERT_TRUE(dict.GetMode(&h.mode));
37 EXPECT_EQ(ProxyPrefs::MODE_AUTO_DETECT, h.mode);
38 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
39 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
40 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
41}
42
43TEST(ProxyConfigDictionaryTest, CreatePacScript) {
Steven Bennetts3e470ac2018-07-27 18:29:2744 ProxyConfigDictionary dict(
45 ProxyConfigDictionary::CreatePacScript("pac", false));
[email protected]c2f23d012011-02-09 14:52:1746 ProxyConfigHolder h;
47
48 ASSERT_TRUE(dict.GetMode(&h.mode));
49 EXPECT_EQ(ProxyPrefs::MODE_PAC_SCRIPT, h.mode);
50 ASSERT_TRUE(dict.GetPacUrl(&h.bypass_list));
51 EXPECT_EQ("pac", h.bypass_list);
52 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
53 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
54}
55
56TEST(ProxyConfigDictionaryTest, CreateFixedServers) {
Steven Bennetts3e470ac2018-07-27 18:29:2757 ProxyConfigDictionary dict(ProxyConfigDictionary::CreateFixedServers(
58 "http://1.2.3.4", "http://foo"));
[email protected]c2f23d012011-02-09 14:52:1759 ProxyConfigHolder h;
60
61 ASSERT_TRUE(dict.GetMode(&h.mode));
62 EXPECT_EQ(ProxyPrefs::MODE_FIXED_SERVERS, h.mode);
63 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
64 ASSERT_TRUE(dict.GetProxyServer(&h.proxy_server));
65 EXPECT_EQ("http://1.2.3.4", h.proxy_server);
66 ASSERT_TRUE(dict.GetBypassList(&h.bypass_list));
67 EXPECT_EQ("http://foo", h.bypass_list);
68}
69
70TEST(ProxyConfigDictionaryTest, CreateSystem) {
Steven Bennetts3e470ac2018-07-27 18:29:2771 ProxyConfigDictionary dict(ProxyConfigDictionary::CreateSystem());
[email protected]c2f23d012011-02-09 14:52:1772 ProxyConfigHolder h;
73
74 ASSERT_TRUE(dict.GetMode(&h.mode));
75 EXPECT_EQ(ProxyPrefs::MODE_SYSTEM, h.mode);
76 ASSERT_FALSE(dict.GetPacUrl(&h.bypass_list));
77 ASSERT_FALSE(dict.GetProxyServer(&h.proxy_server));
78 ASSERT_FALSE(dict.GetBypassList(&h.bypass_list));
79}