Chromium Code Reviews| Index: net/base/net_util_unittest.cc |
| diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc |
| index 0e17f1a13b76f92abd45821d6633389d4ae530e6..c1d4c301f0f1c2414f430fb8ed747eda56ce3982 100644 |
| --- a/net/base/net_util_unittest.cc |
| +++ b/net/base/net_util_unittest.cc |
| @@ -82,45 +82,43 @@ TEST(NetUtilTest, GetIdentityFromURL) { |
| const char* expected_username; |
| const char* expected_password; |
| } tests[] = { |
| - { |
| - "http://username:password@google.com", |
| - "username", |
| - "password", |
| - }, |
| - { // Test for http://crbug.com/19200 |
| - "http://username:p@ssword@google.com", |
| - "username", |
| - "p@ssword", |
| - }, |
| - { // Special URL characters should be unescaped. |
| - "http://username:p%3fa%26s%2fs%23@google.com", |
| - "username", |
| - "p?a&s/s#", |
| - }, |
| - { // Username contains %20. |
| - "http://use rname:password@google.com", |
| - "use rname", |
| - "password", |
| - }, |
| - { // Keep %00 as is. |
| - "http://use%00rname:password@google.com", |
| - "use%00rname", |
| - "password", |
| - }, |
| - { // Use a '+' in the username. |
| - "http://use+rname:password@google.com", |
| - "use+rname", |
| - "password", |
| - }, |
| - { // Use a '&' in the password. |
| - "http://username:p&ssword@google.com", |
| - "username", |
| - "p&ssword", |
| - }, |
| - }; |
| + { |
| + "http://username:password@google.com", "username", "password", |
| + }, |
| + {// Test for http://crbug.com/19200 |
| + "http://username:p@ssword@google.com", |
| + "username", |
| + "p@ssword", |
| + }, |
| + {// Special URL characters should be unescaped. |
| + "http://username:p%3fa%26s%2fs%23@google.com", |
| + "username", |
| + "p?a&s/s#", |
| + }, |
| + {// Username contains %20. |
| + "http://use rname:password@google.com", |
| + "use rname", |
| + "password", |
| + }, |
| + {// Keep %00 as is. |
| + "http://use%00rname:password@google.com", |
| + "use%00rname", |
| + "password", |
| + }, |
| + {// Use a '+' in the username. |
| + "http://use+rname:password@google.com", |
| + "use+rname", |
| + "password", |
| + }, |
| + {// Use a '&' in the password. |
| + "http://username:p&ssword@google.com", |
| + "username", |
| + "p&ssword", |
| + }, |
| + }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| - SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
| - tests[i].input_url)); |
| + SCOPED_TRACE( |
| + base::StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url)); |
| GURL url(tests[i].input_url); |
| base::string16 username, password; |
| @@ -160,7 +158,7 @@ const char* google_headers = |
| "Set-Cookie: HEHE_AT=6666x66beef666x6-66xx6666x66; Path=/mail\n" |
| "Set-Cookie: HEHE_HELP=owned:0;Path=/\n" |
| "Set-Cookie: S=gmail=Xxx-beefbeefbeef_beefb:gmail_yj=beefbeef000beefbee" |
| - "fbee:gmproxy=bee-fbeefbe; Domain=.google.com; Path=/\n" |
| + "fbee:gmproxy=bee-fbeefbe; Domain=.google.com; Path=/\n" |
| "X-Google-Google2: /one/two/three/four/five/six/seven-height/nine:9411\n" |
| "Server: GFE/1.3\n" |
| "Transfer-Encoding: chunked\n" |
| @@ -172,11 +170,11 @@ const char* google_headers = |
| TEST(NetUtilTest, GetSpecificHeader) { |
| const HeaderCase tests[] = { |
| - {"content-type", "text/html; charset=utf-8"}, |
| - {"CONTENT-LENGTH", "378557"}, |
| - {"Date", "Mon, 13 Nov 2006 21:38:09 GMT"}, |
| - {"Bad-Header", ""}, |
| - {"", ""}, |
| + {"content-type", "text/html; charset=utf-8"}, |
| + {"CONTENT-LENGTH", "378557"}, |
| + {"Date", "Mon, 13 Nov 2006 21:38:09 GMT"}, |
| + {"Bad-Header", ""}, |
| + {"", ""}, |
| }; |
| // Test first with google_headers. |
| @@ -200,28 +198,28 @@ TEST(NetUtilTest, CompliantHost) { |
| }; |
| const CompliantHostCase compliant_host_cases[] = { |
| - {"", false}, |
| - {"a", true}, |
| - {"-", false}, |
| - {".", false}, |
| - {"9", true}, |
| - {"9a", true}, |
| - {"a.", true}, |
| - {"a.a", true}, |
| - {"9.a", true}, |
| - {"a.9", true}, |
| - {"_9a", false}, |
| - {"-9a", false}, |
| - {"a.a9", true}, |
| - {"a.-a9", false}, |
| - {"a+9a", false}, |
| - {"-a.a9", true}, |
| - {"1-.a-b", true}, |
| - {"1_.a-b", false}, |
| - {"1-2.a_b", true}, |
| - {"a.b.c.d.e", true}, |
| - {"1.2.3.4.5", true}, |
| - {"1.2.3.4.5.", true}, |
| + {"", false}, |
| + {"a", true}, |
| + {"-", false}, |
| + {".", false}, |
| + {"9", true}, |
| + {"9a", true}, |
| + {"a.", true}, |
| + {"a.a", true}, |
| + {"9.a", true}, |
| + {"a.9", true}, |
| + {"_9a", false}, |
| + {"-9a", false}, |
| + {"a.a9", true}, |
| + {"a.-a9", false}, |
| + {"a+9a", false}, |
| + {"-a.a9", true}, |
| + {"1-.a-b", true}, |
| + {"1_.a-b", false}, |
| + {"1-2.a_b", true}, |
| + {"a.b.c.d.e", true}, |
| + {"1.2.3.4.5", true}, |
| + {"1.2.3.4.5.", true}, |
| }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(compliant_host_cases); ++i) { |
| @@ -236,43 +234,39 @@ TEST(NetUtilTest, ParseHostAndPort) { |
| bool success; |
| const char* expected_host; |
| int expected_port; |
| - } tests[] = { |
| - // Valid inputs: |
| - {"foo:10", true, "foo", 10}, |
| - {"foo", true, "foo", -1}, |
| - { |
| - "[1080:0:0:0:8:800:200C:4171]:11", |
| - true, |
| - "1080:0:0:0:8:800:200C:4171", |
| - 11 |
| - }, |
| - { |
| - "[1080:0:0:0:8:800:200C:4171]", |
| - true, |
| - "1080:0:0:0:8:800:200C:4171", |
| - -1 |
| - }, |
| - |
| - // Because no validation is done on the host, the following are accepted, |
| - // even though they are invalid names. |
| - {"]", true, "]", -1}, |
| - {"::1", true, ":", 1}, |
| - // Invalid inputs: |
| - {"foo:bar", false, "", -1}, |
| - {"foo:", false, "", -1}, |
| - {":", false, "", -1}, |
| - {":80", false, "", -1}, |
| - {"", false, "", -1}, |
| - {"porttoolong:300000", false, "", -1}, |
| - {"usrname@host", false, "", -1}, |
| - {"usrname:password@host", false, "", -1}, |
| - {":password@host", false, "", -1}, |
| - {":password@host:80", false, "", -1}, |
| - {":password@host", false, "", -1}, |
| - {"@host", false, "", -1}, |
| - {"[", false, "", -1}, |
| - {"[]", false, "", -1}, |
| - }; |
| + } tests[] = {// Valid inputs: |
| + {"foo:10", true, "foo", 10}, |
|
davidben
2014/10/10 20:24:16
This looks worth a bug. I think it overlaps with a
|
| + {"foo", true, "foo", -1}, |
| + {"[1080:0:0:0:8:800:200C:4171]:11", |
| + true, |
| + "1080:0:0:0:8:800:200C:4171", |
| + 11}, |
| + {"[1080:0:0:0:8:800:200C:4171]", |
| + true, |
| + "1080:0:0:0:8:800:200C:4171", |
| + -1}, |
| + |
| + // Because no validation is done on the host, the following are |
| + // accepted, |
| + // even though they are invalid names. |
| + {"]", true, "]", -1}, |
| + {"::1", true, ":", 1}, |
| + // Invalid inputs: |
| + {"foo:bar", false, "", -1}, |
| + {"foo:", false, "", -1}, |
| + {":", false, "", -1}, |
| + {":80", false, "", -1}, |
| + {"", false, "", -1}, |
| + {"porttoolong:300000", false, "", -1}, |
| + {"usrname@host", false, "", -1}, |
| + {"usrname:password@host", false, "", -1}, |
| + {":password@host", false, "", -1}, |
| + {":password@host:80", false, "", -1}, |
| + {":password@host", false, "", -1}, |
| + {"@host", false, "", -1}, |
| + {"[", false, "", -1}, |
| + {"[]", false, "", -1}, |
| + }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| std::string host; |
| @@ -293,13 +287,13 @@ TEST(NetUtilTest, GetHostAndPort) { |
| GURL url; |
| const char* expected_host_and_port; |
| } tests[] = { |
| - { GURL("http://www.foo.com/x"), "www.foo.com:80"}, |
| - { GURL("http://www.foo.com:21/x"), "www.foo.com:21"}, |
| + {GURL("http://www.foo.com/x"), "www.foo.com:80"}, |
| + {GURL("http://www.foo.com:21/x"), "www.foo.com:21"}, |
| - // For IPv6 literals should always include the brackets. |
| - { GURL("http://[1::2]/x"), "[1::2]:80"}, |
| - { GURL("http://[::a]:33/x"), "[::a]:33"}, |
| - }; |
| + // For IPv6 literals should always include the brackets. |
| + {GURL("http://[1::2]/x"), "[1::2]:80"}, |
| + {GURL("http://[::a]:33/x"), "[::a]:33"}, |
| + }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| std::string host_and_port = GetHostAndPort(tests[i].url); |
| EXPECT_EQ(std::string(tests[i].expected_host_and_port), host_and_port); |
| @@ -311,13 +305,13 @@ TEST(NetUtilTest, GetHostAndOptionalPort) { |
| GURL url; |
| const char* expected_host_and_port; |
| } tests[] = { |
| - { GURL("http://www.foo.com/x"), "www.foo.com"}, |
| - { GURL("http://www.foo.com:21/x"), "www.foo.com:21"}, |
| + {GURL("http://www.foo.com/x"), "www.foo.com"}, |
| + {GURL("http://www.foo.com:21/x"), "www.foo.com:21"}, |
| - // For IPv6 literals should always include the brackets. |
| - { GURL("http://[1::2]/x"), "[1::2]"}, |
| - { GURL("http://[::a]:33/x"), "[::a]:33"}, |
| - }; |
| + // For IPv6 literals should always include the brackets. |
| + {GURL("http://[1::2]/x"), "[1::2]"}, |
| + {GURL("http://[::a]:33/x"), "[::a]:33"}, |
| + }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| std::string host_and_port = GetHostAndOptionalPort(tests[i].url); |
| EXPECT_EQ(std::string(tests[i].expected_host_and_port), host_and_port); |
| @@ -353,10 +347,10 @@ TEST(NetUtilTest, NetAddressToString_IPv4) { |
| uint8 addr[4]; |
| const char* result; |
| } tests[] = { |
| - {{0, 0, 0, 0}, "0.0.0.0"}, |
| - {{127, 0, 0, 1}, "127.0.0.1"}, |
| - {{192, 168, 0, 1}, "192.168.0.1"}, |
| - }; |
| + {{0, 0, 0, 0}, "0.0.0.0"}, |
| + {{127, 0, 0, 1}, "127.0.0.1"}, |
| + {{192, 168, 0, 1}, "192.168.0.1"}, |
| + }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| SockaddrStorage storage; |
| @@ -371,16 +365,30 @@ TEST(NetUtilTest, NetAddressToString_IPv6) { |
| uint8 addr[16]; |
| const char* result; |
| } tests[] = { |
| - {{0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA, |
| - 0x98, 0x76, 0x54, 0x32, 0x10}, |
| - "fedc:ba98:7654:3210:fedc:ba98:7654:3210"}, |
| - }; |
| + {{0xFE, |
| + 0xDC, |
| + 0xBA, |
| + 0x98, |
| + 0x76, |
| + 0x54, |
| + 0x32, |
| + 0x10, |
| + 0xFE, |
| + 0xDC, |
| + 0xBA, |
| + 0x98, |
| + 0x76, |
| + 0x54, |
| + 0x32, |
| + 0x10}, |
| + "fedc:ba98:7654:3210:fedc:ba98:7654:3210"}, |
|
davidben
2014/10/10 20:24:16
This block also looks bizarrely indented.
|
| + }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| SockaddrStorage storage; |
| MakeIPv6Address(tests[i].addr, 80, &storage); |
| EXPECT_EQ(std::string(tests[i].result), |
| - NetAddressToString(storage.addr, storage.addr_len)); |
| + NetAddressToString(storage.addr, storage.addr_len)); |
| } |
| } |
| @@ -388,20 +396,32 @@ TEST(NetUtilTest, NetAddressToStringWithPort_IPv4) { |
| uint8 addr[] = {127, 0, 0, 1}; |
| SockaddrStorage storage; |
| MakeIPv4Address(addr, 166, &storage); |
| - std::string result = NetAddressToStringWithPort(storage.addr, |
| - storage.addr_len); |
| + std::string result = |
| + NetAddressToStringWithPort(storage.addr, storage.addr_len); |
| EXPECT_EQ("127.0.0.1:166", result); |
| } |
| TEST(NetUtilTest, NetAddressToStringWithPort_IPv6) { |
| - uint8 addr[] = { |
| - 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0xFE, 0xDC, 0xBA, |
| - 0x98, 0x76, 0x54, 0x32, 0x10 |
| - }; |
| + uint8 addr[] = {0xFE, |
| + 0xDC, |
| + 0xBA, |
| + 0x98, |
| + 0x76, |
| + 0x54, |
| + 0x32, |
| + 0x10, |
| + 0xFE, |
| + 0xDC, |
| + 0xBA, |
| + 0x98, |
| + 0x76, |
| + 0x54, |
| + 0x32, |
| + 0x10}; |
|
davidben
2014/10/10 20:24:16
Might also be worth a bug to get this on one line?
|
| SockaddrStorage storage; |
| MakeIPv6Address(addr, 361, &storage); |
| - std::string result = NetAddressToStringWithPort(storage.addr, |
| - storage.addr_len); |
| + std::string result = |
| + NetAddressToStringWithPort(storage.addr, storage.addr_len); |
| // May fail on systems that don't support IPv6. |
| if (!result.empty()) |
| @@ -421,40 +441,40 @@ TEST(NetUtilTest, SimplifyUrlForRequest) { |
| const char* input_url; |
| const char* expected_simplified_url; |
| } tests[] = { |
| - { |
| - // Reference section should be stripped. |
| - "http://www.google.com:78/foobar?query=1#hash", |
| - "http://www.google.com:78/foobar?query=1", |
| - }, |
| - { |
| - // Reference section can itself contain #. |
| - "http://192.168.0.1?query=1#hash#10#11#13#14", |
| - "http://192.168.0.1?query=1", |
| - }, |
| - { // Strip username/password. |
| - "http://user:pass@google.com", |
| - "http://google.com/", |
| - }, |
| - { // Strip both the reference and the username/password. |
| - "http://user:pass@google.com:80/sup?yo#X#X", |
| - "http://google.com/sup?yo", |
| - }, |
| - { // Try an HTTPS URL -- strip both the reference and the username/password. |
| - "https://user:pass@google.com:80/sup?yo#X#X", |
| - "https://google.com:80/sup?yo", |
| - }, |
| - { // Try an FTP URL -- strip both the reference and the username/password. |
| - "ftp://user:pass@google.com:80/sup?yo#X#X", |
| - "ftp://google.com:80/sup?yo", |
| - }, |
| - { // Try a nonstandard URL |
| - "foobar://user:pass@google.com:80/sup?yo#X#X", |
| - "foobar://user:pass@google.com:80/sup?yo", |
| - }, |
| - }; |
| + {// Reference section should be stripped. |
|
davidben
2014/10/10 20:24:16
Array literal with line comment again.
|
| + "http://www.google.com:78/foobar?query=1#hash", |
| + "http://www.google.com:78/foobar?query=1", |
| + }, |
| + {// Reference section can itself contain #. |
| + "http://192.168.0.1?query=1#hash#10#11#13#14", |
| + "http://192.168.0.1?query=1", |
| + }, |
| + {// Strip username/password. |
| + "http://user:pass@google.com", |
| + "http://google.com/", |
| + }, |
| + {// Strip both the reference and the username/password. |
| + "http://user:pass@google.com:80/sup?yo#X#X", |
| + "http://google.com/sup?yo", |
| + }, |
| + {// Try an HTTPS URL -- strip both the reference and the |
| + // username/password. |
| + "https://user:pass@google.com:80/sup?yo#X#X", |
| + "https://google.com:80/sup?yo", |
| + }, |
| + {// Try an FTP URL -- strip both the reference and the |
| + // username/password. |
| + "ftp://user:pass@google.com:80/sup?yo#X#X", |
| + "ftp://google.com:80/sup?yo", |
| + }, |
| + {// Try a nonstandard URL |
| + "foobar://user:pass@google.com:80/sup?yo#X#X", |
| + "foobar://user:pass@google.com:80/sup?yo", |
| + }, |
| + }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| - SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s", i, |
| - tests[i].input_url)); |
| + SCOPED_TRACE( |
| + base::StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url)); |
| GURL input_url(GURL(tests[i].input_url)); |
| GURL expected_url(GURL(tests[i].expected_simplified_url)); |
| EXPECT_EQ(expected_url, SimplifyUrlForRequest(input_url)); |
| @@ -462,8 +482,8 @@ TEST(NetUtilTest, SimplifyUrlForRequest) { |
| } |
| TEST(NetUtilTest, SetExplicitlyAllowedPortsTest) { |
| - std::string invalid[] = { "1,2,a", "'1','2'", "1, 2, 3", "1 0,11,12" }; |
| - std::string valid[] = { "", "1", "1,2", "1,2,3", "10,11,12,13" }; |
| + std::string invalid[] = {"1,2,a", "'1','2'", "1, 2, 3", "1 0,11,12"}; |
| + std::string valid[] = {"", "1", "1,2", "1,2,3", "10,11,12,13"}; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(invalid); ++i) { |
| SetExplicitlyAllowedPorts(invalid[i]); |
| @@ -526,8 +546,7 @@ TEST(NetUtilTest, ConvertIPv4NumberToIPv6Number) { |
| IPAddressNumber ipv4_number; |
| EXPECT_TRUE(ParseIPLiteralToNumber("192.168.0.1", &ipv4_number)); |
| - IPAddressNumber ipv6_number = |
| - ConvertIPv4NumberToIPv6Number(ipv4_number); |
| + IPAddressNumber ipv6_number = ConvertIPv4NumberToIPv6Number(ipv4_number); |
| // ::ffff:192.168.0.1 |
| EXPECT_EQ("0,0,0,0,0,0,0,0,0,0,255,255,192,168,0,1", |
| @@ -585,29 +604,26 @@ TEST(NetUtilTest, ConvertIPv4MappedToIPv4) { |
| // Test parsing invalid CIDR notation literals. |
| TEST(NetUtilTest, ParseCIDRBlock_Invalid) { |
| - const char* bad_literals[] = { |
| - "foobar", |
| - "", |
| - "192.168.0.1", |
| - "::1", |
| - "/", |
| - "/1", |
| - "1", |
| - "192.168.1.1/-1", |
| - "192.168.1.1/33", |
| - "::1/-3", |
| - "a::3/129", |
| - "::1/x", |
| - "192.168.0.1//11" |
| - }; |
| + const char* bad_literals[] = {"foobar", |
| + "", |
| + "192.168.0.1", |
| + "::1", |
| + "/", |
| + "/1", |
| + "1", |
| + "192.168.1.1/-1", |
| + "192.168.1.1/33", |
| + "::1/-3", |
| + "a::3/129", |
| + "::1/x", |
| + "192.168.0.1//11"}; |
| for (size_t i = 0; i < arraysize(bad_literals); ++i) { |
| IPAddressNumber ip_number; |
| size_t prefix_length_in_bits; |
| - EXPECT_FALSE(ParseCIDRBlock(bad_literals[i], |
| - &ip_number, |
| - &prefix_length_in_bits)); |
| + EXPECT_FALSE( |
| + ParseCIDRBlock(bad_literals[i], &ip_number, &prefix_length_in_bits)); |
| } |
| } |
| @@ -616,9 +632,8 @@ TEST(NetUtilTest, ParseCIDRBlock_Valid) { |
| IPAddressNumber ip_number; |
| size_t prefix_length_in_bits; |
| - EXPECT_TRUE(ParseCIDRBlock("192.168.0.1/11", |
| - &ip_number, |
| - &prefix_length_in_bits)); |
| + EXPECT_TRUE( |
| + ParseCIDRBlock("192.168.0.1/11", &ip_number, &prefix_length_in_bits)); |
| EXPECT_EQ("192,168,0,1", DumpIPNumber(ip_number)); |
| EXPECT_EQ(11u, prefix_length_in_bits); |
| @@ -629,62 +644,26 @@ TEST(NetUtilTest, IPNumberMatchesPrefix) { |
| const char* cidr_literal; |
| const char* ip_literal; |
| bool expected_to_match; |
| - } tests[] = { |
| - // IPv4 prefix with IPv4 inputs. |
| - { |
| - "10.10.1.32/27", |
| - "10.10.1.44", |
| - true |
| - }, |
| - { |
| - "10.10.1.32/27", |
| - "10.10.1.90", |
| - false |
| - }, |
| - { |
| - "10.10.1.32/27", |
| - "10.10.1.90", |
| - false |
| - }, |
| - |
| - // IPv6 prefix with IPv6 inputs. |
| - { |
| - "2001:db8::/32", |
| - "2001:DB8:3:4::5", |
| - true |
| - }, |
| - { |
| - "2001:db8::/32", |
| - "2001:c8::", |
| - false |
| - }, |
| - |
| - // IPv6 prefix with IPv4 inputs. |
| - { |
| - "2001:db8::/33", |
| - "192.168.0.1", |
| - false |
| - }, |
| - { |
| - "::ffff:192.168.0.1/112", |
| - "192.168.33.77", |
| - true |
| - }, |
| - |
| - // IPv4 prefix with IPv6 inputs. |
| - { |
| - "10.11.33.44/16", |
| - "::ffff:0a0b:89", |
| - true |
| - }, |
| - { |
| - "10.11.33.44/16", |
| - "::ffff:10.12.33.44", |
| - false |
| - }, |
| - }; |
| + } tests[] = {// IPv4 prefix with IPv4 inputs. |
| + {"10.10.1.32/27", "10.10.1.44", true}, |
| + {"10.10.1.32/27", "10.10.1.90", false}, |
| + {"10.10.1.32/27", "10.10.1.90", false}, |
|
davidben
2014/10/10 20:24:16
Array literal with line comment again.
|
| + |
| + // IPv6 prefix with IPv6 inputs. |
| + {"2001:db8::/32", "2001:DB8:3:4::5", true}, |
| + {"2001:db8::/32", "2001:c8::", false}, |
| + |
| + // IPv6 prefix with IPv4 inputs. |
| + {"2001:db8::/33", "192.168.0.1", false}, |
| + {"::ffff:192.168.0.1/112", "192.168.33.77", true}, |
| + |
| + // IPv4 prefix with IPv6 inputs. |
| + {"10.11.33.44/16", "::ffff:0a0b:89", true}, |
| + {"10.11.33.44/16", "::ffff:10.12.33.44", false}, |
| + }; |
| for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| - SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s, %s", i, |
| + SCOPED_TRACE(base::StringPrintf("Test[%" PRIuS "]: %s, %s", |
| + i, |
| tests[i].cidr_literal, |
| tests[i].ip_literal)); |
| @@ -694,14 +673,12 @@ TEST(NetUtilTest, IPNumberMatchesPrefix) { |
| IPAddressNumber ip_prefix; |
| size_t prefix_length_in_bits; |
| - EXPECT_TRUE(ParseCIDRBlock(tests[i].cidr_literal, |
| - &ip_prefix, |
| - &prefix_length_in_bits)); |
| + EXPECT_TRUE(ParseCIDRBlock( |
| + tests[i].cidr_literal, &ip_prefix, &prefix_length_in_bits)); |
| - EXPECT_EQ(tests[i].expected_to_match, |
| - IPNumberMatchesPrefix(ip_number, |
| - ip_prefix, |
| - prefix_length_in_bits)); |
| + EXPECT_EQ( |
| + tests[i].expected_to_match, |
| + IPNumberMatchesPrefix(ip_number, ip_prefix, prefix_length_in_bits)); |
| } |
| } |
| @@ -737,8 +714,8 @@ TEST(NetUtilTest, IsLocalhost) { |
| TEST(NetUtilTest, GetNetworkList) { |
| NetworkInterfaceList list; |
| ASSERT_TRUE(GetNetworkList(&list, INCLUDE_HOST_SCOPE_VIRTUAL_INTERFACES)); |
| - for (NetworkInterfaceList::iterator it = list.begin(); |
| - it != list.end(); ++it) { |
| + for (NetworkInterfaceList::iterator it = list.begin(); it != list.end(); |
| + ++it) { |
| // Verify that the names are not empty. |
| EXPECT_FALSE(it->name.empty()); |
| EXPECT_FALSE(it->friendly_name.empty()); |
| @@ -763,14 +740,13 @@ TEST(NetUtilTest, GetNetworkList) { |
| base::ScopedNativeLibrary phlpapi_lib( |
| base::FilePath(FILE_PATH_LITERAL("iphlpapi.dll"))); |
| ASSERT_TRUE(phlpapi_lib.is_valid()); |
| - typedef NETIO_STATUS (WINAPI* ConvertInterfaceIndexToLuid)(NET_IFINDEX, |
| + typedef NETIO_STATUS(WINAPI * ConvertInterfaceIndexToLuid)(NET_IFINDEX, |
| PNET_LUID); |
| ConvertInterfaceIndexToLuid interface_to_luid = |
| reinterpret_cast<ConvertInterfaceIndexToLuid>( |
| phlpapi_lib.GetFunctionPointer("ConvertInterfaceIndexToLuid")); |
| - typedef NETIO_STATUS (WINAPI* ConvertInterfaceLuidToGuid)(NET_LUID*, |
| - GUID*); |
| + typedef NETIO_STATUS(WINAPI * ConvertInterfaceLuidToGuid)(NET_LUID*, GUID*); |
| ConvertInterfaceLuidToGuid luid_to_guid = |
| reinterpret_cast<ConvertInterfaceLuidToGuid>( |
| phlpapi_lib.GetFunctionPointer("ConvertInterfaceLuidToGuid")); |
| @@ -788,7 +764,7 @@ TEST(NetUtilTest, GetNetworkList) { |
| } else { |
| EXPECT_LT(base::win::GetVersion(), base::win::VERSION_VISTA); |
| EXPECT_LT(it->interface_index, 1u << 24u); // Must fit 0.x.x.x. |
| - EXPECT_NE(it->interface_index, 0u); // 0 means to use default. |
| + EXPECT_NE(it->interface_index, 0u); // 0 means to use default. |
| } |
| if (it->type == NetworkChangeNotifier::CONNECTION_WIFI) { |
| EXPECT_NE(WIFI_PHY_LAYER_PROTOCOL_NONE, GetWifiPHYLayerProtocol()); |
| @@ -804,8 +780,7 @@ TEST(NetUtilTest, GetNetworkList) { |
| namespace { |
| #if defined(OS_WIN) |
| -bool read_int_or_bool(DWORD data_size, |
| - PVOID data) { |
| +bool read_int_or_bool(DWORD data_size, PVOID data) { |
| switch (data_size) { |
| case 1: |
| return !!*reinterpret_cast<uint8*>(data); |
| @@ -825,14 +800,13 @@ int GetWifiOptions() { |
| internal::WlanHandle client; |
| DWORD cur_version = 0; |
| const DWORD kMaxClientVersion = 2; |
| - DWORD result = wlanapi.OpenHandle( |
| - kMaxClientVersion, &cur_version, &client); |
| + DWORD result = wlanapi.OpenHandle(kMaxClientVersion, &cur_version, &client); |
| if (result != ERROR_SUCCESS) |
| return -1; |
| WLAN_INTERFACE_INFO_LIST* interface_list_ptr = NULL; |
| - result = wlanapi.enum_interfaces_func(client.Get(), NULL, |
| - &interface_list_ptr); |
| + result = |
| + wlanapi.enum_interfaces_func(client.Get(), NULL, &interface_list_ptr); |
| if (result != ERROR_SUCCESS) |
| return -1; |
| scoped_ptr<WLAN_INTERFACE_INFO_LIST, internal::WlanApiDeleter> interface_list( |
| @@ -843,14 +817,14 @@ int GetWifiOptions() { |
| DWORD data_size; |
| PVOID data; |
| int options = 0; |
| - result = wlanapi.query_interface_func( |
| - client.Get(), |
| - &info->InterfaceGuid, |
| - wlan_intf_opcode_background_scan_enabled, |
| - NULL, |
| - &data_size, |
| - &data, |
| - NULL); |
| + result = |
| + wlanapi.query_interface_func(client.Get(), |
| + &info->InterfaceGuid, |
| + wlan_intf_opcode_background_scan_enabled, |
| + NULL, |
| + &data_size, |
| + &data, |
| + NULL); |
| if (result != ERROR_SUCCESS) |
| continue; |
| if (!read_int_or_bool(data_size, data)) { |
| @@ -858,14 +832,13 @@ int GetWifiOptions() { |
| } |
| internal::WlanApi::GetInstance().free_memory_func(data); |
| - result = wlanapi.query_interface_func( |
| - client.Get(), |
| - &info->InterfaceGuid, |
| - wlan_intf_opcode_media_streaming_mode, |
| - NULL, |
| - &data_size, |
| - &data, |
| - NULL); |
| + result = wlanapi.query_interface_func(client.Get(), |
| + &info->InterfaceGuid, |
| + wlan_intf_opcode_media_streaming_mode, |
| + NULL, |
| + &data_size, |
| + &data, |
| + NULL); |
| if (result != ERROR_SUCCESS) |
| continue; |
| if (read_int_or_bool(data_size, data)) { |
| @@ -924,47 +897,47 @@ void PrintTo(const NonUniqueNameTestData& data, std::ostream* os) { |
| const NonUniqueNameTestData kNonUniqueNameTestData[] = { |
| // Domains under ICANN-assigned domains. |
| - { true, "google.com" }, |
| - { true, "google.co.uk" }, |
| + {true, "google.com"}, |
| + {true, "google.co.uk"}, |
| // Domains under private registries. |
| - { true, "appspot.com" }, |
| - { true, "test.appspot.com" }, |
| + {true, "appspot.com"}, |
| + {true, "test.appspot.com"}, |
| // Unreserved IPv4 addresses (in various forms). |
| - { true, "8.8.8.8" }, |
| - { true, "99.64.0.0" }, |
| - { true, "212.15.0.0" }, |
| - { true, "212.15" }, |
| - { true, "212.15.0" }, |
| - { true, "3557752832" }, |
| + {true, "8.8.8.8"}, |
| + {true, "99.64.0.0"}, |
| + {true, "212.15.0.0"}, |
| + {true, "212.15"}, |
| + {true, "212.15.0"}, |
| + {true, "3557752832"}, |
| // Reserved IPv4 addresses (in various forms). |
| - { false, "192.168.0.0" }, |
| - { false, "192.168.0.6" }, |
| - { false, "10.0.0.5" }, |
| - { false, "10.0" }, |
| - { false, "10.0.0" }, |
| - { false, "3232235526" }, |
| + {false, "192.168.0.0"}, |
| + {false, "192.168.0.6"}, |
| + {false, "10.0.0.5"}, |
| + {false, "10.0"}, |
| + {false, "10.0.0"}, |
| + {false, "3232235526"}, |
| // Unreserved IPv6 addresses. |
| - { true, "FFC0:ba98:7654:3210:FEDC:BA98:7654:3210" }, |
| - { true, "2000:ba98:7654:2301:EFCD:BA98:7654:3210" }, |
| + {true, "FFC0:ba98:7654:3210:FEDC:BA98:7654:3210"}, |
| + {true, "2000:ba98:7654:2301:EFCD:BA98:7654:3210"}, |
| // Reserved IPv6 addresses. |
| - { false, "::192.9.5.5" }, |
| - { false, "FEED::BEEF" }, |
| - { false, "FEC0:ba98:7654:3210:FEDC:BA98:7654:3210" }, |
| + {false, "::192.9.5.5"}, |
| + {false, "FEED::BEEF"}, |
| + {false, "FEC0:ba98:7654:3210:FEDC:BA98:7654:3210"}, |
| // 'internal'/non-IANA assigned domains. |
| - { false, "intranet" }, |
| - { false, "intranet." }, |
| - { false, "intranet.example" }, |
| - { false, "host.intranet.example" }, |
| + {false, "intranet"}, |
| + {false, "intranet."}, |
| + {false, "intranet.example"}, |
| + {false, "host.intranet.example"}, |
| // gTLDs under discussion, but not yet assigned. |
| - { false, "intranet.corp" }, |
| - { false, "example.tech" }, |
| - { false, "intranet.internal" }, |
| + {false, "intranet.corp"}, |
| + {false, "example.tech"}, |
| + {false, "intranet.internal"}, |
| // Invalid host names are treated as unique - but expected to be |
| // filtered out before then. |
| - { true, "junk)(£)$*!@~#" }, |
| - { true, "w$w.example.com" }, |
| - { true, "nocolonsallowed:example" }, |
| - { true, "[::4.5.6.9]" }, |
| + {true, "junk)(£)$*!@~#"}, |
| + {true, "w$w.example.com"}, |
| + {true, "nocolonsallowed:example"}, |
| + {true, "[::4.5.6.9]"}, |
| }; |
| class NetUtilNonUniqueNameTest |
| @@ -987,7 +960,8 @@ TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { |
| EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); |
| } |
| -INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, |
| +INSTANTIATE_TEST_CASE_P(, |
|
davidben
2014/10/10 20:24:16
No action: I think this is going to look weird no
|
| + NetUtilNonUniqueNameTest, |
| testing::ValuesIn(kNonUniqueNameTestData)); |
| } // namespace net |