GetEffectiveDomain should handle ws scheme as same as http scheme.
CookieMonster::AnyEquivalentCookie asserts that there are no multiple
cookies that are identical to each other. That is achieved by inserting / deleting
cookies carefully, but it goes wrong with WebSocket schemes.
CookieMonster::DoCookieTaskForURL for given URL loads cookies when
cookies for key = cookie_util::GeteEffectiveDomain(scheme, host) is not
yet loaded. When the task ends, it stores loaded cookies and marks the key as
loaded. cookie_util::GetEffectiveDomain consults
egistry_controlled_domains::GetDomainAndRegistry
when http or https schemes are given, whereas it doesn't when ws or wss
schemes are given.
Imagine we are about to load stored cookies for ws://www.example.com/
and http://www.example.com/. As written above, they have different keys:
www.example.com and example.com. So each of them is loaded and it breaks
the assertion.
BUG=370021
[email protected]
Review URL: https://codereview.chromium.org/859663003
Cr-Commit-Position: refs/heads/master@{#313706}
diff --git a/net/cookies/cookie_util_unittest.cc b/net/cookies/cookie_util_unittest.cc
index fc27631..392faf1 100644
--- a/net/cookies/cookie_util_unittest.cc
+++ b/net/cookies/cookie_util_unittest.cc
@@ -43,8 +43,6 @@
EXPECT_EQ(str_expected, net::cookie_util::SerializeRequestCookieLine(prc));
}
-} // namespace
-
TEST(CookieUtilTest, TestDomainIsHostOnly) {
const struct {
const char* str;
@@ -194,3 +192,20 @@
CheckSerialize(tests[i].parsed, tests[i].str);
}
}
+
+TEST(CookieUtilTest, TestGetEffectiveDomain) {
+ // Note: registry_controlled_domains::GetDomainAndRegistry is tested in its
+ // own unittests.
+ EXPECT_EQ("example.com",
+ net::cookie_util::GetEffectiveDomain("http", "www.example.com"));
+ EXPECT_EQ("example.com",
+ net::cookie_util::GetEffectiveDomain("https", "www.example.com"));
+ EXPECT_EQ("example.com",
+ net::cookie_util::GetEffectiveDomain("ws", "www.example.com"));
+ EXPECT_EQ("example.com",
+ net::cookie_util::GetEffectiveDomain("wss", "www.example.com"));
+ EXPECT_EQ("www.example.com",
+ net::cookie_util::GetEffectiveDomain("ftp", "www.example.com"));
+}
+
+} // namespace