Chromium Code Reviews| Index: net/cookies/cookie_monster_unittest.cc |
| diff --git a/net/cookies/cookie_monster_unittest.cc b/net/cookies/cookie_monster_unittest.cc |
| index 633bca59493b4fff654e8b875cbf1e22446d4e3a..d27739100b5915c02256d9f43a29c6cfe4047eee 100644 |
| --- a/net/cookies/cookie_monster_unittest.cc |
| +++ b/net/cookies/cookie_monster_unittest.cc |
| @@ -2611,6 +2611,85 @@ TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { |
| EXPECT_TRUE(callback.result()); |
| } |
| +TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { |
|
Ryan Sleevi
2015/01/24 03:46:59
Can you add a description to this test explaining
yhirano
2015/01/26 04:45:25
Done.
|
| + 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); |
|
Ryan Sleevi
2015/01/24 03:46:59
I'm confused; Why is this in a separate section th
yhirano
2015/01/26 04:45:25
(All line numbers represents line numbers in PS9 i
Ryan Sleevi
2015/01/26 19:49:54
[Same in mine]
yhirano
2015/01/27 02:07:10
Yes. I created blocks L2640-L2653, L2654-L2662, L2
|
| + EXPECT_FALSE(callback.did_run()); |
|
Ryan Sleevi
2015/01/24 03:46:59
Historically, tests with EXPECTS on callback runni
yhirano
2015/01/26 04:45:25
Done.
|
| + // Pass the cookies to the CookieMonster. |
| + loaded_callback.Run(cookies); |
| + // Now GetAllCookiesForURLTask is done. |
| + EXPECT_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])); |
| + } |
| + { |
| + // Call the function with the same URL and see if it is done synchronously |
|
Ryan Sleevi
2015/01/24 03:46:59
s/see if it/verify it/
The wording suggests it's
yhirano
2015/01/26 04:45:25
Done.
|
| + // without calling LoadCookiesForKey. |
| + GetCookieListCallback callback; |
| + GetAllCookiesForURLTask(cm.get(), url_google_, &callback); |
| + EXPECT_TRUE(callback.did_run()); |
| + ASSERT_EQ(1u, callback.cookies().size()); |
| + EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); |
| + } |
| + { |
| + // Call the function with an https URL and see if it is done synchronously |
| + // without calling LoadCookiesForKey. |
| + GetCookieListCallback callback; |
| + GetAllCookiesForURLTask(cm.get(), url_google_secure_, &callback); |
| + EXPECT_TRUE(callback.did_run()); |
| + ASSERT_EQ(1u, callback.cookies().size()); |
| + EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); |
| + } |
| + { |
| + // Call the function with a ws URL and see if it is done synchronously |
| + // without calling LoadCookiesForKey. |
| + GetCookieListCallback callback; |
| + GetAllCookiesForURLTask(cm.get(), GURL(kUrlGoogleWebSocket), &callback); |
| + EXPECT_TRUE(callback.did_run()); |
| + ASSERT_EQ(1u, callback.cookies().size()); |
| + EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); |
| + } |
| + { |
| + // Call the function with a wss URL and see if it is done synchronously |
| + // without calling LoadCookiesForKey. |
| + GetCookieListCallback callback; |
| + GetAllCookiesForURLTask(cm.get(), GURL(kUrlGoogleWebSocketSecure), |
| + &callback); |
| + EXPECT_TRUE(callback.did_run()); |
| + ASSERT_EQ(1u, callback.cookies().size()); |
| + EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); |
| + } |
|
Ryan Sleevi
2015/01/24 03:46:59
Should this code be refactored to a loop over the
yhirano
2015/01/26 04:45:25
Done.
|
| +} |
| + |
| TEST_F(CookieMonsterTest, InvalidExpiryTime) { |
| std::string cookie_line = |
| std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |