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 "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 RoundTrip(); | 125 RoundTrip(); |
126 store_->DeleteAllCreatedBetweenForHostAsync(delete_begin, delete_end, url, | 126 store_->DeleteAllCreatedBetweenForHostAsync(delete_begin, delete_end, url, |
127 callback); | 127 callback); |
128 } | 128 } |
129 | 129 |
130 void DeleteSessionCookiesAsync(const DeleteCallback& callback) override { | 130 void DeleteSessionCookiesAsync(const DeleteCallback& callback) override { |
131 RoundTrip(); | 131 RoundTrip(); |
132 store_->DeleteSessionCookiesAsync(callback); | 132 store_->DeleteSessionCookiesAsync(callback); |
133 } | 133 } |
134 | 134 |
| 135 void FlushStore(const base::Closure& callback) override { |
| 136 RoundTrip(); |
| 137 store_->FlushStore(callback); |
| 138 } |
| 139 |
135 scoped_ptr<CookieStore::CookieChangedSubscription> AddCallbackForCookie( | 140 scoped_ptr<CookieStore::CookieChangedSubscription> AddCallbackForCookie( |
136 const GURL& url, | 141 const GURL& url, |
137 const std::string& name, | 142 const std::string& name, |
138 const CookieChangedCallback& callback) override { | 143 const CookieChangedCallback& callback) override { |
139 return scoped_ptr<CookieStore::CookieChangedSubscription>(); | 144 return scoped_ptr<CookieStore::CookieChangedSubscription>(); |
140 } | 145 } |
141 | 146 |
142 protected: | 147 protected: |
143 ~RoundTripTestCookieStore() override { store_->UnSynchronize(); } | 148 ~RoundTripTestCookieStore() override { store_->UnSynchronize(); } |
144 | 149 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 options.set_include_httponly(); | 505 options.set_include_httponly(); |
501 cookie_store->SetCookieWithOptionsAsync( | 506 cookie_store->SetCookieWithOptionsAsync( |
502 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); | 507 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); |
503 // Disallow cookies. | 508 // Disallow cookies. |
504 CookieStoreIOS::SetCookiePolicy(CookieStoreIOS::BLOCK); | 509 CookieStoreIOS::SetCookiePolicy(CookieStoreIOS::BLOCK); |
505 // No cookie in the system store. | 510 // No cookie in the system store. |
506 NSHTTPCookieStorage* system_store = | 511 NSHTTPCookieStorage* system_store = |
507 [NSHTTPCookieStorage sharedHTTPCookieStorage]; | 512 [NSHTTPCookieStorage sharedHTTPCookieStorage]; |
508 EXPECT_EQ(0u, [[system_store cookies] count]); | 513 EXPECT_EQ(0u, [[system_store cookies] count]); |
509 // Flushing should not have any effect. | 514 // Flushing should not have any effect. |
510 cookie_store->Flush(base::Closure()); | 515 cookie_store->FlushStore(base::Closure()); |
511 // Check we can get the cookie even though cookies are disabled. | 516 // Check we can get the cookie even though cookies are disabled. |
512 GetAllCookiesCallback callback; | 517 GetAllCookiesCallback callback; |
513 cookie_store->GetAllCookiesForURLAsync( | 518 cookie_store->GetAllCookiesForURLAsync( |
514 kTestCookieURL, | 519 kTestCookieURL, |
515 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback))); | 520 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback))); |
516 EXPECT_TRUE(callback.did_run()); | 521 EXPECT_TRUE(callback.did_run()); |
517 EXPECT_EQ(1u, callback.cookie_list().size()); | 522 EXPECT_EQ(1u, callback.cookie_list().size()); |
518 net::CanonicalCookie cookie = callback.cookie_list()[0]; | 523 net::CanonicalCookie cookie = callback.cookie_list()[0]; |
519 EXPECT_EQ("a", cookie.Name()); | 524 EXPECT_EQ("a", cookie.Name()); |
520 EXPECT_EQ("b", cookie.Value()); | 525 EXPECT_EQ("b", cookie.Value()); |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 | 715 |
711 store_->UnSynchronize(); | 716 store_->UnSynchronize(); |
712 } | 717 } |
713 | 718 |
714 TEST_F(CookieStoreIOSWithBackend, ManualFlush) { | 719 TEST_F(CookieStoreIOSWithBackend, ManualFlush) { |
715 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 720 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); |
716 backend_->RunLoadedCallback(); | 721 backend_->RunLoadedCallback(); |
717 EXPECT_FALSE(backend_->flushed()); | 722 EXPECT_FALSE(backend_->flushed()); |
718 | 723 |
719 // The store should be flushed even if it is not dirty. | 724 // The store should be flushed even if it is not dirty. |
720 store_->Flush(base::Closure()); | 725 store_->FlushStore(base::Closure()); |
721 EXPECT_TRUE(backend_->flushed()); | 726 EXPECT_TRUE(backend_->flushed()); |
722 | 727 |
723 store_->UnSynchronize(); | 728 store_->UnSynchronize(); |
724 } | 729 } |
725 | 730 |
726 TEST_F(CookieStoreIOSWithBackend, FlushOnPolicyChange) { | 731 TEST_F(CookieStoreIOSWithBackend, FlushOnPolicyChange) { |
727 // Start synchronization. | 732 // Start synchronization. |
728 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); | 733 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); |
729 // Toggle cookie policy to trigger a flush. | 734 // Toggle cookie policy to trigger a flush. |
730 EXPECT_FALSE(backend_->flushed()); | 735 EXPECT_FALSE(backend_->flushed()); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 EXPECT_EQ(2U, cookies.size()); | 954 EXPECT_EQ(2U, cookies.size()); |
950 // this deletes the callback | 955 // this deletes the callback |
951 handle.reset(); | 956 handle.reset(); |
952 SetSystemCookie(kTestCookieURL, "abc", "jkl"); | 957 SetSystemCookie(kTestCookieURL, "abc", "jkl"); |
953 EXPECT_EQ(2U, cookies.size()); | 958 EXPECT_EQ(2U, cookies.size()); |
954 DeleteSystemCookie(kTestCookieURL, "abc"); | 959 DeleteSystemCookie(kTestCookieURL, "abc"); |
955 store_->UnSynchronize(); | 960 store_->UnSynchronize(); |
956 } | 961 } |
957 | 962 |
958 } // namespace net | 963 } // namespace net |
OLD | NEW |