blob: 8d88eb3b3957a09537527cfc5b8a1bfb7f112acf [file] [log] [blame]
[email protected]96ce22362009-03-27 20:19:571// Copyright (c) 2009 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 "net/proxy/proxy_config_service_win.h"
6
7#include "net/base/net_errors.h"
8#include "net/proxy/proxy_config.h"
9#include "testing/gtest/include/gtest/gtest.h"
10
11namespace net {
12
13TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
14 const struct {
15 // Input.
16 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config;
17
18 // Expected outputs (fields of the ProxyConfig).
19 bool auto_detect;
20 GURL pac_url;
21 const char* proxy_rules;
22 const char* proxy_bypass_list; // newline separated
23 bool bypass_local_names;
24 } tests[] = {
25 // Auto detect.
26 {
27 { // Input.
28 TRUE, // fAutoDetect
29 NULL, // lpszAutoConfigUrl
30 NULL, // lpszProxy
31 NULL, // lpszProxyBypass
32 },
33
34 // Expected result.
35 true, // auto_detect
36 GURL(), // pac_url
37 "", // proxy_rules
38 "", // proxy_bypass_list
39 false, // bypass_local_names
40 },
41
42 // Valid PAC url
43 {
44 { // Input.
45 FALSE, // fAutoDetect
46 L"http://wpad/wpad.dat", // lpszAutoConfigUrl
47 NULL, // lpszProxy
48 NULL, // lpszProxy_bypass
49 },
50
51 // Expected result.
52 false, // auto_detect
53 GURL("http://wpad/wpad.dat"), // pac_url
54 "", // proxy_rules
55 "", // proxy_bypass_list
56 false, // bypass_local_names
57 },
58
59 // Invalid PAC url string.
60 {
61 { // Input.
62 FALSE, // fAutoDetect
63 L"wpad.dat", // lpszAutoConfigUrl
64 NULL, // lpszProxy
65 NULL, // lpszProxy_bypass
66 },
67
68 // Expected result.
69 false, // auto_detect
70 GURL(), // pac_url
71 "", // proxy_rules
72 "", // proxy_bypass_list
73 false, // bypass_local_names
74 },
75
76 // Single-host in proxy list.
77 {
78 { // Input.
79 FALSE, // fAutoDetect
80 NULL, // lpszAutoConfigUrl
81 L"www.google.com", // lpszProxy
82 NULL, // lpszProxy_bypass
83 },
84
85 // Expected result.
86 false, // auto_detect
87 GURL(), // pac_url
88 "www.google.com", // proxy_rules
89 "", // proxy_bypass_list
90 false, // bypass_local_names
91 },
92
93 // Bypass local names.
94 {
95 { // Input.
96 TRUE, // fAutoDetect
97 NULL, // lpszAutoConfigUrl
98 NULL, // lpszProxy
99 L"<local>", // lpszProxy_bypass
100 },
101
102 true, // auto_detect
103 GURL(), // pac_url
104 "", // proxy_rules
105 "", // proxy_bypass_list
106 true, // bypass_local_names
107 },
108
109 // Bypass "google.com" and local names, using semicolon as delimeter
110 // (ignoring white space).
111 {
112 { // Input.
113 TRUE, // fAutoDetect
114 NULL, // lpszAutoConfigUrl
115 NULL, // lpszProxy
116 L"<local> ; google.com", // lpszProxy_bypass
117 },
118
119 // Expected result.
120 true, // auto_detect
121 GURL(), // pac_url
122 "", // proxy_rules
123 "google.com\n", // proxy_bypass_list
124 true, // bypass_local_names
125 },
126
127 // Bypass "foo.com" and "google.com", using lines as delimeter.
128 {
129 { // Input.
130 TRUE, // fAutoDetect
131 NULL, // lpszAutoConfigUrl
132 NULL, // lpszProxy
133 L"foo.com\r\ngoogle.com", // lpszProxy_bypass
134 },
135
136 // Expected result.
137 true, // auto_detect
138 GURL(), // pac_url
139 "", // proxy_rules
140 "foo.com\ngoogle.com\n", // proxy_bypass_list
141 false, // bypass_local_names
142 },
143 };
144
145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
146 ProxyConfig config;
147 ProxyConfigServiceWin::SetFromIEConfig(&config, tests[i].ie_config);
148
149 EXPECT_EQ(tests[i].auto_detect, config.auto_detect);
150 EXPECT_EQ(tests[i].pac_url, config.pac_url);
151
152 // Join the proxy bypass list using "\n" to make it into a single string.
153 std::string flattened_proxy_bypass;
154 typedef std::vector<std::string> BypassList;
155 for (BypassList::const_iterator it = config.proxy_bypass.begin();
156 it != config.proxy_bypass.end(); ++it) {
157 flattened_proxy_bypass += *it + "\n";
158 }
159
160 EXPECT_EQ(tests[i].proxy_bypass_list, flattened_proxy_bypass);
161 EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names);
162 EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules);
163 }
164}
165
166} // namespace net