Chromium Code Reviews| Index: url/origin_unittest.cc |
| diff --git a/url/origin_unittest.cc b/url/origin_unittest.cc |
| index 74ffd3038db974d9d944c0bdd93e9525f2735dd1..cc3c1b73ac00f5c465faaab5f1d4d2f8d51d1981 100644 |
| --- a/url/origin_unittest.cc |
| +++ b/url/origin_unittest.cc |
| @@ -252,4 +252,53 @@ TEST(OriginTest, UnsafelyCreateUniqueViaEmbeddedNulls) { |
| } |
| } |
| +TEST(OriginTest, DomainIs) { |
|
engedy
2016/08/26 16:48:14
Could you please add an explicit test for a file:
pkalinnikov
2016/08/29 09:53:00
Done.
|
| + const struct { |
| + const char* url; |
| + const char* lower_ascii_domain; |
| + bool expected_domain_is; |
| + } kTestCases[] = { |
| + {"http://google.com/foo", "google.com", true}, |
| + {"http://www.google.com:99/foo", "google.com", true}, |
| + {"http://www.google.com.cn/foo", "google.com", false}, |
| + {"http://www.google.comm", "google.com", false}, |
| + {"http://www.iamnotgoogle.com/foo", "google.com", false}, |
| + {"http://www.google.com/foo", "Google.com", false}, |
| + |
| + // If the host ends with a dot, it matches domains with or without a dot. |
| + {"http://www.google.com./foo", "google.com", true}, |
| + {"http://www.google.com./foo", "google.com.", true}, |
| + {"http://www.google.com./foo", ".com", true}, |
| + {"http://www.google.com./foo", ".com.", true}, |
| + |
| + // But, if the host doesn't end with a dot and the input domain does, then |
| + // it's considered to not match. |
| + {"http://google.com/foo", "google.com.", false}, |
| + |
| + // If the host ends with two dots, it doesn't match. |
| + {"http://www.google.com../foo", "google.com", false}, |
| + |
| + // Filesystem scheme. |
| + {"filesystem:http://www.google.com:99/foo/", "google.com", true}, |
| + {"filesystem:http://www.iamnotgoogle.com/foo/", "google.com", false}, |
| + }; |
| + |
| + for (const auto& test_case : kTestCases) { |
| + SCOPED_TRACE(testing::Message() << "(url, domain): (" << test_case.url |
| + << ", " << test_case.lower_ascii_domain |
| + << ")"); |
| + GURL url(test_case.url); |
| + ASSERT_TRUE(url.is_valid()); |
| + url::Origin origin(url); |
| + |
| + EXPECT_EQ(test_case.expected_domain_is, |
| + origin.DomainIs(test_case.lower_ascii_domain)); |
| + } |
| + |
| + // If the URL is invalid, DomainIs returns false. |
| + GURL invalid_url("google.com"); |
| + ASSERT_FALSE(invalid_url.is_valid()); |
| + EXPECT_FALSE(url::Origin(invalid_url).DomainIs("google.com")); |
| +} |
| + |
| } // namespace url |