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 <ostream> | 9 #include <ostream> |
10 | 10 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 bool success; | 239 bool success; |
240 const char* expected_host; | 240 const char* expected_host; |
241 int expected_port; | 241 int expected_port; |
242 } tests[] = { | 242 } tests[] = { |
243 // Valid inputs: | 243 // Valid inputs: |
244 {"foo:10", true, "foo", 10}, | 244 {"foo:10", true, "foo", 10}, |
245 {"foo", true, "foo", -1}, | 245 {"foo", true, "foo", -1}, |
246 { | 246 { |
247 "[1080:0:0:0:8:800:200C:4171]:11", | 247 "[1080:0:0:0:8:800:200C:4171]:11", |
248 true, | 248 true, |
| 249 "1080:0:0:0:8:800:200C:4171", |
| 250 11 |
| 251 }, |
| 252 { |
249 "[1080:0:0:0:8:800:200C:4171]", | 253 "[1080:0:0:0:8:800:200C:4171]", |
250 11, | 254 true, |
| 255 "1080:0:0:0:8:800:200C:4171", |
| 256 -1 |
251 }, | 257 }, |
| 258 |
| 259 // Because no validation is done on the host, the following are accepted, |
| 260 // even though they are invalid names. |
| 261 {"]", true, "]", -1}, |
| 262 {"::1", true, ":", 1}, |
252 // Invalid inputs: | 263 // Invalid inputs: |
253 {"foo:bar", false, "", -1}, | 264 {"foo:bar", false, "", -1}, |
254 {"foo:", false, "", -1}, | 265 {"foo:", false, "", -1}, |
255 {":", false, "", -1}, | 266 {":", false, "", -1}, |
256 {":80", false, "", -1}, | 267 {":80", false, "", -1}, |
257 {"", false, "", -1}, | 268 {"", false, "", -1}, |
258 {"porttoolong:300000", false, "", -1}, | 269 {"porttoolong:300000", false, "", -1}, |
259 {"usrname@host", false, "", -1}, | 270 {"usrname@host", false, "", -1}, |
260 {"usrname:password@host", false, "", -1}, | 271 {"usrname:password@host", false, "", -1}, |
261 {":password@host", false, "", -1}, | 272 {":password@host", false, "", -1}, |
262 {":password@host:80", false, "", -1}, | 273 {":password@host:80", false, "", -1}, |
263 {":password@host", false, "", -1}, | 274 {":password@host", false, "", -1}, |
264 {"@host", false, "", -1}, | 275 {"@host", false, "", -1}, |
| 276 {"[", false, "", -1}, |
| 277 {"[]", false, "", -1}, |
265 }; | 278 }; |
266 | 279 |
267 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 280 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
268 std::string host; | 281 std::string host; |
269 int port; | 282 int port; |
270 bool ok = ParseHostAndPort(tests[i].input, &host, &port); | 283 bool ok = ParseHostAndPort(tests[i].input, &host, &port); |
271 | 284 |
272 EXPECT_EQ(tests[i].success, ok); | 285 EXPECT_EQ(tests[i].success, ok); |
273 | 286 |
274 if (tests[i].success) { | 287 if (tests[i].success) { |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { | 986 TEST_P(NetUtilNonUniqueNameTest, IsHostnameNonUnique) { |
974 const NonUniqueNameTestData& test_data = GetParam(); | 987 const NonUniqueNameTestData& test_data = GetParam(); |
975 | 988 |
976 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); | 989 EXPECT_EQ(test_data.is_unique, IsUnique(test_data.hostname)); |
977 } | 990 } |
978 | 991 |
979 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, | 992 INSTANTIATE_TEST_CASE_P(, NetUtilNonUniqueNameTest, |
980 testing::ValuesIn(kNonUniqueNameTestData)); | 993 testing::ValuesIn(kNonUniqueNameTestData)); |
981 | 994 |
982 } // namespace net | 995 } // namespace net |
OLD | NEW |