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

Side by Side Diff: ios/net/cookies/cookie_store_ios_unittest.mm

Issue 2601973002: [ios] Do not use SetSynchronizedWithSystemStore in tests. (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « no previous file | 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "ios/net/cookies/cookie_store_ios.h" 5 #include "ios/net/cookies/cookie_store_ios.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 203 }
204 204
205 void IgnoreBoolean(bool ignored) { 205 void IgnoreBoolean(bool ignored) {
206 } 206 }
207 207
208 void IgnoreString(const std::string& ignored) { 208 void IgnoreString(const std::string& ignored) {
209 } 209 }
210 210
211 } // namespace 211 } // namespace
212 212
213 class CookieStoreIOSWithBackend : public testing::Test { 213 // Sets a cookie.
214 void SetCookie(const std::string& cookie_line,
215 const GURL& url,
216 net::CookieStore* store) {
217 net::CookieOptions options;
218 options.set_include_httponly();
219 store->SetCookieWithOptionsAsync(url, cookie_line, options,
220 base::Bind(&IgnoreBoolean));
221 net::CookieStoreIOS::NotifySystemCookiesChanged();
222 // Wait until the flush is posted.
223 base::RunLoop().RunUntilIdle();
224 }
225
226 // Test fixture to exersize net::CookieStoreIOS created with
227 // TestPersistentCookieStore backend and not synchronized with
228 // NSHTTPCookieStorage.
229 class NotSynchronizedCookieStoreIOSWithBackend : public testing::Test {
214 public: 230 public:
215 CookieStoreIOSWithBackend() 231 NotSynchronizedCookieStoreIOSWithBackend()
216 : kTestCookieURL("http://foo.google.com/bar"), 232 : kTestCookieURL("http://foo.google.com/bar"),
217 kTestCookieURL2("http://foo.google.com/baz"),
218 kTestCookieURL3("http://foo.google.com"),
219 kTestCookieURL4("http://bar.google.com/bar"),
220 backend_(new TestPersistentCookieStore), 233 backend_(new TestPersistentCookieStore),
221 store_(new net::CookieStoreIOS(backend_.get())) { 234 store_(new net::CookieStoreIOS(backend_.get())) {
222 cookie_changed_callback_ = store_->AddCallbackForCookie( 235 cookie_changed_callback_ = store_->AddCallbackForCookie(
223 kTestCookieURL, "abc", 236 kTestCookieURL, "abc",
224 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_)); 237 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_));
225 } 238 }
226 239
227 ~CookieStoreIOSWithBackend() override {} 240 ~NotSynchronizedCookieStoreIOSWithBackend() override {}
228 241
229 // Gets the cookies. |callback| will be called on completion. 242 // Gets the cookies. |callback| will be called on completion.
230 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { 243 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) {
231 net::CookieOptions options; 244 net::CookieOptions options;
232 options.set_include_httponly(); 245 options.set_include_httponly();
233 store_->GetCookiesWithOptionsAsync(kTestCookieURL, options, callback); 246 store_->GetCookiesWithOptionsAsync(kTestCookieURL, options, callback);
234 } 247 }
235 248
236 // Sets a cookie. 249 // Sets a cookie.
237 void SetCookie(const std::string& cookie_line) { 250 void SetCookie(const std::string& cookie_line) {
251 ::SetCookie(cookie_line, kTestCookieURL, store_.get());
252 }
253
254 private:
255 const GURL kTestCookieURL;
256
257 protected:
258 base::MessageLoop loop_;
259 scoped_refptr<TestPersistentCookieStore> backend_;
260 std::unique_ptr<net::CookieStoreIOS> store_;
261 std::unique_ptr<net::CookieStore::CookieChangedSubscription>
262 cookie_changed_callback_;
263 std::vector<net::CanonicalCookie> cookies_changed_;
264 std::vector<bool> cookies_removed_;
265 };
266
267 // Test fixture to exersize net::CookieStoreIOS created without backend and
268 // synchronized with |[NSHTTPCookieStorage sharedHTTPCookieStorage]|.
269 class SynchronizedCookieStoreIOS : public testing::Test {
270 public:
271 SynchronizedCookieStoreIOS()
272 : kTestCookieURL("http://foo.google.com/bar"),
273 kTestCookieURL2("http://foo.google.com/baz"),
274 kTestCookieURL3("http://foo.google.com"),
275 kTestCookieURL4("http://bar.google.com/bar"),
276 backend_(new TestPersistentCookieStore),
277 store_(net::CookieStoreIOS::CreateCookieStore(
278 [NSHTTPCookieStorage sharedHTTPCookieStorage])) {
279 cookie_changed_callback_ = store_->AddCallbackForCookie(
280 kTestCookieURL, "abc",
281 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_));
282 }
283
284 ~SynchronizedCookieStoreIOS() override {}
285
286 // Gets the cookies. |callback| will be called on completion.
287 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) {
238 net::CookieOptions options; 288 net::CookieOptions options;
239 options.set_include_httponly(); 289 options.set_include_httponly();
240 store_->SetCookieWithOptionsAsync(kTestCookieURL, cookie_line, options, 290 store_->GetCookiesWithOptionsAsync(kTestCookieURL, options, callback);
241 base::Bind(&IgnoreBoolean)); 291 }
242 net::CookieStoreIOS::NotifySystemCookiesChanged(); 292
243 // Wait until the flush is posted. 293 // Sets a cookie.
244 base::RunLoop().RunUntilIdle(); 294 void SetCookie(const std::string& cookie_line) {
295 ::SetCookie(cookie_line, kTestCookieURL, store_.get());
245 } 296 }
246 297
247 void SetSystemCookie(const GURL& url, 298 void SetSystemCookie(const GURL& url,
248 const std::string& name, 299 const std::string& name,
249 const std::string& value) { 300 const std::string& value) {
250 NSHTTPCookieStorage* storage = 301 NSHTTPCookieStorage* storage =
251 [NSHTTPCookieStorage sharedHTTPCookieStorage]; 302 [NSHTTPCookieStorage sharedHTTPCookieStorage];
252 [storage setCookie:[NSHTTPCookie cookieWithProperties:@{ 303 [storage setCookie:[NSHTTPCookie cookieWithProperties:@{
253 NSHTTPCookiePath : base::SysUTF8ToNSString(url.path()), 304 NSHTTPCookiePath : base::SysUTF8ToNSString(url.path()),
254 NSHTTPCookieName : base::SysUTF8ToNSString(name), 305 NSHTTPCookieName : base::SysUTF8ToNSString(name),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 std::unique_ptr<net::CookieStore::CookieChangedSubscription> 337 std::unique_ptr<net::CookieStore::CookieChangedSubscription>
287 cookie_changed_callback_; 338 cookie_changed_callback_;
288 std::vector<net::CanonicalCookie> cookies_changed_; 339 std::vector<net::CanonicalCookie> cookies_changed_;
289 std::vector<bool> cookies_removed_; 340 std::vector<bool> cookies_removed_;
290 }; 341 };
291 342
292 } // namespace 343 } // namespace
293 344
294 namespace net { 345 namespace net {
295 346
296 TEST_F(CookieStoreIOSWithBackend, SetCookieCallsHookWhenNotSynchronized) { 347 TEST_F(NotSynchronizedCookieStoreIOSWithBackend, SetCookieCallsHook) {
297 ClearCookies(); 348 ClearCookies();
298 SetCookie("abc=def"); 349 SetCookie("abc=def");
299 EXPECT_EQ(0U, cookies_changed_.size()); 350 EXPECT_EQ(0U, cookies_changed_.size());
300 EXPECT_EQ(0U, cookies_removed_.size()); 351 EXPECT_EQ(0U, cookies_removed_.size());
301 backend_->RunLoadedCallback(); 352 backend_->RunLoadedCallback();
302 base::RunLoop().RunUntilIdle(); 353 base::RunLoop().RunUntilIdle();
303 EXPECT_EQ(1U, cookies_changed_.size()); 354 EXPECT_EQ(1U, cookies_changed_.size());
304 EXPECT_EQ(1U, cookies_removed_.size()); 355 EXPECT_EQ(1U, cookies_removed_.size());
305 EXPECT_EQ("abc", cookies_changed_[0].Name()); 356 EXPECT_EQ("abc", cookies_changed_[0].Name());
306 EXPECT_EQ("def", cookies_changed_[0].Value()); 357 EXPECT_EQ("def", cookies_changed_[0].Value());
307 EXPECT_FALSE(cookies_removed_[0]); 358 EXPECT_FALSE(cookies_removed_[0]);
308 359
309 // Replacing an existing cookie is actually a two-phase delete + set 360 // Replacing an existing cookie is actually a two-phase delete + set
310 // operation, so we get an extra notification. 361 // operation, so we get an extra notification.
311 SetCookie("abc=ghi"); 362 SetCookie("abc=ghi");
312 EXPECT_EQ(3U, cookies_changed_.size()); 363 EXPECT_EQ(3U, cookies_changed_.size());
313 EXPECT_EQ(3U, cookies_removed_.size()); 364 EXPECT_EQ(3U, cookies_removed_.size());
314 EXPECT_EQ("abc", cookies_changed_[1].Name()); 365 EXPECT_EQ("abc", cookies_changed_[1].Name());
315 EXPECT_EQ("def", cookies_changed_[1].Value()); 366 EXPECT_EQ("def", cookies_changed_[1].Value());
316 EXPECT_TRUE(cookies_removed_[1]); 367 EXPECT_TRUE(cookies_removed_[1]);
317 EXPECT_EQ("abc", cookies_changed_[2].Name()); 368 EXPECT_EQ("abc", cookies_changed_[2].Name());
318 EXPECT_EQ("ghi", cookies_changed_[2].Value()); 369 EXPECT_EQ("ghi", cookies_changed_[2].Value());
319 EXPECT_FALSE(cookies_removed_[2]); 370 EXPECT_FALSE(cookies_removed_[2]);
320
321 store_->SetSynchronizedWithSystemStore(false);
322 } 371 }
323 372
324 TEST_F(CookieStoreIOSWithBackend, SetCookieCallsHookWhenSynchronized) { 373 TEST_F(SynchronizedCookieStoreIOS, SetCookieCallsHookWhenSynchronized) {
325 store_->SetSynchronizedWithSystemStore(true);
326 GetCookies(base::Bind(&IgnoreString)); 374 GetCookies(base::Bind(&IgnoreString));
327 backend_->RunLoadedCallback();
328 base::RunLoop().RunUntilIdle();
329 ClearCookies(); 375 ClearCookies();
330 SetCookie("abc=def"); 376 SetCookie("abc=def");
331 EXPECT_EQ(1U, cookies_changed_.size()); 377 EXPECT_EQ(1U, cookies_changed_.size());
332 EXPECT_EQ(1U, cookies_removed_.size()); 378 EXPECT_EQ(1U, cookies_removed_.size());
333 EXPECT_EQ("abc", cookies_changed_[0].Name()); 379 EXPECT_EQ("abc", cookies_changed_[0].Name());
334 EXPECT_EQ("def", cookies_changed_[0].Value()); 380 EXPECT_EQ("def", cookies_changed_[0].Value());
335 EXPECT_FALSE(cookies_removed_[0]); 381 EXPECT_FALSE(cookies_removed_[0]);
336 382
337 SetCookie("abc=ghi"); 383 SetCookie("abc=ghi");
338 EXPECT_EQ(3U, cookies_changed_.size()); 384 EXPECT_EQ(3U, cookies_changed_.size());
339 EXPECT_EQ(3U, cookies_removed_.size()); 385 EXPECT_EQ(3U, cookies_removed_.size());
340 EXPECT_EQ("abc", cookies_changed_[1].Name()); 386 EXPECT_EQ("abc", cookies_changed_[1].Name());
341 EXPECT_EQ("def", cookies_changed_[1].Value()); 387 EXPECT_EQ("def", cookies_changed_[1].Value());
342 EXPECT_TRUE(cookies_removed_[1]); 388 EXPECT_TRUE(cookies_removed_[1]);
343 EXPECT_EQ("abc", cookies_changed_[2].Name()); 389 EXPECT_EQ("abc", cookies_changed_[2].Name());
344 EXPECT_EQ("ghi", cookies_changed_[2].Value()); 390 EXPECT_EQ("ghi", cookies_changed_[2].Value());
345 EXPECT_FALSE(cookies_removed_[2]); 391 EXPECT_FALSE(cookies_removed_[2]);
346 DeleteSystemCookie(kTestCookieURL, "abc"); 392 DeleteSystemCookie(kTestCookieURL, "abc");
347
348 store_->SetSynchronizedWithSystemStore(false);
349 } 393 }
350 394
351 TEST_F(CookieStoreIOSWithBackend, DeleteCallsHook) { 395 TEST_F(SynchronizedCookieStoreIOS, DeleteCallsHook) {
352 store_->SetSynchronizedWithSystemStore(true);
353 GetCookies(base::Bind(&IgnoreString)); 396 GetCookies(base::Bind(&IgnoreString));
354 backend_->RunLoadedCallback();
355 base::RunLoop().RunUntilIdle();
356 ClearCookies(); 397 ClearCookies();
357 SetCookie("abc=def"); 398 SetCookie("abc=def");
358 EXPECT_EQ(1U, cookies_changed_.size()); 399 EXPECT_EQ(1U, cookies_changed_.size());
359 EXPECT_EQ(1U, cookies_removed_.size()); 400 EXPECT_EQ(1U, cookies_removed_.size());
360 store_->DeleteCookieAsync(kTestCookieURL, "abc", 401 store_->DeleteCookieAsync(kTestCookieURL, "abc",
361 base::Bind(&IgnoreBoolean, false)); 402 base::Bind(&IgnoreBoolean, false));
362 CookieStoreIOS::NotifySystemCookiesChanged(); 403 CookieStoreIOS::NotifySystemCookiesChanged();
363 base::RunLoop().RunUntilIdle(); 404 base::RunLoop().RunUntilIdle();
364 store_->SetSynchronizedWithSystemStore(false);
365 } 405 }
366 406
367 TEST_F(CookieStoreIOSWithBackend, SameValueDoesNotCallHook) { 407 TEST_F(SynchronizedCookieStoreIOS, SameValueDoesNotCallHook) {
368 store_->SetSynchronizedWithSystemStore(true);
369 GetCookieCallback callback; 408 GetCookieCallback callback;
370 GetCookies(base::Bind(&IgnoreString)); 409 GetCookies(base::Bind(&IgnoreString));
371 backend_->RunLoadedCallback();
372 base::RunLoop().RunUntilIdle();
373 ClearCookies(); 410 ClearCookies();
374 SetCookie("abc=def"); 411 SetCookie("abc=def");
375 EXPECT_EQ(1U, cookies_changed_.size()); 412 EXPECT_EQ(1U, cookies_changed_.size());
376 SetCookie("abc=def"); 413 SetCookie("abc=def");
377 EXPECT_EQ(1U, cookies_changed_.size()); 414 EXPECT_EQ(1U, cookies_changed_.size());
378 store_->SetSynchronizedWithSystemStore(false);
379 } 415 }
380 416
381 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) { 417 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) {
382 base::MessageLoop loop; 418 base::MessageLoop loop;
383 const GURL kTestCookieURL("http://foo.google.com/bar"); 419 const GURL kTestCookieURL("http://foo.google.com/bar");
384 ClearCookies(); 420 ClearCookies();
385 std::unique_ptr<CookieStoreIOS> cookie_store(new CookieStoreIOS(nullptr)); 421 std::unique_ptr<CookieStoreIOS> cookie_store(
386 cookie_store->SetSynchronizedWithSystemStore(true); 422 CookieStoreIOS::CreateCookieStore(
423 [NSHTTPCookieStorage sharedHTTPCookieStorage]));
387 // Add a cookie. 424 // Add a cookie.
388 net::CookieOptions options; 425 net::CookieOptions options;
389 options.set_include_httponly(); 426 options.set_include_httponly();
390 cookie_store->SetCookieWithOptionsAsync( 427 cookie_store->SetCookieWithOptionsAsync(
391 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); 428 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback());
392 // Check we can get the cookie. 429 // Check we can get the cookie.
393 GetAllCookiesCallback callback; 430 GetAllCookiesCallback callback;
394 cookie_store->GetAllCookiesForURLAsync( 431 cookie_store->GetAllCookiesForURLAsync(
395 kTestCookieURL, 432 kTestCookieURL,
396 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback))); 433 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback)));
397 EXPECT_TRUE(callback.did_run()); 434 EXPECT_TRUE(callback.did_run());
398 EXPECT_EQ(1u, callback.cookie_list().size()); 435 EXPECT_EQ(1u, callback.cookie_list().size());
399 net::CanonicalCookie cookie = callback.cookie_list()[0]; 436 net::CanonicalCookie cookie = callback.cookie_list()[0];
400 EXPECT_EQ("a", cookie.Name()); 437 EXPECT_EQ("a", cookie.Name());
401 EXPECT_EQ("b", cookie.Value()); 438 EXPECT_EQ("b", cookie.Value());
402 } 439 }
403 440
404 // Tests that cookies can be read before the backend is loaded. 441 // Tests that cookies can be read before the backend is loaded.
405 TEST_F(CookieStoreIOSWithBackend, NotSynchronized) { 442 TEST_F(NotSynchronizedCookieStoreIOSWithBackend, NotSynchronized) {
406 // Start fetching the cookie. 443 // Start fetching the cookie.
407 GetCookieCallback callback; 444 GetCookieCallback callback;
408 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); 445 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback)));
409 // Backend loading completes. 446 // Backend loading completes.
410 backend_->RunLoadedCallback(); 447 backend_->RunLoadedCallback();
411 EXPECT_TRUE(callback.did_run()); 448 EXPECT_TRUE(callback.did_run());
412 EXPECT_EQ("a=b", callback.cookie_line()); 449 EXPECT_EQ("a=b", callback.cookie_line());
413 } 450 }
414 451
415 // Tests that cookies can be read before synchronization is complete. 452 TEST_F(SynchronizedCookieStoreIOS, NoInitialNotifyWithNoCookie) {
416 TEST_F(CookieStoreIOSWithBackend, Synchronizing) {
417 // Start synchronization.
418 store_->SetSynchronizedWithSystemStore(true);
419 GetCookieCallback callback;
420 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback)));
421 // Backend loading completes (end of synchronization).
422 backend_->RunLoadedCallback();
423 EXPECT_TRUE(callback.did_run());
424 EXPECT_EQ("a=b", callback.cookie_line());
425 store_->SetSynchronizedWithSystemStore(false);
426 }
427
428 TEST_F(CookieStoreIOSWithBackend, FlushOnCookieChanged) {
429 store_->SetSynchronizedWithSystemStore(true);
430 store_->set_flush_delay_for_testing(base::TimeDelta());
431 backend_->RunLoadedCallback();
432 EXPECT_FALSE(backend_->flushed());
433
434 // Set a cookie an check that it triggers a flush.
435 SetCookie("x=y");
436 EXPECT_TRUE(backend_->flushed());
437
438 store_->SetSynchronizedWithSystemStore(false);
439 }
440
441 TEST_F(CookieStoreIOSWithBackend, ManualFlush) {
442 store_->SetSynchronizedWithSystemStore(true);
443 backend_->RunLoadedCallback();
444 EXPECT_FALSE(backend_->flushed());
445
446 // The store should be flushed even if it is not dirty.
447 store_->FlushStore(base::Closure());
448 EXPECT_TRUE(backend_->flushed());
449
450 store_->SetSynchronizedWithSystemStore(false);
451 }
452
453 TEST_F(CookieStoreIOSWithBackend, NoInitialNotifyWithNoCookie) {
454 store_->SetSynchronizedWithSystemStore(true);
455 std::vector<net::CanonicalCookie> cookies; 453 std::vector<net::CanonicalCookie> cookies;
456 store_->AddCallbackForCookie( 454 store_->AddCallbackForCookie(
457 kTestCookieURL, "abc", 455 kTestCookieURL, "abc",
458 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 456 base::Bind(&RecordCookieChanges, &cookies, nullptr));
459 EXPECT_EQ(0U, cookies.size()); 457 EXPECT_EQ(0U, cookies.size());
460 store_->SetSynchronizedWithSystemStore(false);
461 } 458 }
462 459
463 TEST_F(CookieStoreIOSWithBackend, NoInitialNotifyWithSystemCookie) { 460 TEST_F(SynchronizedCookieStoreIOS, NoInitialNotifyWithSystemCookie) {
464 store_->SetSynchronizedWithSystemStore(true);
465 SetSystemCookie(kTestCookieURL, "abc", "def"); 461 SetSystemCookie(kTestCookieURL, "abc", "def");
466 std::vector<net::CanonicalCookie> cookies; 462 std::vector<net::CanonicalCookie> cookies;
467 store_->AddCallbackForCookie( 463 store_->AddCallbackForCookie(
468 kTestCookieURL, "abc", 464 kTestCookieURL, "abc",
469 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 465 base::Bind(&RecordCookieChanges, &cookies, nullptr));
470 EXPECT_EQ(0U, cookies.size()); 466 EXPECT_EQ(0U, cookies.size());
471 DeleteSystemCookie(kTestCookieURL, "abc"); 467 DeleteSystemCookie(kTestCookieURL, "abc");
472 store_->SetSynchronizedWithSystemStore(false);
473 } 468 }
474 469
475 TEST_F(CookieStoreIOSWithBackend, NotifyOnAdd) { 470 TEST_F(SynchronizedCookieStoreIOS, NotifyOnAdd) {
476 store_->SetSynchronizedWithSystemStore(true);
477 backend_->RunLoadedCallback();
478 std::vector<net::CanonicalCookie> cookies; 471 std::vector<net::CanonicalCookie> cookies;
479 std::vector<bool> removes; 472 std::vector<bool> removes;
480 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 473 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
481 store_->AddCallbackForCookie( 474 store_->AddCallbackForCookie(
482 kTestCookieURL, "abc", 475 kTestCookieURL, "abc",
483 base::Bind(&RecordCookieChanges, &cookies, &removes)); 476 base::Bind(&RecordCookieChanges, &cookies, &removes));
484 EXPECT_EQ(0U, cookies.size()); 477 EXPECT_EQ(0U, cookies.size());
485 EXPECT_EQ(0U, removes.size()); 478 EXPECT_EQ(0U, removes.size());
486 SetSystemCookie(kTestCookieURL, "abc", "def"); 479 SetSystemCookie(kTestCookieURL, "abc", "def");
487 EXPECT_EQ(1U, cookies.size()); 480 EXPECT_EQ(1U, cookies.size());
488 EXPECT_EQ(1U, removes.size()); 481 EXPECT_EQ(1U, removes.size());
489 EXPECT_EQ("abc", cookies[0].Name()); 482 EXPECT_EQ("abc", cookies[0].Name());
490 EXPECT_EQ("def", cookies[0].Value()); 483 EXPECT_EQ("def", cookies[0].Value());
491 EXPECT_FALSE(removes[0]); 484 EXPECT_FALSE(removes[0]);
492 485
493 SetSystemCookie(kTestCookieURL, "ghi", "jkl"); 486 SetSystemCookie(kTestCookieURL, "ghi", "jkl");
494 EXPECT_EQ(1U, cookies.size()); 487 EXPECT_EQ(1U, cookies.size());
495 EXPECT_EQ(1U, removes.size()); 488 EXPECT_EQ(1U, removes.size());
496 489
497 DeleteSystemCookie(kTestCookieURL, "abc"); 490 DeleteSystemCookie(kTestCookieURL, "abc");
498 DeleteSystemCookie(kTestCookieURL, "ghi"); 491 DeleteSystemCookie(kTestCookieURL, "ghi");
499 store_->SetSynchronizedWithSystemStore(false);
500 } 492 }
501 493
502 TEST_F(CookieStoreIOSWithBackend, NotifyOnChange) { 494 TEST_F(SynchronizedCookieStoreIOS, NotifyOnChange) {
503 store_->SetSynchronizedWithSystemStore(true);
504 backend_->RunLoadedCallback();
505 std::vector<net::CanonicalCookie> cookies; 495 std::vector<net::CanonicalCookie> cookies;
506 std::vector<bool> removes; 496 std::vector<bool> removes;
507 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 497 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
508 store_->AddCallbackForCookie( 498 store_->AddCallbackForCookie(
509 kTestCookieURL, "abc", 499 kTestCookieURL, "abc",
510 base::Bind(&RecordCookieChanges, &cookies, &removes)); 500 base::Bind(&RecordCookieChanges, &cookies, &removes));
511 EXPECT_EQ(0U, cookies.size()); 501 EXPECT_EQ(0U, cookies.size());
512 SetSystemCookie(kTestCookieURL, "abc", "def"); 502 SetSystemCookie(kTestCookieURL, "abc", "def");
513 EXPECT_EQ(1U, cookies.size()); 503 EXPECT_EQ(1U, cookies.size());
514 SetSystemCookie(kTestCookieURL, "abc", "ghi"); 504 SetSystemCookie(kTestCookieURL, "abc", "ghi");
515 EXPECT_EQ(3U, cookies.size()); 505 EXPECT_EQ(3U, cookies.size());
516 EXPECT_EQ(3U, removes.size()); 506 EXPECT_EQ(3U, removes.size());
517 EXPECT_EQ("abc", cookies[1].Name()); 507 EXPECT_EQ("abc", cookies[1].Name());
518 EXPECT_EQ("def", cookies[1].Value()); 508 EXPECT_EQ("def", cookies[1].Value());
519 EXPECT_TRUE(removes[1]); 509 EXPECT_TRUE(removes[1]);
520 EXPECT_EQ("abc", cookies[2].Name()); 510 EXPECT_EQ("abc", cookies[2].Name());
521 EXPECT_EQ("ghi", cookies[2].Value()); 511 EXPECT_EQ("ghi", cookies[2].Value());
522 EXPECT_FALSE(removes[2]); 512 EXPECT_FALSE(removes[2]);
523 513
524 DeleteSystemCookie(kTestCookieURL, "abc"); 514 DeleteSystemCookie(kTestCookieURL, "abc");
525 store_->SetSynchronizedWithSystemStore(false);
526 } 515 }
527 516
528 TEST_F(CookieStoreIOSWithBackend, NotifyOnDelete) { 517 TEST_F(SynchronizedCookieStoreIOS, NotifyOnDelete) {
529 store_->SetSynchronizedWithSystemStore(true);
530 backend_->RunLoadedCallback();
531 std::vector<net::CanonicalCookie> cookies; 518 std::vector<net::CanonicalCookie> cookies;
532 std::vector<bool> removes; 519 std::vector<bool> removes;
533 SetSystemCookie(kTestCookieURL, "abc", "def"); 520 SetSystemCookie(kTestCookieURL, "abc", "def");
534 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 521 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
535 store_->AddCallbackForCookie( 522 store_->AddCallbackForCookie(
536 kTestCookieURL, "abc", 523 kTestCookieURL, "abc",
537 base::Bind(&RecordCookieChanges, &cookies, &removes)); 524 base::Bind(&RecordCookieChanges, &cookies, &removes));
538 EXPECT_EQ(0U, cookies.size()); 525 EXPECT_EQ(0U, cookies.size());
539 DeleteSystemCookie(kTestCookieURL, "abc"); 526 DeleteSystemCookie(kTestCookieURL, "abc");
540 EXPECT_EQ(1U, cookies.size()); 527 EXPECT_EQ(1U, cookies.size());
541 EXPECT_EQ(1U, removes.size()); 528 EXPECT_EQ(1U, removes.size());
542 EXPECT_TRUE(removes[0]); 529 EXPECT_TRUE(removes[0]);
543 SetSystemCookie(kTestCookieURL, "abc", "def"); 530 SetSystemCookie(kTestCookieURL, "abc", "def");
544 EXPECT_EQ(2U, cookies.size()); 531 EXPECT_EQ(2U, cookies.size());
545 EXPECT_EQ(2U, removes.size()); 532 EXPECT_EQ(2U, removes.size());
546 EXPECT_FALSE(removes[1]); 533 EXPECT_FALSE(removes[1]);
547 DeleteSystemCookie(kTestCookieURL, "abc"); 534 DeleteSystemCookie(kTestCookieURL, "abc");
548 store_->SetSynchronizedWithSystemStore(false);
549 } 535 }
550 536
551 TEST_F(CookieStoreIOSWithBackend, NoNotifyOnNoChange) { 537 TEST_F(SynchronizedCookieStoreIOS, NoNotifyOnNoChange) {
552 store_->SetSynchronizedWithSystemStore(true);
553 backend_->RunLoadedCallback();
554 std::vector<net::CanonicalCookie> cookies; 538 std::vector<net::CanonicalCookie> cookies;
555 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 539 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
556 store_->AddCallbackForCookie( 540 store_->AddCallbackForCookie(
557 kTestCookieURL, "abc", 541 kTestCookieURL, "abc",
558 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 542 base::Bind(&RecordCookieChanges, &cookies, nullptr));
559 EXPECT_EQ(0U, cookies.size()); 543 EXPECT_EQ(0U, cookies.size());
560 SetSystemCookie(kTestCookieURL, "abc", "def"); 544 SetSystemCookie(kTestCookieURL, "abc", "def");
561 EXPECT_EQ(1U, cookies.size()); 545 EXPECT_EQ(1U, cookies.size());
562 SetSystemCookie(kTestCookieURL, "abc", "def"); 546 SetSystemCookie(kTestCookieURL, "abc", "def");
563 EXPECT_EQ(1U, cookies.size()); 547 EXPECT_EQ(1U, cookies.size());
564 DeleteSystemCookie(kTestCookieURL, "abc"); 548 DeleteSystemCookie(kTestCookieURL, "abc");
565 store_->SetSynchronizedWithSystemStore(false);
566 } 549 }
567 550
568 TEST_F(CookieStoreIOSWithBackend, MultipleNotifies) { 551 TEST_F(SynchronizedCookieStoreIOS, MultipleNotifies) {
569 store_->SetSynchronizedWithSystemStore(true);
570 backend_->RunLoadedCallback();
571 std::vector<net::CanonicalCookie> cookies; 552 std::vector<net::CanonicalCookie> cookies;
572 std::vector<net::CanonicalCookie> cookies2; 553 std::vector<net::CanonicalCookie> cookies2;
573 std::vector<net::CanonicalCookie> cookies3; 554 std::vector<net::CanonicalCookie> cookies3;
574 std::vector<net::CanonicalCookie> cookies4; 555 std::vector<net::CanonicalCookie> cookies4;
575 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 556 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
576 store_->AddCallbackForCookie( 557 store_->AddCallbackForCookie(
577 kTestCookieURL, "abc", 558 kTestCookieURL, "abc",
578 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 559 base::Bind(&RecordCookieChanges, &cookies, nullptr));
579 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle2 = 560 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle2 =
580 store_->AddCallbackForCookie( 561 store_->AddCallbackForCookie(
581 kTestCookieURL2, "abc", 562 kTestCookieURL2, "abc",
582 base::Bind(&RecordCookieChanges, &cookies2, nullptr)); 563 base::Bind(&RecordCookieChanges, &cookies2, nullptr));
583 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle3 = 564 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle3 =
584 store_->AddCallbackForCookie( 565 store_->AddCallbackForCookie(
585 kTestCookieURL3, "abc", 566 kTestCookieURL3, "abc",
586 base::Bind(&RecordCookieChanges, &cookies3, nullptr)); 567 base::Bind(&RecordCookieChanges, &cookies3, nullptr));
587 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle4 = 568 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle4 =
588 store_->AddCallbackForCookie( 569 store_->AddCallbackForCookie(
589 kTestCookieURL4, "abc", 570 kTestCookieURL4, "abc",
590 base::Bind(&RecordCookieChanges, &cookies4, nullptr)); 571 base::Bind(&RecordCookieChanges, &cookies4, nullptr));
591 SetSystemCookie(kTestCookieURL, "abc", "def"); 572 SetSystemCookie(kTestCookieURL, "abc", "def");
592 SetSystemCookie(kTestCookieURL2, "abc", "def"); 573 SetSystemCookie(kTestCookieURL2, "abc", "def");
593 SetSystemCookie(kTestCookieURL3, "abc", "def"); 574 SetSystemCookie(kTestCookieURL3, "abc", "def");
594 SetSystemCookie(kTestCookieURL4, "abc", "def"); 575 SetSystemCookie(kTestCookieURL4, "abc", "def");
595 EXPECT_EQ(2U, cookies.size()); 576 EXPECT_EQ(1U, cookies.size());
Eugene But (OOO till 7-30) 2016/12/28 19:34:23 Synchronized CookieStoreIOS works differently if c
marq (ping after 24h) 2016/12/30 09:24:38 I don't know these interfaces well at all, so I wo
596 EXPECT_EQ(2U, cookies2.size()); 577 EXPECT_EQ(1U, cookies2.size());
597 EXPECT_EQ(1U, cookies3.size()); 578 EXPECT_EQ(0U, cookies3.size());
598 EXPECT_EQ(1U, cookies4.size()); 579 EXPECT_EQ(1U, cookies4.size());
599 DeleteSystemCookie(kTestCookieURL, "abc"); 580 DeleteSystemCookie(kTestCookieURL, "abc");
600 DeleteSystemCookie(kTestCookieURL2, "abc"); 581 DeleteSystemCookie(kTestCookieURL2, "abc");
601 DeleteSystemCookie(kTestCookieURL3, "abc"); 582 DeleteSystemCookie(kTestCookieURL3, "abc");
602 DeleteSystemCookie(kTestCookieURL4, "abc"); 583 DeleteSystemCookie(kTestCookieURL4, "abc");
603 store_->SetSynchronizedWithSystemStore(false);
604 } 584 }
605 585
606 TEST_F(CookieStoreIOSWithBackend, LessSpecificNestedCookie) { 586 TEST_F(SynchronizedCookieStoreIOS, LessSpecificNestedCookie) {
607 store_->SetSynchronizedWithSystemStore(true);
608 backend_->RunLoadedCallback();
609 std::vector<net::CanonicalCookie> cookies; 587 std::vector<net::CanonicalCookie> cookies;
610 SetSystemCookie(kTestCookieURL2, "abc", "def"); 588 SetSystemCookie(kTestCookieURL2, "abc", "def");
611 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 589 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
612 store_->AddCallbackForCookie( 590 store_->AddCallbackForCookie(
613 kTestCookieURL2, "abc", 591 kTestCookieURL2, "abc",
614 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 592 base::Bind(&RecordCookieChanges, &cookies, nullptr));
615 EXPECT_EQ(0U, cookies.size()); 593 EXPECT_EQ(0U, cookies.size());
616 SetSystemCookie(kTestCookieURL3, "abc", "ghi"); 594 SetSystemCookie(kTestCookieURL3, "abc", "ghi");
617 EXPECT_EQ(1U, cookies.size()); 595 EXPECT_EQ(1U, cookies.size());
618 DeleteSystemCookie(kTestCookieURL, "abc"); 596 DeleteSystemCookie(kTestCookieURL, "abc");
619 store_->SetSynchronizedWithSystemStore(false);
620 } 597 }
621 598
622 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookie) { 599 TEST_F(SynchronizedCookieStoreIOS, MoreSpecificNestedCookie) {
623 store_->SetSynchronizedWithSystemStore(true);
624 backend_->RunLoadedCallback();
625 std::vector<net::CanonicalCookie> cookies; 600 std::vector<net::CanonicalCookie> cookies;
626 SetSystemCookie(kTestCookieURL3, "abc", "def"); 601 SetSystemCookie(kTestCookieURL3, "abc", "def");
627 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 602 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
628 store_->AddCallbackForCookie( 603 store_->AddCallbackForCookie(
629 kTestCookieURL2, "abc", 604 kTestCookieURL2, "abc",
630 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 605 base::Bind(&RecordCookieChanges, &cookies, nullptr));
631 EXPECT_EQ(0U, cookies.size()); 606 EXPECT_EQ(0U, cookies.size());
632 SetSystemCookie(kTestCookieURL2, "abc", "ghi"); 607 SetSystemCookie(kTestCookieURL2, "abc", "ghi");
633 EXPECT_EQ(1U, cookies.size()); 608 EXPECT_EQ(2U, cookies.size());
Eugene But (OOO till 7-30) 2016/12/28 19:34:23 Same change here
634 DeleteSystemCookie(kTestCookieURL, "abc"); 609 DeleteSystemCookie(kTestCookieURL, "abc");
635 store_->SetSynchronizedWithSystemStore(false);
636 } 610 }
637 611
638 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookieWithSameValue) { 612 TEST_F(SynchronizedCookieStoreIOS, MoreSpecificNestedCookieWithSameValue) {
639 store_->SetSynchronizedWithSystemStore(true);
640 backend_->RunLoadedCallback();
641 std::vector<net::CanonicalCookie> cookies; 613 std::vector<net::CanonicalCookie> cookies;
642 SetSystemCookie(kTestCookieURL3, "abc", "def"); 614 SetSystemCookie(kTestCookieURL3, "abc", "def");
643 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 615 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
644 store_->AddCallbackForCookie( 616 store_->AddCallbackForCookie(
645 kTestCookieURL2, "abc", 617 kTestCookieURL2, "abc",
646 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 618 base::Bind(&RecordCookieChanges, &cookies, nullptr));
647 EXPECT_EQ(0U, cookies.size()); 619 EXPECT_EQ(0U, cookies.size());
648 SetSystemCookie(kTestCookieURL2, "abc", "def"); 620 SetSystemCookie(kTestCookieURL2, "abc", "def");
649 EXPECT_EQ(1U, cookies.size()); 621 EXPECT_EQ(2U, cookies.size());
Eugene But (OOO till 7-30) 2016/12/28 19:34:23 And here...
650 DeleteSystemCookie(kTestCookieURL, "abc"); 622 DeleteSystemCookie(kTestCookieURL, "abc");
651 store_->SetSynchronizedWithSystemStore(false);
652 } 623 }
653 624
654 TEST_F(CookieStoreIOSWithBackend, RemoveCallback) { 625 TEST_F(SynchronizedCookieStoreIOS, RemoveCallback) {
655 store_->SetSynchronizedWithSystemStore(true);
656 backend_->RunLoadedCallback();
657 std::vector<net::CanonicalCookie> cookies; 626 std::vector<net::CanonicalCookie> cookies;
658 SetSystemCookie(kTestCookieURL, "abc", "def"); 627 SetSystemCookie(kTestCookieURL, "abc", "def");
659 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = 628 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
660 store_->AddCallbackForCookie( 629 store_->AddCallbackForCookie(
661 kTestCookieURL, "abc", 630 kTestCookieURL, "abc",
662 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 631 base::Bind(&RecordCookieChanges, &cookies, nullptr));
663 EXPECT_EQ(0U, cookies.size()); 632 EXPECT_EQ(0U, cookies.size());
664 SetSystemCookie(kTestCookieURL, "abc", "ghi"); 633 SetSystemCookie(kTestCookieURL, "abc", "ghi");
665 EXPECT_EQ(2U, cookies.size()); 634 EXPECT_EQ(2U, cookies.size());
666 // this deletes the callback 635 // this deletes the callback
667 handle.reset(); 636 handle.reset();
668 SetSystemCookie(kTestCookieURL, "abc", "jkl"); 637 SetSystemCookie(kTestCookieURL, "abc", "jkl");
669 EXPECT_EQ(2U, cookies.size()); 638 EXPECT_EQ(2U, cookies.size());
670 DeleteSystemCookie(kTestCookieURL, "abc"); 639 DeleteSystemCookie(kTestCookieURL, "abc");
671 store_->SetSynchronizedWithSystemStore(false);
672 } 640 }
673 641
674 } // namespace net 642 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698