Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/cookies/cookie_store_unittest.h" | 5 #include "net/cookies/cookie_store_unittest.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2604 it = cookies.begin(); | 2604 it = cookies.begin(); |
| 2605 base::Closure task = base::Bind( | 2605 base::Closure task = base::Bind( |
| 2606 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, | 2606 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, |
| 2607 base::Unretained(this), | 2607 base::Unretained(this), |
| 2608 cm, *it, &callback); | 2608 cm, *it, &callback); |
| 2609 RunOnOtherThread(task); | 2609 RunOnOtherThread(task); |
| 2610 EXPECT_TRUE(callback.did_run()); | 2610 EXPECT_TRUE(callback.did_run()); |
| 2611 EXPECT_TRUE(callback.result()); | 2611 EXPECT_TRUE(callback.result()); |
| 2612 } | 2612 } |
| 2613 | 2613 |
| 2614 // Ensure that cookies for http, https, ws, and wss all share the same storage | |
| 2615 // 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.
| |
| 2616 // on MultiThreadedCookieMonsterTest in order to call GetAllCookiesForURLAsync | |
| 2617 // 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.
| |
| 2618 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { | |
| 2619 std::vector<CanonicalCookie*> cookies; | |
| 2620 // This cookie will be freed by the CookieMonster. | |
| 2621 cookies.push_back(CanonicalCookie::Create(url_google_, kValidCookieLine, | |
| 2622 Time::Now(), CookieOptions())); | |
| 2623 CanonicalCookie cookie = *cookies[0]; | |
| 2624 scoped_refptr<NewMockPersistentCookieStore> store( | |
| 2625 new NewMockPersistentCookieStore); | |
| 2626 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | |
| 2627 | |
| 2628 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback; | |
| 2629 ::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint; | |
| 2630 const std::string key = | |
| 2631 cookie_util::GetEffectiveDomain(url_google_.scheme(), url_google_.host()); | |
| 2632 | |
| 2633 { | |
| 2634 ::testing::InSequence s; | |
| 2635 EXPECT_CALL(checkpoint, Call(0)); | |
| 2636 EXPECT_CALL(*store, Load(::testing::_)); | |
| 2637 EXPECT_CALL(*store, LoadCookiesForKey(key, ::testing::_)) | |
| 2638 .WillOnce(::testing::SaveArg<1>(&loaded_callback)); | |
| 2639 EXPECT_CALL(checkpoint, Call(1)); | |
| 2640 // LoadCookiesForKey will never be called, because all URLs below share | |
| 2641 // the same key. | |
| 2642 } | |
| 2643 | |
| 2644 { | |
| 2645 GetCookieListCallback callback; | |
| 2646 checkpoint.Call(0); | |
| 2647 GetAllCookiesForURLTask(cm.get(), url_google_, &callback); | |
| 2648 checkpoint.Call(1); | |
| 2649 ASSERT_FALSE(callback.did_run()); | |
| 2650 // Pass the cookies to the CookieMonster. | |
| 2651 loaded_callback.Run(cookies); | |
| 2652 // Now GetAllCookiesForURLTask is done. | |
| 2653 ASSERT_TRUE(callback.did_run()); | |
| 2654 // See that the callback was called with the cookies. | |
| 2655 ASSERT_EQ(1u, callback.cookies().size()); | |
| 2656 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); | |
| 2657 } | |
| 2658 | |
| 2659 // 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.
| |
| 2660 const GURL urls[] = { | |
|
Ryan Sleevi
2015/01/26 19:49:54
nit NAMING: s/urls/kUrls/
yhirano
2015/01/27 02:07:10
Done.
| |
| 2661 url_google_, | |
| 2662 url_google_secure_, | |
| 2663 GURL(kUrlGoogleWebSocket), | |
| 2664 GURL(kUrlGoogleWebSocketSecure), | |
| 2665 }; | |
| 2666 for (const GURL& url : urls) { | |
| 2667 // Call the function with |url| and verify it is done synchronously without | |
| 2668 // calling LoadCookiesForKey. | |
| 2669 GetCookieListCallback callback; | |
| 2670 GetAllCookiesForURLTask(cm.get(), url, &callback); | |
| 2671 ASSERT_TRUE(callback.did_run()); | |
| 2672 ASSERT_EQ(1u, callback.cookies().size()); | |
| 2673 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); | |
| 2674 } | |
| 2675 } | |
| 2676 | |
| 2614 TEST_F(CookieMonsterTest, InvalidExpiryTime) { | 2677 TEST_F(CookieMonsterTest, InvalidExpiryTime) { |
| 2615 std::string cookie_line = | 2678 std::string cookie_line = |
| 2616 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; | 2679 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |
| 2617 scoped_ptr<CanonicalCookie> cookie( | 2680 scoped_ptr<CanonicalCookie> cookie( |
| 2618 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(), | 2681 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(), |
| 2619 CookieOptions())); | 2682 CookieOptions())); |
| 2620 ASSERT_FALSE(cookie->IsPersistent()); | 2683 ASSERT_FALSE(cookie->IsPersistent()); |
| 2621 } | 2684 } |
| 2622 | 2685 |
| 2623 // Test that CookieMonster writes session cookies into the underlying | 2686 // Test that CookieMonster writes session cookies into the underlying |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2879 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( | 2942 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( |
| 2880 monster()->AddCallbackForCookie(test_url_, "abc", | 2943 monster()->AddCallbackForCookie(test_url_, "abc", |
| 2881 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 2944 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 2882 SetCookie(monster(), test_url_, "abc=def"); | 2945 SetCookie(monster(), test_url_, "abc=def"); |
| 2883 base::MessageLoop::current()->RunUntilIdle(); | 2946 base::MessageLoop::current()->RunUntilIdle(); |
| 2884 EXPECT_EQ(1U, cookies0.size()); | 2947 EXPECT_EQ(1U, cookies0.size()); |
| 2885 EXPECT_EQ(1U, cookies0.size()); | 2948 EXPECT_EQ(1U, cookies0.size()); |
| 2886 } | 2949 } |
| 2887 | 2950 |
| 2888 } // namespace net | 2951 } // namespace net |
| OLD | NEW |