OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/dns/dns_config_service_win.h" | 5 #include "net/dns/dns_config_service_win.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
10 #include "net/dns/dns_protocol.h" | 10 #include "net/dns/dns_protocol.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 TEST(DnsConfigServiceWinTest, ParseSearchList) { | 17 TEST(DnsConfigServiceWinTest, ParseSearchList) { |
18 const struct TestCase { | 18 const struct TestCase { |
19 const wchar_t* input; | 19 const wchar_t* input; |
20 const char* output[4]; // NULL-terminated, empty if expected false | 20 const char* output[4]; // NULL-terminated, empty if expected false |
21 } cases[] = { | 21 } cases[] = { |
22 { L"chromium.org", { "chromium.org", NULL } }, | 22 {L"chromium.org", {"chromium.org", NULL}}, |
23 { L"chromium.org,org", { "chromium.org", "org", NULL } }, | 23 {L"chromium.org,org", {"chromium.org", "org", NULL}}, |
24 // Empty suffixes terminate the list | 24 // Empty suffixes terminate the list |
25 { L"crbug.com,com,,org", { "crbug.com", "com", NULL } }, | 25 {L"crbug.com,com,,org", {"crbug.com", "com", NULL}}, |
26 // IDN are converted to punycode | 26 // IDN are converted to punycode |
27 { L"\u017c\xf3\u0142ta.pi\u0119\u015b\u0107.pl,pl", | 27 {L"\u017c\xf3\u0142ta.pi\u0119\u015b\u0107.pl,pl", |
28 { "xn--ta-4ja03asj.xn--pi-wla5e0q.pl", "pl", NULL } }, | 28 {"xn--ta-4ja03asj.xn--pi-wla5e0q.pl", "pl", NULL}}, |
29 // Empty search list is invalid | 29 // Empty search list is invalid |
30 { L"", { NULL } }, | 30 {L"", {NULL}}, |
31 { L",,", { NULL } }, | 31 {L",,", {NULL}}, |
32 }; | 32 }; |
33 | 33 |
34 std::vector<std::string> actual_output, expected_output; | 34 std::vector<std::string> actual_output, expected_output; |
35 for (unsigned i = 0; i < arraysize(cases); ++i) { | 35 for (unsigned i = 0; i < arraysize(cases); ++i) { |
36 const TestCase& t = cases[i]; | 36 const TestCase& t = cases[i]; |
37 actual_output.clear(); | 37 actual_output.clear(); |
38 actual_output.push_back("UNSET"); | 38 actual_output.push_back("UNSET"); |
39 expected_output.clear(); | 39 expected_output.clear(); |
40 for (const char* const* output = t.output; *output; ++output) { | 40 for (const char* const* output = t.output; *output; ++output) { |
41 expected_output.push_back(*output); | 41 expected_output.push_back(*output); |
42 } | 42 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 TEST(DnsConfigServiceWinTest, ConvertAdapterAddresses) { | 117 TEST(DnsConfigServiceWinTest, ConvertAdapterAddresses) { |
118 // Check nameservers and connection-specific suffix. | 118 // Check nameservers and connection-specific suffix. |
119 const struct TestCase { | 119 const struct TestCase { |
120 AdapterInfo input_adapters[4]; // |if_type| == 0 indicates end. | 120 AdapterInfo input_adapters[4]; // |if_type| == 0 indicates end. |
121 std::string expected_nameservers[4]; // Empty string indicates end. | 121 std::string expected_nameservers[4]; // Empty string indicates end. |
122 std::string expected_suffix; | 122 std::string expected_suffix; |
123 int expected_ports[4]; | 123 int expected_ports[4]; |
124 } cases[] = { | 124 } cases[] = { |
125 { // Ignore loopback and inactive adapters. | 125 {// Ignore loopback and inactive adapters. |
126 { | 126 { |
127 { IF_TYPE_SOFTWARE_LOOPBACK, IfOperStatusUp, L"funnyloop", | 127 {IF_TYPE_SOFTWARE_LOOPBACK, |
128 { "2.0.0.2" } }, | 128 IfOperStatusUp, |
129 { IF_TYPE_FASTETHER, IfOperStatusDormant, L"example.com", | 129 L"funnyloop", |
130 { "1.0.0.1" } }, | 130 {"2.0.0.2"}}, |
131 { IF_TYPE_USB, IfOperStatusUp, L"chromium.org", | 131 {IF_TYPE_FASTETHER, IfOperStatusDormant, L"example.com", {"1.0.0.1"}}, |
132 { "10.0.0.10", "2001:FFFF::1111" } }, | 132 {IF_TYPE_USB, |
133 { 0 }, | 133 IfOperStatusUp, |
134 }, | 134 L"chromium.org", |
135 { "10.0.0.10", "2001:FFFF::1111" }, | 135 {"10.0.0.10", "2001:FFFF::1111"}}, |
136 "chromium.org", | 136 {0}, |
137 }, | 137 }, |
138 { // Respect configured ports. | 138 {"10.0.0.10", "2001:FFFF::1111"}, |
139 { | 139 "chromium.org", |
140 { IF_TYPE_USB, IfOperStatusUp, L"chromium.org", | 140 }, |
141 { "10.0.0.10", "2001:FFFF::1111" }, { 1024, 24 } }, | 141 {// Respect configured ports. |
142 { 0 }, | 142 { |
143 }, | 143 {IF_TYPE_USB, |
144 { "10.0.0.10", "2001:FFFF::1111" }, | 144 IfOperStatusUp, |
145 "chromium.org", | 145 L"chromium.org", |
146 { 1024, 24 }, | 146 {"10.0.0.10", "2001:FFFF::1111"}, |
147 }, | 147 {1024, 24}}, |
148 { // Use the preferred adapter (first in binding order) and filter | 148 {0}, |
149 // stateless DNS discovery addresses. | 149 }, |
150 { | 150 {"10.0.0.10", "2001:FFFF::1111"}, |
151 { IF_TYPE_SOFTWARE_LOOPBACK, IfOperStatusUp, L"funnyloop", | 151 "chromium.org", |
152 { "2.0.0.2" } }, | 152 {1024, 24}, |
153 { IF_TYPE_FASTETHER, IfOperStatusUp, L"example.com", | 153 }, |
154 { "1.0.0.1", "fec0:0:0:ffff::2", "8.8.8.8" } }, | 154 {// Use the preferred adapter (first in binding order) and filter |
155 { IF_TYPE_USB, IfOperStatusUp, L"chromium.org", | 155 // stateless DNS discovery addresses. |
156 { "10.0.0.10", "2001:FFFF::1111" } }, | 156 { |
157 { 0 }, | 157 {IF_TYPE_SOFTWARE_LOOPBACK, |
158 }, | 158 IfOperStatusUp, |
159 { "1.0.0.1", "8.8.8.8" }, | 159 L"funnyloop", |
160 "example.com", | 160 {"2.0.0.2"}}, |
161 }, | 161 {IF_TYPE_FASTETHER, |
162 { // No usable adapters. | 162 IfOperStatusUp, |
163 { | 163 L"example.com", |
164 { IF_TYPE_SOFTWARE_LOOPBACK, IfOperStatusUp, L"localhost", | 164 {"1.0.0.1", "fec0:0:0:ffff::2", "8.8.8.8"}}, |
165 { "2.0.0.2" } }, | 165 {IF_TYPE_USB, |
166 { IF_TYPE_FASTETHER, IfOperStatusDormant, L"example.com", | 166 IfOperStatusUp, |
167 { "1.0.0.1" } }, | 167 L"chromium.org", |
168 { IF_TYPE_USB, IfOperStatusUp, L"chromium.org" }, | 168 {"10.0.0.10", "2001:FFFF::1111"}}, |
169 { 0 }, | 169 {0}, |
170 }, | 170 }, |
171 }, | 171 {"1.0.0.1", "8.8.8.8"}, |
172 }; | 172 "example.com", |
| 173 }, |
| 174 {// No usable adapters. |
| 175 { |
| 176 {IF_TYPE_SOFTWARE_LOOPBACK, |
| 177 IfOperStatusUp, |
| 178 L"localhost", |
| 179 {"2.0.0.2"}}, |
| 180 {IF_TYPE_FASTETHER, IfOperStatusDormant, L"example.com", {"1.0.0.1"}}, |
| 181 {IF_TYPE_USB, IfOperStatusUp, L"chromium.org"}, |
| 182 {0}, |
| 183 }, |
| 184 }, |
| 185 }; |
173 | 186 |
174 for (size_t i = 0; i < arraysize(cases); ++i) { | 187 for (size_t i = 0; i < arraysize(cases); ++i) { |
175 const TestCase& t = cases[i]; | 188 const TestCase& t = cases[i]; |
176 internal::DnsSystemSettings settings = { | 189 internal::DnsSystemSettings settings = { |
177 CreateAdapterAddresses(t.input_adapters), | 190 CreateAdapterAddresses(t.input_adapters), |
178 // Default settings for the rest. | 191 // Default settings for the rest. |
179 }; | 192 }; |
180 std::vector<IPEndPoint> expected_nameservers; | 193 std::vector<IPEndPoint> expected_nameservers; |
181 for (size_t j = 0; !t.expected_nameservers[j].empty(); ++j) { | 194 for (size_t j = 0; !t.expected_nameservers[j].empty(); ++j) { |
182 IPAddressNumber ip; | 195 IPAddressNumber ip; |
183 ASSERT_TRUE(ParseIPLiteralToNumber(t.expected_nameservers[j], &ip)); | 196 ASSERT_TRUE(ParseIPLiteralToNumber(t.expected_nameservers[j], &ip)); |
184 int port = t.expected_ports[j]; | 197 int port = t.expected_ports[j]; |
185 if (!port) | 198 if (!port) |
186 port = dns_protocol::kDefaultPort; | 199 port = dns_protocol::kDefaultPort; |
187 expected_nameservers.push_back(IPEndPoint(ip, port)); | 200 expected_nameservers.push_back(IPEndPoint(ip, port)); |
188 } | 201 } |
189 | 202 |
190 DnsConfig config; | 203 DnsConfig config; |
191 internal::ConfigParseWinResult result = | 204 internal::ConfigParseWinResult result = |
192 internal::ConvertSettingsToDnsConfig(settings, &config); | 205 internal::ConvertSettingsToDnsConfig(settings, &config); |
193 internal::ConfigParseWinResult expected_result = | 206 internal::ConfigParseWinResult expected_result = |
194 expected_nameservers.empty() ? internal::CONFIG_PARSE_WIN_NO_NAMESERVERS | 207 expected_nameservers.empty() ? internal::CONFIG_PARSE_WIN_NO_NAMESERVERS |
195 : internal::CONFIG_PARSE_WIN_OK; | 208 : internal::CONFIG_PARSE_WIN_OK; |
196 EXPECT_EQ(expected_result, result); | 209 EXPECT_EQ(expected_result, result); |
197 EXPECT_EQ(expected_nameservers, config.nameservers); | 210 EXPECT_EQ(expected_nameservers, config.nameservers); |
198 if (result == internal::CONFIG_PARSE_WIN_OK) { | 211 if (result == internal::CONFIG_PARSE_WIN_OK) { |
199 ASSERT_EQ(1u, config.search.size()); | 212 ASSERT_EQ(1u, config.search.size()); |
200 EXPECT_EQ(t.expected_suffix, config.search[0]); | 213 EXPECT_EQ(t.expected_suffix, config.search[0]); |
201 } | 214 } |
202 } | 215 } |
203 } | 216 } |
204 | 217 |
205 TEST(DnsConfigServiceWinTest, ConvertSuffixSearch) { | 218 TEST(DnsConfigServiceWinTest, ConvertSuffixSearch) { |
206 AdapterInfo infos[2] = { | 219 AdapterInfo infos[2] = { |
207 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, | 220 {IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", {"1.0.0.1"}}, {0}, |
208 { 0 }, | |
209 }; | 221 }; |
210 | 222 |
211 const struct TestCase { | 223 const struct TestCase { |
212 internal::DnsSystemSettings input_settings; | 224 internal::DnsSystemSettings input_settings; |
213 std::string expected_search[5]; | 225 std::string expected_search[5]; |
214 } cases[] = { | 226 } cases[] = { |
215 { // Policy SearchList override. | 227 {// Policy SearchList override. |
216 { | 228 { |
217 CreateAdapterAddresses(infos), | 229 CreateAdapterAddresses(infos), |
218 { true, L"policy.searchlist.a,policy.searchlist.b" }, | 230 {true, L"policy.searchlist.a,policy.searchlist.b"}, |
219 { true, L"tcpip.searchlist.a,tcpip.searchlist.b" }, | 231 {true, L"tcpip.searchlist.a,tcpip.searchlist.b"}, |
220 { true, L"tcpip.domain" }, | 232 {true, L"tcpip.domain"}, |
221 { true, L"primary.dns.suffix" }, | 233 {true, L"primary.dns.suffix"}, |
222 }, | 234 }, |
223 { "policy.searchlist.a", "policy.searchlist.b" }, | 235 {"policy.searchlist.a", "policy.searchlist.b"}, |
224 }, | 236 }, |
225 { // User-specified SearchList override. | 237 {// User-specified SearchList override. |
226 { | 238 { |
227 CreateAdapterAddresses(infos), | 239 CreateAdapterAddresses(infos), |
228 { false }, | 240 {false}, |
229 { true, L"tcpip.searchlist.a,tcpip.searchlist.b" }, | 241 {true, L"tcpip.searchlist.a,tcpip.searchlist.b"}, |
230 { true, L"tcpip.domain" }, | 242 {true, L"tcpip.domain"}, |
231 { true, L"primary.dns.suffix" }, | 243 {true, L"primary.dns.suffix"}, |
232 }, | 244 }, |
233 { "tcpip.searchlist.a", "tcpip.searchlist.b" }, | 245 {"tcpip.searchlist.a", "tcpip.searchlist.b"}, |
234 }, | 246 }, |
235 { // Void SearchList. Using tcpip.domain | 247 {// Void SearchList. Using tcpip.domain |
236 { | 248 { |
237 CreateAdapterAddresses(infos), | 249 CreateAdapterAddresses(infos), |
238 { true, L",bad.searchlist,parsed.as.empty" }, | 250 {true, L",bad.searchlist,parsed.as.empty"}, |
239 { true, L"tcpip.searchlist,good.but.overridden" }, | 251 {true, L"tcpip.searchlist,good.but.overridden"}, |
240 { true, L"tcpip.domain" }, | 252 {true, L"tcpip.domain"}, |
241 { false }, | 253 {false}, |
242 }, | 254 }, |
243 { "tcpip.domain", "connection.suffix" }, | 255 {"tcpip.domain", "connection.suffix"}, |
244 }, | 256 }, |
245 { // Void SearchList. Using primary.dns.suffix | 257 {// Void SearchList. Using primary.dns.suffix |
246 { | 258 { |
247 CreateAdapterAddresses(infos), | 259 CreateAdapterAddresses(infos), |
248 { true, L",bad.searchlist,parsed.as.empty" }, | 260 {true, L",bad.searchlist,parsed.as.empty"}, |
249 { true, L"tcpip.searchlist,good.but.overridden" }, | 261 {true, L"tcpip.searchlist,good.but.overridden"}, |
250 { true, L"tcpip.domain" }, | 262 {true, L"tcpip.domain"}, |
251 { true, L"primary.dns.suffix" }, | 263 {true, L"primary.dns.suffix"}, |
252 }, | 264 }, |
253 { "primary.dns.suffix", "connection.suffix" }, | 265 {"primary.dns.suffix", "connection.suffix"}, |
254 }, | 266 }, |
255 { // Void SearchList. Using tcpip.domain when primary.dns.suffix is empty | 267 {// Void SearchList. Using tcpip.domain when primary.dns.suffix is empty |
256 { | 268 { |
257 CreateAdapterAddresses(infos), | 269 CreateAdapterAddresses(infos), |
258 { true, L",bad.searchlist,parsed.as.empty" }, | 270 {true, L",bad.searchlist,parsed.as.empty"}, |
259 { true, L"tcpip.searchlist,good.but.overridden" }, | 271 {true, L"tcpip.searchlist,good.but.overridden"}, |
260 { true, L"tcpip.domain" }, | 272 {true, L"tcpip.domain"}, |
261 { true, L"" }, | 273 {true, L""}, |
262 }, | 274 }, |
263 { "tcpip.domain", "connection.suffix" }, | 275 {"tcpip.domain", "connection.suffix"}, |
264 }, | 276 }, |
265 { // Void SearchList. Using tcpip.domain when primary.dns.suffix is NULL | 277 {// Void SearchList. Using tcpip.domain when primary.dns.suffix is NULL |
266 { | 278 { |
267 CreateAdapterAddresses(infos), | 279 CreateAdapterAddresses(infos), |
268 { true, L",bad.searchlist,parsed.as.empty" }, | 280 {true, L",bad.searchlist,parsed.as.empty"}, |
269 { true, L"tcpip.searchlist,good.but.overridden" }, | 281 {true, L"tcpip.searchlist,good.but.overridden"}, |
270 { true, L"tcpip.domain" }, | 282 {true, L"tcpip.domain"}, |
271 { true }, | 283 {true}, |
272 }, | 284 }, |
273 { "tcpip.domain", "connection.suffix" }, | 285 {"tcpip.domain", "connection.suffix"}, |
274 }, | 286 }, |
275 { // No primary suffix. Devolution does not matter. | 287 {// No primary suffix. Devolution does not matter. |
276 { | 288 { |
277 CreateAdapterAddresses(infos), | 289 CreateAdapterAddresses(infos), |
278 { false }, | 290 {false}, |
279 { false }, | 291 {false}, |
280 { true }, | 292 {true}, |
281 { true }, | 293 {true}, |
282 { { true, 1 }, { true, 2 } }, | 294 {{true, 1}, {true, 2}}, |
283 }, | 295 }, |
284 { "connection.suffix" }, | 296 {"connection.suffix"}, |
285 }, | 297 }, |
286 { // Devolution enabled by policy, level by dnscache. | 298 {// Devolution enabled by policy, level by dnscache. |
287 { | 299 { |
288 CreateAdapterAddresses(infos), | 300 CreateAdapterAddresses(infos), |
289 { false }, | 301 {false}, |
290 { false }, | 302 {false}, |
291 { true, L"a.b.c.d.e" }, | 303 {true, L"a.b.c.d.e"}, |
292 { false }, | 304 {false}, |
293 { { true, 1 }, { false } }, // policy_devolution: enabled, level | 305 {{true, 1}, {false}}, // policy_devolution: enabled, level |
294 { { true, 0 }, { true, 3 } }, // dnscache_devolution | 306 {{true, 0}, {true, 3}}, // dnscache_devolution |
295 { { true, 0 }, { true, 1 } }, // tcpip_devolution | 307 {{true, 0}, {true, 1}}, // tcpip_devolution |
296 }, | 308 }, |
297 { "a.b.c.d.e", "connection.suffix", "b.c.d.e", "c.d.e" }, | 309 {"a.b.c.d.e", "connection.suffix", "b.c.d.e", "c.d.e"}, |
298 }, | 310 }, |
299 { // Devolution enabled by dnscache, level by policy. | 311 {// Devolution enabled by dnscache, level by policy. |
300 { | 312 { |
301 CreateAdapterAddresses(infos), | 313 CreateAdapterAddresses(infos), |
302 { false }, | 314 {false}, |
303 { false }, | 315 {false}, |
304 { true, L"a.b.c.d.e" }, | 316 {true, L"a.b.c.d.e"}, |
305 { true, L"f.g.i.l.j" }, | 317 {true, L"f.g.i.l.j"}, |
306 { { false }, { true, 4 } }, | 318 {{false}, {true, 4}}, |
307 { { true, 1 }, { false } }, | 319 {{true, 1}, {false}}, |
308 { { true, 0 }, { true, 3 } }, | 320 {{true, 0}, {true, 3}}, |
309 }, | 321 }, |
310 { "f.g.i.l.j", "connection.suffix", "g.i.l.j" }, | 322 {"f.g.i.l.j", "connection.suffix", "g.i.l.j"}, |
311 }, | 323 }, |
312 { // Devolution enabled by default. | 324 {// Devolution enabled by default. |
313 { | 325 { |
314 CreateAdapterAddresses(infos), | 326 CreateAdapterAddresses(infos), |
315 { false }, | 327 {false}, |
316 { false }, | 328 {false}, |
317 { true, L"a.b.c.d.e" }, | 329 {true, L"a.b.c.d.e"}, |
318 { false }, | 330 {false}, |
319 { { false }, { false } }, | 331 {{false}, {false}}, |
320 { { false }, { true, 3 } }, | 332 {{false}, {true, 3}}, |
321 { { false }, { true, 1 } }, | 333 {{false}, {true, 1}}, |
322 }, | 334 }, |
323 { "a.b.c.d.e", "connection.suffix", "b.c.d.e", "c.d.e" }, | 335 {"a.b.c.d.e", "connection.suffix", "b.c.d.e", "c.d.e"}, |
324 }, | 336 }, |
325 { // Devolution enabled at level = 2, but nothing to devolve. | 337 {// Devolution enabled at level = 2, but nothing to devolve. |
326 { | 338 { |
327 CreateAdapterAddresses(infos), | 339 CreateAdapterAddresses(infos), |
328 { false }, | 340 {false}, |
329 { false }, | 341 {false}, |
330 { true, L"a.b" }, | 342 {true, L"a.b"}, |
331 { false }, | 343 {false}, |
332 { { false }, { false } }, | 344 {{false}, {false}}, |
333 { { false }, { true, 2 } }, | 345 {{false}, {true, 2}}, |
334 { { false }, { true, 2 } }, | 346 {{false}, {true, 2}}, |
335 }, | 347 }, |
336 { "a.b", "connection.suffix" }, | 348 {"a.b", "connection.suffix"}, |
337 }, | 349 }, |
338 { // Devolution disabled when no explicit level. | 350 {// Devolution disabled when no explicit level. |
339 // Windows XP and Vista use a default level = 2, but we don't. | 351 // Windows XP and Vista use a default level = 2, but we don't. |
340 { | 352 { |
341 CreateAdapterAddresses(infos), | 353 CreateAdapterAddresses(infos), |
342 { false }, | 354 {false}, |
343 { false }, | 355 {false}, |
344 { true, L"a.b.c.d.e" }, | 356 {true, L"a.b.c.d.e"}, |
345 { false }, | 357 {false}, |
346 { { true, 1 }, { false } }, | 358 {{true, 1}, {false}}, |
347 { { true, 1 }, { false } }, | 359 {{true, 1}, {false}}, |
348 { { true, 1 }, { false } }, | 360 {{true, 1}, {false}}, |
349 }, | 361 }, |
350 { "a.b.c.d.e", "connection.suffix" }, | 362 {"a.b.c.d.e", "connection.suffix"}, |
351 }, | 363 }, |
352 { // Devolution disabled by policy level. | 364 {// Devolution disabled by policy level. |
353 { | 365 { |
354 CreateAdapterAddresses(infos), | 366 CreateAdapterAddresses(infos), |
355 { false }, | 367 {false}, |
356 { false }, | 368 {false}, |
357 { true, L"a.b.c.d.e" }, | 369 {true, L"a.b.c.d.e"}, |
358 { false }, | 370 {false}, |
359 { { false }, { true, 1 } }, | 371 {{false}, {true, 1}}, |
360 { { true, 1 }, { true, 3 } }, | 372 {{true, 1}, {true, 3}}, |
361 { { true, 1 }, { true, 4 } }, | 373 {{true, 1}, {true, 4}}, |
362 }, | 374 }, |
363 { "a.b.c.d.e", "connection.suffix" }, | 375 {"a.b.c.d.e", "connection.suffix"}, |
364 }, | 376 }, |
365 { // Devolution disabled by user setting. | 377 {// Devolution disabled by user setting. |
366 { | 378 { |
367 CreateAdapterAddresses(infos), | 379 CreateAdapterAddresses(infos), |
368 { false }, | 380 {false}, |
369 { false }, | 381 {false}, |
370 { true, L"a.b.c.d.e" }, | 382 {true, L"a.b.c.d.e"}, |
371 { false }, | 383 {false}, |
372 { { false }, { true, 3 } }, | 384 {{false}, {true, 3}}, |
373 { { false }, { true, 3 } }, | 385 {{false}, {true, 3}}, |
374 { { true, 0 }, { true, 3 } }, | 386 {{true, 0}, {true, 3}}, |
375 }, | 387 }, |
376 { "a.b.c.d.e", "connection.suffix" }, | 388 {"a.b.c.d.e", "connection.suffix"}, |
377 }, | 389 }, |
378 }; | 390 }; |
379 | 391 |
380 for (size_t i = 0; i < arraysize(cases); ++i) { | 392 for (size_t i = 0; i < arraysize(cases); ++i) { |
381 const TestCase& t = cases[i]; | 393 const TestCase& t = cases[i]; |
382 DnsConfig config; | 394 DnsConfig config; |
383 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, | 395 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, |
384 internal::ConvertSettingsToDnsConfig(t.input_settings, &config)); | 396 internal::ConvertSettingsToDnsConfig(t.input_settings, &config)); |
385 std::vector<std::string> expected_search; | 397 std::vector<std::string> expected_search; |
386 for (size_t j = 0; !t.expected_search[j].empty(); ++j) { | 398 for (size_t j = 0; !t.expected_search[j].empty(); ++j) { |
387 expected_search.push_back(t.expected_search[j]); | 399 expected_search.push_back(t.expected_search[j]); |
388 } | 400 } |
389 EXPECT_EQ(expected_search, config.search); | 401 EXPECT_EQ(expected_search, config.search); |
390 } | 402 } |
391 } | 403 } |
392 | 404 |
393 TEST(DnsConfigServiceWinTest, AppendToMultiLabelName) { | 405 TEST(DnsConfigServiceWinTest, AppendToMultiLabelName) { |
394 AdapterInfo infos[2] = { | 406 AdapterInfo infos[2] = { |
395 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, | 407 {IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", {"1.0.0.1"}}, {0}, |
396 { 0 }, | |
397 }; | 408 }; |
398 | 409 |
399 // The default setting was true pre-Vista. | 410 // The default setting was true pre-Vista. |
400 bool default_value = (base::win::GetVersion() < base::win::VERSION_VISTA); | 411 bool default_value = (base::win::GetVersion() < base::win::VERSION_VISTA); |
401 | 412 |
402 const struct TestCase { | 413 const struct TestCase { |
403 internal::DnsSystemSettings::RegDword input; | 414 internal::DnsSystemSettings::RegDword input; |
404 bool expected_output; | 415 bool expected_output; |
405 } cases[] = { | 416 } cases[] = { |
406 { { true, 0 }, false }, | 417 {{true, 0}, false}, {{true, 1}, true}, {{false, 0}, default_value}, |
407 { { true, 1 }, true }, | 418 }; |
408 { { false, 0 }, default_value }, | |
409 }; | |
410 | 419 |
411 for (size_t i = 0; i < arraysize(cases); ++i) { | 420 for (size_t i = 0; i < arraysize(cases); ++i) { |
412 const TestCase& t = cases[i]; | 421 const TestCase& t = cases[i]; |
413 internal::DnsSystemSettings settings = { | 422 internal::DnsSystemSettings settings = { |
414 CreateAdapterAddresses(infos), | 423 CreateAdapterAddresses(infos), |
415 { false }, { false }, { false }, { false }, | 424 {false}, |
416 { { false }, { false } }, | 425 {false}, |
417 { { false }, { false } }, | 426 {false}, |
418 { { false }, { false } }, | 427 {false}, |
419 t.input, | 428 {{false}, {false}}, |
| 429 {{false}, {false}}, |
| 430 {{false}, {false}}, |
| 431 t.input, |
420 }; | 432 }; |
421 DnsConfig config; | 433 DnsConfig config; |
422 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, | 434 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, |
423 internal::ConvertSettingsToDnsConfig(settings, &config)); | 435 internal::ConvertSettingsToDnsConfig(settings, &config)); |
424 EXPECT_EQ(t.expected_output, config.append_to_multi_label_name); | 436 EXPECT_EQ(t.expected_output, config.append_to_multi_label_name); |
425 } | 437 } |
426 } | 438 } |
427 | 439 |
428 // Setting have_name_resolution_policy_table should set unhandled_options. | 440 // Setting have_name_resolution_policy_table should set unhandled_options. |
429 TEST(DnsConfigServiceWinTest, HaveNRPT) { | 441 TEST(DnsConfigServiceWinTest, HaveNRPT) { |
430 AdapterInfo infos[2] = { | 442 AdapterInfo infos[2] = { |
431 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, | 443 {IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", {"1.0.0.1"}}, {0}, |
432 { 0 }, | |
433 }; | 444 }; |
434 | 445 |
435 const struct TestCase { | 446 const struct TestCase { |
436 bool have_nrpt; | 447 bool have_nrpt; |
437 bool unhandled_options; | 448 bool unhandled_options; |
438 internal::ConfigParseWinResult result; | 449 internal::ConfigParseWinResult result; |
439 } cases[] = { | 450 } cases[] = { |
440 { false, false, internal::CONFIG_PARSE_WIN_OK }, | 451 {false, false, internal::CONFIG_PARSE_WIN_OK}, |
441 { true, true, internal::CONFIG_PARSE_WIN_UNHANDLED_OPTIONS }, | 452 {true, true, internal::CONFIG_PARSE_WIN_UNHANDLED_OPTIONS}, |
442 }; | 453 }; |
443 | 454 |
444 for (size_t i = 0; i < arraysize(cases); ++i) { | 455 for (size_t i = 0; i < arraysize(cases); ++i) { |
445 const TestCase& t = cases[i]; | 456 const TestCase& t = cases[i]; |
446 internal::DnsSystemSettings settings = { | 457 internal::DnsSystemSettings settings = { |
447 CreateAdapterAddresses(infos), | 458 CreateAdapterAddresses(infos), |
448 { false }, { false }, { false }, { false }, | 459 {false}, |
449 { { false }, { false } }, | 460 {false}, |
450 { { false }, { false } }, | 461 {false}, |
451 { { false }, { false } }, | 462 {false}, |
452 { false }, | 463 {{false}, {false}}, |
453 t.have_nrpt, | 464 {{false}, {false}}, |
| 465 {{false}, {false}}, |
| 466 {false}, |
| 467 t.have_nrpt, |
454 }; | 468 }; |
455 DnsConfig config; | 469 DnsConfig config; |
456 EXPECT_EQ(t.result, | 470 EXPECT_EQ(t.result, |
457 internal::ConvertSettingsToDnsConfig(settings, &config)); | 471 internal::ConvertSettingsToDnsConfig(settings, &config)); |
458 EXPECT_EQ(t.unhandled_options, config.unhandled_options); | 472 EXPECT_EQ(t.unhandled_options, config.unhandled_options); |
459 EXPECT_EQ(t.have_nrpt, config.use_local_ipv6); | 473 EXPECT_EQ(t.have_nrpt, config.use_local_ipv6); |
460 } | 474 } |
461 } | 475 } |
462 | 476 |
463 | |
464 } // namespace | 477 } // namespace |
465 | 478 |
466 } // namespace net | 479 } // namespace net |
467 | |
OLD | NEW |