Chromium Code Reviews| 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 // Some simple structs without constructors to enable brace style | |
| 18 // initialization in these tests. | |
| 19 struct RegStringInit { | |
| 20 internal::DnsSystemSettings::RegString toRegString() const { | |
| 21 internal::DnsSystemSettings::RegString regString; | |
| 22 regString.set = set; | |
| 23 regString.value = value; | |
| 24 return regString; | |
| 25 } | |
| 26 | |
| 27 bool set; | |
| 28 base::string16 value; | |
| 29 }; | |
| 30 | |
| 31 struct RegDwordInit { | |
| 32 internal::DnsSystemSettings::RegDword toRegDword() const { | |
| 33 internal::DnsSystemSettings::RegDword regDword; | |
| 34 regDword.set = set; | |
| 35 regDword.value = value; | |
| 36 return regDword; | |
| 37 } | |
| 38 | |
| 39 bool set; | |
| 40 DWORD value; | |
| 41 }; | |
| 42 | |
| 43 struct DevolutionSettingInit { | |
| 44 internal::DnsSystemSettings::DevolutionSetting toDevolutionSetting() const { | |
| 45 internal::DnsSystemSettings::DevolutionSetting setting; | |
| 46 setting.enabled = enabled.toRegDword(); | |
| 47 setting.level = level.toRegDword(); | |
| 48 return setting; | |
| 49 } | |
| 50 | |
| 51 RegDwordInit enabled; | |
| 52 RegDwordInit level; | |
| 53 }; | |
| 54 | |
| 17 TEST(DnsConfigServiceWinTest, ParseSearchList) { | 55 TEST(DnsConfigServiceWinTest, ParseSearchList) { |
| 18 const struct TestCase { | 56 const struct TestCase { |
| 19 const wchar_t* input; | 57 const wchar_t* input; |
| 20 const char* output[4]; // NULL-terminated, empty if expected false | 58 const char* output[4]; // NULL-terminated, empty if expected false |
| 21 } cases[] = { | 59 } cases[] = { |
| 22 { L"chromium.org", { "chromium.org", NULL } }, | 60 { L"chromium.org", { "chromium.org", NULL } }, |
| 23 { L"chromium.org,org", { "chromium.org", "org", NULL } }, | 61 { L"chromium.org,org", { "chromium.org", "org", NULL } }, |
| 24 // Empty suffixes terminate the list | 62 // Empty suffixes terminate the list |
| 25 { L"crbug.com,com,,org", { "crbug.com", "com", NULL } }, | 63 { L"crbug.com,com,,org", { "crbug.com", "com", NULL } }, |
| 26 // IDN are converted to punycode | 64 // IDN are converted to punycode |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 } | 236 } |
| 199 | 237 |
| 200 TEST(DnsConfigServiceWinTest, ConvertSuffixSearch) { | 238 TEST(DnsConfigServiceWinTest, ConvertSuffixSearch) { |
| 201 AdapterInfo infos[2] = { | 239 AdapterInfo infos[2] = { |
| 202 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, | 240 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, |
| 203 { 0 }, | 241 { 0 }, |
| 204 }; | 242 }; |
| 205 | 243 |
| 206 const struct TestCase { | 244 const struct TestCase { |
| 207 struct { | 245 struct { |
| 208 internal::DnsSystemSettings::RegString policy_search_list; | 246 RegStringInit policy_search_list; |
| 209 internal::DnsSystemSettings::RegString tcpip_search_list; | 247 RegStringInit tcpip_search_list; |
| 210 internal::DnsSystemSettings::RegString tcpip_domain; | 248 RegStringInit tcpip_domain; |
| 211 internal::DnsSystemSettings::RegString primary_dns_suffix; | 249 RegStringInit primary_dns_suffix; |
| 212 internal::DnsSystemSettings::DevolutionSetting policy_devolution; | 250 DevolutionSettingInit policy_devolution; |
| 213 internal::DnsSystemSettings::DevolutionSetting dnscache_devolution; | 251 DevolutionSettingInit dnscache_devolution; |
| 214 internal::DnsSystemSettings::DevolutionSetting tcpip_devolution; | 252 DevolutionSettingInit tcpip_devolution; |
| 215 } input_settings; | 253 } input_settings; |
| 216 std::string expected_search[5]; | 254 std::string expected_search[5]; |
| 217 } cases[] = { | 255 } cases[] = { |
| 218 { // Policy SearchList override. | 256 { // Policy SearchList override. |
| 219 { | 257 { |
| 220 { true, L"policy.searchlist.a,policy.searchlist.b" }, | 258 { true, L"policy.searchlist.a,policy.searchlist.b" }, |
| 221 { true, L"tcpip.searchlist.a,tcpip.searchlist.b" }, | 259 { true, L"tcpip.searchlist.a,tcpip.searchlist.b" }, |
| 222 { true, L"tcpip.domain" }, | 260 { true, L"tcpip.domain" }, |
| 223 { true, L"primary.dns.suffix" }, | 261 { true, L"primary.dns.suffix" }, |
|
Nico
2015/05/11 04:08:29
Huh, I thought that using a brace initializer for
benwells
2015/05/11 05:12:38
The problem was elsewhere, with these changes fall
| |
| 224 }, | 262 }, |
| 225 { "policy.searchlist.a", "policy.searchlist.b" }, | 263 { "policy.searchlist.a", "policy.searchlist.b" }, |
| 226 }, | 264 }, |
| 227 { // User-specified SearchList override. | 265 { // User-specified SearchList override. |
| 228 { | 266 { |
| 229 { false }, | 267 { false }, |
| 230 { true, L"tcpip.searchlist.a,tcpip.searchlist.b" }, | 268 { true, L"tcpip.searchlist.a,tcpip.searchlist.b" }, |
| 231 { true, L"tcpip.domain" }, | 269 { true, L"tcpip.domain" }, |
| 232 { true, L"primary.dns.suffix" }, | 270 { true, L"primary.dns.suffix" }, |
| 233 }, | 271 }, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 { { false }, { true, 3 } }, | 400 { { false }, { true, 3 } }, |
| 363 { { true, 0 }, { true, 3 } }, | 401 { { true, 0 }, { true, 3 } }, |
| 364 }, | 402 }, |
| 365 { "a.b.c.d.e", "connection.suffix" }, | 403 { "a.b.c.d.e", "connection.suffix" }, |
| 366 }, | 404 }, |
| 367 }; | 405 }; |
| 368 | 406 |
| 369 for (auto& t : cases) { | 407 for (auto& t : cases) { |
| 370 internal::DnsSystemSettings settings; | 408 internal::DnsSystemSettings settings; |
| 371 settings.addresses = CreateAdapterAddresses(infos); | 409 settings.addresses = CreateAdapterAddresses(infos); |
| 372 settings.policy_search_list = t.input_settings.policy_search_list; | 410 settings.policy_search_list = |
| 373 settings.tcpip_search_list = t.input_settings.tcpip_search_list; | 411 t.input_settings.policy_search_list.toRegString(); |
| 374 settings.tcpip_domain = t.input_settings.tcpip_domain; | 412 settings.tcpip_search_list = |
| 375 settings.primary_dns_suffix = t.input_settings.primary_dns_suffix; | 413 t.input_settings.tcpip_search_list.toRegString(); |
| 376 settings.policy_devolution = t.input_settings.policy_devolution; | 414 settings.tcpip_domain = t.input_settings.tcpip_domain.toRegString(); |
| 377 settings.dnscache_devolution = t.input_settings.dnscache_devolution; | 415 settings.primary_dns_suffix = |
| 378 settings.tcpip_devolution = t.input_settings.tcpip_devolution; | 416 t.input_settings.primary_dns_suffix.toRegString(); |
| 417 settings.policy_devolution = | |
| 418 t.input_settings.policy_devolution.toDevolutionSetting(); | |
| 419 settings.dnscache_devolution = | |
| 420 t.input_settings.dnscache_devolution.toDevolutionSetting(); | |
| 421 settings.tcpip_devolution = | |
| 422 t.input_settings.tcpip_devolution.toDevolutionSetting(); | |
| 379 | 423 |
| 380 DnsConfig config; | 424 DnsConfig config; |
| 381 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, | 425 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, |
| 382 internal::ConvertSettingsToDnsConfig(settings, &config)); | 426 internal::ConvertSettingsToDnsConfig(settings, &config)); |
| 383 std::vector<std::string> expected_search; | 427 std::vector<std::string> expected_search; |
| 384 for (size_t j = 0; !t.expected_search[j].empty(); ++j) { | 428 for (size_t j = 0; !t.expected_search[j].empty(); ++j) { |
| 385 expected_search.push_back(t.expected_search[j]); | 429 expected_search.push_back(t.expected_search[j]); |
| 386 } | 430 } |
| 387 EXPECT_EQ(expected_search, config.search); | 431 EXPECT_EQ(expected_search, config.search); |
| 388 } | 432 } |
| 389 } | 433 } |
| 390 | 434 |
| 391 TEST(DnsConfigServiceWinTest, AppendToMultiLabelName) { | 435 TEST(DnsConfigServiceWinTest, AppendToMultiLabelName) { |
| 392 AdapterInfo infos[2] = { | 436 AdapterInfo infos[2] = { |
| 393 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, | 437 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, |
| 394 { 0 }, | 438 { 0 }, |
| 395 }; | 439 }; |
| 396 | 440 |
| 397 // The default setting was true pre-Vista. | 441 // The default setting was true pre-Vista. |
| 398 bool default_value = (base::win::GetVersion() < base::win::VERSION_VISTA); | 442 bool default_value = (base::win::GetVersion() < base::win::VERSION_VISTA); |
| 399 | 443 |
| 400 const struct TestCase { | 444 const struct TestCase { |
| 401 internal::DnsSystemSettings::RegDword input; | 445 RegDwordInit input; |
| 402 bool expected_output; | 446 bool expected_output; |
| 403 } cases[] = { | 447 } cases[] = { |
| 404 { { true, 0 }, false }, | 448 { { true, 0 }, false }, |
| 405 { { true, 1 }, true }, | 449 { { true, 1 }, true }, |
| 406 { { false, 0 }, default_value }, | 450 { { false, 0 }, default_value }, |
| 407 }; | 451 }; |
| 408 | 452 |
| 409 for (const auto& t : cases) { | 453 for (const auto& t : cases) { |
| 410 internal::DnsSystemSettings settings; | 454 internal::DnsSystemSettings settings; |
| 411 settings.addresses = CreateAdapterAddresses(infos); | 455 settings.addresses = CreateAdapterAddresses(infos); |
| 412 settings.append_to_multi_label_name = t.input; | 456 settings.append_to_multi_label_name = t.input.toRegDword(); |
| 413 DnsConfig config; | 457 DnsConfig config; |
| 414 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, | 458 EXPECT_EQ(internal::CONFIG_PARSE_WIN_OK, |
| 415 internal::ConvertSettingsToDnsConfig(settings, &config)); | 459 internal::ConvertSettingsToDnsConfig(settings, &config)); |
| 416 EXPECT_EQ(t.expected_output, config.append_to_multi_label_name); | 460 EXPECT_EQ(t.expected_output, config.append_to_multi_label_name); |
| 417 } | 461 } |
| 418 } | 462 } |
| 419 | 463 |
| 420 // Setting have_name_resolution_policy_table should set unhandled_options. | 464 // Setting have_name_resolution_policy_table should set unhandled_options. |
| 421 TEST(DnsConfigServiceWinTest, HaveNRPT) { | 465 TEST(DnsConfigServiceWinTest, HaveNRPT) { |
| 422 AdapterInfo infos[2] = { | 466 AdapterInfo infos[2] = { |
| 423 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, | 467 { IF_TYPE_USB, IfOperStatusUp, L"connection.suffix", { "1.0.0.1" } }, |
| 424 { 0 }, | 468 { 0 }, |
| 425 }; | 469 }; |
| 426 | 470 |
| 427 const struct TestCase { | 471 const struct TestCase { |
| 428 bool have_nrpt; | 472 bool have_nrpt; |
| 429 bool unhandled_options; | 473 bool unhandled_options; |
| 430 internal::ConfigParseWinResult result; | 474 internal::ConfigParseWinResult result; |
| 431 } cases[] = { | 475 } cases[] = { |
| 432 { false, false, internal::CONFIG_PARSE_WIN_OK }, | 476 { false, false, internal::CONFIG_PARSE_WIN_OK }, |
| 433 { true, true, internal::CONFIG_PARSE_WIN_UNHANDLED_OPTIONS }, | 477 { true, true, internal::CONFIG_PARSE_WIN_UNHANDLED_OPTIONS }, |
| 434 }; | 478 }; |
| 435 | 479 |
| 436 for (const auto& t : cases) { | 480 for (const auto& t : cases) { |
| 437 internal::DnsSystemSettings settings; | 481 internal::DnsSystemSettings settings; |
| 438 settings.addresses = CreateAdapterAddresses(infos); | 482 settings.addresses = CreateAdapterAddresses(infos); |
| 439 settings.have_name_resolution_policy = t.have_nrpt; | 483 settings.have_name_resolution_policy = t.have_nrpt; |
| 440 DnsConfig config; | 484 DnsConfig config; |
| 441 EXPECT_EQ(t.result, | 485 EXPECT_EQ(t.result, |
| 442 internal::ConvertSettingsToDnsConfig(settings, &config)); | 486 internal::ConvertSettingsToDnsConfig(settings, &config)); |
|
benwells
2015/05/11 05:12:38
This was the line causing the error that I investi
| |
| 443 EXPECT_EQ(t.unhandled_options, config.unhandled_options); | 487 EXPECT_EQ(t.unhandled_options, config.unhandled_options); |
| 444 EXPECT_EQ(t.have_nrpt, config.use_local_ipv6); | 488 EXPECT_EQ(t.have_nrpt, config.use_local_ipv6); |
| 445 } | 489 } |
| 446 } | 490 } |
| 447 | 491 |
| 448 | 492 |
| 449 } // namespace | 493 } // namespace |
| 450 | 494 |
| 451 } // namespace net | 495 } // namespace net |
| 452 | 496 |
| OLD | NEW |