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

Side by Side Diff: net/cookies/cookie_monster_unittest.cc

Issue 683113005: Update from chromium https://crrev.com/302282 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/cookies/cookie_store.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2739 matching lines...) Expand 10 before | Expand all | Expand 10 after
2750 CookieMonster* monster() { return monster_.get(); } 2750 CookieMonster* monster() { return monster_.get(); }
2751 2751
2752 protected: 2752 protected:
2753 const GURL test_url_; 2753 const GURL test_url_;
2754 2754
2755 private: 2755 private:
2756 scoped_refptr<MockPersistentCookieStore> store_; 2756 scoped_refptr<MockPersistentCookieStore> store_;
2757 scoped_refptr<CookieMonster> monster_; 2757 scoped_refptr<CookieMonster> monster_;
2758 }; 2758 };
2759 2759
2760 void CountCalls(int *calls) { 2760 void RecordCookieChanges(std::vector<net::CanonicalCookie>* out_cookies,
2761 (*calls)++; 2761 std::vector<bool>* out_removes,
2762 const net::CanonicalCookie& cookie,
2763 bool removed) {
2764 DCHECK(out_cookies);
2765 out_cookies->push_back(cookie);
2766 if (out_removes)
2767 out_removes->push_back(removed);
2762 } 2768 }
2763 2769
2764 TEST_F(CookieMonsterNotificationTest, NoNotifyWithNoCookie) { 2770 TEST_F(CookieMonsterNotificationTest, NoNotifyWithNoCookie) {
2765 int calls = 0; 2771 std::vector<net::CanonicalCookie> cookies;
2766 scoped_ptr<CookieStore::CookieChangedSubscription> sub( 2772 scoped_ptr<CookieStore::CookieChangedSubscription> sub(
2767 monster()->AddCallbackForCookie(test_url_, "abc", 2773 monster()->AddCallbackForCookie(test_url_, "abc",
2768 base::Bind(&CountCalls, &calls))); 2774 base::Bind(&RecordCookieChanges, &cookies, nullptr)));
2769 base::MessageLoop::current()->RunUntilIdle(); 2775 base::MessageLoop::current()->RunUntilIdle();
2770 EXPECT_EQ(0, calls); 2776 EXPECT_EQ(0U, cookies.size());
2771 } 2777 }
2772 2778
2773 TEST_F(CookieMonsterNotificationTest, NoNotifyWithInitialCookie) { 2779 TEST_F(CookieMonsterNotificationTest, NoNotifyWithInitialCookie) {
2774 int calls = 0; 2780 std::vector<net::CanonicalCookie> cookies;
2775 SetCookie(monster(), test_url_, "abc=def"); 2781 SetCookie(monster(), test_url_, "abc=def");
2776 base::MessageLoop::current()->RunUntilIdle(); 2782 base::MessageLoop::current()->RunUntilIdle();
2777 scoped_ptr<CookieStore::CookieChangedSubscription> sub( 2783 scoped_ptr<CookieStore::CookieChangedSubscription> sub(
2778 monster()->AddCallbackForCookie(test_url_, "abc", 2784 monster()->AddCallbackForCookie(test_url_, "abc",
2779 base::Bind(&CountCalls, &calls))); 2785 base::Bind(&RecordCookieChanges, &cookies, nullptr)));
2780 base::MessageLoop::current()->RunUntilIdle(); 2786 base::MessageLoop::current()->RunUntilIdle();
2781 EXPECT_EQ(0, calls); 2787 EXPECT_EQ(0U, cookies.size());
2782 } 2788 }
2783 2789
2784 TEST_F(CookieMonsterNotificationTest, NotifyOnSet) { 2790 TEST_F(CookieMonsterNotificationTest, NotifyOnSet) {
2785 int calls = 0; 2791 std::vector<net::CanonicalCookie> cookies;
2792 std::vector<bool> removes;
2786 scoped_ptr<CookieStore::CookieChangedSubscription> sub( 2793 scoped_ptr<CookieStore::CookieChangedSubscription> sub(
2787 monster()->AddCallbackForCookie(test_url_, "abc", 2794 monster()->AddCallbackForCookie(test_url_, "abc",
2788 base::Bind(&CountCalls, &calls))); 2795 base::Bind(&RecordCookieChanges, &cookies, &removes)));
2789 SetCookie(monster(), test_url_, "abc=def"); 2796 SetCookie(monster(), test_url_, "abc=def");
2790 base::MessageLoop::current()->RunUntilIdle(); 2797 base::MessageLoop::current()->RunUntilIdle();
2791 EXPECT_EQ(1, calls); 2798 EXPECT_EQ(1U, cookies.size());
2799 EXPECT_EQ(1U, removes.size());
2800
2801 EXPECT_EQ("abc", cookies[0].Name());
2802 EXPECT_EQ("def", cookies[0].Value());
2803 EXPECT_FALSE(removes[0]);
2792 } 2804 }
2793 2805
2794 TEST_F(CookieMonsterNotificationTest, NotifyOnDelete) { 2806 TEST_F(CookieMonsterNotificationTest, NotifyOnDelete) {
2795 int calls = 0; 2807 std::vector<net::CanonicalCookie> cookies;
2808 std::vector<bool> removes;
2796 scoped_ptr<CookieStore::CookieChangedSubscription> sub( 2809 scoped_ptr<CookieStore::CookieChangedSubscription> sub(
2797 monster()->AddCallbackForCookie(test_url_, "abc", 2810 monster()->AddCallbackForCookie(test_url_, "abc",
2798 base::Bind(&CountCalls, &calls))); 2811 base::Bind(&RecordCookieChanges, &cookies, &removes)));
2799 SetCookie(monster(), test_url_, "abc=def"); 2812 SetCookie(monster(), test_url_, "abc=def");
2800 base::MessageLoop::current()->RunUntilIdle(); 2813 base::MessageLoop::current()->RunUntilIdle();
2801 EXPECT_EQ(1, calls); 2814 EXPECT_EQ(1U, cookies.size());
2815 EXPECT_EQ(1U, removes.size());
2816
2802 DeleteCookie(monster(), test_url_, "abc"); 2817 DeleteCookie(monster(), test_url_, "abc");
2803 base::MessageLoop::current()->RunUntilIdle(); 2818 base::MessageLoop::current()->RunUntilIdle();
2804 EXPECT_EQ(2, calls); 2819 EXPECT_EQ(2U, cookies.size());
2820 EXPECT_EQ(2U, removes.size());
2821
2822 EXPECT_EQ("abc", cookies[1].Name());
2823 EXPECT_EQ("def", cookies[1].Value());
2824 EXPECT_TRUE(removes[1]);
2805 } 2825 }
2806 2826
2807 TEST_F(CookieMonsterNotificationTest, NotifyOnUpdate) { 2827 TEST_F(CookieMonsterNotificationTest, NotifyOnUpdate) {
2808 int calls = 0; 2828 std::vector<net::CanonicalCookie> cookies;
2829 std::vector<bool> removes;
2809 scoped_ptr<CookieStore::CookieChangedSubscription> sub( 2830 scoped_ptr<CookieStore::CookieChangedSubscription> sub(
2810 monster()->AddCallbackForCookie(test_url_, "abc", 2831 monster()->AddCallbackForCookie(test_url_, "abc",
2811 base::Bind(&CountCalls, &calls))); 2832 base::Bind(&RecordCookieChanges, &cookies, &removes)));
2812 SetCookie(monster(), test_url_, "abc=def"); 2833 SetCookie(monster(), test_url_, "abc=def");
2813 base::MessageLoop::current()->RunUntilIdle(); 2834 base::MessageLoop::current()->RunUntilIdle();
2814 EXPECT_EQ(1, calls); 2835 EXPECT_EQ(1U, cookies.size());
2836
2815 // Replacing an existing cookie is actually a two-phase delete + set 2837 // Replacing an existing cookie is actually a two-phase delete + set
2816 // operation, so we get an extra notification. :( 2838 // operation, so we get an extra notification.
2817 SetCookie(monster(), test_url_, "abc=ghi"); 2839 SetCookie(monster(), test_url_, "abc=ghi");
2818 base::MessageLoop::current()->RunUntilIdle(); 2840 base::MessageLoop::current()->RunUntilIdle();
2819 EXPECT_EQ(3, calls); 2841
2842 EXPECT_EQ(3U, cookies.size());
2843 EXPECT_EQ(3U, removes.size());
2844
2845 EXPECT_EQ("abc", cookies[1].Name());
2846 EXPECT_EQ("def", cookies[1].Value());
2847 EXPECT_TRUE(removes[1]);
2848
2849 EXPECT_EQ("abc", cookies[2].Name());
2850 EXPECT_EQ("ghi", cookies[2].Value());
2851 EXPECT_FALSE(removes[2]);
2820 } 2852 }
2821 2853
2822 TEST_F(CookieMonsterNotificationTest, MultipleNotifies) { 2854 TEST_F(CookieMonsterNotificationTest, MultipleNotifies) {
2823 int calls0 = 0; 2855 std::vector<net::CanonicalCookie> cookies0;
2824 int calls1 = 0; 2856 std::vector<net::CanonicalCookie> cookies1;
2825 scoped_ptr<CookieStore::CookieChangedSubscription> sub0( 2857 scoped_ptr<CookieStore::CookieChangedSubscription> sub0(
2826 monster()->AddCallbackForCookie(test_url_, "abc", 2858 monster()->AddCallbackForCookie(test_url_, "abc",
2827 base::Bind(&CountCalls, &calls0))); 2859 base::Bind(&RecordCookieChanges, &cookies0, nullptr)));
2828 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( 2860 scoped_ptr<CookieStore::CookieChangedSubscription> sub1(
2829 monster()->AddCallbackForCookie(test_url_, "def", 2861 monster()->AddCallbackForCookie(test_url_, "def",
2830 base::Bind(&CountCalls, &calls1))); 2862 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
2831 SetCookie(monster(), test_url_, "abc=def"); 2863 SetCookie(monster(), test_url_, "abc=def");
2832 base::MessageLoop::current()->RunUntilIdle(); 2864 base::MessageLoop::current()->RunUntilIdle();
2833 EXPECT_EQ(1, calls0); 2865 EXPECT_EQ(1U, cookies0.size());
2834 EXPECT_EQ(0, calls1); 2866 EXPECT_EQ(0U, cookies1.size());
2835 SetCookie(monster(), test_url_, "def=abc"); 2867 SetCookie(monster(), test_url_, "def=abc");
2836 base::MessageLoop::current()->RunUntilIdle(); 2868 base::MessageLoop::current()->RunUntilIdle();
2837 EXPECT_EQ(1, calls0); 2869 EXPECT_EQ(1U, cookies0.size());
2838 EXPECT_EQ(1, calls1); 2870 EXPECT_EQ(1U, cookies1.size());
2839 } 2871 }
2840 2872
2841 TEST_F(CookieMonsterNotificationTest, MultipleSameNotifies) { 2873 TEST_F(CookieMonsterNotificationTest, MultipleSameNotifies) {
2842 int calls0 = 0; 2874 std::vector<net::CanonicalCookie> cookies0;
2843 int calls1 = 0; 2875 std::vector<net::CanonicalCookie> cookies1;
2844 scoped_ptr<CookieStore::CookieChangedSubscription> sub0( 2876 scoped_ptr<CookieStore::CookieChangedSubscription> sub0(
2845 monster()->AddCallbackForCookie(test_url_, "abc", 2877 monster()->AddCallbackForCookie(test_url_, "abc",
2846 base::Bind(&CountCalls, &calls0))); 2878 base::Bind(&RecordCookieChanges, &cookies0, nullptr)));
2847 scoped_ptr<CookieStore::CookieChangedSubscription> sub1( 2879 scoped_ptr<CookieStore::CookieChangedSubscription> sub1(
2848 monster()->AddCallbackForCookie(test_url_, "abc", 2880 monster()->AddCallbackForCookie(test_url_, "abc",
2849 base::Bind(&CountCalls, &calls1))); 2881 base::Bind(&RecordCookieChanges, &cookies1, nullptr)));
2850 SetCookie(monster(), test_url_, "abc=def"); 2882 SetCookie(monster(), test_url_, "abc=def");
2851 base::MessageLoop::current()->RunUntilIdle(); 2883 base::MessageLoop::current()->RunUntilIdle();
2852 EXPECT_EQ(1, calls0); 2884 EXPECT_EQ(1U, cookies0.size());
2853 EXPECT_EQ(1, calls1); 2885 EXPECT_EQ(1U, cookies0.size());
2854 } 2886 }
2855 2887
2856 } // namespace net 2888 } // namespace net
OLDNEW
« no previous file with comments | « net/cookies/cookie_monster.cc ('k') | net/cookies/cookie_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698