OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <time.h> | 5 #include <time.h> |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 3561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3572 | 3572 |
3573 TEST_F(CookieMonsterTest, InvalidExpiryTime) { | 3573 TEST_F(CookieMonsterTest, InvalidExpiryTime) { |
3574 CookieMonster::ParsedCookie pc( | 3574 CookieMonster::ParsedCookie pc( |
3575 std::string(kValidCookieLine) + "; expires=Blarg arg arg"); | 3575 std::string(kValidCookieLine) + "; expires=Blarg arg arg"); |
3576 scoped_ptr<CookieMonster::CanonicalCookie> cookie( | 3576 scoped_ptr<CookieMonster::CanonicalCookie> cookie( |
3577 CookieMonster::CanonicalCookie::Create(url_google_, pc)); | 3577 CookieMonster::CanonicalCookie::Create(url_google_, pc)); |
3578 | 3578 |
3579 ASSERT_FALSE(cookie->DoesExpire()); | 3579 ASSERT_FALSE(cookie->DoesExpire()); |
3580 } | 3580 } |
3581 | 3581 |
| 3582 // Test that CookieMonster writes session cookies into the underlying |
| 3583 // CookieStore if the "persist session cookies" option is on. |
| 3584 TEST_F(CookieMonsterTest, PersistSessionCookies) { |
| 3585 scoped_refptr<MockPersistentCookieStore> store( |
| 3586 new MockPersistentCookieStore); |
| 3587 scoped_refptr<CookieMonster> cm(new CookieMonster(store, NULL)); |
| 3588 cm->SetPersistSessionCookies(true); |
| 3589 |
| 3590 // All cookies set with SetCookie are session cookies. |
| 3591 EXPECT_TRUE(SetCookie(cm, url_google_, "A=B")); |
| 3592 EXPECT_EQ("A=B", GetCookies(cm, url_google_)); |
| 3593 |
| 3594 // The cookie was written to the backing store. |
| 3595 EXPECT_EQ(1u, store->commands().size()); |
| 3596 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[0].type); |
| 3597 EXPECT_EQ("A", store->commands()[0].cookie.Name()); |
| 3598 EXPECT_EQ("B", store->commands()[0].cookie.Value()); |
| 3599 |
| 3600 // Modify the cookie. |
| 3601 EXPECT_TRUE(SetCookie(cm, url_google_, "A=C")); |
| 3602 EXPECT_EQ("A=C", GetCookies(cm, url_google_)); |
| 3603 EXPECT_EQ(3u, store->commands().size()); |
| 3604 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[1].type); |
| 3605 EXPECT_EQ("A", store->commands()[1].cookie.Name()); |
| 3606 EXPECT_EQ("B", store->commands()[1].cookie.Value()); |
| 3607 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[2].type); |
| 3608 EXPECT_EQ("A", store->commands()[2].cookie.Name()); |
| 3609 EXPECT_EQ("C", store->commands()[2].cookie.Value()); |
| 3610 |
| 3611 // Delete the cookie. |
| 3612 DeleteCookie(cm, url_google_, "A"); |
| 3613 EXPECT_EQ("", GetCookies(cm, url_google_)); |
| 3614 EXPECT_EQ(4u, store->commands().size()); |
| 3615 EXPECT_EQ(CookieStoreCommand::REMOVE, store->commands()[3].type); |
| 3616 EXPECT_EQ("A", store->commands()[3].cookie.Name()); |
| 3617 EXPECT_EQ("C", store->commands()[3].cookie.Value()); |
| 3618 } |
| 3619 |
3582 } // namespace net | 3620 } // namespace net |
OLD | NEW |