| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/macros.h" |
| 5 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "url/gurl.h" | 7 #include "url/gurl.h" |
| 7 #include "url/url_canon.h" | 8 #include "url/url_canon.h" |
| 8 #include "url/url_test_utils.h" | 9 #include "url/url_test_utils.h" |
| 9 | 10 |
| 10 // Some implementations of base/basictypes.h may define ARRAYSIZE. | |
| 11 // If it's not defined, we define it to the ARRAYSIZE_UNSAFE macro | |
| 12 // which is in our version of basictypes.h. | |
| 13 #ifndef ARRAYSIZE | |
| 14 #define ARRAYSIZE ARRAYSIZE_UNSAFE | |
| 15 #endif | |
| 16 | |
| 17 namespace url { | 11 namespace url { |
| 18 | 12 |
| 19 using test_utils::WStringToUTF16; | 13 using test_utils::WStringToUTF16; |
| 20 using test_utils::ConvertUTF8ToUTF16; | 14 using test_utils::ConvertUTF8ToUTF16; |
| 21 | 15 |
| 22 namespace { | 16 namespace { |
| 23 | 17 |
| 24 template<typename CHAR> | 18 template<typename CHAR> |
| 25 void SetupReplacement( | 19 void SetupReplacement( |
| 26 void (Replacements<CHAR>::*func)(const CHAR*, const Component&), | 20 void (Replacements<CHAR>::*func)(const CHAR*, const Component&), |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 "http://user:pass@google.com", | 219 "http://user:pass@google.com", |
| 226 "http://google.com:12345", | 220 "http://google.com:12345", |
| 227 "http://google.com/path", | 221 "http://google.com/path", |
| 228 "http://google.com//path", | 222 "http://google.com//path", |
| 229 "http://google.com?k=v#fragment", | 223 "http://google.com?k=v#fragment", |
| 230 "http://user:pass@google.com:12345/path?k=v#fragment", | 224 "http://user:pass@google.com:12345/path?k=v#fragment", |
| 231 "http:/path", | 225 "http:/path", |
| 232 "http:path", | 226 "http:path", |
| 233 "://google.com", | 227 "://google.com", |
| 234 }; | 228 }; |
| 235 for (size_t i = 0; i < ARRAYSIZE(valid_cases); i++) { | 229 for (size_t i = 0; i < arraysize(valid_cases); i++) { |
| 236 EXPECT_TRUE(GURL(valid_cases[i]).is_valid()) | 230 EXPECT_TRUE(GURL(valid_cases[i]).is_valid()) |
| 237 << "Case: " << valid_cases[i]; | 231 << "Case: " << valid_cases[i]; |
| 238 } | 232 } |
| 239 | 233 |
| 240 const char* invalid_cases[] = { | 234 const char* invalid_cases[] = { |
| 241 "http://?k=v", | 235 "http://?k=v", |
| 242 "http:://google.com", | 236 "http:://google.com", |
| 243 "http//google.com", | 237 "http//google.com", |
| 244 "http://google.com:12three45", | 238 "http://google.com:12three45", |
| 245 "path", | 239 "path", |
| 246 }; | 240 }; |
| 247 for (size_t i = 0; i < ARRAYSIZE(invalid_cases); i++) { | 241 for (size_t i = 0; i < arraysize(invalid_cases); i++) { |
| 248 EXPECT_FALSE(GURL(invalid_cases[i]).is_valid()) | 242 EXPECT_FALSE(GURL(invalid_cases[i]).is_valid()) |
| 249 << "Case: " << invalid_cases[i]; | 243 << "Case: " << invalid_cases[i]; |
| 250 } | 244 } |
| 251 } | 245 } |
| 252 | 246 |
| 253 TEST(GURLTest, ExtraSlashesBeforeAuthority) { | 247 TEST(GURLTest, ExtraSlashesBeforeAuthority) { |
| 254 // According to RFC3986, the hier-part for URI with an authority must use only | 248 // According to RFC3986, the hier-part for URI with an authority must use only |
| 255 // two slashes, GURL intentionally just ignores slashes more than 2 and parses | 249 // two slashes, GURL intentionally just ignores slashes more than 2 and parses |
| 256 // the following part as an authority. | 250 // the following part as an authority. |
| 257 GURL url("http:///host"); | 251 GURL url("http:///host"); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 {"http://www.google.com/foo#bar", "#com", true, "http://www.google.com/foo#c
om"}, | 286 {"http://www.google.com/foo#bar", "#com", true, "http://www.google.com/foo#c
om"}, |
| 293 {"http://www.google.com/", "Https:images.google.com", true, "https://images.
google.com/"}, | 287 {"http://www.google.com/", "Https:images.google.com", true, "https://images.
google.com/"}, |
| 294 // A non-standard base can be replaced with a standard absolute URL. | 288 // A non-standard base can be replaced with a standard absolute URL. |
| 295 {"data:blahblah", "http://google.com/", true, "http://google.com/"}, | 289 {"data:blahblah", "http://google.com/", true, "http://google.com/"}, |
| 296 {"data:blahblah", "http:google.com", true, "http://google.com/"}, | 290 {"data:blahblah", "http:google.com", true, "http://google.com/"}, |
| 297 // Filesystem URLs have different paths to test. | 291 // Filesystem URLs have different paths to test. |
| 298 {"filesystem:http://www.google.com/type/", "foo.html", true, "filesystem:htt
p://www.google.com/type/foo.html"}, | 292 {"filesystem:http://www.google.com/type/", "foo.html", true, "filesystem:htt
p://www.google.com/type/foo.html"}, |
| 299 {"filesystem:http://www.google.com/type/", "../foo.html", true, "filesystem:
http://www.google.com/type/foo.html"}, | 293 {"filesystem:http://www.google.com/type/", "../foo.html", true, "filesystem:
http://www.google.com/type/foo.html"}, |
| 300 }; | 294 }; |
| 301 | 295 |
| 302 for (size_t i = 0; i < ARRAYSIZE(resolve_cases); i++) { | 296 for (size_t i = 0; i < arraysize(resolve_cases); i++) { |
| 303 // 8-bit code path. | 297 // 8-bit code path. |
| 304 GURL input(resolve_cases[i].base); | 298 GURL input(resolve_cases[i].base); |
| 305 GURL output = input.Resolve(resolve_cases[i].relative); | 299 GURL output = input.Resolve(resolve_cases[i].relative); |
| 306 EXPECT_EQ(resolve_cases[i].expected_valid, output.is_valid()) << i; | 300 EXPECT_EQ(resolve_cases[i].expected_valid, output.is_valid()) << i; |
| 307 EXPECT_EQ(resolve_cases[i].expected, output.spec()) << i; | 301 EXPECT_EQ(resolve_cases[i].expected, output.spec()) << i; |
| 308 EXPECT_EQ(output.SchemeIsFileSystem(), output.inner_url() != NULL); | 302 EXPECT_EQ(output.SchemeIsFileSystem(), output.inner_url() != NULL); |
| 309 | 303 |
| 310 // Wide code path. | 304 // Wide code path. |
| 311 GURL inputw(ConvertUTF8ToUTF16(resolve_cases[i].base)); | 305 GURL inputw(ConvertUTF8ToUTF16(resolve_cases[i].base)); |
| 312 GURL outputw = | 306 GURL outputw = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 324 } cases[] = { | 318 } cases[] = { |
| 325 {"http://www.google.com", "http://www.google.com/"}, | 319 {"http://www.google.com", "http://www.google.com/"}, |
| 326 {"javascript:window.alert(\"hello,world\");", ""}, | 320 {"javascript:window.alert(\"hello,world\");", ""}, |
| 327 {"http://user:pass@www.google.com:21/blah#baz", "http://www.google.com:21/"}
, | 321 {"http://user:pass@www.google.com:21/blah#baz", "http://www.google.com:21/"}
, |
| 328 {"http://user@www.google.com", "http://www.google.com/"}, | 322 {"http://user@www.google.com", "http://www.google.com/"}, |
| 329 {"http://:pass@www.google.com", "http://www.google.com/"}, | 323 {"http://:pass@www.google.com", "http://www.google.com/"}, |
| 330 {"http://:@www.google.com", "http://www.google.com/"}, | 324 {"http://:@www.google.com", "http://www.google.com/"}, |
| 331 {"filesystem:http://www.google.com/temp/foo?q#b", "http://www.google.com/"}, | 325 {"filesystem:http://www.google.com/temp/foo?q#b", "http://www.google.com/"}, |
| 332 {"filesystem:http://user:pass@google.com:21/blah#baz", "http://google.com:21
/"}, | 326 {"filesystem:http://user:pass@google.com:21/blah#baz", "http://google.com:21
/"}, |
| 333 }; | 327 }; |
| 334 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 328 for (size_t i = 0; i < arraysize(cases); i++) { |
| 335 GURL url(cases[i].input); | 329 GURL url(cases[i].input); |
| 336 GURL origin = url.GetOrigin(); | 330 GURL origin = url.GetOrigin(); |
| 337 EXPECT_EQ(cases[i].expected, origin.spec()); | 331 EXPECT_EQ(cases[i].expected, origin.spec()); |
| 338 } | 332 } |
| 339 } | 333 } |
| 340 | 334 |
| 341 TEST(GURLTest, GetAsReferrer) { | 335 TEST(GURLTest, GetAsReferrer) { |
| 342 struct TestCase { | 336 struct TestCase { |
| 343 const char* input; | 337 const char* input; |
| 344 const char* expected; | 338 const char* expected; |
| 345 } cases[] = { | 339 } cases[] = { |
| 346 {"http://www.google.com", "http://www.google.com/"}, | 340 {"http://www.google.com", "http://www.google.com/"}, |
| 347 {"http://user:pass@www.google.com:21/blah#baz", "http://www.google.com:21/bl
ah"}, | 341 {"http://user:pass@www.google.com:21/blah#baz", "http://www.google.com:21/bl
ah"}, |
| 348 {"http://user@www.google.com", "http://www.google.com/"}, | 342 {"http://user@www.google.com", "http://www.google.com/"}, |
| 349 {"http://:pass@www.google.com", "http://www.google.com/"}, | 343 {"http://:pass@www.google.com", "http://www.google.com/"}, |
| 350 {"http://:@www.google.com", "http://www.google.com/"}, | 344 {"http://:@www.google.com", "http://www.google.com/"}, |
| 351 {"http://www.google.com/temp/foo?q#b", "http://www.google.com/temp/foo?q"}, | 345 {"http://www.google.com/temp/foo?q#b", "http://www.google.com/temp/foo?q"}, |
| 352 }; | 346 }; |
| 353 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 347 for (size_t i = 0; i < arraysize(cases); i++) { |
| 354 GURL url(cases[i].input); | 348 GURL url(cases[i].input); |
| 355 GURL origin = url.GetAsReferrer(); | 349 GURL origin = url.GetAsReferrer(); |
| 356 EXPECT_EQ(cases[i].expected, origin.spec()); | 350 EXPECT_EQ(cases[i].expected, origin.spec()); |
| 357 } | 351 } |
| 358 } | 352 } |
| 359 | 353 |
| 360 TEST(GURLTest, GetWithEmptyPath) { | 354 TEST(GURLTest, GetWithEmptyPath) { |
| 361 struct TestCase { | 355 struct TestCase { |
| 362 const char* input; | 356 const char* input; |
| 363 const char* expected; | 357 const char* expected; |
| 364 } cases[] = { | 358 } cases[] = { |
| 365 {"http://www.google.com", "http://www.google.com/"}, | 359 {"http://www.google.com", "http://www.google.com/"}, |
| 366 {"javascript:window.alert(\"hello, world\");", ""}, | 360 {"javascript:window.alert(\"hello, world\");", ""}, |
| 367 {"http://www.google.com/foo/bar.html?baz=22", "http://www.google.com/"}, | 361 {"http://www.google.com/foo/bar.html?baz=22", "http://www.google.com/"}, |
| 368 {"filesystem:http://www.google.com/temporary/bar.html?baz=22", "filesystem:h
ttp://www.google.com/temporary/"}, | 362 {"filesystem:http://www.google.com/temporary/bar.html?baz=22", "filesystem:h
ttp://www.google.com/temporary/"}, |
| 369 {"filesystem:file:///temporary/bar.html?baz=22", "filesystem:file:///tempora
ry/"}, | 363 {"filesystem:file:///temporary/bar.html?baz=22", "filesystem:file:///tempora
ry/"}, |
| 370 }; | 364 }; |
| 371 | 365 |
| 372 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 366 for (size_t i = 0; i < arraysize(cases); i++) { |
| 373 GURL url(cases[i].input); | 367 GURL url(cases[i].input); |
| 374 GURL empty_path = url.GetWithEmptyPath(); | 368 GURL empty_path = url.GetWithEmptyPath(); |
| 375 EXPECT_EQ(cases[i].expected, empty_path.spec()); | 369 EXPECT_EQ(cases[i].expected, empty_path.spec()); |
| 376 } | 370 } |
| 377 } | 371 } |
| 378 | 372 |
| 379 TEST(GURLTest, Replacements) { | 373 TEST(GURLTest, Replacements) { |
| 380 // The url canonicalizer replacement test will handle most of these case. | 374 // The url canonicalizer replacement test will handle most of these case. |
| 381 // The most important thing to do here is to check that the proper | 375 // The most important thing to do here is to check that the proper |
| 382 // canonicalizer gets called based on the scheme of the input. | 376 // canonicalizer gets called based on the scheme of the input. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 394 } replace_cases[] = { | 388 } replace_cases[] = { |
| 395 {"http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL, NULL, NULL,
"/", "", "", "http://www.google.com/"}, | 389 {"http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL, NULL, NULL,
"/", "", "", "http://www.google.com/"}, |
| 396 {"http://www.google.com/foo/bar.html?foo#bar", "javascript", "", "", "", "",
"window.open('foo');", "", "", "javascript:window.open('foo');"}, | 390 {"http://www.google.com/foo/bar.html?foo#bar", "javascript", "", "", "", "",
"window.open('foo');", "", "", "javascript:window.open('foo');"}, |
| 397 {"file:///C:/foo/bar.txt", "http", NULL, NULL, "www.google.com", "99", "/foo
","search", "ref", "http://www.google.com:99/foo?search#ref"}, | 391 {"file:///C:/foo/bar.txt", "http", NULL, NULL, "www.google.com", "99", "/foo
","search", "ref", "http://www.google.com:99/foo?search#ref"}, |
| 398 #ifdef WIN32 | 392 #ifdef WIN32 |
| 399 {"http://www.google.com/foo/bar.html?foo#bar", "file", "", "", "", "", "c:\\
", "", "", "file:///C:/"}, | 393 {"http://www.google.com/foo/bar.html?foo#bar", "file", "", "", "", "", "c:\\
", "", "", "file:///C:/"}, |
| 400 #endif | 394 #endif |
| 401 {"filesystem:http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL,
NULL, NULL, "/", "", "", "filesystem:http://www.google.com/foo/"}, | 395 {"filesystem:http://www.google.com/foo/bar.html?foo#bar", NULL, NULL, NULL,
NULL, NULL, "/", "", "", "filesystem:http://www.google.com/foo/"}, |
| 402 }; | 396 }; |
| 403 | 397 |
| 404 for (size_t i = 0; i < ARRAYSIZE(replace_cases); i++) { | 398 for (size_t i = 0; i < arraysize(replace_cases); i++) { |
| 405 const ReplaceCase& cur = replace_cases[i]; | 399 const ReplaceCase& cur = replace_cases[i]; |
| 406 GURL url(cur.base); | 400 GURL url(cur.base); |
| 407 GURL::Replacements repl; | 401 GURL::Replacements repl; |
| 408 SetupReplacement(&GURL::Replacements::SetScheme, &repl, cur.scheme); | 402 SetupReplacement(&GURL::Replacements::SetScheme, &repl, cur.scheme); |
| 409 SetupReplacement(&GURL::Replacements::SetUsername, &repl, cur.username); | 403 SetupReplacement(&GURL::Replacements::SetUsername, &repl, cur.username); |
| 410 SetupReplacement(&GURL::Replacements::SetPassword, &repl, cur.password); | 404 SetupReplacement(&GURL::Replacements::SetPassword, &repl, cur.password); |
| 411 SetupReplacement(&GURL::Replacements::SetHost, &repl, cur.host); | 405 SetupReplacement(&GURL::Replacements::SetHost, &repl, cur.host); |
| 412 SetupReplacement(&GURL::Replacements::SetPort, &repl, cur.port); | 406 SetupReplacement(&GURL::Replacements::SetPort, &repl, cur.port); |
| 413 SetupReplacement(&GURL::Replacements::SetPath, &repl, cur.path); | 407 SetupReplacement(&GURL::Replacements::SetPath, &repl, cur.path); |
| 414 SetupReplacement(&GURL::Replacements::SetQuery, &repl, cur.query); | 408 SetupReplacement(&GURL::Replacements::SetQuery, &repl, cur.query); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 } cases[] = { | 445 } cases[] = { |
| 452 {"http://www.google.com", "/", NULL}, | 446 {"http://www.google.com", "/", NULL}, |
| 453 {"http://www.google.com/", "/", NULL}, | 447 {"http://www.google.com/", "/", NULL}, |
| 454 {"http://www.google.com/foo/bar.html?baz=22", "/foo/bar.html?baz=22", NULL}, | 448 {"http://www.google.com/foo/bar.html?baz=22", "/foo/bar.html?baz=22", NULL}, |
| 455 {"http://www.google.com/foo/bar.html#ref", "/foo/bar.html", NULL}, | 449 {"http://www.google.com/foo/bar.html#ref", "/foo/bar.html", NULL}, |
| 456 {"http://www.google.com/foo/bar.html?query#ref", "/foo/bar.html?query", NULL
}, | 450 {"http://www.google.com/foo/bar.html?query#ref", "/foo/bar.html?query", NULL
}, |
| 457 {"filesystem:http://www.google.com/temporary/foo/bar.html?query#ref", "/foo/
bar.html?query", "/temporary"}, | 451 {"filesystem:http://www.google.com/temporary/foo/bar.html?query#ref", "/foo/
bar.html?query", "/temporary"}, |
| 458 {"filesystem:http://www.google.com/temporary/foo/bar.html?query", "/foo/bar.
html?query", "/temporary"}, | 452 {"filesystem:http://www.google.com/temporary/foo/bar.html?query", "/foo/bar.
html?query", "/temporary"}, |
| 459 }; | 453 }; |
| 460 | 454 |
| 461 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 455 for (size_t i = 0; i < arraysize(cases); i++) { |
| 462 GURL url(cases[i].input); | 456 GURL url(cases[i].input); |
| 463 std::string path_request = url.PathForRequest(); | 457 std::string path_request = url.PathForRequest(); |
| 464 EXPECT_EQ(cases[i].expected, path_request); | 458 EXPECT_EQ(cases[i].expected, path_request); |
| 465 EXPECT_EQ(cases[i].inner_expected == NULL, url.inner_url() == NULL); | 459 EXPECT_EQ(cases[i].inner_expected == NULL, url.inner_url() == NULL); |
| 466 if (url.inner_url() && cases[i].inner_expected) | 460 if (url.inner_url() && cases[i].inner_expected) |
| 467 EXPECT_EQ(cases[i].inner_expected, url.inner_url()->PathForRequest()); | 461 EXPECT_EQ(cases[i].inner_expected, url.inner_url()->PathForRequest()); |
| 468 } | 462 } |
| 469 } | 463 } |
| 470 | 464 |
| 471 TEST(GURLTest, EffectiveIntPort) { | 465 TEST(GURLTest, EffectiveIntPort) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 499 | 493 |
| 500 // data - no port | 494 // data - no port |
| 501 {"data:www.google.com:90", PORT_UNSPECIFIED}, | 495 {"data:www.google.com:90", PORT_UNSPECIFIED}, |
| 502 {"data:www.google.com", PORT_UNSPECIFIED}, | 496 {"data:www.google.com", PORT_UNSPECIFIED}, |
| 503 | 497 |
| 504 // filesystem - no port | 498 // filesystem - no port |
| 505 {"filesystem:http://www.google.com:90/t/foo", PORT_UNSPECIFIED}, | 499 {"filesystem:http://www.google.com:90/t/foo", PORT_UNSPECIFIED}, |
| 506 {"filesystem:file:///t/foo", PORT_UNSPECIFIED}, | 500 {"filesystem:file:///t/foo", PORT_UNSPECIFIED}, |
| 507 }; | 501 }; |
| 508 | 502 |
| 509 for (size_t i = 0; i < ARRAYSIZE(port_tests); i++) { | 503 for (size_t i = 0; i < arraysize(port_tests); i++) { |
| 510 GURL url(port_tests[i].spec); | 504 GURL url(port_tests[i].spec); |
| 511 EXPECT_EQ(port_tests[i].expected_int_port, url.EffectiveIntPort()); | 505 EXPECT_EQ(port_tests[i].expected_int_port, url.EffectiveIntPort()); |
| 512 } | 506 } |
| 513 } | 507 } |
| 514 | 508 |
| 515 TEST(GURLTest, IPAddress) { | 509 TEST(GURLTest, IPAddress) { |
| 516 struct IPTest { | 510 struct IPTest { |
| 517 const char* spec; | 511 const char* spec; |
| 518 bool expected_ip; | 512 bool expected_ip; |
| 519 } ip_tests[] = { | 513 } ip_tests[] = { |
| 520 {"http://www.google.com/", false}, | 514 {"http://www.google.com/", false}, |
| 521 {"http://192.168.9.1/", true}, | 515 {"http://192.168.9.1/", true}, |
| 522 {"http://192.168.9.1.2/", false}, | 516 {"http://192.168.9.1.2/", false}, |
| 523 {"http://192.168.m.1/", false}, | 517 {"http://192.168.m.1/", false}, |
| 524 {"http://2001:db8::1/", false}, | 518 {"http://2001:db8::1/", false}, |
| 525 {"http://[2001:db8::1]/", true}, | 519 {"http://[2001:db8::1]/", true}, |
| 526 {"", false}, | 520 {"", false}, |
| 527 {"some random input!", false}, | 521 {"some random input!", false}, |
| 528 }; | 522 }; |
| 529 | 523 |
| 530 for (size_t i = 0; i < ARRAYSIZE(ip_tests); i++) { | 524 for (size_t i = 0; i < arraysize(ip_tests); i++) { |
| 531 GURL url(ip_tests[i].spec); | 525 GURL url(ip_tests[i].spec); |
| 532 EXPECT_EQ(ip_tests[i].expected_ip, url.HostIsIPAddress()); | 526 EXPECT_EQ(ip_tests[i].expected_ip, url.HostIsIPAddress()); |
| 533 } | 527 } |
| 534 } | 528 } |
| 535 | 529 |
| 536 TEST(GURLTest, HostNoBrackets) { | 530 TEST(GURLTest, HostNoBrackets) { |
| 537 struct TestCase { | 531 struct TestCase { |
| 538 const char* input; | 532 const char* input; |
| 539 const char* expected_host; | 533 const char* expected_host; |
| 540 const char* expected_plainhost; | 534 const char* expected_plainhost; |
| 541 } cases[] = { | 535 } cases[] = { |
| 542 {"http://www.google.com", "www.google.com", "www.google.com"}, | 536 {"http://www.google.com", "www.google.com", "www.google.com"}, |
| 543 {"http://[2001:db8::1]/", "[2001:db8::1]", "2001:db8::1"}, | 537 {"http://[2001:db8::1]/", "[2001:db8::1]", "2001:db8::1"}, |
| 544 {"http://[::]/", "[::]", "::"}, | 538 {"http://[::]/", "[::]", "::"}, |
| 545 | 539 |
| 546 // Don't require a valid URL, but don't crash either. | 540 // Don't require a valid URL, but don't crash either. |
| 547 {"http://[]/", "[]", ""}, | 541 {"http://[]/", "[]", ""}, |
| 548 {"http://[x]/", "[x]", "x"}, | 542 {"http://[x]/", "[x]", "x"}, |
| 549 {"http://[x/", "[x", "[x"}, | 543 {"http://[x/", "[x", "[x"}, |
| 550 {"http://x]/", "x]", "x]"}, | 544 {"http://x]/", "x]", "x]"}, |
| 551 {"http://[/", "[", "["}, | 545 {"http://[/", "[", "["}, |
| 552 {"http://]/", "]", "]"}, | 546 {"http://]/", "]", "]"}, |
| 553 {"", "", ""}, | 547 {"", "", ""}, |
| 554 }; | 548 }; |
| 555 for (size_t i = 0; i < ARRAYSIZE(cases); i++) { | 549 for (size_t i = 0; i < arraysize(cases); i++) { |
| 556 GURL url(cases[i].input); | 550 GURL url(cases[i].input); |
| 557 EXPECT_EQ(cases[i].expected_host, url.host()); | 551 EXPECT_EQ(cases[i].expected_host, url.host()); |
| 558 EXPECT_EQ(cases[i].expected_plainhost, url.HostNoBrackets()); | 552 EXPECT_EQ(cases[i].expected_plainhost, url.HostNoBrackets()); |
| 559 } | 553 } |
| 560 } | 554 } |
| 561 | 555 |
| 562 TEST(GURLTest, DomainIs) { | 556 TEST(GURLTest, DomainIs) { |
| 563 const char google_domain[] = "google.com"; | 557 const char google_domain[] = "google.com"; |
| 564 | 558 |
| 565 GURL url_1("http://www.google.com:99/foo"); | 559 GURL url_1("http://www.google.com:99/foo"); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS()); | 629 EXPECT_FALSE(GURL("http://bar/").SchemeIsWSOrWSS()); |
| 636 } | 630 } |
| 637 | 631 |
| 638 TEST(GURLTest, SchemeIsBlob) { | 632 TEST(GURLTest, SchemeIsBlob) { |
| 639 EXPECT_TRUE(GURL("BLOB://BAR/").SchemeIsBlob()); | 633 EXPECT_TRUE(GURL("BLOB://BAR/").SchemeIsBlob()); |
| 640 EXPECT_TRUE(GURL("blob://bar/").SchemeIsBlob()); | 634 EXPECT_TRUE(GURL("blob://bar/").SchemeIsBlob()); |
| 641 EXPECT_FALSE(GURL("http://bar/").SchemeIsBlob()); | 635 EXPECT_FALSE(GURL("http://bar/").SchemeIsBlob()); |
| 642 } | 636 } |
| 643 | 637 |
| 644 } // namespace url | 638 } // namespace url |
| OLD | NEW |