| OLD | NEW |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // RoundTripTestCookieStore is un-synchronized and re-synchronized after all | 72 // RoundTripTestCookieStore is un-synchronized and re-synchronized after all |
| 73 // cookie operations. This means all system cookies are converted to Chrome | 73 // cookie operations. This means all system cookies are converted to Chrome |
| 74 // cookies and converted back. | 74 // cookies and converted back. |
| 75 // The purpose of this class is to test that cookie conversions do not break the | 75 // The purpose of this class is to test that cookie conversions do not break the |
| 76 // cookie store. | 76 // cookie store. |
| 77 class RoundTripTestCookieStore : public net::CookieStore { | 77 class RoundTripTestCookieStore : public net::CookieStore { |
| 78 public: | 78 public: |
| 79 RoundTripTestCookieStore() | 79 RoundTripTestCookieStore() |
| 80 : store_(new CookieStoreIOS(nullptr)), | 80 : store_(new CookieStoreIOS(nullptr)), |
| 81 dummy_store_(new CookieStoreIOS(nullptr)) { | 81 dummy_store_(new CookieStoreIOS(nullptr)) { |
| 82 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 82 store_->SetSynchronizedWithSystemStore(true); |
| 83 } | 83 } |
| 84 | 84 |
| 85 ~RoundTripTestCookieStore() override { store_->UnSynchronize(); } | 85 ~RoundTripTestCookieStore() override { |
| 86 store_->SetSynchronizedWithSystemStore(false); |
| 87 } |
| 86 | 88 |
| 87 // Inherited CookieStore methods. | 89 // Inherited CookieStore methods. |
| 88 void SetCookieWithOptionsAsync(const GURL& url, | 90 void SetCookieWithOptionsAsync(const GURL& url, |
| 89 const std::string& cookie_line, | 91 const std::string& cookie_line, |
| 90 const net::CookieOptions& options, | 92 const net::CookieOptions& options, |
| 91 const SetCookiesCallback& callback) override { | 93 const SetCookiesCallback& callback) override { |
| 92 RoundTrip(); | 94 RoundTrip(); |
| 93 store_->SetCookieWithOptionsAsync(url, cookie_line, options, callback); | 95 store_->SetCookieWithOptionsAsync(url, cookie_line, options, callback); |
| 94 } | 96 } |
| 95 | 97 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 const CookieChangedCallback& callback) override { | 183 const CookieChangedCallback& callback) override { |
| 182 return std::unique_ptr<CookieStore::CookieChangedSubscription>(); | 184 return std::unique_ptr<CookieStore::CookieChangedSubscription>(); |
| 183 } | 185 } |
| 184 | 186 |
| 185 bool IsEphemeral() override { | 187 bool IsEphemeral() override { |
| 186 return store_->IsEphemeral(); | 188 return store_->IsEphemeral(); |
| 187 } | 189 } |
| 188 | 190 |
| 189 private: | 191 private: |
| 190 void RoundTrip() { | 192 void RoundTrip() { |
| 191 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store_.get()); | 193 store_->SetSynchronizedWithSystemStore(false); |
| 194 dummy_store_->SetSynchronizedWithSystemStore(true); |
| 192 // Check that the system store is empty, because it is synchronized with | 195 // Check that the system store is empty, because it is synchronized with |
| 193 // |dummy_store_| which is empty. | 196 // |dummy_store_| which is empty. |
| 194 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; | 197 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; |
| 195 EXPECT_EQ(0u, [[store cookies] count]); | 198 EXPECT_EQ(0u, [[store cookies] count]); |
| 196 CookieStoreIOS::SwitchSynchronizedStore(dummy_store_.get(), store_.get()); | 199 dummy_store_->SetSynchronizedWithSystemStore(false); |
| 200 store_->SetSynchronizedWithSystemStore(true); |
| 197 } | 201 } |
| 198 | 202 |
| 199 std::unique_ptr<CookieStoreIOS> store_; | 203 std::unique_ptr<CookieStoreIOS> store_; |
| 200 // |dummy_store_| is not directly used, but is needed to make |store_| | 204 // |dummy_store_| is not directly used, but is needed to make |store_| |
| 201 // inactive. | 205 // inactive. |
| 202 std::unique_ptr<CookieStoreIOS> dummy_store_; | 206 std::unique_ptr<CookieStoreIOS> dummy_store_; |
| 203 }; | 207 }; |
| 204 | 208 |
| 205 struct RoundTripTestCookieStoreTraits { | 209 struct RoundTripTestCookieStoreTraits { |
| 206 static std::unique_ptr<net::CookieStore> Create() { | 210 static std::unique_ptr<net::CookieStore> Create() { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 SetCookie("abc=ghi"); | 469 SetCookie("abc=ghi"); |
| 466 EXPECT_EQ(3U, cookies_changed_.size()); | 470 EXPECT_EQ(3U, cookies_changed_.size()); |
| 467 EXPECT_EQ(3U, cookies_removed_.size()); | 471 EXPECT_EQ(3U, cookies_removed_.size()); |
| 468 EXPECT_EQ("abc", cookies_changed_[1].Name()); | 472 EXPECT_EQ("abc", cookies_changed_[1].Name()); |
| 469 EXPECT_EQ("def", cookies_changed_[1].Value()); | 473 EXPECT_EQ("def", cookies_changed_[1].Value()); |
| 470 EXPECT_TRUE(cookies_removed_[1]); | 474 EXPECT_TRUE(cookies_removed_[1]); |
| 471 EXPECT_EQ("abc", cookies_changed_[2].Name()); | 475 EXPECT_EQ("abc", cookies_changed_[2].Name()); |
| 472 EXPECT_EQ("ghi", cookies_changed_[2].Value()); | 476 EXPECT_EQ("ghi", cookies_changed_[2].Value()); |
| 473 EXPECT_FALSE(cookies_removed_[2]); | 477 EXPECT_FALSE(cookies_removed_[2]); |
| 474 | 478 |
| 475 store_->UnSynchronize(); | 479 store_->SetSynchronizedWithSystemStore(false); |
| 476 } | 480 } |
| 477 | 481 |
| 478 TEST_F(CookieStoreIOSWithBackend, SetCookieCallsHookWhenSynchronized) { | 482 TEST_F(CookieStoreIOSWithBackend, SetCookieCallsHookWhenSynchronized) { |
| 479 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 483 store_->SetSynchronizedWithSystemStore(true); |
| 480 GetCookies(base::Bind(&IgnoreString)); | 484 GetCookies(base::Bind(&IgnoreString)); |
| 481 backend_->RunLoadedCallback(); | 485 backend_->RunLoadedCallback(); |
| 482 base::RunLoop().RunUntilIdle(); | 486 base::RunLoop().RunUntilIdle(); |
| 483 ClearCookies(); | 487 ClearCookies(); |
| 484 SetCookie("abc=def"); | 488 SetCookie("abc=def"); |
| 485 EXPECT_EQ(1U, cookies_changed_.size()); | 489 EXPECT_EQ(1U, cookies_changed_.size()); |
| 486 EXPECT_EQ(1U, cookies_removed_.size()); | 490 EXPECT_EQ(1U, cookies_removed_.size()); |
| 487 EXPECT_EQ("abc", cookies_changed_[0].Name()); | 491 EXPECT_EQ("abc", cookies_changed_[0].Name()); |
| 488 EXPECT_EQ("def", cookies_changed_[0].Value()); | 492 EXPECT_EQ("def", cookies_changed_[0].Value()); |
| 489 EXPECT_FALSE(cookies_removed_[0]); | 493 EXPECT_FALSE(cookies_removed_[0]); |
| 490 | 494 |
| 491 SetCookie("abc=ghi"); | 495 SetCookie("abc=ghi"); |
| 492 EXPECT_EQ(3U, cookies_changed_.size()); | 496 EXPECT_EQ(3U, cookies_changed_.size()); |
| 493 EXPECT_EQ(3U, cookies_removed_.size()); | 497 EXPECT_EQ(3U, cookies_removed_.size()); |
| 494 EXPECT_EQ("abc", cookies_changed_[1].Name()); | 498 EXPECT_EQ("abc", cookies_changed_[1].Name()); |
| 495 EXPECT_EQ("def", cookies_changed_[1].Value()); | 499 EXPECT_EQ("def", cookies_changed_[1].Value()); |
| 496 EXPECT_TRUE(cookies_removed_[1]); | 500 EXPECT_TRUE(cookies_removed_[1]); |
| 497 EXPECT_EQ("abc", cookies_changed_[2].Name()); | 501 EXPECT_EQ("abc", cookies_changed_[2].Name()); |
| 498 EXPECT_EQ("ghi", cookies_changed_[2].Value()); | 502 EXPECT_EQ("ghi", cookies_changed_[2].Value()); |
| 499 EXPECT_FALSE(cookies_removed_[2]); | 503 EXPECT_FALSE(cookies_removed_[2]); |
| 500 DeleteSystemCookie(kTestCookieURL, "abc"); | 504 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 501 | 505 |
| 502 store_->UnSynchronize(); | 506 store_->SetSynchronizedWithSystemStore(false); |
| 503 } | 507 } |
| 504 | 508 |
| 505 TEST_F(CookieStoreIOSWithBackend, DeleteCallsHook) { | 509 TEST_F(CookieStoreIOSWithBackend, DeleteCallsHook) { |
| 506 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 510 store_->SetSynchronizedWithSystemStore(true); |
| 507 GetCookies(base::Bind(&IgnoreString)); | 511 GetCookies(base::Bind(&IgnoreString)); |
| 508 backend_->RunLoadedCallback(); | 512 backend_->RunLoadedCallback(); |
| 509 base::RunLoop().RunUntilIdle(); | 513 base::RunLoop().RunUntilIdle(); |
| 510 ClearCookies(); | 514 ClearCookies(); |
| 511 SetCookie("abc=def"); | 515 SetCookie("abc=def"); |
| 512 EXPECT_EQ(1U, cookies_changed_.size()); | 516 EXPECT_EQ(1U, cookies_changed_.size()); |
| 513 EXPECT_EQ(1U, cookies_removed_.size()); | 517 EXPECT_EQ(1U, cookies_removed_.size()); |
| 514 store_->DeleteCookieAsync(kTestCookieURL, "abc", | 518 store_->DeleteCookieAsync(kTestCookieURL, "abc", |
| 515 base::Bind(&IgnoreBoolean, false)); | 519 base::Bind(&IgnoreBoolean, false)); |
| 516 CookieStoreIOS::NotifySystemCookiesChanged(); | 520 CookieStoreIOS::NotifySystemCookiesChanged(); |
| 517 base::RunLoop().RunUntilIdle(); | 521 base::RunLoop().RunUntilIdle(); |
| 518 store_->UnSynchronize(); | 522 store_->SetSynchronizedWithSystemStore(false); |
| 519 } | 523 } |
| 520 | 524 |
| 521 TEST_F(CookieStoreIOSWithBackend, SameValueDoesNotCallHook) { | 525 TEST_F(CookieStoreIOSWithBackend, SameValueDoesNotCallHook) { |
| 522 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 526 store_->SetSynchronizedWithSystemStore(true); |
| 523 GetCookieCallback callback; | 527 GetCookieCallback callback; |
| 524 GetCookies(base::Bind(&IgnoreString)); | 528 GetCookies(base::Bind(&IgnoreString)); |
| 525 backend_->RunLoadedCallback(); | 529 backend_->RunLoadedCallback(); |
| 526 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
| 527 ClearCookies(); | 531 ClearCookies(); |
| 528 SetCookie("abc=def"); | 532 SetCookie("abc=def"); |
| 529 EXPECT_EQ(1U, cookies_changed_.size()); | 533 EXPECT_EQ(1U, cookies_changed_.size()); |
| 530 SetCookie("abc=def"); | 534 SetCookie("abc=def"); |
| 531 EXPECT_EQ(1U, cookies_changed_.size()); | 535 EXPECT_EQ(1U, cookies_changed_.size()); |
| 532 store_->UnSynchronize(); | 536 store_->SetSynchronizedWithSystemStore(false); |
| 533 } | 537 } |
| 534 | 538 |
| 535 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) { | 539 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) { |
| 536 base::MessageLoop loop; | 540 base::MessageLoop loop; |
| 537 const GURL kTestCookieURL("http://foo.google.com/bar"); | 541 const GURL kTestCookieURL("http://foo.google.com/bar"); |
| 538 ClearCookies(); | 542 ClearCookies(); |
| 539 std::unique_ptr<CookieStoreIOS> cookie_store(new CookieStoreIOS(nullptr)); | 543 std::unique_ptr<CookieStoreIOS> cookie_store(new CookieStoreIOS(nullptr)); |
| 540 CookieStoreIOS::SwitchSynchronizedStore(nullptr, cookie_store.get()); | 544 cookie_store->SetSynchronizedWithSystemStore(true); |
| 541 // Add a cookie. | 545 // Add a cookie. |
| 542 net::CookieOptions options; | 546 net::CookieOptions options; |
| 543 options.set_include_httponly(); | 547 options.set_include_httponly(); |
| 544 cookie_store->SetCookieWithOptionsAsync( | 548 cookie_store->SetCookieWithOptionsAsync( |
| 545 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); | 549 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); |
| 546 // Check we can get the cookie. | 550 // Check we can get the cookie. |
| 547 GetAllCookiesCallback callback; | 551 GetAllCookiesCallback callback; |
| 548 cookie_store->GetAllCookiesForURLAsync( | 552 cookie_store->GetAllCookiesForURLAsync( |
| 549 kTestCookieURL, | 553 kTestCookieURL, |
| 550 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback))); | 554 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback))); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 562 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); | 566 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); |
| 563 // Backend loading completes. | 567 // Backend loading completes. |
| 564 backend_->RunLoadedCallback(); | 568 backend_->RunLoadedCallback(); |
| 565 EXPECT_TRUE(callback.did_run()); | 569 EXPECT_TRUE(callback.did_run()); |
| 566 EXPECT_EQ("a=b", callback.cookie_line()); | 570 EXPECT_EQ("a=b", callback.cookie_line()); |
| 567 } | 571 } |
| 568 | 572 |
| 569 // Tests that cookies can be read before synchronization is complete. | 573 // Tests that cookies can be read before synchronization is complete. |
| 570 TEST_F(CookieStoreIOSWithBackend, Synchronizing) { | 574 TEST_F(CookieStoreIOSWithBackend, Synchronizing) { |
| 571 // Start synchronization. | 575 // Start synchronization. |
| 572 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 576 store_->SetSynchronizedWithSystemStore(true); |
| 573 GetCookieCallback callback; | 577 GetCookieCallback callback; |
| 574 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); | 578 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); |
| 575 // Backend loading completes (end of synchronization). | 579 // Backend loading completes (end of synchronization). |
| 576 backend_->RunLoadedCallback(); | 580 backend_->RunLoadedCallback(); |
| 577 EXPECT_TRUE(callback.did_run()); | 581 EXPECT_TRUE(callback.did_run()); |
| 578 EXPECT_EQ("a=b", callback.cookie_line()); | 582 EXPECT_EQ("a=b", callback.cookie_line()); |
| 579 store_->UnSynchronize(); | 583 store_->SetSynchronizedWithSystemStore(false); |
| 580 } | 584 } |
| 581 | 585 |
| 582 // Tests that Synchronization can be "aborted" (i.e. the cookie store is | 586 // Tests that Synchronization can be "aborted" (i.e. the cookie store is |
| 583 // unsynchronized while synchronization is in progress). | 587 // unsynchronized while synchronization is in progress). |
| 584 TEST_F(CookieStoreIOSWithBackend, SyncThenUnsync) { | 588 TEST_F(CookieStoreIOSWithBackend, SyncThenUnsync) { |
| 585 ClearCookies(); | 589 ClearCookies(); |
| 586 std::unique_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr)); | 590 std::unique_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr)); |
| 587 // Switch back and forth before synchronization can complete. | 591 // Switch back and forth before synchronization can complete. |
| 588 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 592 store_->SetSynchronizedWithSystemStore(true); |
| 589 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get()); | 593 store_->SetSynchronizedWithSystemStore(false); |
| 594 dummy_store->SetSynchronizedWithSystemStore(true); |
| 590 backend_->RunLoadedCallback(); | 595 backend_->RunLoadedCallback(); |
| 591 // No cookie leak in the system store. | 596 // No cookie leak in the system store. |
| 592 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; | 597 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; |
| 593 EXPECT_EQ(0u, [[store cookies] count]); | 598 EXPECT_EQ(0u, [[store cookies] count]); |
| 594 // No cookie lost. | 599 // No cookie lost. |
| 595 GetCookieCallback callback; | 600 GetCookieCallback callback; |
| 596 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); | 601 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); |
| 597 EXPECT_TRUE(callback.did_run()); | 602 EXPECT_TRUE(callback.did_run()); |
| 598 EXPECT_EQ("a=b", callback.cookie_line()); | 603 EXPECT_EQ("a=b", callback.cookie_line()); |
| 599 dummy_store->UnSynchronize(); | 604 dummy_store->SetSynchronizedWithSystemStore(false); |
| 600 } | 605 } |
| 601 | 606 |
| 602 // Tests that Synchronization can be "aborted" while there are pending tasks | 607 // Tests that Synchronization can be "aborted" while there are pending tasks |
| 603 // (i.e. the cookie store is unsynchronized while synchronization is in progress | 608 // (i.e. the cookie store is unsynchronized while synchronization is in progress |
| 604 // and there are pending tasks). | 609 // and there are pending tasks). |
| 605 TEST_F(CookieStoreIOSWithBackend, SyncThenUnsyncWithPendingTasks) { | 610 TEST_F(CookieStoreIOSWithBackend, SyncThenUnsyncWithPendingTasks) { |
| 606 ClearCookies(); | 611 ClearCookies(); |
| 607 std::unique_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr)); | 612 std::unique_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr)); |
| 608 // Start synchornization. | 613 // Start synchornization. |
| 609 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 614 store_->SetSynchronizedWithSystemStore(true); |
| 610 // Create a pending task while synchronization is in progress. | 615 // Create a pending task while synchronization is in progress. |
| 611 GetCookieCallback callback; | 616 GetCookieCallback callback; |
| 612 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); | 617 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); |
| 613 // Cancel the synchronization. | 618 // Cancel the synchronization. |
| 614 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get()); | 619 store_->SetSynchronizedWithSystemStore(false); |
| 620 dummy_store->SetSynchronizedWithSystemStore(true); |
| 615 // Synchronization completes after being cancelled. | 621 // Synchronization completes after being cancelled. |
| 616 backend_->RunLoadedCallback(); | 622 backend_->RunLoadedCallback(); |
| 617 // The task is not lost. | 623 // The task is not lost. |
| 618 EXPECT_TRUE(callback.did_run()); | 624 EXPECT_TRUE(callback.did_run()); |
| 619 EXPECT_EQ("a=b", callback.cookie_line()); | 625 EXPECT_EQ("a=b", callback.cookie_line()); |
| 620 dummy_store->UnSynchronize(); | 626 dummy_store->SetSynchronizedWithSystemStore(false); |
| 621 } | 627 } |
| 622 | 628 |
| 623 TEST_F(CookieStoreIOSWithBackend, UnSynchronizeBeforeLoadComplete) { | 629 TEST_F(CookieStoreIOSWithBackend, UnSynchronizeBeforeLoadComplete) { |
| 624 ClearCookies(); | 630 ClearCookies(); |
| 625 // Switch back and forth before synchronization can complete. | 631 // Switch back and forth before synchronization can complete. |
| 626 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 632 store_->SetSynchronizedWithSystemStore(true); |
| 627 store_->UnSynchronize(); | 633 store_->SetSynchronizedWithSystemStore(false); |
| 628 backend_->RunLoadedCallback(); | 634 backend_->RunLoadedCallback(); |
| 629 // No cookie lost. | 635 // No cookie lost. |
| 630 GetCookieCallback callback; | 636 GetCookieCallback callback; |
| 631 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); | 637 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); |
| 632 EXPECT_TRUE(callback.did_run()); | 638 EXPECT_TRUE(callback.did_run()); |
| 633 EXPECT_EQ("a=b", callback.cookie_line()); | 639 EXPECT_EQ("a=b", callback.cookie_line()); |
| 634 } | 640 } |
| 635 | 641 |
| 636 TEST_F(CookieStoreIOSWithBackend, UnSynchronize) { | 642 TEST_F(CookieStoreIOSWithBackend, UnSynchronize) { |
| 637 ClearCookies(); | 643 ClearCookies(); |
| 638 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 644 store_->SetSynchronizedWithSystemStore(true); |
| 639 backend_->RunLoadedCallback(); | 645 backend_->RunLoadedCallback(); |
| 640 store_->UnSynchronize(); | 646 store_->SetSynchronizedWithSystemStore(false); |
| 641 // No cookie lost. | 647 // No cookie lost. |
| 642 GetCookieCallback callback; | 648 GetCookieCallback callback; |
| 643 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); | 649 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); |
| 644 EXPECT_TRUE(callback.did_run()); | 650 EXPECT_TRUE(callback.did_run()); |
| 645 EXPECT_EQ("a=b", callback.cookie_line()); | 651 EXPECT_EQ("a=b", callback.cookie_line()); |
| 646 } | 652 } |
| 647 | 653 |
| 648 TEST_F(CookieStoreIOSWithBackend, FlushOnUnSynchronize) { | 654 TEST_F(CookieStoreIOSWithBackend, FlushOnUnSynchronize) { |
| 649 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 655 store_->SetSynchronizedWithSystemStore(true); |
| 650 EXPECT_FALSE(backend_->flushed()); | 656 EXPECT_FALSE(backend_->flushed()); |
| 651 store_->UnSynchronize(); | 657 store_->SetSynchronizedWithSystemStore(false); |
| 652 EXPECT_TRUE(backend_->flushed()); | 658 EXPECT_TRUE(backend_->flushed()); |
| 653 } | 659 } |
| 654 | 660 |
| 655 TEST_F(CookieStoreIOSWithBackend, FlushOnSwitch) { | |
| 656 std::unique_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr)); | |
| 657 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | |
| 658 EXPECT_FALSE(backend_->flushed()); | |
| 659 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get()); | |
| 660 EXPECT_TRUE(backend_->flushed()); | |
| 661 dummy_store->UnSynchronize(); | |
| 662 } | |
| 663 | |
| 664 TEST_F(CookieStoreIOSWithBackend, FlushOnCookieChanged) { | 661 TEST_F(CookieStoreIOSWithBackend, FlushOnCookieChanged) { |
| 665 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 662 store_->SetSynchronizedWithSystemStore(true); |
| 666 store_->set_flush_delay_for_testing(base::TimeDelta()); | 663 store_->set_flush_delay_for_testing(base::TimeDelta()); |
| 667 backend_->RunLoadedCallback(); | 664 backend_->RunLoadedCallback(); |
| 668 EXPECT_FALSE(backend_->flushed()); | 665 EXPECT_FALSE(backend_->flushed()); |
| 669 | 666 |
| 670 // Set a cookie an check that it triggers a flush. | 667 // Set a cookie an check that it triggers a flush. |
| 671 SetCookie("x=y"); | 668 SetCookie("x=y"); |
| 672 EXPECT_TRUE(backend_->flushed()); | 669 EXPECT_TRUE(backend_->flushed()); |
| 673 | 670 |
| 674 store_->UnSynchronize(); | 671 store_->SetSynchronizedWithSystemStore(false); |
| 675 } | 672 } |
| 676 | 673 |
| 677 TEST_F(CookieStoreIOSWithBackend, ManualFlush) { | 674 TEST_F(CookieStoreIOSWithBackend, ManualFlush) { |
| 678 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 675 store_->SetSynchronizedWithSystemStore(true); |
| 679 backend_->RunLoadedCallback(); | 676 backend_->RunLoadedCallback(); |
| 680 EXPECT_FALSE(backend_->flushed()); | 677 EXPECT_FALSE(backend_->flushed()); |
| 681 | 678 |
| 682 // The store should be flushed even if it is not dirty. | 679 // The store should be flushed even if it is not dirty. |
| 683 store_->FlushStore(base::Closure()); | 680 store_->FlushStore(base::Closure()); |
| 684 EXPECT_TRUE(backend_->flushed()); | 681 EXPECT_TRUE(backend_->flushed()); |
| 685 | 682 |
| 686 store_->UnSynchronize(); | 683 store_->SetSynchronizedWithSystemStore(false); |
| 687 } | 684 } |
| 688 | 685 |
| 689 TEST_F(CookieStoreIOSWithBackend, NoInitialNotifyWithNoCookie) { | 686 TEST_F(CookieStoreIOSWithBackend, NoInitialNotifyWithNoCookie) { |
| 690 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 687 store_->SetSynchronizedWithSystemStore(true); |
| 691 std::vector<net::CanonicalCookie> cookies; | 688 std::vector<net::CanonicalCookie> cookies; |
| 692 store_->AddCallbackForCookie( | 689 store_->AddCallbackForCookie( |
| 693 kTestCookieURL, "abc", | 690 kTestCookieURL, "abc", |
| 694 base::Bind(&RecordCookieChanges, &cookies, nullptr)); | 691 base::Bind(&RecordCookieChanges, &cookies, nullptr)); |
| 695 EXPECT_EQ(0U, cookies.size()); | 692 EXPECT_EQ(0U, cookies.size()); |
| 696 store_->UnSynchronize(); | 693 store_->SetSynchronizedWithSystemStore(false); |
| 697 } | 694 } |
| 698 | 695 |
| 699 TEST_F(CookieStoreIOSWithBackend, NoInitialNotifyWithSystemCookie) { | 696 TEST_F(CookieStoreIOSWithBackend, NoInitialNotifyWithSystemCookie) { |
| 700 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 697 store_->SetSynchronizedWithSystemStore(true); |
| 701 SetSystemCookie(kTestCookieURL, "abc", "def"); | 698 SetSystemCookie(kTestCookieURL, "abc", "def"); |
| 702 std::vector<net::CanonicalCookie> cookies; | 699 std::vector<net::CanonicalCookie> cookies; |
| 703 store_->AddCallbackForCookie( | 700 store_->AddCallbackForCookie( |
| 704 kTestCookieURL, "abc", | 701 kTestCookieURL, "abc", |
| 705 base::Bind(&RecordCookieChanges, &cookies, nullptr)); | 702 base::Bind(&RecordCookieChanges, &cookies, nullptr)); |
| 706 EXPECT_EQ(0U, cookies.size()); | 703 EXPECT_EQ(0U, cookies.size()); |
| 707 DeleteSystemCookie(kTestCookieURL, "abc"); | 704 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 708 store_->UnSynchronize(); | 705 store_->SetSynchronizedWithSystemStore(false); |
| 709 } | 706 } |
| 710 | 707 |
| 711 TEST_F(CookieStoreIOSWithBackend, NotifyOnAdd) { | 708 TEST_F(CookieStoreIOSWithBackend, NotifyOnAdd) { |
| 712 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 709 store_->SetSynchronizedWithSystemStore(true); |
| 713 backend_->RunLoadedCallback(); | 710 backend_->RunLoadedCallback(); |
| 714 std::vector<net::CanonicalCookie> cookies; | 711 std::vector<net::CanonicalCookie> cookies; |
| 715 std::vector<bool> removes; | 712 std::vector<bool> removes; |
| 716 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 713 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 717 store_->AddCallbackForCookie( | 714 store_->AddCallbackForCookie( |
| 718 kTestCookieURL, "abc", | 715 kTestCookieURL, "abc", |
| 719 base::Bind(&RecordCookieChanges, &cookies, &removes)); | 716 base::Bind(&RecordCookieChanges, &cookies, &removes)); |
| 720 EXPECT_EQ(0U, cookies.size()); | 717 EXPECT_EQ(0U, cookies.size()); |
| 721 EXPECT_EQ(0U, removes.size()); | 718 EXPECT_EQ(0U, removes.size()); |
| 722 SetSystemCookie(kTestCookieURL, "abc", "def"); | 719 SetSystemCookie(kTestCookieURL, "abc", "def"); |
| 723 EXPECT_EQ(1U, cookies.size()); | 720 EXPECT_EQ(1U, cookies.size()); |
| 724 EXPECT_EQ(1U, removes.size()); | 721 EXPECT_EQ(1U, removes.size()); |
| 725 EXPECT_EQ("abc", cookies[0].Name()); | 722 EXPECT_EQ("abc", cookies[0].Name()); |
| 726 EXPECT_EQ("def", cookies[0].Value()); | 723 EXPECT_EQ("def", cookies[0].Value()); |
| 727 EXPECT_FALSE(removes[0]); | 724 EXPECT_FALSE(removes[0]); |
| 728 | 725 |
| 729 SetSystemCookie(kTestCookieURL, "ghi", "jkl"); | 726 SetSystemCookie(kTestCookieURL, "ghi", "jkl"); |
| 730 EXPECT_EQ(1U, cookies.size()); | 727 EXPECT_EQ(1U, cookies.size()); |
| 731 EXPECT_EQ(1U, removes.size()); | 728 EXPECT_EQ(1U, removes.size()); |
| 732 | 729 |
| 733 DeleteSystemCookie(kTestCookieURL, "abc"); | 730 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 734 DeleteSystemCookie(kTestCookieURL, "ghi"); | 731 DeleteSystemCookie(kTestCookieURL, "ghi"); |
| 735 store_->UnSynchronize(); | 732 store_->SetSynchronizedWithSystemStore(false); |
| 736 } | 733 } |
| 737 | 734 |
| 738 TEST_F(CookieStoreIOSWithBackend, NotifyOnChange) { | 735 TEST_F(CookieStoreIOSWithBackend, NotifyOnChange) { |
| 739 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 736 store_->SetSynchronizedWithSystemStore(true); |
| 740 backend_->RunLoadedCallback(); | 737 backend_->RunLoadedCallback(); |
| 741 std::vector<net::CanonicalCookie> cookies; | 738 std::vector<net::CanonicalCookie> cookies; |
| 742 std::vector<bool> removes; | 739 std::vector<bool> removes; |
| 743 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 740 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 744 store_->AddCallbackForCookie( | 741 store_->AddCallbackForCookie( |
| 745 kTestCookieURL, "abc", | 742 kTestCookieURL, "abc", |
| 746 base::Bind(&RecordCookieChanges, &cookies, &removes)); | 743 base::Bind(&RecordCookieChanges, &cookies, &removes)); |
| 747 EXPECT_EQ(0U, cookies.size()); | 744 EXPECT_EQ(0U, cookies.size()); |
| 748 SetSystemCookie(kTestCookieURL, "abc", "def"); | 745 SetSystemCookie(kTestCookieURL, "abc", "def"); |
| 749 EXPECT_EQ(1U, cookies.size()); | 746 EXPECT_EQ(1U, cookies.size()); |
| 750 SetSystemCookie(kTestCookieURL, "abc", "ghi"); | 747 SetSystemCookie(kTestCookieURL, "abc", "ghi"); |
| 751 EXPECT_EQ(3U, cookies.size()); | 748 EXPECT_EQ(3U, cookies.size()); |
| 752 EXPECT_EQ(3U, removes.size()); | 749 EXPECT_EQ(3U, removes.size()); |
| 753 EXPECT_EQ("abc", cookies[1].Name()); | 750 EXPECT_EQ("abc", cookies[1].Name()); |
| 754 EXPECT_EQ("def", cookies[1].Value()); | 751 EXPECT_EQ("def", cookies[1].Value()); |
| 755 EXPECT_TRUE(removes[1]); | 752 EXPECT_TRUE(removes[1]); |
| 756 EXPECT_EQ("abc", cookies[2].Name()); | 753 EXPECT_EQ("abc", cookies[2].Name()); |
| 757 EXPECT_EQ("ghi", cookies[2].Value()); | 754 EXPECT_EQ("ghi", cookies[2].Value()); |
| 758 EXPECT_FALSE(removes[2]); | 755 EXPECT_FALSE(removes[2]); |
| 759 | 756 |
| 760 DeleteSystemCookie(kTestCookieURL, "abc"); | 757 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 761 store_->UnSynchronize(); | 758 store_->SetSynchronizedWithSystemStore(false); |
| 762 } | 759 } |
| 763 | 760 |
| 764 TEST_F(CookieStoreIOSWithBackend, NotifyOnDelete) { | 761 TEST_F(CookieStoreIOSWithBackend, NotifyOnDelete) { |
| 765 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 762 store_->SetSynchronizedWithSystemStore(true); |
| 766 backend_->RunLoadedCallback(); | 763 backend_->RunLoadedCallback(); |
| 767 std::vector<net::CanonicalCookie> cookies; | 764 std::vector<net::CanonicalCookie> cookies; |
| 768 std::vector<bool> removes; | 765 std::vector<bool> removes; |
| 769 SetSystemCookie(kTestCookieURL, "abc", "def"); | 766 SetSystemCookie(kTestCookieURL, "abc", "def"); |
| 770 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 767 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 771 store_->AddCallbackForCookie( | 768 store_->AddCallbackForCookie( |
| 772 kTestCookieURL, "abc", | 769 kTestCookieURL, "abc", |
| 773 base::Bind(&RecordCookieChanges, &cookies, &removes)); | 770 base::Bind(&RecordCookieChanges, &cookies, &removes)); |
| 774 EXPECT_EQ(0U, cookies.size()); | 771 EXPECT_EQ(0U, cookies.size()); |
| 775 DeleteSystemCookie(kTestCookieURL, "abc"); | 772 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 776 EXPECT_EQ(1U, cookies.size()); | 773 EXPECT_EQ(1U, cookies.size()); |
| 777 EXPECT_EQ(1U, removes.size()); | 774 EXPECT_EQ(1U, removes.size()); |
| 778 EXPECT_TRUE(removes[0]); | 775 EXPECT_TRUE(removes[0]); |
| 779 SetSystemCookie(kTestCookieURL, "abc", "def"); | 776 SetSystemCookie(kTestCookieURL, "abc", "def"); |
| 780 EXPECT_EQ(2U, cookies.size()); | 777 EXPECT_EQ(2U, cookies.size()); |
| 781 EXPECT_EQ(2U, removes.size()); | 778 EXPECT_EQ(2U, removes.size()); |
| 782 EXPECT_FALSE(removes[1]); | 779 EXPECT_FALSE(removes[1]); |
| 783 DeleteSystemCookie(kTestCookieURL, "abc"); | 780 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 784 store_->UnSynchronize(); | 781 store_->SetSynchronizedWithSystemStore(false); |
| 785 } | 782 } |
| 786 | 783 |
| 787 TEST_F(CookieStoreIOSWithBackend, NoNotifyOnNoChange) { | 784 TEST_F(CookieStoreIOSWithBackend, NoNotifyOnNoChange) { |
| 788 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 785 store_->SetSynchronizedWithSystemStore(true); |
| 789 backend_->RunLoadedCallback(); | 786 backend_->RunLoadedCallback(); |
| 790 std::vector<net::CanonicalCookie> cookies; | 787 std::vector<net::CanonicalCookie> cookies; |
| 791 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 788 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 792 store_->AddCallbackForCookie( | 789 store_->AddCallbackForCookie( |
| 793 kTestCookieURL, "abc", | 790 kTestCookieURL, "abc", |
| 794 base::Bind(&RecordCookieChanges, &cookies, nullptr)); | 791 base::Bind(&RecordCookieChanges, &cookies, nullptr)); |
| 795 EXPECT_EQ(0U, cookies.size()); | 792 EXPECT_EQ(0U, cookies.size()); |
| 796 SetSystemCookie(kTestCookieURL, "abc", "def"); | 793 SetSystemCookie(kTestCookieURL, "abc", "def"); |
| 797 EXPECT_EQ(1U, cookies.size()); | 794 EXPECT_EQ(1U, cookies.size()); |
| 798 SetSystemCookie(kTestCookieURL, "abc", "def"); | 795 SetSystemCookie(kTestCookieURL, "abc", "def"); |
| 799 EXPECT_EQ(1U, cookies.size()); | 796 EXPECT_EQ(1U, cookies.size()); |
| 800 DeleteSystemCookie(kTestCookieURL, "abc"); | 797 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 801 store_->UnSynchronize(); | 798 store_->SetSynchronizedWithSystemStore(false); |
| 802 } | 799 } |
| 803 | 800 |
| 804 TEST_F(CookieStoreIOSWithBackend, MultipleNotifies) { | 801 TEST_F(CookieStoreIOSWithBackend, MultipleNotifies) { |
| 805 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 802 store_->SetSynchronizedWithSystemStore(true); |
| 806 backend_->RunLoadedCallback(); | 803 backend_->RunLoadedCallback(); |
| 807 std::vector<net::CanonicalCookie> cookies; | 804 std::vector<net::CanonicalCookie> cookies; |
| 808 std::vector<net::CanonicalCookie> cookies2; | 805 std::vector<net::CanonicalCookie> cookies2; |
| 809 std::vector<net::CanonicalCookie> cookies3; | 806 std::vector<net::CanonicalCookie> cookies3; |
| 810 std::vector<net::CanonicalCookie> cookies4; | 807 std::vector<net::CanonicalCookie> cookies4; |
| 811 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 808 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 812 store_->AddCallbackForCookie( | 809 store_->AddCallbackForCookie( |
| 813 kTestCookieURL, "abc", | 810 kTestCookieURL, "abc", |
| 814 base::Bind(&RecordCookieChanges, &cookies, nullptr)); | 811 base::Bind(&RecordCookieChanges, &cookies, nullptr)); |
| 815 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle2 = | 812 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle2 = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 829 SetSystemCookie(kTestCookieURL3, "abc", "def"); | 826 SetSystemCookie(kTestCookieURL3, "abc", "def"); |
| 830 SetSystemCookie(kTestCookieURL4, "abc", "def"); | 827 SetSystemCookie(kTestCookieURL4, "abc", "def"); |
| 831 EXPECT_EQ(2U, cookies.size()); | 828 EXPECT_EQ(2U, cookies.size()); |
| 832 EXPECT_EQ(2U, cookies2.size()); | 829 EXPECT_EQ(2U, cookies2.size()); |
| 833 EXPECT_EQ(1U, cookies3.size()); | 830 EXPECT_EQ(1U, cookies3.size()); |
| 834 EXPECT_EQ(1U, cookies4.size()); | 831 EXPECT_EQ(1U, cookies4.size()); |
| 835 DeleteSystemCookie(kTestCookieURL, "abc"); | 832 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 836 DeleteSystemCookie(kTestCookieURL2, "abc"); | 833 DeleteSystemCookie(kTestCookieURL2, "abc"); |
| 837 DeleteSystemCookie(kTestCookieURL3, "abc"); | 834 DeleteSystemCookie(kTestCookieURL3, "abc"); |
| 838 DeleteSystemCookie(kTestCookieURL4, "abc"); | 835 DeleteSystemCookie(kTestCookieURL4, "abc"); |
| 839 store_->UnSynchronize(); | 836 store_->SetSynchronizedWithSystemStore(false); |
| 840 } | 837 } |
| 841 | 838 |
| 842 TEST_F(CookieStoreIOSWithBackend, LessSpecificNestedCookie) { | 839 TEST_F(CookieStoreIOSWithBackend, LessSpecificNestedCookie) { |
| 843 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 840 store_->SetSynchronizedWithSystemStore(true); |
| 844 backend_->RunLoadedCallback(); | 841 backend_->RunLoadedCallback(); |
| 845 std::vector<net::CanonicalCookie> cookies; | 842 std::vector<net::CanonicalCookie> cookies; |
| 846 SetSystemCookie(kTestCookieURL2, "abc", "def"); | 843 SetSystemCookie(kTestCookieURL2, "abc", "def"); |
| 847 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 844 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 848 store_->AddCallbackForCookie( | 845 store_->AddCallbackForCookie( |
| 849 kTestCookieURL2, "abc", | 846 kTestCookieURL2, "abc", |
| 850 base::Bind(&RecordCookieChanges, &cookies, nullptr)); | 847 base::Bind(&RecordCookieChanges, &cookies, nullptr)); |
| 851 EXPECT_EQ(0U, cookies.size()); | 848 EXPECT_EQ(0U, cookies.size()); |
| 852 SetSystemCookie(kTestCookieURL3, "abc", "ghi"); | 849 SetSystemCookie(kTestCookieURL3, "abc", "ghi"); |
| 853 EXPECT_EQ(1U, cookies.size()); | 850 EXPECT_EQ(1U, cookies.size()); |
| 854 DeleteSystemCookie(kTestCookieURL, "abc"); | 851 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 855 store_->UnSynchronize(); | 852 store_->SetSynchronizedWithSystemStore(false); |
| 856 } | 853 } |
| 857 | 854 |
| 858 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookie) { | 855 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookie) { |
| 859 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 856 store_->SetSynchronizedWithSystemStore(true); |
| 860 backend_->RunLoadedCallback(); | 857 backend_->RunLoadedCallback(); |
| 861 std::vector<net::CanonicalCookie> cookies; | 858 std::vector<net::CanonicalCookie> cookies; |
| 862 SetSystemCookie(kTestCookieURL3, "abc", "def"); | 859 SetSystemCookie(kTestCookieURL3, "abc", "def"); |
| 863 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 860 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 864 store_->AddCallbackForCookie( | 861 store_->AddCallbackForCookie( |
| 865 kTestCookieURL2, "abc", | 862 kTestCookieURL2, "abc", |
| 866 base::Bind(&RecordCookieChanges, &cookies, nullptr)); | 863 base::Bind(&RecordCookieChanges, &cookies, nullptr)); |
| 867 EXPECT_EQ(0U, cookies.size()); | 864 EXPECT_EQ(0U, cookies.size()); |
| 868 SetSystemCookie(kTestCookieURL2, "abc", "ghi"); | 865 SetSystemCookie(kTestCookieURL2, "abc", "ghi"); |
| 869 EXPECT_EQ(1U, cookies.size()); | 866 EXPECT_EQ(1U, cookies.size()); |
| 870 DeleteSystemCookie(kTestCookieURL, "abc"); | 867 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 871 store_->UnSynchronize(); | 868 store_->SetSynchronizedWithSystemStore(false); |
| 872 } | 869 } |
| 873 | 870 |
| 874 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookieWithSameValue) { | 871 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookieWithSameValue) { |
| 875 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 872 store_->SetSynchronizedWithSystemStore(true); |
| 876 backend_->RunLoadedCallback(); | 873 backend_->RunLoadedCallback(); |
| 877 std::vector<net::CanonicalCookie> cookies; | 874 std::vector<net::CanonicalCookie> cookies; |
| 878 SetSystemCookie(kTestCookieURL3, "abc", "def"); | 875 SetSystemCookie(kTestCookieURL3, "abc", "def"); |
| 879 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 876 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 880 store_->AddCallbackForCookie( | 877 store_->AddCallbackForCookie( |
| 881 kTestCookieURL2, "abc", | 878 kTestCookieURL2, "abc", |
| 882 base::Bind(&RecordCookieChanges, &cookies, nullptr)); | 879 base::Bind(&RecordCookieChanges, &cookies, nullptr)); |
| 883 EXPECT_EQ(0U, cookies.size()); | 880 EXPECT_EQ(0U, cookies.size()); |
| 884 SetSystemCookie(kTestCookieURL2, "abc", "def"); | 881 SetSystemCookie(kTestCookieURL2, "abc", "def"); |
| 885 EXPECT_EQ(1U, cookies.size()); | 882 EXPECT_EQ(1U, cookies.size()); |
| 886 DeleteSystemCookie(kTestCookieURL, "abc"); | 883 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 887 store_->UnSynchronize(); | 884 store_->SetSynchronizedWithSystemStore(false); |
| 888 } | 885 } |
| 889 | 886 |
| 890 TEST_F(CookieStoreIOSWithBackend, RemoveCallback) { | 887 TEST_F(CookieStoreIOSWithBackend, RemoveCallback) { |
| 891 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 888 store_->SetSynchronizedWithSystemStore(true); |
| 892 backend_->RunLoadedCallback(); | 889 backend_->RunLoadedCallback(); |
| 893 std::vector<net::CanonicalCookie> cookies; | 890 std::vector<net::CanonicalCookie> cookies; |
| 894 SetSystemCookie(kTestCookieURL, "abc", "def"); | 891 SetSystemCookie(kTestCookieURL, "abc", "def"); |
| 895 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = | 892 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle = |
| 896 store_->AddCallbackForCookie( | 893 store_->AddCallbackForCookie( |
| 897 kTestCookieURL, "abc", | 894 kTestCookieURL, "abc", |
| 898 base::Bind(&RecordCookieChanges, &cookies, nullptr)); | 895 base::Bind(&RecordCookieChanges, &cookies, nullptr)); |
| 899 EXPECT_EQ(0U, cookies.size()); | 896 EXPECT_EQ(0U, cookies.size()); |
| 900 SetSystemCookie(kTestCookieURL, "abc", "ghi"); | 897 SetSystemCookie(kTestCookieURL, "abc", "ghi"); |
| 901 EXPECT_EQ(2U, cookies.size()); | 898 EXPECT_EQ(2U, cookies.size()); |
| 902 // this deletes the callback | 899 // this deletes the callback |
| 903 handle.reset(); | 900 handle.reset(); |
| 904 SetSystemCookie(kTestCookieURL, "abc", "jkl"); | 901 SetSystemCookie(kTestCookieURL, "abc", "jkl"); |
| 905 EXPECT_EQ(2U, cookies.size()); | 902 EXPECT_EQ(2U, cookies.size()); |
| 906 DeleteSystemCookie(kTestCookieURL, "abc"); | 903 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 907 store_->UnSynchronize(); | 904 store_->SetSynchronizedWithSystemStore(false); |
| 908 } | 905 } |
| 909 | 906 |
| 910 } // namespace net | 907 } // namespace net |
| OLD | NEW |