Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: url/url_util_unittest.cc

Issue 2287483002: Provide the equivalent of GURL::DomainIs for url::Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor changes. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « url/url_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « url/url_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698