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/third_party/mozilla/url_parse.h" | 9 #include "url/third_party/mozilla/url_parse.h" |
10 #include "url/url_canon.h" | 10 #include "url/url_canon.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 Parsed resolved_parsed; | 367 Parsed resolved_parsed; |
368 | 368 |
369 bool valid = ResolveRelative(base, strlen(base), | 369 bool valid = ResolveRelative(base, strlen(base), |
370 base_parsed, rel, | 370 base_parsed, rel, |
371 strlen(rel), NULL, &output, | 371 strlen(rel), NULL, &output, |
372 &resolved_parsed); | 372 &resolved_parsed); |
373 EXPECT_TRUE(valid); | 373 EXPECT_TRUE(valid); |
374 EXPECT_FALSE(resolved_parsed.ref.is_valid()); | 374 EXPECT_FALSE(resolved_parsed.ref.is_valid()); |
375 } | 375 } |
376 | 376 |
| 377 TEST(URLUtilTest, TestDomainIs) { |
| 378 const struct { |
| 379 const char* canonicalized_host; |
| 380 const char* lower_ascii_domain; |
| 381 bool expected_domain_is; |
| 382 } kTestCases[] = { |
| 383 {"google.com", "google.com", true}, |
| 384 {"www.google.com", "google.com", true}, // Subdomain is ignored. |
| 385 {"www.google.com.cn", "google.com", false}, // Different TLD. |
| 386 {"www.google.comm", "google.com", false}, |
| 387 {"www.iamnotgoogle.com", "google.com", false}, // Different hostname. |
| 388 {"www.google.com", "Google.com", false}, // The input is not lower-cased. |
| 389 |
| 390 // If the host ends with a dot, it matches domains with or without a dot. |
| 391 {"www.google.com.", "google.com", true}, |
| 392 {"www.google.com.", "google.com.", true}, |
| 393 {"www.google.com.", ".com", true}, |
| 394 {"www.google.com.", ".com.", true}, |
| 395 |
| 396 // But, if the host doesn't end with a dot and the input domain does, then |
| 397 // it's considered to not match. |
| 398 {"www.google.com", "google.com.", false}, |
| 399 |
| 400 // If the host ends with two dots, it doesn't match. |
| 401 {"www.google.com..", "google.com", false}, |
| 402 |
| 403 // Empty parameters. |
| 404 {"www.google.com", "", false}, |
| 405 {"", "www.google.com", false}, |
| 406 {"", "", false}, |
| 407 }; |
| 408 |
| 409 for (const auto& test_case : kTestCases) { |
| 410 SCOPED_TRACE(testing::Message() << "(host, domain): (" |
| 411 << test_case.canonicalized_host << ", " |
| 412 << test_case.lower_ascii_domain << ")"); |
| 413 |
| 414 EXPECT_EQ( |
| 415 test_case.expected_domain_is, |
| 416 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain)); |
| 417 } |
| 418 } |
| 419 |
377 } // namespace url | 420 } // namespace url |
OLD | NEW |