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

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

Issue 15380003: Rename test callbacks for CookieStore to represent the argument type. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months 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 | « no previous file | net/cookies/cookie_store_test_callbacks.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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 const GURL& url, 148 const GURL& url,
149 const std::string& name, 149 const std::string& name,
150 const std::string& value, 150 const std::string& value,
151 const std::string& domain, 151 const std::string& domain,
152 const std::string& path, 152 const std::string& path,
153 const base::Time& expiration_time, 153 const base::Time& expiration_time,
154 bool secure, 154 bool secure,
155 bool http_only, 155 bool http_only,
156 CookiePriority priority) { 156 CookiePriority priority) {
157 DCHECK(cm); 157 DCHECK(cm);
158 SetCookieCallback callback; 158 BoolResultCookieCallback callback;
159 cm->SetCookieWithDetailsAsync( 159 cm->SetCookieWithDetailsAsync(
160 url, name, value, domain, path, expiration_time, secure, http_only, 160 url, name, value, domain, path, expiration_time, secure, http_only,
161 priority, 161 priority,
162 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); 162 base::Bind(&BoolResultCookieCallback::Run,
163 base::Unretained(&callback)));
163 RunFor(kTimeout); 164 RunFor(kTimeout);
164 EXPECT_TRUE(callback.did_run()); 165 EXPECT_TRUE(callback.did_run());
165 return callback.result(); 166 return callback.result();
166 } 167 }
167 168
168 int DeleteAll(CookieMonster*cm) { 169 int DeleteAll(CookieMonster*cm) {
169 DCHECK(cm); 170 DCHECK(cm);
170 DeleteCallback callback; 171 IntResultCookieCallback callback;
171 cm->DeleteAllAsync( 172 cm->DeleteAllAsync(
172 base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); 173 base::Bind(&IntResultCookieCallback::Run, base::Unretained(&callback)));
173 RunFor(kTimeout); 174 RunFor(kTimeout);
174 EXPECT_TRUE(callback.did_run()); 175 EXPECT_TRUE(callback.did_run());
175 return callback.num_deleted(); 176 return callback.result();
176 } 177 }
177 178
178 int DeleteAllCreatedBetween(CookieMonster*cm, 179 int DeleteAllCreatedBetween(CookieMonster*cm,
179 const base::Time& delete_begin, 180 const base::Time& delete_begin,
180 const base::Time& delete_end) { 181 const base::Time& delete_end) {
181 DCHECK(cm); 182 DCHECK(cm);
182 DeleteCallback callback; 183 IntResultCookieCallback callback;
183 cm->DeleteAllCreatedBetweenAsync( 184 cm->DeleteAllCreatedBetweenAsync(
184 delete_begin, delete_end, 185 delete_begin, delete_end,
185 base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); 186 base::Bind(&IntResultCookieCallback::Run, base::Unretained(&callback)));
186 RunFor(kTimeout); 187 RunFor(kTimeout);
187 EXPECT_TRUE(callback.did_run()); 188 EXPECT_TRUE(callback.did_run());
188 return callback.num_deleted(); 189 return callback.result();
189 } 190 }
190 191
191 int DeleteAllForHost(CookieMonster*cm, 192 int DeleteAllForHost(CookieMonster*cm,
192 const GURL& url) { 193 const GURL& url) {
193 DCHECK(cm); 194 DCHECK(cm);
194 DeleteCallback callback; 195 IntResultCookieCallback callback;
195 cm->DeleteAllForHostAsync( 196 cm->DeleteAllForHostAsync(
196 url, base::Bind(&DeleteCallback::Run, base::Unretained(&callback))); 197 url, base::Bind(&IntResultCookieCallback::Run,
198 base::Unretained(&callback)));
197 RunFor(kTimeout); 199 RunFor(kTimeout);
198 EXPECT_TRUE(callback.did_run()); 200 EXPECT_TRUE(callback.did_run());
199 return callback.num_deleted(); 201 return callback.result();
200 } 202 }
201 203
202 bool DeleteCanonicalCookie(CookieMonster*cm, const CanonicalCookie& cookie) { 204 bool DeleteCanonicalCookie(CookieMonster*cm, const CanonicalCookie& cookie) {
203 DCHECK(cm); 205 DCHECK(cm);
204 SetCookieCallback callback; 206 BoolResultCookieCallback callback;
205 cm->DeleteCanonicalCookieAsync( 207 cm->DeleteCanonicalCookieAsync(
206 cookie, 208 cookie,
207 base::Bind(&SetCookieCallback::Run, base::Unretained(&callback))); 209 base::Bind(&BoolResultCookieCallback::Run,
210 base::Unretained(&callback)));
208 RunFor(kTimeout); 211 RunFor(kTimeout);
209 EXPECT_TRUE(callback.did_run()); 212 EXPECT_TRUE(callback.did_run());
210 return callback.result(); 213 return callback.result();
211 } 214 }
212 215
213 // Helper for DeleteAllForHost test; repopulates CM with same layout 216 // Helper for DeleteAllForHost test; repopulates CM with same layout
214 // each time. 217 // each time.
215 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) { 218 void PopulateCmForDeleteAllForHost(scoped_refptr<CookieMonster> cm) {
216 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1); 219 GURL url_top_level_domain_plus_1(kTopLevelDomainPlus1);
217 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2); 220 GURL url_top_level_domain_plus_2(kTopLevelDomainPlus2);
(...skipping 1943 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 void GetAllCookiesForURLWithOptionsTask(CookieMonster* cm, 2164 void GetAllCookiesForURLWithOptionsTask(CookieMonster* cm,
2162 const GURL& url, 2165 const GURL& url,
2163 const CookieOptions& options, 2166 const CookieOptions& options,
2164 GetCookieListCallback* callback) { 2167 GetCookieListCallback* callback) {
2165 cm->GetAllCookiesForURLWithOptionsAsync( 2168 cm->GetAllCookiesForURLWithOptionsAsync(
2166 url, options, 2169 url, options,
2167 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback))); 2170 base::Bind(&GetCookieListCallback::Run, base::Unretained(callback)));
2168 } 2171 }
2169 2172
2170 void SetCookieWithDetailsTask(CookieMonster* cm, const GURL& url, 2173 void SetCookieWithDetailsTask(CookieMonster* cm, const GURL& url,
2171 SetCookieCallback* callback) { 2174 BoolResultCookieCallback* callback) {
2172 // Define the parameters here instead of in the calling fucntion. 2175 // Define the parameters here instead of in the calling fucntion.
2173 // The maximum number of parameters for Bind function is 6. 2176 // The maximum number of parameters for Bind function is 6.
2174 std::string name = "A"; 2177 std::string name = "A";
2175 std::string value = "B"; 2178 std::string value = "B";
2176 std::string domain = std::string(); 2179 std::string domain = std::string();
2177 std::string path = "/foo"; 2180 std::string path = "/foo";
2178 base::Time expiration_time = base::Time(); 2181 base::Time expiration_time = base::Time();
2179 bool secure = false; 2182 bool secure = false;
2180 bool http_only = false; 2183 bool http_only = false;
2181 CookiePriority priority = COOKIE_PRIORITY_DEFAULT; 2184 CookiePriority priority = COOKIE_PRIORITY_DEFAULT;
2182 cm->SetCookieWithDetailsAsync( 2185 cm->SetCookieWithDetailsAsync(
2183 url, name, value, domain, path, expiration_time, secure, http_only, 2186 url, name, value, domain, path, expiration_time, secure, http_only,
2184 priority, 2187 priority,
2185 base::Bind(&SetCookieCallback::Run, base::Unretained(callback))); 2188 base::Bind(&BoolResultCookieCallback::Run, base::Unretained(callback)));
2186 } 2189 }
2187 2190
2188 void DeleteAllCreatedBetweenTask(CookieMonster* cm, 2191 void DeleteAllCreatedBetweenTask(CookieMonster* cm,
2189 const base::Time& delete_begin, 2192 const base::Time& delete_begin,
2190 const base::Time& delete_end, 2193 const base::Time& delete_end,
2191 DeleteCallback* callback) { 2194 IntResultCookieCallback* callback) {
2192 cm->DeleteAllCreatedBetweenAsync( 2195 cm->DeleteAllCreatedBetweenAsync(
2193 delete_begin, delete_end, 2196 delete_begin, delete_end,
2194 base::Bind(&DeleteCallback::Run, 2197 base::Bind(&IntResultCookieCallback::Run,
2195 base::Unretained(callback))); 2198 base::Unretained(callback)));
2196 } 2199 }
2197 2200
2198 void DeleteAllForHostTask(CookieMonster* cm, 2201 void DeleteAllForHostTask(CookieMonster* cm,
2199 const GURL& url, 2202 const GURL& url,
2200 DeleteCallback* callback) { 2203 IntResultCookieCallback* callback) {
2201 cm->DeleteAllForHostAsync( 2204 cm->DeleteAllForHostAsync(
2202 url, 2205 url,
2203 base::Bind(&DeleteCallback::Run, base::Unretained(callback))); 2206 base::Bind(&IntResultCookieCallback::Run, base::Unretained(callback)));
2204 } 2207 }
2205 2208
2206 void DeleteCanonicalCookieTask(CookieMonster* cm, 2209 void DeleteCanonicalCookieTask(CookieMonster* cm,
2207 const CanonicalCookie& cookie, 2210 const CanonicalCookie& cookie,
2208 SetCookieCallback* callback) { 2211 BoolResultCookieCallback* callback) {
2209 cm->DeleteCanonicalCookieAsync( 2212 cm->DeleteCanonicalCookieAsync(
2210 cookie, 2213 cookie,
2211 base::Bind(&SetCookieCallback::Run, base::Unretained(callback))); 2214 base::Bind(&BoolResultCookieCallback::Run, base::Unretained(callback)));
2212 } 2215 }
2213 2216
2214 protected: 2217 protected:
2215 void RunOnOtherThread(const base::Closure& task) { 2218 void RunOnOtherThread(const base::Closure& task) {
2216 other_thread_.Start(); 2219 other_thread_.Start();
2217 other_thread_.message_loop()->PostTask(FROM_HERE, task); 2220 other_thread_.message_loop()->PostTask(FROM_HERE, task);
2218 RunFor(kTimeout); 2221 RunFor(kTimeout);
2219 other_thread_.Stop(); 2222 other_thread_.Stop();
2220 } 2223 }
2221 2224
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 EXPECT_EQ("A", it->Name()); 2297 EXPECT_EQ("A", it->Name());
2295 ASSERT_TRUE(++it == callback.cookies().end()); 2298 ASSERT_TRUE(++it == callback.cookies().end());
2296 } 2299 }
2297 2300
2298 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) { 2301 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckSetCookieWithDetails) {
2299 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2302 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2300 EXPECT_TRUE(SetCookieWithDetails( 2303 EXPECT_TRUE(SetCookieWithDetails(
2301 cm, url_google_foo_, 2304 cm, url_google_foo_,
2302 "A", "B", std::string(), "/foo", base::Time(), 2305 "A", "B", std::string(), "/foo", base::Time(),
2303 false, false, COOKIE_PRIORITY_DEFAULT)); 2306 false, false, COOKIE_PRIORITY_DEFAULT));
2304 SetCookieCallback callback(&other_thread_); 2307 BoolResultCookieCallback callback(&other_thread_);
2305 base::Closure task = base::Bind( 2308 base::Closure task = base::Bind(
2306 &net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask, 2309 &net::MultiThreadedCookieMonsterTest::SetCookieWithDetailsTask,
2307 base::Unretained(this), 2310 base::Unretained(this),
2308 cm, url_google_foo_, &callback); 2311 cm, url_google_foo_, &callback);
2309 RunOnOtherThread(task); 2312 RunOnOtherThread(task);
2310 EXPECT_TRUE(callback.did_run()); 2313 EXPECT_TRUE(callback.did_run());
2311 EXPECT_TRUE(callback.result()); 2314 EXPECT_TRUE(callback.result());
2312 } 2315 }
2313 2316
2314 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) { 2317 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllCreatedBetween) {
2315 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2318 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2316 CookieOptions options; 2319 CookieOptions options;
2317 Time now = Time::Now(); 2320 Time now = Time::Now();
2318 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2321 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
2319 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99), 2322 EXPECT_EQ(1, DeleteAllCreatedBetween(cm, now - TimeDelta::FromDays(99),
2320 Time())); 2323 Time()));
2321 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2324 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
2322 DeleteCallback callback(&other_thread_); 2325 IntResultCookieCallback callback(&other_thread_);
2323 base::Closure task = base::Bind( 2326 base::Closure task = base::Bind(
2324 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask, 2327 &net::MultiThreadedCookieMonsterTest::DeleteAllCreatedBetweenTask,
2325 base::Unretained(this), 2328 base::Unretained(this),
2326 cm, now - TimeDelta::FromDays(99), 2329 cm, now - TimeDelta::FromDays(99),
2327 Time(), &callback); 2330 Time(), &callback);
2328 RunOnOtherThread(task); 2331 RunOnOtherThread(task);
2329 EXPECT_TRUE(callback.did_run()); 2332 EXPECT_TRUE(callback.did_run());
2330 EXPECT_EQ(1, callback.num_deleted()); 2333 EXPECT_EQ(1, callback.result());
2331 } 2334 }
2332 2335
2333 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) { 2336 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteAllForHost) {
2334 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2337 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2335 CookieOptions options; 2338 CookieOptions options;
2336 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2339 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
2337 EXPECT_EQ(1, DeleteAllForHost(cm, url_google_)); 2340 EXPECT_EQ(1, DeleteAllForHost(cm, url_google_));
2338 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2341 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
2339 DeleteCallback callback(&other_thread_); 2342 IntResultCookieCallback callback(&other_thread_);
2340 base::Closure task = base::Bind( 2343 base::Closure task = base::Bind(
2341 &net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask, 2344 &net::MultiThreadedCookieMonsterTest::DeleteAllForHostTask,
2342 base::Unretained(this), 2345 base::Unretained(this),
2343 cm, url_google_, &callback); 2346 cm, url_google_, &callback);
2344 RunOnOtherThread(task); 2347 RunOnOtherThread(task);
2345 EXPECT_TRUE(callback.did_run()); 2348 EXPECT_TRUE(callback.did_run());
2346 EXPECT_EQ(1, callback.num_deleted()); 2349 EXPECT_EQ(1, callback.result());
2347 } 2350 }
2348 2351
2349 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) { 2352 TEST_F(MultiThreadedCookieMonsterTest, ThreadCheckDeleteCanonicalCookie) {
2350 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL)); 2353 scoped_refptr<CookieMonster> cm(new CookieMonster(NULL, NULL));
2351 CookieOptions options; 2354 CookieOptions options;
2352 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2355 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
2353 CookieList cookies = GetAllCookies(cm); 2356 CookieList cookies = GetAllCookies(cm);
2354 CookieList::iterator it = cookies.begin(); 2357 CookieList::iterator it = cookies.begin();
2355 EXPECT_TRUE(DeleteCanonicalCookie(cm, *it)); 2358 EXPECT_TRUE(DeleteCanonicalCookie(cm, *it));
2356 2359
2357 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options)); 2360 EXPECT_TRUE(SetCookieWithOptions(cm, url_google_, "A=B", options));
2358 SetCookieCallback callback(&other_thread_); 2361 BoolResultCookieCallback callback(&other_thread_);
2359 cookies = GetAllCookies(cm); 2362 cookies = GetAllCookies(cm);
2360 it = cookies.begin(); 2363 it = cookies.begin();
2361 base::Closure task = base::Bind( 2364 base::Closure task = base::Bind(
2362 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask, 2365 &net::MultiThreadedCookieMonsterTest::DeleteCanonicalCookieTask,
2363 base::Unretained(this), 2366 base::Unretained(this),
2364 cm, *it, &callback); 2367 cm, *it, &callback);
2365 RunOnOtherThread(task); 2368 RunOnOtherThread(task);
2366 EXPECT_TRUE(callback.did_run()); 2369 EXPECT_TRUE(callback.did_run());
2367 EXPECT_TRUE(callback.result()); 2370 EXPECT_TRUE(callback.result());
2368 } 2371 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2447 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type); 2450 EXPECT_EQ(CookieStoreCommand::ADD, store->commands()[4].type);
2448 2451
2449 // Create some non-persistent cookies and check that they don't go to the 2452 // Create some non-persistent cookies and check that they don't go to the
2450 // persistent storage. 2453 // persistent storage.
2451 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar")); 2454 EXPECT_TRUE(SetCookie(cm, url_google_, "B=Bar"));
2452 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_)); 2455 this->MatchCookieLines("A=Foo; B=Bar", GetCookies(cm, url_google_));
2453 EXPECT_EQ(5u, store->commands().size()); 2456 EXPECT_EQ(5u, store->commands().size());
2454 } 2457 }
2455 2458
2456 } // namespace net 2459 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/cookies/cookie_store_test_callbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698