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/base/net_util.h" | 5 #include "net/base/net_util.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
24 | 24 |
25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
26 #include <iphlpapi.h> | 26 #include <iphlpapi.h> |
27 #include <objbase.h> | 27 #include <objbase.h> |
28 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
29 #elif !defined(OS_ANDROID) | 29 #elif !defined(OS_ANDROID) |
30 #include <net/if.h> | 30 #include <net/if.h> |
31 #endif // OS_WIN | 31 #endif // OS_WIN |
32 | 32 |
| 33 using base::ASCIIToUTF16; |
| 34 using base::WideToUTF16; |
| 35 |
33 namespace net { | 36 namespace net { |
34 | 37 |
35 namespace { | 38 namespace { |
36 | 39 |
37 static const size_t kNpos = base::string16::npos; | 40 static const size_t kNpos = base::string16::npos; |
38 | 41 |
39 struct FileCase { | 42 struct FileCase { |
40 const wchar_t* file; | 43 const wchar_t* file; |
41 const char* url; | 44 const char* url; |
42 }; | 45 }; |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 std::string out; | 489 std::string out; |
487 for (size_t i = 0; i < v.size(); ++i) { | 490 for (size_t i = 0; i < v.size(); ++i) { |
488 if (i != 0) | 491 if (i != 0) |
489 out.append(","); | 492 out.append(","); |
490 out.append(base::IntToString(static_cast<int>(v[i]))); | 493 out.append(base::IntToString(static_cast<int>(v[i]))); |
491 } | 494 } |
492 return out; | 495 return out; |
493 } | 496 } |
494 | 497 |
495 void RunGenerateFileNameTestCase(const GenerateFilenameCase* test_case) { | 498 void RunGenerateFileNameTestCase(const GenerateFilenameCase* test_case) { |
496 std::string default_filename(WideToUTF8(test_case->default_filename)); | 499 std::string default_filename(base::WideToUTF8(test_case->default_filename)); |
497 base::FilePath file_path = GenerateFileName( | 500 base::FilePath file_path = GenerateFileName( |
498 GURL(test_case->url), test_case->content_disp_header, | 501 GURL(test_case->url), test_case->content_disp_header, |
499 test_case->referrer_charset, test_case->suggested_filename, | 502 test_case->referrer_charset, test_case->suggested_filename, |
500 test_case->mime_type, default_filename); | 503 test_case->mime_type, default_filename); |
501 EXPECT_EQ(test_case->expected_filename, | 504 EXPECT_EQ(test_case->expected_filename, |
502 file_util::FilePathAsWString(file_path)) | 505 file_util::FilePathAsWString(file_path)) |
503 << "test case at line number: " << test_case->lineno; | 506 << "test case at line number: " << test_case->lineno; |
504 } | 507 } |
505 | 508 |
506 } // anonymous namespace | 509 } // anonymous namespace |
(...skipping 2830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3337 reinterpret_cast<ConvertInterfaceLuidToGuid>( | 3340 reinterpret_cast<ConvertInterfaceLuidToGuid>( |
3338 phlpapi_lib.GetFunctionPointer("ConvertInterfaceLuidToGuid")); | 3341 phlpapi_lib.GetFunctionPointer("ConvertInterfaceLuidToGuid")); |
3339 | 3342 |
3340 if (interface_to_luid && luid_to_guid) { | 3343 if (interface_to_luid && luid_to_guid) { |
3341 NET_LUID luid; | 3344 NET_LUID luid; |
3342 EXPECT_EQ(interface_to_luid(it->interface_index, &luid), NO_ERROR); | 3345 EXPECT_EQ(interface_to_luid(it->interface_index, &luid), NO_ERROR); |
3343 GUID guid; | 3346 GUID guid; |
3344 EXPECT_EQ(luid_to_guid(&luid, &guid), NO_ERROR); | 3347 EXPECT_EQ(luid_to_guid(&luid, &guid), NO_ERROR); |
3345 LPOLESTR name; | 3348 LPOLESTR name; |
3346 StringFromCLSID(guid, &name); | 3349 StringFromCLSID(guid, &name); |
3347 EXPECT_STREQ(UTF8ToWide(it->name).c_str(), name); | 3350 EXPECT_STREQ(base::UTF8ToWide(it->name).c_str(), name); |
3348 CoTaskMemFree(name); | 3351 CoTaskMemFree(name); |
3349 continue; | 3352 continue; |
3350 } else { | 3353 } else { |
3351 EXPECT_LT(base::win::GetVersion(), base::win::VERSION_VISTA); | 3354 EXPECT_LT(base::win::GetVersion(), base::win::VERSION_VISTA); |
3352 EXPECT_LT(it->interface_index, 1u << 24u); // Must fit 0.x.x.x. | 3355 EXPECT_LT(it->interface_index, 1u << 24u); // Must fit 0.x.x.x. |
3353 EXPECT_NE(it->interface_index, 0u); // 0 means to use default. | 3356 EXPECT_NE(it->interface_index, 0u); // 0 means to use default. |
3354 } | 3357 } |
3355 #elif !defined(OS_ANDROID) | 3358 #elif !defined(OS_ANDROID) |
3356 char name[IF_NAMESIZE]; | 3359 char name[IF_NAMESIZE]; |
3357 EXPECT_TRUE(if_indextoname(it->interface_index, name)); | 3360 EXPECT_TRUE(if_indextoname(it->interface_index, name)); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3516 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { | 3519 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { |
3517 const NonUniqueNameTestData& test_data = GetParam(); | 3520 const NonUniqueNameTestData& test_data = GetParam(); |
3518 | 3521 |
3519 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); | 3522 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); |
3520 } | 3523 } |
3521 | 3524 |
3522 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, | 3525 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, |
3523 testing::ValuesIn(kNonUniqueNameTestData)); | 3526 testing::ValuesIn(kNonUniqueNameTestData)); |
3524 | 3527 |
3525 } // namespace net | 3528 } // namespace net |
OLD | NEW |