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 TEST_F(MultiThreadedCookieMonsterTest, GetAllCookiesForURLEffectiveDomain) { | |
| 2615 std::vector<CanonicalCookie*> cookies; | |
| 2616 // This cookie is freed by the CookieMonster. | |
|
Ryan Sleevi
2015/01/22 01:43:41
is? or will be?
yhirano
2015/01/23 03:34:36
Done.
| |
| 2617 cookies.push_back(CanonicalCookie::Create(url_google_, kValidCookieLine, | |
| 2618 Time::Now(), CookieOptions())); | |
| 2619 CanonicalCookie cookie = *cookies[0]; | |
|
Ryan Sleevi
2015/01/22 01:43:41
Did you mean to copy? If so, why?
yhirano
2015/01/23 03:34:36
I want to have a cookie to verify the result below
| |
| 2620 scoped_refptr<NewMockPersistentCookieStore> store( | |
| 2621 new NewMockPersistentCookieStore); | |
| 2622 scoped_refptr<CookieMonster> cm(new CookieMonster(store.get(), NULL)); | |
| 2623 | |
| 2624 CookieMonster::PersistentCookieStore::LoadedCallback loaded_callback; | |
| 2625 ::testing::StrictMock<::testing::MockFunction<void(int)>> checkpoint; | |
|
Ryan Sleevi
2015/01/22 01:43:41
This seems unnecessary/overkill. The relation of c
yhirano
2015/01/23 03:34:36
I want to check that all monitored calls happens b
| |
| 2626 const std::string key = "google.izzle"; | |
|
Ryan Sleevi
2015/01/22 01:43:41
What is this magic string and why are you using it
yhirano
2015/01/23 03:34:36
Done.
| |
| 2627 | |
| 2628 { | |
| 2629 ::testing::InSequence s; | |
| 2630 EXPECT_CALL(checkpoint, Call(0)); | |
| 2631 EXPECT_CALL(*store, Load(::testing::_)); | |
| 2632 EXPECT_CALL(*store, LoadCookiesForKey(key, ::testing::_)) | |
| 2633 .WillOnce(::testing::SaveArg<1>(&loaded_callback)); | |
| 2634 EXPECT_CALL(checkpoint, Call(1)); | |
| 2635 // LoadCookiesForKey will never be called, because they share the same key. | |
| 2636 } | |
| 2637 | |
| 2638 checkpoint.Call(0); | |
| 2639 { | |
| 2640 GetCookieListCallback callback; | |
| 2641 GetAllCookiesForURLTask(cm.get(), url_google_, &callback); | |
| 2642 checkpoint.Call(1); | |
| 2643 EXPECT_FALSE(callback.did_run()); | |
| 2644 loaded_callback.Run(cookies); | |
|
Ryan Sleevi
2015/01/22 01:43:41
This is a bit surprising and non-obvious. Needs be
yhirano
2015/01/23 03:34:36
It is necessary. By calling loaded_callback, we no
| |
| 2645 EXPECT_TRUE(callback.did_run()); | |
| 2646 ASSERT_EQ(1u, callback.cookies().size()); | |
| 2647 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); | |
| 2648 } | |
| 2649 { | |
| 2650 GetCookieListCallback callback; | |
| 2651 GetAllCookiesForURLTask(cm.get(), url_google_, &callback); | |
| 2652 EXPECT_TRUE(callback.did_run()); | |
| 2653 ASSERT_EQ(1u, callback.cookies().size()); | |
| 2654 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); | |
| 2655 } | |
| 2656 { | |
| 2657 GetCookieListCallback callback; | |
| 2658 GetAllCookiesForURLTask(cm.get(), url_google_secure_, &callback); | |
| 2659 EXPECT_TRUE(callback.did_run()); | |
| 2660 ASSERT_EQ(1u, callback.cookies().size()); | |
| 2661 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); | |
| 2662 } | |
| 2663 { | |
| 2664 GetCookieListCallback callback; | |
| 2665 GetAllCookiesForURLTask(cm.get(), GURL(kUrlGoogleWebSocket), &callback); | |
| 2666 EXPECT_TRUE(callback.did_run()); | |
| 2667 ASSERT_EQ(1u, callback.cookies().size()); | |
| 2668 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); | |
| 2669 } | |
| 2670 { | |
| 2671 GetCookieListCallback callback; | |
| 2672 GetAllCookiesForURLTask(cm.get(), GURL(kUrlGoogleWebSocketSecure), | |
| 2673 &callback); | |
| 2674 EXPECT_TRUE(callback.did_run()); | |
| 2675 ASSERT_EQ(1u, callback.cookies().size()); | |
| 2676 EXPECT_TRUE(cookie.IsEquivalent(callback.cookies()[0])); | |
| 2677 } | |
|
Ryan Sleevi
2015/01/22 01:43:41
The documentation for each of these assertions is
yhirano
2015/01/23 03:34:36
Done.
| |
| 2678 } | |
| 2679 | |
| 2614 TEST_F(CookieMonsterTest, InvalidExpiryTime) { | 2680 TEST_F(CookieMonsterTest, InvalidExpiryTime) { |
| 2615 std::string cookie_line = | 2681 std::string cookie_line = |
| 2616 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; | 2682 std::string(kValidCookieLine) + "; expires=Blarg arg arg"; |
| 2617 scoped_ptr<CanonicalCookie> cookie( | 2683 scoped_ptr<CanonicalCookie> cookie( |
| 2618 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(), | 2684 CanonicalCookie::Create(url_google_, cookie_line, Time::Now(), |
| 2619 CookieOptions())); | 2685 CookieOptions())); |
| 2620 ASSERT_FALSE(cookie->IsPersistent()); | 2686 ASSERT_FALSE(cookie->IsPersistent()); |
| 2621 } | 2687 } |
| 2622 | 2688 |
| 2623 // Test that CookieMonster writes session cookies into the underlying | 2689 // 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( | 2945 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( |
| 2880 monster()->AddCallbackForCookie(test_url_, "abc", | 2946 monster()->AddCallbackForCookie(test_url_, "abc", |
| 2881 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); | 2947 base::Bind(&RecordCookieChanges, &cookies1, nullptr))); |
| 2882 SetCookie(monster(), test_url_, "abc=def"); | 2948 SetCookie(monster(), test_url_, "abc=def"); |
| 2883 base::MessageLoop::current()->RunUntilIdle(); | 2949 base::MessageLoop::current()->RunUntilIdle(); |
| 2884 EXPECT_EQ(1U, cookies0.size()); | 2950 EXPECT_EQ(1U, cookies0.size()); |
| 2885 EXPECT_EQ(1U, cookies0.size()); | 2951 EXPECT_EQ(1U, cookies0.size()); |
| 2886 } | 2952 } |
| 2887 | 2953 |
| 2888 } // namespace net | 2954 } // namespace net |
| OLD | NEW |