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

Side by Side Diff: net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc

Issue 1783813002: SameSite: Strict/Lax behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@strict-lax
Patch Set: Comment. Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/registry_controlled_domains/registry_controlled_domain.h" 5 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "url/gurl.h" 7 #include "url/gurl.h"
8 #include "url/origin.h"
8 9
9 namespace { 10 namespace {
10 namespace test1 { 11 namespace test1 {
11 #include "net/base/registry_controlled_domains/effective_tld_names_unittest1-inc .cc" 12 #include "net/base/registry_controlled_domains/effective_tld_names_unittest1-inc .cc"
12 } 13 }
13 namespace test2 { 14 namespace test2 {
14 #include "net/base/registry_controlled_domains/effective_tld_names_unittest2-inc .cc" 15 #include "net/base/registry_controlled_domains/effective_tld_names_unittest2-inc .cc"
15 } 16 }
16 namespace test3 { 17 namespace test3 {
17 #include "net/base/registry_controlled_domains/effective_tld_names_unittest3-inc .cc" 18 #include "net/base/registry_controlled_domains/effective_tld_names_unittest3-inc .cc"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 UnknownRegistryFilter unknown_filter) { 61 UnknownRegistryFilter unknown_filter) {
61 return GetRegistryLength(host, unknown_filter, EXCLUDE_PRIVATE_REGISTRIES); 62 return GetRegistryLength(host, unknown_filter, EXCLUDE_PRIVATE_REGISTRIES);
62 } 63 }
63 64
64 size_t GetRegistryLengthFromHostIncludingPrivate( 65 size_t GetRegistryLengthFromHostIncludingPrivate(
65 const std::string& host, 66 const std::string& host,
66 UnknownRegistryFilter unknown_filter) { 67 UnknownRegistryFilter unknown_filter) {
67 return GetRegistryLength(host, unknown_filter, INCLUDE_PRIVATE_REGISTRIES); 68 return GetRegistryLength(host, unknown_filter, INCLUDE_PRIVATE_REGISTRIES);
68 } 69 }
69 70
70 bool CompareDomains(const std::string& url1, const std::string& url2) {
71 GURL g1 = GURL(url1);
72 GURL g2 = GURL(url2);
73 return SameDomainOrHost(g1, g2, EXCLUDE_PRIVATE_REGISTRIES);
74 }
75
76 } // namespace 71 } // namespace
77 72
78 class RegistryControlledDomainTest : public testing::Test { 73 class RegistryControlledDomainTest : public testing::Test {
79 protected: 74 protected:
80 template <typename Graph> 75 template <typename Graph>
81 void UseDomainData(const Graph& graph) { 76 void UseDomainData(const Graph& graph) {
82 SetFindDomainGraph(graph, sizeof(Graph)); 77 SetFindDomainGraph(graph, sizeof(Graph));
83 } 78 }
84 79
80 bool CompareDomains(const std::string& url1, const std::string& url2) {
81 SCOPED_TRACE(url1 + " " + url2);
82 GURL g1 = GURL(url1);
83 GURL g2 = GURL(url2);
84 url::Origin o1 = url::Origin(g1);
85 url::Origin o2 = url::Origin(g2);
86 EXPECT_EQ(SameDomainOrHost(o1, o2, EXCLUDE_PRIVATE_REGISTRIES),
87 SameDomainOrHost(g1, g2, EXCLUDE_PRIVATE_REGISTRIES));
88 return SameDomainOrHost(g1, g2, EXCLUDE_PRIVATE_REGISTRIES);
89 }
90
85 void TearDown() override { SetFindDomainGraph(); } 91 void TearDown() override { SetFindDomainGraph(); }
86 }; 92 };
87 93
88 TEST_F(RegistryControlledDomainTest, TestGetDomainAndRegistry) { 94 TEST_F(RegistryControlledDomainTest, TestGetDomainAndRegistry) {
89 UseDomainData(test1::kDafsa); 95 UseDomainData(test1::kDafsa);
90 96
91 // Test GURL version of GetDomainAndRegistry(). 97 // Test GURL version of GetDomainAndRegistry().
92 EXPECT_EQ("baz.jp", GetDomainFromURL("http://a.baz.jp/file.html")); // 1 98 EXPECT_EQ("baz.jp", GetDomainFromURL("http://a.baz.jp/file.html")); // 1
93 EXPECT_EQ("baz.jp.", GetDomainFromURL("http://a.baz.jp./file.html")); // 1 99 EXPECT_EQ("baz.jp.", GetDomainFromURL("http://a.baz.jp./file.html")); // 1
94 EXPECT_EQ("", GetDomainFromURL("http://ac.jp")); // 2 100 EXPECT_EQ("", GetDomainFromURL("http://ac.jp")); // 2
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 GetRegistryLengthFromHostIncludingPrivate( 497 GetRegistryLengthFromHostIncludingPrivate(
492 key4, EXCLUDE_UNKNOWN_REGISTRIES)); 498 key4, EXCLUDE_UNKNOWN_REGISTRIES));
493 EXPECT_EQ(0U, 499 EXPECT_EQ(0U,
494 GetRegistryLengthFromHostIncludingPrivate( 500 GetRegistryLengthFromHostIncludingPrivate(
495 key5, EXCLUDE_UNKNOWN_REGISTRIES)); 501 key5, EXCLUDE_UNKNOWN_REGISTRIES));
496 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES)); 502 EXPECT_EQ(5U, GetRegistryLengthFromHost(key6, EXCLUDE_UNKNOWN_REGISTRIES));
497 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES)); 503 EXPECT_EQ(5U, GetRegistryLengthFromHost(key7, EXCLUDE_UNKNOWN_REGISTRIES));
498 } 504 }
499 } // namespace registry_controlled_domains 505 } // namespace registry_controlled_domains
500 } // namespace net 506 } // namespace net
OLDNEW
« no previous file with comments | « net/base/registry_controlled_domains/registry_controlled_domain.cc ('k') | net/cookies/canonical_cookie.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698