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

Unified Diff: net/cookies/cookie_monster_unittest.cc

Issue 859663003: GetEffectiveDomain should handle ws scheme as same as http scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/cookies/cookie_store_unittest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cookies/cookie_monster_unittest.cc
diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc
index d5067ae7cfbaeebdee34280e71141a805c122ec4..8b4bd355715a8505c21498bea573e8fdb2eb96cc 100644
--- a/net/cookies/cookie_monster_unittest.cc
+++ b/net/cookies/cookie_monster_unittest.cc
@@ -2611,6 +2611,69 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) {
EXPECT_TRUE(callback.result());
}
+// Ensure that cookies for http, https, ws, and wss all share the same storage
+// and policies, when GetAllCookiesForURLAsync is used. This test is located
Ryan Sleevi 2015/01/26 19:49:54 grammar nit: no comma between policies and when.
yhirano 2015/01/27 02:07:10 Done.
+// on MultiThreadedCookieMonsterTest in order to call GetAllCookiesForURLAsync
+// asynchronously, but doesn't use a separate thread in spite of the name.
Ryan Sleevi 2015/01/26 19:49:54 grammar nit: I found this second sentence a bit co
yhirano 2015/01/27 02:07:10 Done.
+TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) {
+ std::vector<CanonicalCookie*> cookies;
+ // This cookie will be freed by the CookieMonster.
+ cookies.push_back(CanonicalCookie::Create(url_google_, kValidCookieLine,
+ Time::Now(), CookieOptions()));
+ CanonicalCookie cookie = *cookies[0];
+ scoped_refptr<NewMockPersistentCookieStore> store(
+ new NewMockPersistentCookieStore);
+ scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL));
+
+ CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback;
+ ::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint;
+ const std::string key =
+ cookie_util::GetEffectiveDomain(url_google_.scheme(), url_google_.host());
+
+ {
+ ::testing::InSequence s;
+ EXPECT_CALL(checkpoint, Call(0));
+ EXPECT_CALL(*store, Load(::testing::_));
+ EXPECT_CALL(*store, LoadCookiesForKey(key, ::testing::_))
+ .WillOnce(::testing::SaveArg<1>(&loaded_callback));
+ EXPECT_CALL(checkpoint, Call(1));
+ // LoadCookiesForKey will never be called, because all URLs below share
+ // the same key.
+ }
+
+ {
+ GetCookieListCallback callback;
+ checkpoint.Call(0);
+ GetAllCookiesForURLTask(cm.get(), url_google_, &callback);
+ checkpoint.Call(1);
+ ASSERT_FALSE(callback.did_run());
+ // Pass the cookies to the CookieMonster.
+ loaded_callback.Run(cookies);
+ // Now GetAllCookiesForURLTask is done.
+ ASSERT_TRUE(callback.did_run());
+ // See that the callback was called with the cookies.
+ ASSERT_EQ(1u, callback.cookies().size());
+ EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
+ }
+
+ // All urls in |urls| share the same cookie domain.
Ryan Sleevi 2015/01/26 19:49:54 s/share/should share/
yhirano 2015/01/27 02:07:10 Done.
+ const GURL urls[] = {
Ryan Sleevi 2015/01/26 19:49:54 nit NAMING: s/urls/kUrls/
yhirano 2015/01/27 02:07:10 Done.
+ url_google_,
+ url_google_secure_,
+ GURL(kUrlGoogleWebSocket),
+ GURL(kUrlGoogleWebSocketSecure),
+ };
+ for (const GURL& url : urls) {
+ // Call the function with |url| and verify it is done synchronously without
+ // calling LoadCookiesForKey.
+ GetCookieListCallback callback;
+ GetAllCookiesForURLTask(cm.get(), url, &callback);
+ ASSERT_TRUE(callback.did_run());
+ ASSERT_EQ(1u, callback.cookies().size());
+ EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0]));
+ }
+}
+
TEST_F(CookieMonsterTest, InvalidExpiryTime) {
std::string cookie_line =
std::string(kValidCookieLine) + "; expires=Blarg arg arg";
« no previous file with comments | « no previous file | net/cookies/cookie_store_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698