| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/stringprintf.h" |
| 11 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 13 #include "base/time.h" |
| 12 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 13 #include "base/time.h" | |
| 14 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 15 #include "net/base/sys_addrinfo.h" | 16 #include "net/base/sys_addrinfo.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 class NetUtilTest : public testing::Test { | 21 class NetUtilTest : public testing::Test { |
| 21 }; | 22 }; |
| 22 | 23 |
| 23 struct FileCase { | 24 struct FileCase { |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 "use+rname", | 610 "use+rname", |
| 610 "password", | 611 "password", |
| 611 }, | 612 }, |
| 612 { // Use a '&' in the password. | 613 { // Use a '&' in the password. |
| 613 "http://username:p&ssword@google.com", | 614 "http://username:p&ssword@google.com", |
| 614 "username", | 615 "username", |
| 615 "p&ssword", | 616 "p&ssword", |
| 616 }, | 617 }, |
| 617 }; | 618 }; |
| 618 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 619 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 619 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url)); | 620 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
| 621 tests[i].input_url)); |
| 620 GURL url(tests[i].input_url); | 622 GURL url(tests[i].input_url); |
| 621 | 623 |
| 622 string16 username, password; | 624 string16 username, password; |
| 623 net::GetIdentityFromURL(url, &username, &password); | 625 net::GetIdentityFromURL(url, &username, &password); |
| 624 | 626 |
| 625 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_username), username); | 627 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_username), username); |
| 626 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_password), password); | 628 EXPECT_EQ(ASCIIToUTF16(tests[i].expected_password), password); |
| 627 } | 629 } |
| 628 } | 630 } |
| 629 | 631 |
| (...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 { // Try an FTP URL -- strip both the reference and the username/password. | 1861 { // Try an FTP URL -- strip both the reference and the username/password. |
| 1860 "ftp://user:pass@google.com:80/sup?yo#X#X", | 1862 "ftp://user:pass@google.com:80/sup?yo#X#X", |
| 1861 "ftp://google.com:80/sup?yo", | 1863 "ftp://google.com:80/sup?yo", |
| 1862 }, | 1864 }, |
| 1863 { // Try an nonstandard URL | 1865 { // Try an nonstandard URL |
| 1864 "foobar://user:pass@google.com:80/sup?yo#X#X", | 1866 "foobar://user:pass@google.com:80/sup?yo#X#X", |
| 1865 "foobar://user:pass@google.com:80/sup?yo#X#X", | 1867 "foobar://user:pass@google.com:80/sup?yo#X#X", |
| 1866 }, | 1868 }, |
| 1867 }; | 1869 }; |
| 1868 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 1870 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 1869 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url)); | 1871 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
| 1872 tests[i].input_url)); |
| 1870 GURL input_url(GURL(tests[i].input_url)); | 1873 GURL input_url(GURL(tests[i].input_url)); |
| 1871 GURL expected_url(GURL(tests[i].expected_simplified_url)); | 1874 GURL expected_url(GURL(tests[i].expected_simplified_url)); |
| 1872 EXPECT_EQ(expected_url, net::SimplifyUrlForRequest(input_url)); | 1875 EXPECT_EQ(expected_url, net::SimplifyUrlForRequest(input_url)); |
| 1873 } | 1876 } |
| 1874 } | 1877 } |
| 1875 | 1878 |
| 1876 TEST(NetUtilTest, SetExplicitlyAllowedPortsTest) { | 1879 TEST(NetUtilTest, SetExplicitlyAllowedPortsTest) { |
| 1877 std::string invalid[] = { "1,2,a", "'1','2'", "1, 2, 3", "1 0,11,12" }; | 1880 std::string invalid[] = { "1,2,a", "'1','2'", "1, 2, 3", "1 0,11,12" }; |
| 1878 std::string valid[] = { "", "1", "1,2", "1,2,3", "10,11,12,13" }; | 1881 std::string valid[] = { "", "1", "1,2", "1,2,3", "10,11,12,13" }; |
| 1879 | 1882 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 "::ffff:0a0b:89", | 2033 "::ffff:0a0b:89", |
| 2031 true | 2034 true |
| 2032 }, | 2035 }, |
| 2033 { | 2036 { |
| 2034 "10.11.33.44/16", | 2037 "10.11.33.44/16", |
| 2035 "::ffff:10.12.33.44", | 2038 "::ffff:10.12.33.44", |
| 2036 false | 2039 false |
| 2037 }, | 2040 }, |
| 2038 }; | 2041 }; |
| 2039 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 2042 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 2040 SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s, %s", i, | 2043 SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s, %s", i, |
| 2041 tests[i].cidr_literal, | 2044 tests[i].cidr_literal, |
| 2042 tests[i].ip_literal)); | 2045 tests[i].ip_literal)); |
| 2043 | 2046 |
| 2044 net::IPAddressNumber ip_number; | 2047 net::IPAddressNumber ip_number; |
| 2045 EXPECT_TRUE(net::ParseIPLiteralToNumber(tests[i].ip_literal, &ip_number)); | 2048 EXPECT_TRUE(net::ParseIPLiteralToNumber(tests[i].ip_literal, &ip_number)); |
| 2046 | 2049 |
| 2047 net::IPAddressNumber ip_prefix; | 2050 net::IPAddressNumber ip_prefix; |
| 2048 size_t prefix_length_in_bits; | 2051 size_t prefix_length_in_bits; |
| 2049 | 2052 |
| 2050 EXPECT_TRUE(net::ParseCIDRBlock(tests[i].cidr_literal, | 2053 EXPECT_TRUE(net::ParseCIDRBlock(tests[i].cidr_literal, |
| 2051 &ip_prefix, | 2054 &ip_prefix, |
| 2052 &prefix_length_in_bits)); | 2055 &prefix_length_in_bits)); |
| 2053 | 2056 |
| 2054 EXPECT_EQ(tests[i].expected_to_match, | 2057 EXPECT_EQ(tests[i].expected_to_match, |
| 2055 net::IPNumberMatchesPrefix(ip_number, | 2058 net::IPNumberMatchesPrefix(ip_number, |
| 2056 ip_prefix, | 2059 ip_prefix, |
| 2057 prefix_length_in_bits)); | 2060 prefix_length_in_bits)); |
| 2058 } | 2061 } |
| 2059 } | 2062 } |
| OLD | NEW |