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

Side by Side Diff: chrome/browser/browsing_data/browsing_data_cookie_helper_unittest.cc

Issue 11341011: Make the BrowsingDataCookieHelper create canonical cookies with the correct cookie-domain attribute. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use better method and test names Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_cookie_helper.cc ('k') | no next file » | 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 "chrome/browser/browsing_data/browsing_data_cookie_helper.h" 5 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
6 6
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 scoped_refptr<net::CookieMonster> cookie_monster = 61 scoped_refptr<net::CookieMonster> cookie_monster =
62 testing_profile_->GetCookieMonster(); 62 testing_profile_->GetCookieMonster();
63 cookie_monster->SetCookieWithOptionsAsync( 63 cookie_monster->SetCookieWithOptionsAsync(
64 GURL("http://www.google.com"), "A=1", net::CookieOptions(), 64 GURL("http://www.google.com"), "A=1", net::CookieOptions(),
65 net::CookieMonster::SetCookiesCallback()); 65 net::CookieMonster::SetCookiesCallback());
66 cookie_monster->SetCookieWithOptionsAsync( 66 cookie_monster->SetCookieWithOptionsAsync(
67 GURL("http://www.gmail.google.com"), "B=1", net::CookieOptions(), 67 GURL("http://www.gmail.google.com"), "B=1", net::CookieOptions(),
68 net::CookieMonster::SetCookiesCallback()); 68 net::CookieMonster::SetCookiesCallback());
69 } 69 }
70 70
71 void CreateCookiesForDomainCookieTest() {
72 scoped_refptr<net::CookieMonster> cookie_monster =
73 testing_profile_->GetCookieMonster();
74 cookie_monster->SetCookieWithOptionsAsync(
75 GURL("http://www.google.com"), "A=1", net::CookieOptions(),
76 net::CookieMonster::SetCookiesCallback());
77 cookie_monster->SetCookieWithOptionsAsync(
78 GURL("http://www.google.com"), "A=2; Domain=.www.google.com ",
79 net::CookieOptions(), net::CookieMonster::SetCookiesCallback());
80 }
81
71 void FetchCallback(const net::CookieList& cookies) { 82 void FetchCallback(const net::CookieList& cookies) {
72 ASSERT_EQ(2UL, cookies.size()); 83 ASSERT_EQ(2UL, cookies.size());
73 cookie_list_ = cookies; 84 cookie_list_ = cookies;
74 net::CookieList::const_iterator it = cookies.begin(); 85 net::CookieList::const_iterator it = cookies.begin();
75 86
76 // Correct because fetching cookies will get a sorted cookie list. 87 // Correct because fetching cookies will get a sorted cookie list.
77 ASSERT_TRUE(it != cookies.end()); 88 ASSERT_TRUE(it != cookies.end());
78 EXPECT_EQ("www.google.com", it->Domain()); 89 EXPECT_EQ("www.google.com", it->Domain());
79 EXPECT_EQ("A", it->Name()); 90 EXPECT_EQ("A", it->Name());
80 91
81 ASSERT_TRUE(++it != cookies.end()); 92 ASSERT_TRUE(++it != cookies.end());
82 EXPECT_EQ("www.gmail.google.com", it->Domain()); 93 EXPECT_EQ("www.gmail.google.com", it->Domain());
83 EXPECT_EQ("B", it->Name()); 94 EXPECT_EQ("B", it->Name());
84 95
85 ASSERT_TRUE(++it == cookies.end()); 96 ASSERT_TRUE(++it == cookies.end());
86 MessageLoop::current()->Quit(); 97 MessageLoop::current()->Quit();
87 } 98 }
88 99
100 void DomainCookieCallback(const net::CookieList& cookies) {
101 ASSERT_EQ(2UL, cookies.size());
102 cookie_list_ = cookies;
103 net::CookieList::const_iterator it = cookies.begin();
104
105 // Correct because fetching cookies will get a sorted cookie list.
106 ASSERT_TRUE(it != cookies.end());
107 EXPECT_EQ("www.google.com", it->Domain());
108 EXPECT_EQ("A", it->Name());
battre 2012/10/29 18:11:04 please test EXPECT_EQ("1", it->Value());
markusheintz_ 2012/10/29 18:13:00 Done.
109
110 ASSERT_TRUE(++it != cookies.end());
111 EXPECT_EQ(".www.google.com", it->Domain());
112 EXPECT_EQ("A", it->Name());
113 EXPECT_EQ("2", it->Value());
114
115 ASSERT_TRUE(++it == cookies.end());
116 MessageLoop::current()->Quit();
117 }
118
89 void DeleteCallback(const net::CookieList& cookies) { 119 void DeleteCallback(const net::CookieList& cookies) {
90 ASSERT_EQ(1UL, cookies.size()); 120 ASSERT_EQ(1UL, cookies.size());
91 net::CookieList::const_iterator it = cookies.begin(); 121 net::CookieList::const_iterator it = cookies.begin();
92 122
93 ASSERT_TRUE(it != cookies.end()); 123 ASSERT_TRUE(it != cookies.end());
94 EXPECT_EQ("www.gmail.google.com", it->Domain()); 124 EXPECT_EQ("www.gmail.google.com", it->Domain());
95 EXPECT_EQ("B", it->Name()); 125 EXPECT_EQ("B", it->Name());
96 126
97 ASSERT_TRUE(++it == cookies.end()); 127 ASSERT_TRUE(++it == cookies.end());
98 MessageLoop::current()->Quit(); 128 MessageLoop::current()->Quit();
99 } 129 }
100 130
101 void CannedUniqueCallback(const net::CookieList& cookies) { 131 void CannedUniqueCallback(const net::CookieList& cookies) {
102 ASSERT_EQ(1UL, cookies.size()); 132 ASSERT_EQ(1UL, cookies.size());
103 cookie_list_ = cookies; 133 cookie_list_ = cookies;
104 net::CookieList::const_iterator it = cookies.begin(); 134 net::CookieList::const_iterator it = cookies.begin();
105 135
106 ASSERT_TRUE(it != cookies.end()); 136 ASSERT_TRUE(it != cookies.end());
107 EXPECT_EQ("http://www.google.com/", it->Source()); 137 EXPECT_EQ("http://www.google.com/", it->Source());
108 EXPECT_EQ("A", it->Name()); 138 EXPECT_EQ("A", it->Name());
109 139
110 ASSERT_TRUE(++it == cookies.end()); 140 ASSERT_TRUE(++it == cookies.end());
111 } 141 }
112 142
143 void CannedDomainCookieCallback(const net::CookieList& cookies) {
144 ASSERT_EQ(2UL, cookies.size());
145 cookie_list_ = cookies;
146 net::CookieList::const_iterator it = cookies.begin();
147
148 ASSERT_TRUE(it != cookies.end());
149 EXPECT_EQ("http://www.google.com/", it->Source());
150 EXPECT_EQ("A", it->Name());
151 EXPECT_EQ("www.google.com", it->Domain());
152
153 ASSERT_TRUE(++it != cookies.end());
154 EXPECT_EQ("http://www.google.com/", it->Source());
155 EXPECT_EQ("A", it->Name());
156 EXPECT_EQ(".www.google.com", it->Domain());
157
158 ASSERT_TRUE(++it == cookies.end());
159 }
160
113 void CannedDifferentFramesCallback(const net::CookieList& cookie_list) { 161 void CannedDifferentFramesCallback(const net::CookieList& cookie_list) {
114 ASSERT_EQ(3U, cookie_list.size()); 162 ASSERT_EQ(3U, cookie_list.size());
115 } 163 }
116 164
117 protected: 165 protected:
118 MessageLoop message_loop_; 166 MessageLoop message_loop_;
119 scoped_ptr<content::TestBrowserThread> ui_thread_; 167 scoped_ptr<content::TestBrowserThread> ui_thread_;
120 scoped_ptr<content::TestBrowserThread> io_thread_; 168 scoped_ptr<content::TestBrowserThread> io_thread_;
121 scoped_ptr<TestingProfile> testing_profile_; 169 scoped_ptr<TestingProfile> testing_profile_;
122 170
123 net::CookieList cookie_list_; 171 net::CookieList cookie_list_;
124 }; 172 };
125 173
126 TEST_F(BrowsingDataCookieHelperTest, FetchData) { 174 TEST_F(BrowsingDataCookieHelperTest, FetchData) {
127 CreateCookiesForTest(); 175 CreateCookiesForTest();
128 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( 176 scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
129 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); 177 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext()));
130 178
131 cookie_helper->StartFetching( 179 cookie_helper->StartFetching(
132 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, 180 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback,
133 base::Unretained(this))); 181 base::Unretained(this)));
134 182
135 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. 183 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
136 MessageLoop::current()->Run(); 184 MessageLoop::current()->Run();
137 } 185 }
138 186
187 TEST_F(BrowsingDataCookieHelperTest, DomainCookie) {
188 CreateCookiesForDomainCookieTest();
189 scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
190 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext()));
191
192 cookie_helper->StartFetching(
193 base::Bind(&BrowsingDataCookieHelperTest::DomainCookieCallback,
194 base::Unretained(this)));
195
196 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
197 MessageLoop::current()->Run();
198 }
199
139 TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) { 200 TEST_F(BrowsingDataCookieHelperTest, DeleteCookie) {
140 CreateCookiesForTest(); 201 CreateCookiesForTest();
141 scoped_refptr<BrowsingDataCookieHelper> cookie_helper( 202 scoped_refptr<BrowsingDataCookieHelper> cookie_helper(
142 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext())); 203 new BrowsingDataCookieHelper(testing_profile_->GetRequestContext()));
143 204
144 cookie_helper->StartFetching( 205 cookie_helper->StartFetching(
145 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback, 206 base::Bind(&BrowsingDataCookieHelperTest::FetchCallback,
146 base::Unretained(this))); 207 base::Unretained(this)));
147 208
148 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified. 209 // Blocks until BrowsingDataCookieHelperTest::FetchCallback is notified.
149 MessageLoop::current()->Run(); 210 MessageLoop::current()->Run();
150 211
151 net::CanonicalCookie cookie = cookie_list_[0]; 212 net::CanonicalCookie cookie = cookie_list_[0];
152 cookie_helper->DeleteCookie(cookie); 213 cookie_helper->DeleteCookie(cookie);
153 214
154 cookie_helper->StartFetching( 215 cookie_helper->StartFetching(
155 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback, 216 base::Bind(&BrowsingDataCookieHelperTest::DeleteCallback,
156 base::Unretained(this))); 217 base::Unretained(this)));
157 MessageLoop::current()->Run(); 218 MessageLoop::current()->Run();
158 } 219 }
159 220
221 TEST_F(BrowsingDataCookieHelperTest, CannedDomainCookie) {
222 const GURL origin("http://www.google.com");
223 net::CookieList cookie;
224
225 scoped_refptr<CannedBrowsingDataCookieHelper> helper(
226 new CannedBrowsingDataCookieHelper(
227 testing_profile_->GetRequestContext()));
228
229 ASSERT_TRUE(helper->empty());
230 helper->AddChangedCookie(origin, origin, "A=1", net::CookieOptions());
231 helper->AddChangedCookie(origin, origin, "A=1; Domain=.www.google.com",
232 net::CookieOptions());
233
234 helper->StartFetching(
235 base::Bind(&BrowsingDataCookieHelperTest::CannedDomainCookieCallback,
236 base::Unretained(this)));
237 cookie = cookie_list_;
238
239 helper->Reset();
240 ASSERT_TRUE(helper->empty());
241
242 helper->AddReadCookies(origin, origin, cookie);
243 helper->StartFetching(
244 base::Bind(&BrowsingDataCookieHelperTest::CannedDomainCookieCallback,
245 base::Unretained(this)));
246 }
247
248
249
battre 2012/10/29 18:11:04 nit: -2 new lines
markusheintz_ 2012/10/29 18:13:00 Done.
160 TEST_F(BrowsingDataCookieHelperTest, CannedUnique) { 250 TEST_F(BrowsingDataCookieHelperTest, CannedUnique) {
161 const GURL origin("http://www.google.com"); 251 const GURL origin("http://www.google.com");
162 net::CookieList cookie; 252 net::CookieList cookie;
163 253
164 scoped_refptr<CannedBrowsingDataCookieHelper> helper( 254 scoped_refptr<CannedBrowsingDataCookieHelper> helper(
165 new CannedBrowsingDataCookieHelper( 255 new CannedBrowsingDataCookieHelper(
166 testing_profile_->GetRequestContext())); 256 testing_profile_->GetRequestContext()));
167 257
168 ASSERT_TRUE(helper->empty()); 258 ASSERT_TRUE(helper->empty());
169 helper->AddChangedCookie(origin, origin, "A=1", net::CookieOptions()); 259 helper->AddChangedCookie(origin, origin, "A=1", net::CookieOptions());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 net::CookieOptions()); 314 net::CookieOptions());
225 helper->AddChangedCookie(frame2_url, request_url, "c=1", 315 helper->AddChangedCookie(frame2_url, request_url, "c=1",
226 net::CookieOptions()); 316 net::CookieOptions());
227 317
228 helper->StartFetching( 318 helper->StartFetching(
229 base::Bind(&BrowsingDataCookieHelperTest::CannedDifferentFramesCallback, 319 base::Bind(&BrowsingDataCookieHelperTest::CannedDifferentFramesCallback,
230 base::Unretained(this))); 320 base::Unretained(this)));
231 } 321 }
232 322
233 } // namespace 323 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_cookie_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698