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 3153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3164 | 3164 |
3165 TEST(NetUtilTest, GetHostOrSpecFromURL) { | 3165 TEST(NetUtilTest, GetHostOrSpecFromURL) { |
3166 EXPECT_EQ("example.com", | 3166 EXPECT_EQ("example.com", |
3167 GetHostOrSpecFromURL(GURL("http://example.com/test"))); | 3167 GetHostOrSpecFromURL(GURL("http://example.com/test"))); |
3168 EXPECT_EQ("example.com", | 3168 EXPECT_EQ("example.com", |
3169 GetHostOrSpecFromURL(GURL("http://example.com./test"))); | 3169 GetHostOrSpecFromURL(GURL("http://example.com./test"))); |
3170 EXPECT_EQ("file:///tmp/test.html", | 3170 EXPECT_EQ("file:///tmp/test.html", |
3171 GetHostOrSpecFromURL(GURL("file:///tmp/test.html"))); | 3171 GetHostOrSpecFromURL(GURL("file:///tmp/test.html"))); |
3172 } | 3172 } |
3173 | 3173 |
| 3174 TEST(NetUtilTest, GetAddressFamily) { |
| 3175 IPAddressNumber number; |
| 3176 EXPECT_TRUE(ParseIPLiteralToNumber("192.168.0.1", &number)); |
| 3177 EXPECT_EQ(ADDRESS_FAMILY_IPV4, GetAddressFamily(number)); |
| 3178 EXPECT_TRUE(ParseIPLiteralToNumber("1:abcd::3:4:ff", &number)); |
| 3179 EXPECT_EQ(ADDRESS_FAMILY_IPV6, GetAddressFamily(number)); |
| 3180 } |
| 3181 |
3174 // Test that invalid IP literals fail to parse. | 3182 // Test that invalid IP literals fail to parse. |
3175 TEST(NetUtilTest, ParseIPLiteralToNumber_FailParse) { | 3183 TEST(NetUtilTest, ParseIPLiteralToNumber_FailParse) { |
3176 IPAddressNumber number; | 3184 IPAddressNumber number; |
3177 | 3185 |
3178 EXPECT_FALSE(ParseIPLiteralToNumber("bad value", &number)); | 3186 EXPECT_FALSE(ParseIPLiteralToNumber("bad value", &number)); |
3179 EXPECT_FALSE(ParseIPLiteralToNumber("bad:value", &number)); | 3187 EXPECT_FALSE(ParseIPLiteralToNumber("bad:value", &number)); |
3180 EXPECT_FALSE(ParseIPLiteralToNumber(std::string(), &number)); | 3188 EXPECT_FALSE(ParseIPLiteralToNumber(std::string(), &number)); |
3181 EXPECT_FALSE(ParseIPLiteralToNumber("192.168.0.1:30", &number)); | 3189 EXPECT_FALSE(ParseIPLiteralToNumber("192.168.0.1:30", &number)); |
3182 EXPECT_FALSE(ParseIPLiteralToNumber(" 192.168.0.1 ", &number)); | 3190 EXPECT_FALSE(ParseIPLiteralToNumber(" 192.168.0.1 ", &number)); |
3183 EXPECT_FALSE(ParseIPLiteralToNumber("[::1]", &number)); | 3191 EXPECT_FALSE(ParseIPLiteralToNumber("[::1]", &number)); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3487 kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; | 3495 kUnsafePortableBasenames[i]))) << kUnsafePortableBasenames[i]; |
3488 if (!base::FilePath::StringType(kUnsafePortableBasenames[i]).empty()) { | 3496 if (!base::FilePath::StringType(kUnsafePortableBasenames[i]).empty()) { |
3489 EXPECT_FALSE(IsSafePortableRelativePath(safe_dirname.Append( | 3497 EXPECT_FALSE(IsSafePortableRelativePath(safe_dirname.Append( |
3490 base::FilePath(kUnsafePortableBasenames[i])))) | 3498 base::FilePath(kUnsafePortableBasenames[i])))) |
3491 << kUnsafePortableBasenames[i]; | 3499 << kUnsafePortableBasenames[i]; |
3492 } | 3500 } |
3493 } | 3501 } |
3494 } | 3502 } |
3495 | 3503 |
3496 } // namespace net | 3504 } // namespace net |
OLD | NEW |