diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-06 12:48:11 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:33:43 +0000 |
commit | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (patch) | |
tree | fa14ba0ca8d2683ba2efdabd246dc9b18a1229c6 /chromium/net/base/registry_controlled_domains | |
parent | 79b4f909db1049fca459c07cca55af56a9b54fe3 (diff) | |
download | qtwebengine-chromium-7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3.tar.gz |
BASELINE: Update Chromium to 84.0.4147.141
Change-Id: Ib85eb4cfa1cbe2b2b81e5022c8cad5c493969535
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/net/base/registry_controlled_domains')
3 files changed, 57 insertions, 35 deletions
diff --git a/chromium/net/base/registry_controlled_domains/registry_controlled_domain.cc b/chromium/net/base/registry_controlled_domains/registry_controlled_domain.cc index 37dc4fd786b..b39132b6e2c 100644 --- a/chromium/net/base/registry_controlled_domains/registry_controlled_domain.cc +++ b/chromium/net/base/registry_controlled_domains/registry_controlled_domain.cc @@ -45,7 +45,8 @@ #include "net/base/registry_controlled_domains/registry_controlled_domain.h" -#include "base/logging.h" +#include "base/check_op.h" +#include "base/notreached.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "net/base/lookup_string_in_fixed_set.h" @@ -351,6 +352,11 @@ std::string GetDomainAndRegistry(const GURL& gurl, .as_string(); } +std::string GetDomainAndRegistry(const url::Origin& origin, + PrivateRegistryFilter filter) { + return GetDomainAndRegistryAsStringPiece(origin.host(), filter).as_string(); +} + std::string GetDomainAndRegistry(base::StringPiece host, PrivateRegistryFilter filter) { url::CanonHostInfo host_info; diff --git a/chromium/net/base/registry_controlled_domains/registry_controlled_domain.h b/chromium/net/base/registry_controlled_domains/registry_controlled_domain.h index 9f86d6fb053..998819ca878 100644 --- a/chromium/net/base/registry_controlled_domains/registry_controlled_domain.h +++ b/chromium/net/base/registry_controlled_domains/registry_controlled_domain.h @@ -183,8 +183,14 @@ enum UnknownRegistryFilter { NET_EXPORT std::string GetDomainAndRegistry(const GURL& gurl, PrivateRegistryFilter filter); -// Like the GURL version, but takes a host (which is canonicalized internally) -// instead of a full GURL. +// Like the GURL version, but takes an Origin. Returns an empty string if the +// Origin is opaque. +NET_EXPORT std::string GetDomainAndRegistry(const url::Origin& origin, + PrivateRegistryFilter filter); + +// Like the GURL / Origin versions, but takes a host (which is canonicalized +// internally). Prefer either the GURL or Origin variants instead of this one +// to avoid needing to re-canonicalize the host. NET_EXPORT std::string GetDomainAndRegistry(base::StringPiece host, PrivateRegistryFilter filter); diff --git a/chromium/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc b/chromium/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc index 8a6ad63da6e..d43ec299ab0 100644 --- a/chromium/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc +++ b/chromium/net/base/registry_controlled_domains/registry_controlled_domain_unittest.cc @@ -38,10 +38,6 @@ namespace registry_controlled_domains { namespace { -std::string GetDomainFromURL(const std::string& url) { - return GetDomainAndRegistry(GURL(url), EXCLUDE_PRIVATE_REGISTRIES); -} - std::string GetDomainFromHost(const std::string& host) { return GetDomainAndRegistry(host, EXCLUDE_PRIVATE_REGISTRIES); } @@ -113,34 +109,47 @@ class RegistryControlledDomainTest : public testing::Test { TEST_F(RegistryControlledDomainTest, TestGetDomainAndRegistry) { UseDomainData(test1::kDafsa); - // Test GURL version of GetDomainAndRegistry(). - EXPECT_EQ("baz.jp", GetDomainFromURL("http://a.baz.jp/file.html")); // 1 - EXPECT_EQ("baz.jp.", GetDomainFromURL("http://a.baz.jp./file.html")); // 1 - EXPECT_EQ("", GetDomainFromURL("http://ac.jp")); // 2 - EXPECT_EQ("", GetDomainFromURL("http://a.bar.jp")); // 3 - EXPECT_EQ("", GetDomainFromURL("http://bar.jp")); // 3 - EXPECT_EQ("", GetDomainFromURL("http://baz.bar.jp")); // 3 4 - EXPECT_EQ("a.b.baz.bar.jp", GetDomainFromURL("http://a.b.baz.bar.jp")); - // 4 - EXPECT_EQ("pref.bar.jp", GetDomainFromURL("http://baz.pref.bar.jp")); // 5 - EXPECT_EQ("b.bar.baz.com.", GetDomainFromURL("http://a.b.bar.baz.com.")); - // 6 - EXPECT_EQ("a.d.c", GetDomainFromURL("http://a.d.c")); // 7 - EXPECT_EQ("a.d.c", GetDomainFromURL("http://.a.d.c")); // 7 - EXPECT_EQ("a.d.c", GetDomainFromURL("http://..a.d.c")); // 7 - EXPECT_EQ("b.c", GetDomainFromURL("http://a.b.c")); // 7 8 - EXPECT_EQ("baz.com", GetDomainFromURL("http://baz.com")); // none - EXPECT_EQ("baz.com.", GetDomainFromURL("http://baz.com.")); // none - - EXPECT_EQ("", GetDomainFromURL(std::string())); - EXPECT_EQ("", GetDomainFromURL("http://")); - EXPECT_EQ("", GetDomainFromURL("file:///C:/file.html")); - EXPECT_EQ("", GetDomainFromURL("http://foo.com..")); - EXPECT_EQ("", GetDomainFromURL("http://...")); - EXPECT_EQ("", GetDomainFromURL("http://192.168.0.1")); - EXPECT_EQ("", GetDomainFromURL("http://localhost")); - EXPECT_EQ("", GetDomainFromURL("http://localhost.")); - EXPECT_EQ("", GetDomainFromURL("http:////Comment")); + struct { + std::string url; + std::string expected_domain_and_registry; + } kTestCases[] = { + {"http://a.baz.jp/file.html", "baz.jp"}, + {"http://a.baz.jp./file.html", "baz.jp."}, + {"http://ac.jp", ""}, + {"http://a.bar.jp", ""}, + {"http://bar.jp", ""}, + {"http://baz.bar.jp", ""}, + {"http://a.b.baz.bar.jp", "a.b.baz.bar.jp"}, + + {"http://baz.pref.bar.jp", "pref.bar.jp"}, + {"http://a.b.bar.baz.com.", "b.bar.baz.com."}, + + {"http://a.d.c", "a.d.c"}, + {"http://.a.d.c", "a.d.c"}, + {"http://..a.d.c", "a.d.c"}, + {"http://a.b.c", "b.c"}, + {"http://baz.com", "baz.com"}, + {"http://baz.com.", "baz.com."}, + + {"", ""}, + {"http://", ""}, + {"file:///C:/file.html", ""}, + {"http://foo.com..", ""}, + {"http://...", ""}, + {"http://192.168.0.1", ""}, + {"http://[2001:0db8:85a3:0000:0000:8a2e:0370:7334]/", ""}, + {"http://localhost", ""}, + {"http://localhost.", ""}, + {"http:////Comment", ""}, + }; + for (const auto& test_case : kTestCases) { + const GURL url(test_case.url); + EXPECT_EQ(test_case.expected_domain_and_registry, + GetDomainAndRegistry(url, EXCLUDE_PRIVATE_REGISTRIES)); + EXPECT_EQ(test_case.expected_domain_and_registry, + GetDomainAndRegistry(url::Origin::Create(url), + EXCLUDE_PRIVATE_REGISTRIES)); + } // Test std::string version of GetDomainAndRegistry(). Uses the same // underpinnings as the GURL version, so this is really more of a check of @@ -165,6 +174,7 @@ TEST_F(RegistryControlledDomainTest, TestGetDomainAndRegistry) { EXPECT_EQ("", GetDomainFromHost("foo.com..")); EXPECT_EQ("", GetDomainFromHost("...")); EXPECT_EQ("", GetDomainFromHost("192.168.0.1")); + EXPECT_EQ("", GetDomainFromHost("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]")); EXPECT_EQ("", GetDomainFromHost("localhost.")); EXPECT_EQ("", GetDomainFromHost(".localhost.")); } |