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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
10 #include "url/third_party/mozilla/url_parse.h" | 10 #include "url/third_party/mozilla/url_parse.h" |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 EXPECT_TRUE(IsAboutBlank(GURL(url))); | 426 EXPECT_TRUE(IsAboutBlank(GURL(url))); |
427 | 427 |
428 const std::string kNotAboutBlankUrls[] = { | 428 const std::string kNotAboutBlankUrls[] = { |
429 "http:blank", "about:blan", "about://blank", | 429 "http:blank", "about:blan", "about://blank", |
430 "about:blank/foo", "about://:8000/blank", "about://foo:foo@/blank", | 430 "about:blank/foo", "about://:8000/blank", "about://foo:foo@/blank", |
431 "foo@about:blank", "foo:bar@about:blank", "about:blank:8000"}; | 431 "foo@about:blank", "foo:bar@about:blank", "about:blank:8000"}; |
432 for (const auto& url : kNotAboutBlankUrls) | 432 for (const auto& url : kNotAboutBlankUrls) |
433 EXPECT_FALSE(IsAboutBlank(GURL(url))); | 433 EXPECT_FALSE(IsAboutBlank(GURL(url))); |
434 } | 434 } |
435 | 435 |
| 436 TEST(URLUtilTest, EqualsIgnoringRef) { |
| 437 const struct { |
| 438 const char* url_a; |
| 439 const char* url_b; |
| 440 bool are_equals; |
| 441 } kTestCases[] = { |
| 442 // No ref. |
| 443 {"http://a.com", "http://a.com", true}, |
| 444 {"http://a.com", "http://b.com", false}, |
| 445 |
| 446 // Same Ref. |
| 447 {"http://a.com#foo", "http://a.com#foo", true}, |
| 448 {"http://a.com#foo", "http://b.com#foo", false}, |
| 449 |
| 450 // Different Refs. |
| 451 {"http://a.com#foo", "http://a.com#bar", true}, |
| 452 {"http://a.com#foo", "http://b.com#bar", false}, |
| 453 |
| 454 // One has a ref, the other doesn't. |
| 455 {"http://a.com#foo", "http://a.com", true}, |
| 456 {"http://a.com#foo", "http://b.com", false}, |
| 457 |
| 458 // Empty refs. |
| 459 {"http://a.com#", "http://a.com#", true}, |
| 460 {"http://a.com#", "http://a.com", true}, |
| 461 |
| 462 // URLs that differ only by their last character. |
| 463 {"http://aaa", "http://aab", false}, |
| 464 {"http://aaa#foo", "http://aab#foo", false}, |
| 465 |
| 466 // Different size of the part before the ref. |
| 467 {"http://123#a", "http://123456#a", false}, |
| 468 |
| 469 // Blob URLs |
| 470 {"blob:http://a.com#foo", "blob:http://a.com#foo", true}, |
| 471 {"blob:http://a.com#foo", "blob:http://a.com#bar", true}, |
| 472 {"blob:http://a.com#foo", "blob:http://b.com#bar", false}, |
| 473 |
| 474 // Filesystem URLs |
| 475 {"filesystem:http://a.com#foo", "filesystem:http://a.com#foo", true}, |
| 476 {"filesystem:http://a.com#foo", "filesystem:http://a.com#bar", true}, |
| 477 {"filesystem:http://a.com#foo", "filesystem:http://b.com#bar", false}, |
| 478 }; |
| 479 |
| 480 for (const auto& test_case : kTestCases) { |
| 481 SCOPED_TRACE(testing::Message() |
| 482 << std::endl |
| 483 << "url_a = " << test_case.url_a << std::endl |
| 484 << "url_b = " << test_case.url_b << std::endl); |
| 485 // A versus B. |
| 486 EXPECT_EQ(test_case.are_equals, |
| 487 GURL(test_case.url_a).EqualsIgnoringRef(GURL(test_case.url_b))); |
| 488 // B versus A. |
| 489 EXPECT_EQ(test_case.are_equals, |
| 490 GURL(test_case.url_b).EqualsIgnoringRef(GURL(test_case.url_a))); |
| 491 } |
| 492 } |
| 493 |
436 } // namespace url | 494 } // namespace url |
OLD | NEW |