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 "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "url/gurl.h" | 10 #include "url/gurl.h" |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 {"filesystem:http://example.com/path", "/"}, | 733 {"filesystem:http://example.com/path", "/"}, |
734 }; | 734 }; |
735 | 735 |
736 for (const auto& test : cases) { | 736 for (const auto& test : cases) { |
737 GURL url(test.url); | 737 GURL url(test.url); |
738 EXPECT_EQ(test.expected, url.path()) << test.url; | 738 EXPECT_EQ(test.expected, url.path()) << test.url; |
739 EXPECT_EQ(test.expected, url.GetContent()) << test.url; | 739 EXPECT_EQ(test.expected, url.GetContent()) << test.url; |
740 } | 740 } |
741 } | 741 } |
742 | 742 |
| 743 TEST(GURLTest, IsAboutBlank) { |
| 744 const std::string kAboutBlankUrls[] = {"about:blank", "about:blank?foo", |
| 745 "about:blank/#foo", |
| 746 "about:blank?foo#foo"}; |
| 747 for (const auto& url : kAboutBlankUrls) |
| 748 EXPECT_TRUE(GURL(url).IsAboutBlank()) << url; |
| 749 |
| 750 const std::string kNotAboutBlankUrls[] = { |
| 751 "http:blank", "about:blan", "about://blank", |
| 752 "about:blank/foo", "about://:8000/blank", "about://foo:foo@/blank", |
| 753 "foo@about:blank", "foo:bar@about:blank", "about:blank:8000"}; |
| 754 for (const auto& url : kNotAboutBlankUrls) |
| 755 EXPECT_FALSE(GURL(url).IsAboutBlank()) << url; |
| 756 } |
| 757 |
| 758 TEST(GURLTest, EqualsIgnoringRef) { |
| 759 const struct { |
| 760 const char* url_a; |
| 761 const char* url_b; |
| 762 bool are_equals; |
| 763 } kTestCases[] = { |
| 764 // No ref. |
| 765 {"http://a.com", "http://a.com", true}, |
| 766 {"http://a.com", "http://b.com", false}, |
| 767 |
| 768 // Same Ref. |
| 769 {"http://a.com#foo", "http://a.com#foo", true}, |
| 770 {"http://a.com#foo", "http://b.com#foo", false}, |
| 771 |
| 772 // Different Refs. |
| 773 {"http://a.com#foo", "http://a.com#bar", true}, |
| 774 {"http://a.com#foo", "http://b.com#bar", false}, |
| 775 |
| 776 // One has a ref, the other doesn't. |
| 777 {"http://a.com#foo", "http://a.com", true}, |
| 778 {"http://a.com#foo", "http://b.com", false}, |
| 779 |
| 780 // Empty refs. |
| 781 {"http://a.com#", "http://a.com#", true}, |
| 782 {"http://a.com#", "http://a.com", true}, |
| 783 |
| 784 // URLs that differ only by their last character. |
| 785 {"http://aaa", "http://aab", false}, |
| 786 {"http://aaa#foo", "http://aab#foo", false}, |
| 787 |
| 788 // Different size of the part before the ref. |
| 789 {"http://123#a", "http://123456#a", false}, |
| 790 |
| 791 // Blob URLs |
| 792 {"blob:http://a.com#foo", "blob:http://a.com#foo", true}, |
| 793 {"blob:http://a.com#foo", "blob:http://a.com#bar", true}, |
| 794 {"blob:http://a.com#foo", "blob:http://b.com#bar", false}, |
| 795 |
| 796 // Filesystem URLs |
| 797 {"filesystem:http://a.com#foo", "filesystem:http://a.com#foo", true}, |
| 798 {"filesystem:http://a.com#foo", "filesystem:http://a.com#bar", true}, |
| 799 {"filesystem:http://a.com#foo", "filesystem:http://b.com#bar", false}, |
| 800 }; |
| 801 |
| 802 for (const auto& test_case : kTestCases) { |
| 803 SCOPED_TRACE(testing::Message() |
| 804 << std::endl |
| 805 << "url_a = " << test_case.url_a << std::endl |
| 806 << "url_b = " << test_case.url_b << std::endl); |
| 807 // A versus B. |
| 808 EXPECT_EQ(test_case.are_equals, |
| 809 GURL(test_case.url_a).EqualsIgnoringRef(GURL(test_case.url_b))); |
| 810 // B versus A. |
| 811 EXPECT_EQ(test_case.are_equals, |
| 812 GURL(test_case.url_b).EqualsIgnoringRef(GURL(test_case.url_a))); |
| 813 } |
| 814 } |
| 815 |
743 } // namespace url | 816 } // namespace url |
OLD | NEW |