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

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

Issue 1861593005: Convert //ios from scoped_ptr to std::unique_ptr. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase? Created 4 years, 8 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 | « ios/net/cookies/cookie_store_ios.mm ('k') | ios/net/crn_http_protocol_handler.mm » ('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 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>
10
9 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/memory/ptr_util.h"
10 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
13 #include "base/strings/sys_string_conversions.h" 15 #include "base/strings/sys_string_conversions.h"
14 #import "net/base/mac/url_conversions.h" 16 #import "net/base/mac/url_conversions.h"
15 #include "net/cookies/cookie_store_unittest.h" 17 #include "net/cookies/cookie_store_unittest.h"
16 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
17 19
18 namespace { 20 namespace {
19 // Clears the underlying NSHTTPCookieStorage. 21 // Clears the underlying NSHTTPCookieStorage.
20 void ClearCookies() { 22 void ClearCookies() {
21 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 23 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage];
22 [store setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; 24 [store setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
23 NSArray* cookies = [store cookies]; 25 NSArray* cookies = [store cookies];
24 for (NSHTTPCookie* cookie in cookies) 26 for (NSHTTPCookie* cookie in cookies)
25 [store deleteCookie:cookie]; 27 [store deleteCookie:cookie];
26 EXPECT_EQ(0u, [[store cookies] count]); 28 EXPECT_EQ(0u, [[store cookies] count]);
27 } 29 }
28 } // namespace 30 } // namespace
29 31
30 namespace net { 32 namespace net {
31 33
32 struct CookieStoreIOSTestTraits { 34 struct CookieStoreIOSTestTraits {
33 static scoped_ptr<net::CookieStore> Create() { 35 static std::unique_ptr<net::CookieStore> Create() {
34 ClearCookies(); 36 ClearCookies();
35 scoped_ptr<CookieStoreIOS> store(new CookieStoreIOS(nullptr)); 37 std::unique_ptr<CookieStoreIOS> store(new CookieStoreIOS(nullptr));
36 store->synchronization_state_ = CookieStoreIOS::SYNCHRONIZED; 38 store->synchronization_state_ = CookieStoreIOS::SYNCHRONIZED;
37 return std::move(store); 39 return std::move(store);
38 } 40 }
39 41
40 static const bool supports_http_only = false; 42 static const bool supports_http_only = false;
41 static const bool supports_non_dotted_domains = false; 43 static const bool supports_non_dotted_domains = false;
42 static const bool preserves_trailing_dots = false; 44 static const bool preserves_trailing_dots = false;
43 static const bool filters_schemes = false; 45 static const bool filters_schemes = false;
44 static const bool has_path_prefix_bug = true; 46 static const bool has_path_prefix_bug = true;
45 static const int creation_time_granularity_in_ms = 1000; 47 static const int creation_time_granularity_in_ms = 1000;
46 static const bool enforce_strict_secure = false; 48 static const bool enforce_strict_secure = false;
47 49
48 base::MessageLoop loop_; 50 base::MessageLoop loop_;
49 }; 51 };
50 52
51 struct InactiveCookieStoreIOSTestTraits { 53 struct InactiveCookieStoreIOSTestTraits {
52 static scoped_ptr<net::CookieStore> Create() { 54 static std::unique_ptr<net::CookieStore> Create() {
53 return make_scoped_ptr(new CookieStoreIOS(nullptr)); 55 return base::WrapUnique(new CookieStoreIOS(nullptr));
54 } 56 }
55 57
56 static const bool is_cookie_monster = false; 58 static const bool is_cookie_monster = false;
57 static const bool supports_http_only = false; 59 static const bool supports_http_only = false;
58 static const bool supports_non_dotted_domains = true; 60 static const bool supports_non_dotted_domains = true;
59 static const bool preserves_trailing_dots = true; 61 static const bool preserves_trailing_dots = true;
60 static const bool filters_schemes = false; 62 static const bool filters_schemes = false;
61 static const bool has_path_prefix_bug = false; 63 static const bool has_path_prefix_bug = false;
62 static const int creation_time_granularity_in_ms = 0; 64 static const int creation_time_granularity_in_ms = 0;
63 static const int enforces_prefixes = true; 65 static const int enforces_prefixes = true;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 void DeleteSessionCookiesAsync(const DeleteCallback& callback) override { 167 void DeleteSessionCookiesAsync(const DeleteCallback& callback) override {
166 RoundTrip(); 168 RoundTrip();
167 store_->DeleteSessionCookiesAsync(callback); 169 store_->DeleteSessionCookiesAsync(callback);
168 } 170 }
169 171
170 void FlushStore(const base::Closure& callback) override { 172 void FlushStore(const base::Closure& callback) override {
171 RoundTrip(); 173 RoundTrip();
172 store_->FlushStore(callback); 174 store_->FlushStore(callback);
173 } 175 }
174 176
175 scoped_ptr<CookieStore::CookieChangedSubscription> AddCallbackForCookie( 177 std::unique_ptr<CookieStore::CookieChangedSubscription> AddCallbackForCookie(
176 const GURL& url, 178 const GURL& url,
177 const std::string& name, 179 const std::string& name,
178 const CookieChangedCallback& callback) override { 180 const CookieChangedCallback& callback) override {
179 return scoped_ptr<CookieStore::CookieChangedSubscription>(); 181 return std::unique_ptr<CookieStore::CookieChangedSubscription>();
180 } 182 }
181 183
182 bool IsEphemeral() override { 184 bool IsEphemeral() override {
183 return store_->IsEphemeral(); 185 return store_->IsEphemeral();
184 } 186 }
185 187
186 private: 188 private:
187 void RoundTrip() { 189 void RoundTrip() {
188 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store_.get()); 190 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store_.get());
189 // Check that the system store is empty, because it is synchronized with 191 // Check that the system store is empty, because it is synchronized with
190 // |dummy_store_| which is empty. 192 // |dummy_store_| which is empty.
191 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 193 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage];
192 EXPECT_EQ(0u, [[store cookies] count]); 194 EXPECT_EQ(0u, [[store cookies] count]);
193 CookieStoreIOS::SwitchSynchronizedStore(dummy_store_.get(), store_.get()); 195 CookieStoreIOS::SwitchSynchronizedStore(dummy_store_.get(), store_.get());
194 } 196 }
195 197
196 scoped_ptr<CookieStoreIOS> store_; 198 std::unique_ptr<CookieStoreIOS> store_;
197 // |dummy_store_| is not directly used, but is needed to make |store_| 199 // |dummy_store_| is not directly used, but is needed to make |store_|
198 // inactive. 200 // inactive.
199 scoped_ptr<CookieStoreIOS> dummy_store_; 201 std::unique_ptr<CookieStoreIOS> dummy_store_;
200 }; 202 };
201 203
202 struct RoundTripTestCookieStoreTraits { 204 struct RoundTripTestCookieStoreTraits {
203 static scoped_ptr<net::CookieStore> Create() { 205 static std::unique_ptr<net::CookieStore> Create() {
204 ClearCookies(); 206 ClearCookies();
205 return make_scoped_ptr(new RoundTripTestCookieStore()); 207 return base::WrapUnique(new RoundTripTestCookieStore());
206 } 208 }
207 209
208 static const bool is_cookie_monster = false; 210 static const bool is_cookie_monster = false;
209 static const bool supports_http_only = false; 211 static const bool supports_http_only = false;
210 static const bool supports_non_dotted_domains = false; 212 static const bool supports_non_dotted_domains = false;
211 static const bool preserves_trailing_dots = false; 213 static const bool preserves_trailing_dots = false;
212 static const bool filters_schemes = false; 214 static const bool filters_schemes = false;
213 static const bool has_path_prefix_bug = true; 215 static const bool has_path_prefix_bug = true;
214 static const int creation_time_granularity_in_ms = 1000; 216 static const int creation_time_granularity_in_ms = 1000;
215 static const int enforces_prefixes = true; 217 static const int enforces_prefixes = true;
(...skipping 27 matching lines...) Expand all
243 public: 245 public:
244 TestPersistentCookieStore() 246 TestPersistentCookieStore()
245 : kTestCookieURL("http://foo.google.com/bar"), flushed_(false) {} 247 : kTestCookieURL("http://foo.google.com/bar"), flushed_(false) {}
246 248
247 // Runs the completion callback with a "a=b" cookie. 249 // Runs the completion callback with a "a=b" cookie.
248 void RunLoadedCallback() { 250 void RunLoadedCallback() {
249 std::vector<net::CanonicalCookie*> cookies; 251 std::vector<net::CanonicalCookie*> cookies;
250 net::CookieOptions options; 252 net::CookieOptions options;
251 options.set_include_httponly(); 253 options.set_include_httponly();
252 254
253 scoped_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( 255 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create(
254 kTestCookieURL, "a=b", base::Time::Now(), options)); 256 kTestCookieURL, "a=b", base::Time::Now(), options));
255 cookies.push_back(cookie.release()); 257 cookies.push_back(cookie.release());
256 258
257 // Some canonical cookies cannot be converted into System cookies, for 259 // Some canonical cookies cannot be converted into System cookies, for
258 // example if value is not valid utf8. Such cookies are ignored. 260 // example if value is not valid utf8. Such cookies are ignored.
259 net::CanonicalCookie* bad_canonical_cookie = new net::CanonicalCookie( 261 net::CanonicalCookie* bad_canonical_cookie = new net::CanonicalCookie(
260 kTestCookieURL, "name", "\x81r\xe4\xbd\xa0\xe5\xa5\xbd", "domain", 262 kTestCookieURL, "name", "\x81r\xe4\xbd\xa0\xe5\xa5\xbd", "domain",
261 "path/", 263 "path/",
262 base::Time(), // creation 264 base::Time(), // creation
263 base::Time(), // expires 265 base::Time(), // expires
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } 428 }
427 429
428 protected: 430 protected:
429 const GURL kTestCookieURL; 431 const GURL kTestCookieURL;
430 const GURL kTestCookieURL2; 432 const GURL kTestCookieURL2;
431 const GURL kTestCookieURL3; 433 const GURL kTestCookieURL3;
432 const GURL kTestCookieURL4; 434 const GURL kTestCookieURL4;
433 435
434 base::MessageLoop loop_; 436 base::MessageLoop loop_;
435 scoped_refptr<TestPersistentCookieStore> backend_; 437 scoped_refptr<TestPersistentCookieStore> backend_;
436 scoped_ptr<net::CookieStoreIOS> store_; 438 std::unique_ptr<net::CookieStoreIOS> store_;
437 scoped_ptr<net::CookieStore::CookieChangedSubscription> 439 std::unique_ptr<net::CookieStore::CookieChangedSubscription>
438 cookie_changed_callback_; 440 cookie_changed_callback_;
439 std::vector<net::CanonicalCookie> cookies_changed_; 441 std::vector<net::CanonicalCookie> cookies_changed_;
440 std::vector<bool> cookies_removed_; 442 std::vector<bool> cookies_removed_;
441 }; 443 };
442 444
443 } // namespace 445 } // namespace
444 446
445 namespace net { 447 namespace net {
446 448
447 TEST_F(CookieStoreIOSWithBackend, SetCookieCallsHookWhenNotSynchronized) { 449 TEST_F(CookieStoreIOSWithBackend, SetCookieCallsHookWhenNotSynchronized) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 EXPECT_EQ(1U, cookies_changed_.size()); 528 EXPECT_EQ(1U, cookies_changed_.size());
527 SetCookie("abc=def"); 529 SetCookie("abc=def");
528 EXPECT_EQ(1U, cookies_changed_.size()); 530 EXPECT_EQ(1U, cookies_changed_.size());
529 store_->UnSynchronize(); 531 store_->UnSynchronize();
530 } 532 }
531 533
532 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) { 534 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) {
533 base::MessageLoop loop; 535 base::MessageLoop loop;
534 const GURL kTestCookieURL("http://foo.google.com/bar"); 536 const GURL kTestCookieURL("http://foo.google.com/bar");
535 ClearCookies(); 537 ClearCookies();
536 scoped_ptr<CookieStoreIOS> cookie_store(new CookieStoreIOS(nullptr)); 538 std::unique_ptr<CookieStoreIOS> cookie_store(new CookieStoreIOS(nullptr));
537 CookieStoreIOS::SwitchSynchronizedStore(nullptr, cookie_store.get()); 539 CookieStoreIOS::SwitchSynchronizedStore(nullptr, cookie_store.get());
538 // Add a cookie. 540 // Add a cookie.
539 net::CookieOptions options; 541 net::CookieOptions options;
540 options.set_include_httponly(); 542 options.set_include_httponly();
541 cookie_store->SetCookieWithOptionsAsync( 543 cookie_store->SetCookieWithOptionsAsync(
542 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); 544 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback());
543 // Disallow cookies. 545 // Disallow cookies.
544 CookieStoreIOS::SetCookiePolicy(CookieStoreIOS::BLOCK); 546 CookieStoreIOS::SetCookiePolicy(CookieStoreIOS::BLOCK);
545 // No cookie in the system store. 547 // No cookie in the system store.
546 NSHTTPCookieStorage* system_store = 548 NSHTTPCookieStorage* system_store =
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 backend_->RunLoadedCallback(); 606 backend_->RunLoadedCallback();
605 EXPECT_TRUE(callback.did_run()); 607 EXPECT_TRUE(callback.did_run());
606 EXPECT_EQ("a=b", callback.cookie_line()); 608 EXPECT_EQ("a=b", callback.cookie_line());
607 store_->UnSynchronize(); 609 store_->UnSynchronize();
608 } 610 }
609 611
610 // Tests that Synchronization can be "aborted" (i.e. the cookie store is 612 // Tests that Synchronization can be "aborted" (i.e. the cookie store is
611 // unsynchronized while synchronization is in progress). 613 // unsynchronized while synchronization is in progress).
612 TEST_F(CookieStoreIOSWithBackend, SyncThenUnsync) { 614 TEST_F(CookieStoreIOSWithBackend, SyncThenUnsync) {
613 ClearCookies(); 615 ClearCookies();
614 scoped_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr)); 616 std::unique_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr));
615 // Switch back and forth before synchronization can complete. 617 // Switch back and forth before synchronization can complete.
616 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 618 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
617 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get()); 619 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get());
618 backend_->RunLoadedCallback(); 620 backend_->RunLoadedCallback();
619 // No cookie leak in the system store. 621 // No cookie leak in the system store.
620 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 622 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage];
621 EXPECT_EQ(0u, [[store cookies] count]); 623 EXPECT_EQ(0u, [[store cookies] count]);
622 // No cookie lost. 624 // No cookie lost.
623 GetCookieCallback callback; 625 GetCookieCallback callback;
624 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); 626 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback)));
625 EXPECT_TRUE(callback.did_run()); 627 EXPECT_TRUE(callback.did_run());
626 EXPECT_EQ("a=b", callback.cookie_line()); 628 EXPECT_EQ("a=b", callback.cookie_line());
627 dummy_store->UnSynchronize(); 629 dummy_store->UnSynchronize();
628 } 630 }
629 631
630 // Tests that Synchronization can be "aborted" while there are pending tasks 632 // Tests that Synchronization can be "aborted" while there are pending tasks
631 // (i.e. the cookie store is unsynchronized while synchronization is in progress 633 // (i.e. the cookie store is unsynchronized while synchronization is in progress
632 // and there are pending tasks). 634 // and there are pending tasks).
633 TEST_F(CookieStoreIOSWithBackend, SyncThenUnsyncWithPendingTasks) { 635 TEST_F(CookieStoreIOSWithBackend, SyncThenUnsyncWithPendingTasks) {
634 ClearCookies(); 636 ClearCookies();
635 scoped_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr)); 637 std::unique_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr));
636 // Start synchornization. 638 // Start synchornization.
637 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 639 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
638 // Create a pending task while synchronization is in progress. 640 // Create a pending task while synchronization is in progress.
639 GetCookieCallback callback; 641 GetCookieCallback callback;
640 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); 642 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback)));
641 // Cancel the synchronization. 643 // Cancel the synchronization.
642 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get()); 644 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get());
643 // Synchronization completes after being cancelled. 645 // Synchronization completes after being cancelled.
644 backend_->RunLoadedCallback(); 646 backend_->RunLoadedCallback();
645 // The task is not lost. 647 // The task is not lost.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 } 725 }
724 726
725 TEST_F(CookieStoreIOSWithBackend, FlushOnUnSynchronize) { 727 TEST_F(CookieStoreIOSWithBackend, FlushOnUnSynchronize) {
726 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 728 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
727 EXPECT_FALSE(backend_->flushed()); 729 EXPECT_FALSE(backend_->flushed());
728 store_->UnSynchronize(); 730 store_->UnSynchronize();
729 EXPECT_TRUE(backend_->flushed()); 731 EXPECT_TRUE(backend_->flushed());
730 } 732 }
731 733
732 TEST_F(CookieStoreIOSWithBackend, FlushOnSwitch) { 734 TEST_F(CookieStoreIOSWithBackend, FlushOnSwitch) {
733 scoped_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr)); 735 std::unique_ptr<CookieStoreIOS> dummy_store(new CookieStoreIOS(nullptr));
734 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 736 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
735 EXPECT_FALSE(backend_->flushed()); 737 EXPECT_FALSE(backend_->flushed());
736 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get()); 738 CookieStoreIOS::SwitchSynchronizedStore(store_.get(), dummy_store.get());
737 EXPECT_TRUE(backend_->flushed()); 739 EXPECT_TRUE(backend_->flushed());
738 dummy_store->UnSynchronize(); 740 dummy_store->UnSynchronize();
739 } 741 }
740 742
741 TEST_F(CookieStoreIOSWithBackend, FlushOnCookieChanged) { 743 TEST_F(CookieStoreIOSWithBackend, FlushOnCookieChanged) {
742 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 744 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
743 store_->set_flush_delay_for_testing(base::TimeDelta()); 745 store_->set_flush_delay_for_testing(base::TimeDelta());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 EXPECT_EQ(0U, cookies.size()); 796 EXPECT_EQ(0U, cookies.size());
795 DeleteSystemCookie(kTestCookieURL, "abc"); 797 DeleteSystemCookie(kTestCookieURL, "abc");
796 store_->UnSynchronize(); 798 store_->UnSynchronize();
797 } 799 }
798 800
799 TEST_F(CookieStoreIOSWithBackend, NotifyOnAdd) { 801 TEST_F(CookieStoreIOSWithBackend, NotifyOnAdd) {
800 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 802 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
801 backend_->RunLoadedCallback(); 803 backend_->RunLoadedCallback();
802 std::vector<net::CanonicalCookie> cookies; 804 std::vector<net::CanonicalCookie> cookies;
803 std::vector<bool> removes; 805 std::vector<bool> removes;
804 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 806 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
805 store_->AddCallbackForCookie( 807 store_->AddCallbackForCookie(
806 kTestCookieURL, "abc", 808 kTestCookieURL, "abc",
807 base::Bind(&RecordCookieChanges, &cookies, &removes)); 809 base::Bind(&RecordCookieChanges, &cookies, &removes));
808 EXPECT_EQ(0U, cookies.size()); 810 EXPECT_EQ(0U, cookies.size());
809 EXPECT_EQ(0U, removes.size()); 811 EXPECT_EQ(0U, removes.size());
810 SetSystemCookie(kTestCookieURL, "abc", "def"); 812 SetSystemCookie(kTestCookieURL, "abc", "def");
811 EXPECT_EQ(1U, cookies.size()); 813 EXPECT_EQ(1U, cookies.size());
812 EXPECT_EQ(1U, removes.size()); 814 EXPECT_EQ(1U, removes.size());
813 EXPECT_EQ("abc", cookies[0].Name()); 815 EXPECT_EQ("abc", cookies[0].Name());
814 EXPECT_EQ("def", cookies[0].Value()); 816 EXPECT_EQ("def", cookies[0].Value());
815 EXPECT_FALSE(removes[0]); 817 EXPECT_FALSE(removes[0]);
816 818
817 SetSystemCookie(kTestCookieURL, "ghi", "jkl"); 819 SetSystemCookie(kTestCookieURL, "ghi", "jkl");
818 EXPECT_EQ(1U, cookies.size()); 820 EXPECT_EQ(1U, cookies.size());
819 EXPECT_EQ(1U, removes.size()); 821 EXPECT_EQ(1U, removes.size());
820 822
821 DeleteSystemCookie(kTestCookieURL, "abc"); 823 DeleteSystemCookie(kTestCookieURL, "abc");
822 DeleteSystemCookie(kTestCookieURL, "ghi"); 824 DeleteSystemCookie(kTestCookieURL, "ghi");
823 store_->UnSynchronize(); 825 store_->UnSynchronize();
824 } 826 }
825 827
826 TEST_F(CookieStoreIOSWithBackend, NotifyOnChange) { 828 TEST_F(CookieStoreIOSWithBackend, NotifyOnChange) {
827 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 829 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
828 backend_->RunLoadedCallback(); 830 backend_->RunLoadedCallback();
829 std::vector<net::CanonicalCookie> cookies; 831 std::vector<net::CanonicalCookie> cookies;
830 std::vector<bool> removes; 832 std::vector<bool> removes;
831 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 833 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
832 store_->AddCallbackForCookie( 834 store_->AddCallbackForCookie(
833 kTestCookieURL, "abc", 835 kTestCookieURL, "abc",
834 base::Bind(&RecordCookieChanges, &cookies, &removes)); 836 base::Bind(&RecordCookieChanges, &cookies, &removes));
835 EXPECT_EQ(0U, cookies.size()); 837 EXPECT_EQ(0U, cookies.size());
836 SetSystemCookie(kTestCookieURL, "abc", "def"); 838 SetSystemCookie(kTestCookieURL, "abc", "def");
837 EXPECT_EQ(1U, cookies.size()); 839 EXPECT_EQ(1U, cookies.size());
838 SetSystemCookie(kTestCookieURL, "abc", "ghi"); 840 SetSystemCookie(kTestCookieURL, "abc", "ghi");
839 EXPECT_EQ(3U, cookies.size()); 841 EXPECT_EQ(3U, cookies.size());
840 EXPECT_EQ(3U, removes.size()); 842 EXPECT_EQ(3U, removes.size());
841 EXPECT_EQ("abc", cookies[1].Name()); 843 EXPECT_EQ("abc", cookies[1].Name());
842 EXPECT_EQ("def", cookies[1].Value()); 844 EXPECT_EQ("def", cookies[1].Value());
843 EXPECT_TRUE(removes[1]); 845 EXPECT_TRUE(removes[1]);
844 EXPECT_EQ("abc", cookies[2].Name()); 846 EXPECT_EQ("abc", cookies[2].Name());
845 EXPECT_EQ("ghi", cookies[2].Value()); 847 EXPECT_EQ("ghi", cookies[2].Value());
846 EXPECT_FALSE(removes[2]); 848 EXPECT_FALSE(removes[2]);
847 849
848 DeleteSystemCookie(kTestCookieURL, "abc"); 850 DeleteSystemCookie(kTestCookieURL, "abc");
849 store_->UnSynchronize(); 851 store_->UnSynchronize();
850 } 852 }
851 853
852 TEST_F(CookieStoreIOSWithBackend, NotifyOnDelete) { 854 TEST_F(CookieStoreIOSWithBackend, NotifyOnDelete) {
853 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 855 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
854 backend_->RunLoadedCallback(); 856 backend_->RunLoadedCallback();
855 std::vector<net::CanonicalCookie> cookies; 857 std::vector<net::CanonicalCookie> cookies;
856 std::vector<bool> removes; 858 std::vector<bool> removes;
857 SetSystemCookie(kTestCookieURL, "abc", "def"); 859 SetSystemCookie(kTestCookieURL, "abc", "def");
858 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 860 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
859 store_->AddCallbackForCookie( 861 store_->AddCallbackForCookie(
860 kTestCookieURL, "abc", 862 kTestCookieURL, "abc",
861 base::Bind(&RecordCookieChanges, &cookies, &removes)); 863 base::Bind(&RecordCookieChanges, &cookies, &removes));
862 EXPECT_EQ(0U, cookies.size()); 864 EXPECT_EQ(0U, cookies.size());
863 DeleteSystemCookie(kTestCookieURL, "abc"); 865 DeleteSystemCookie(kTestCookieURL, "abc");
864 EXPECT_EQ(1U, cookies.size()); 866 EXPECT_EQ(1U, cookies.size());
865 EXPECT_EQ(1U, removes.size()); 867 EXPECT_EQ(1U, removes.size());
866 EXPECT_TRUE(removes[0]); 868 EXPECT_TRUE(removes[0]);
867 SetSystemCookie(kTestCookieURL, "abc", "def"); 869 SetSystemCookie(kTestCookieURL, "abc", "def");
868 EXPECT_EQ(2U, cookies.size()); 870 EXPECT_EQ(2U, cookies.size());
869 EXPECT_EQ(2U, removes.size()); 871 EXPECT_EQ(2U, removes.size());
870 EXPECT_FALSE(removes[1]); 872 EXPECT_FALSE(removes[1]);
871 DeleteSystemCookie(kTestCookieURL, "abc"); 873 DeleteSystemCookie(kTestCookieURL, "abc");
872 store_->UnSynchronize(); 874 store_->UnSynchronize();
873 } 875 }
874 876
875 TEST_F(CookieStoreIOSWithBackend, NoNotifyOnNoChange) { 877 TEST_F(CookieStoreIOSWithBackend, NoNotifyOnNoChange) {
876 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 878 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
877 backend_->RunLoadedCallback(); 879 backend_->RunLoadedCallback();
878 std::vector<net::CanonicalCookie> cookies; 880 std::vector<net::CanonicalCookie> cookies;
879 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 881 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
880 store_->AddCallbackForCookie( 882 store_->AddCallbackForCookie(
881 kTestCookieURL, "abc", 883 kTestCookieURL, "abc",
882 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 884 base::Bind(&RecordCookieChanges, &cookies, nullptr));
883 EXPECT_EQ(0U, cookies.size()); 885 EXPECT_EQ(0U, cookies.size());
884 SetSystemCookie(kTestCookieURL, "abc", "def"); 886 SetSystemCookie(kTestCookieURL, "abc", "def");
885 EXPECT_EQ(1U, cookies.size()); 887 EXPECT_EQ(1U, cookies.size());
886 SetSystemCookie(kTestCookieURL, "abc", "def"); 888 SetSystemCookie(kTestCookieURL, "abc", "def");
887 EXPECT_EQ(1U, cookies.size()); 889 EXPECT_EQ(1U, cookies.size());
888 DeleteSystemCookie(kTestCookieURL, "abc"); 890 DeleteSystemCookie(kTestCookieURL, "abc");
889 store_->UnSynchronize(); 891 store_->UnSynchronize();
890 } 892 }
891 893
892 TEST_F(CookieStoreIOSWithBackend, MultipleNotifies) { 894 TEST_F(CookieStoreIOSWithBackend, MultipleNotifies) {
893 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 895 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
894 backend_->RunLoadedCallback(); 896 backend_->RunLoadedCallback();
895 std::vector<net::CanonicalCookie> cookies; 897 std::vector<net::CanonicalCookie> cookies;
896 std::vector<net::CanonicalCookie> cookies2; 898 std::vector<net::CanonicalCookie> cookies2;
897 std::vector<net::CanonicalCookie> cookies3; 899 std::vector<net::CanonicalCookie> cookies3;
898 std::vector<net::CanonicalCookie> cookies4; 900 std::vector<net::CanonicalCookie> cookies4;
899 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 901 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
900 store_->AddCallbackForCookie( 902 store_->AddCallbackForCookie(
901 kTestCookieURL, "abc", 903 kTestCookieURL, "abc",
902 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 904 base::Bind(&RecordCookieChanges, &cookies, nullptr));
903 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle2 = 905 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle2 =
904 store_->AddCallbackForCookie( 906 store_->AddCallbackForCookie(
905 kTestCookieURL2, "abc", 907 kTestCookieURL2, "abc",
906 base::Bind(&RecordCookieChanges, &cookies2, nullptr)); 908 base::Bind(&RecordCookieChanges, &cookies2, nullptr));
907 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle3 = 909 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle3 =
908 store_->AddCallbackForCookie( 910 store_->AddCallbackForCookie(
909 kTestCookieURL3, "abc", 911 kTestCookieURL3, "abc",
910 base::Bind(&RecordCookieChanges, &cookies3, nullptr)); 912 base::Bind(&RecordCookieChanges, &cookies3, nullptr));
911 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle4 = 913 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle4 =
912 store_->AddCallbackForCookie( 914 store_->AddCallbackForCookie(
913 kTestCookieURL4, "abc", 915 kTestCookieURL4, "abc",
914 base::Bind(&RecordCookieChanges, &cookies4, nullptr)); 916 base::Bind(&RecordCookieChanges, &cookies4, nullptr));
915 SetSystemCookie(kTestCookieURL, "abc", "def"); 917 SetSystemCookie(kTestCookieURL, "abc", "def");
916 SetSystemCookie(kTestCookieURL2, "abc", "def"); 918 SetSystemCookie(kTestCookieURL2, "abc", "def");
917 SetSystemCookie(kTestCookieURL3, "abc", "def"); 919 SetSystemCookie(kTestCookieURL3, "abc", "def");
918 SetSystemCookie(kTestCookieURL4, "abc", "def"); 920 SetSystemCookie(kTestCookieURL4, "abc", "def");
919 EXPECT_EQ(2U, cookies.size()); 921 EXPECT_EQ(2U, cookies.size());
920 EXPECT_EQ(2U, cookies2.size()); 922 EXPECT_EQ(2U, cookies2.size());
921 EXPECT_EQ(1U, cookies3.size()); 923 EXPECT_EQ(1U, cookies3.size());
922 EXPECT_EQ(1U, cookies4.size()); 924 EXPECT_EQ(1U, cookies4.size());
923 DeleteSystemCookie(kTestCookieURL, "abc"); 925 DeleteSystemCookie(kTestCookieURL, "abc");
924 DeleteSystemCookie(kTestCookieURL2, "abc"); 926 DeleteSystemCookie(kTestCookieURL2, "abc");
925 DeleteSystemCookie(kTestCookieURL3, "abc"); 927 DeleteSystemCookie(kTestCookieURL3, "abc");
926 DeleteSystemCookie(kTestCookieURL4, "abc"); 928 DeleteSystemCookie(kTestCookieURL4, "abc");
927 store_->UnSynchronize(); 929 store_->UnSynchronize();
928 } 930 }
929 931
930 TEST_F(CookieStoreIOSWithBackend, LessSpecificNestedCookie) { 932 TEST_F(CookieStoreIOSWithBackend, LessSpecificNestedCookie) {
931 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 933 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
932 backend_->RunLoadedCallback(); 934 backend_->RunLoadedCallback();
933 std::vector<net::CanonicalCookie> cookies; 935 std::vector<net::CanonicalCookie> cookies;
934 SetSystemCookie(kTestCookieURL2, "abc", "def"); 936 SetSystemCookie(kTestCookieURL2, "abc", "def");
935 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 937 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
936 store_->AddCallbackForCookie( 938 store_->AddCallbackForCookie(
937 kTestCookieURL2, "abc", 939 kTestCookieURL2, "abc",
938 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 940 base::Bind(&RecordCookieChanges, &cookies, nullptr));
939 EXPECT_EQ(0U, cookies.size()); 941 EXPECT_EQ(0U, cookies.size());
940 SetSystemCookie(kTestCookieURL3, "abc", "ghi"); 942 SetSystemCookie(kTestCookieURL3, "abc", "ghi");
941 EXPECT_EQ(1U, cookies.size()); 943 EXPECT_EQ(1U, cookies.size());
942 DeleteSystemCookie(kTestCookieURL, "abc"); 944 DeleteSystemCookie(kTestCookieURL, "abc");
943 store_->UnSynchronize(); 945 store_->UnSynchronize();
944 } 946 }
945 947
946 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookie) { 948 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookie) {
947 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 949 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
948 backend_->RunLoadedCallback(); 950 backend_->RunLoadedCallback();
949 std::vector<net::CanonicalCookie> cookies; 951 std::vector<net::CanonicalCookie> cookies;
950 SetSystemCookie(kTestCookieURL3, "abc", "def"); 952 SetSystemCookie(kTestCookieURL3, "abc", "def");
951 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 953 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
952 store_->AddCallbackForCookie( 954 store_->AddCallbackForCookie(
953 kTestCookieURL2, "abc", 955 kTestCookieURL2, "abc",
954 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 956 base::Bind(&RecordCookieChanges, &cookies, nullptr));
955 EXPECT_EQ(0U, cookies.size()); 957 EXPECT_EQ(0U, cookies.size());
956 SetSystemCookie(kTestCookieURL2, "abc", "ghi"); 958 SetSystemCookie(kTestCookieURL2, "abc", "ghi");
957 EXPECT_EQ(1U, cookies.size()); 959 EXPECT_EQ(1U, cookies.size());
958 DeleteSystemCookie(kTestCookieURL, "abc"); 960 DeleteSystemCookie(kTestCookieURL, "abc");
959 store_->UnSynchronize(); 961 store_->UnSynchronize();
960 } 962 }
961 963
962 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookieWithSameValue) { 964 TEST_F(CookieStoreIOSWithBackend, MoreSpecificNestedCookieWithSameValue) {
963 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 965 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
964 backend_->RunLoadedCallback(); 966 backend_->RunLoadedCallback();
965 std::vector<net::CanonicalCookie> cookies; 967 std::vector<net::CanonicalCookie> cookies;
966 SetSystemCookie(kTestCookieURL3, "abc", "def"); 968 SetSystemCookie(kTestCookieURL3, "abc", "def");
967 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 969 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
968 store_->AddCallbackForCookie( 970 store_->AddCallbackForCookie(
969 kTestCookieURL2, "abc", 971 kTestCookieURL2, "abc",
970 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 972 base::Bind(&RecordCookieChanges, &cookies, nullptr));
971 EXPECT_EQ(0U, cookies.size()); 973 EXPECT_EQ(0U, cookies.size());
972 SetSystemCookie(kTestCookieURL2, "abc", "def"); 974 SetSystemCookie(kTestCookieURL2, "abc", "def");
973 EXPECT_EQ(1U, cookies.size()); 975 EXPECT_EQ(1U, cookies.size());
974 DeleteSystemCookie(kTestCookieURL, "abc"); 976 DeleteSystemCookie(kTestCookieURL, "abc");
975 store_->UnSynchronize(); 977 store_->UnSynchronize();
976 } 978 }
977 979
978 TEST_F(CookieStoreIOSWithBackend, RemoveCallback) { 980 TEST_F(CookieStoreIOSWithBackend, RemoveCallback) {
979 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get()); 981 CookieStoreIOS::SwitchSynchronizedStore(nullptr, store_.get());
980 backend_->RunLoadedCallback(); 982 backend_->RunLoadedCallback();
981 std::vector<net::CanonicalCookie> cookies; 983 std::vector<net::CanonicalCookie> cookies;
982 SetSystemCookie(kTestCookieURL, "abc", "def"); 984 SetSystemCookie(kTestCookieURL, "abc", "def");
983 scoped_ptr<net::CookieStore::CookieChangedSubscription> handle = 985 std::unique_ptr<net::CookieStore::CookieChangedSubscription> handle =
984 store_->AddCallbackForCookie( 986 store_->AddCallbackForCookie(
985 kTestCookieURL, "abc", 987 kTestCookieURL, "abc",
986 base::Bind(&RecordCookieChanges, &cookies, nullptr)); 988 base::Bind(&RecordCookieChanges, &cookies, nullptr));
987 EXPECT_EQ(0U, cookies.size()); 989 EXPECT_EQ(0U, cookies.size());
988 SetSystemCookie(kTestCookieURL, "abc", "ghi"); 990 SetSystemCookie(kTestCookieURL, "abc", "ghi");
989 EXPECT_EQ(2U, cookies.size()); 991 EXPECT_EQ(2U, cookies.size());
990 // this deletes the callback 992 // this deletes the callback
991 handle.reset(); 993 handle.reset();
992 SetSystemCookie(kTestCookieURL, "abc", "jkl"); 994 SetSystemCookie(kTestCookieURL, "abc", "jkl");
993 EXPECT_EQ(2U, cookies.size()); 995 EXPECT_EQ(2U, cookies.size());
994 DeleteSystemCookie(kTestCookieURL, "abc"); 996 DeleteSystemCookie(kTestCookieURL, "abc");
995 store_->UnSynchronize(); 997 store_->UnSynchronize();
996 } 998 }
997 999
998 } // namespace net 1000 } // namespace net
OLDNEW
« no previous file with comments | « ios/net/cookies/cookie_store_ios.mm ('k') | ios/net/crn_http_protocol_handler.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698