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

Side by Side Diff: url/url_util_unittest.cc

Issue 2686853004: Move IsAboutBlank from url_utils to GURL (Closed)
Patch Set: Addressed nit Created 3 years, 10 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/gurl.h"
10 #include "url/third_party/mozilla/url_parse.h" 9 #include "url/third_party/mozilla/url_parse.h"
11 #include "url/url_canon.h" 10 #include "url/url_canon.h"
12 #include "url/url_canon_stdstring.h" 11 #include "url/url_canon_stdstring.h"
13 #include "url/url_test_utils.h" 12 #include "url/url_test_utils.h"
14 #include "url/url_util.h" 13 #include "url/url_util.h"
15 14
16 namespace url { 15 namespace url {
17 16
18 TEST(URLUtilTest, FindAndCompareScheme) { 17 TEST(URLUtilTest, FindAndCompareScheme) {
19 Component found_scheme; 18 Component found_scheme;
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 SCOPED_TRACE(testing::Message() << "(host, domain): (" 410 SCOPED_TRACE(testing::Message() << "(host, domain): ("
412 << test_case.canonicalized_host << ", " 411 << test_case.canonicalized_host << ", "
413 << test_case.lower_ascii_domain << ")"); 412 << test_case.lower_ascii_domain << ")");
414 413
415 EXPECT_EQ( 414 EXPECT_EQ(
416 test_case.expected_domain_is, 415 test_case.expected_domain_is,
417 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain)); 416 DomainIs(test_case.canonicalized_host, test_case.lower_ascii_domain));
418 } 417 }
419 } 418 }
420 419
421 TEST(URLUtilTest, IsAboutBlank) {
422 const std::string kAboutBlankUrls[] = {"about:blank", "about:blank?foo",
423 "about:blank/#foo",
424 "about:blank?foo#foo"};
425 for (const auto& url : kAboutBlankUrls)
426 EXPECT_TRUE(IsAboutBlank(GURL(url)));
427
428 const std::string kNotAboutBlankUrls[] = {
429 "http:blank", "about:blan", "about://blank",
430 "about:blank/foo", "about://:8000/blank", "about://foo:foo@/blank",
431 "foo@about:blank", "foo:bar@about:blank", "about:blank:8000"};
432 for (const auto& url : kNotAboutBlankUrls)
433 EXPECT_FALSE(IsAboutBlank(GURL(url)));
434 }
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
494 } // 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