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

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

Issue 2649083002: Divide CookieStoreIOS into two different classes with different backends (Closed)
Patch Set: Eugene's comments 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
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
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/sys_string_conversions.h" 16 #include "base/strings/sys_string_conversions.h"
17 #import "ios/net/cookies/cookie_store_ios_persistent.h"
17 #import "net/base/mac/url_conversions.h" 18 #import "net/base/mac/url_conversions.h"
18 #include "net/cookies/cookie_store_unittest.h" 19 #include "net/cookies/cookie_store_unittest.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace { 22 namespace {
22 // Clears the underlying NSHTTPCookieStorage. 23 // Clears the underlying NSHTTPCookieStorage.
23 void ClearCookies() { 24 void ClearCookies() {
24 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 25 NSHTTPCookieStorage* store = [NSHTTPCookieStorage sharedHTTPCookieStorage];
25 [store setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; 26 [store setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
26 NSArray* cookies = [store cookies]; 27 NSArray* cookies = [store cookies];
27 for (NSHTTPCookie* cookie in cookies) 28 for (NSHTTPCookie* cookie in cookies)
28 [store deleteCookie:cookie]; 29 [store deleteCookie:cookie];
29 EXPECT_EQ(0u, [[store cookies] count]); 30 EXPECT_EQ(0u, [[store cookies] count]);
30 } 31 }
31 } // namespace 32 } // namespace
32 33
33 namespace net { 34 namespace net {
34 35
35 struct CookieStoreIOSTestTraits { 36 struct CookieStoreIOSTestTraits {
36 static std::unique_ptr<net::CookieStore> Create() { 37 static std::unique_ptr<net::CookieStore> Create() {
37 ClearCookies(); 38 ClearCookies();
38 std::unique_ptr<CookieStoreIOS> store(new CookieStoreIOS(nullptr)); 39 return base::MakeUnique<CookieStoreIOS>(
39 store->synchronization_state_ = CookieStoreIOS::SYNCHRONIZED; 40 [NSHTTPCookieStorage sharedHTTPCookieStorage]);
40 return std::move(store);
41 } 41 }
42 42
43 static const bool supports_http_only = false; 43 static const bool supports_http_only = false;
44 static const bool supports_non_dotted_domains = false; 44 static const bool supports_non_dotted_domains = false;
45 static const bool preserves_trailing_dots = false; 45 static const bool preserves_trailing_dots = false;
46 static const bool filters_schemes = false; 46 static const bool filters_schemes = false;
47 static const bool has_path_prefix_bug = true; 47 static const bool has_path_prefix_bug = true;
48 static const int creation_time_granularity_in_ms = 1000; 48 static const int creation_time_granularity_in_ms = 1000;
49 static const bool enforce_strict_secure = false; 49 static const bool enforce_strict_secure = false;
50 50
51 base::MessageLoop loop_; 51 base::MessageLoop loop_;
52 }; 52 };
53 53
54 struct InactiveCookieStoreIOSTestTraits { 54 struct InactiveCookieStoreIOSTestTraits {
55 static std::unique_ptr<net::CookieStore> Create() { 55 static std::unique_ptr<net::CookieStore> Create() {
56 return base::MakeUnique<CookieStoreIOS>(nullptr); 56 return base::MakeUnique<CookieStoreIOSPersistent>(nullptr);
57 } 57 }
58 58
59 static const bool is_cookie_monster = false; 59 static const bool is_cookie_monster = false;
60 static const bool supports_http_only = false; 60 static const bool supports_http_only = false;
61 static const bool supports_non_dotted_domains = true; 61 static const bool supports_non_dotted_domains = true;
62 static const bool preserves_trailing_dots = true; 62 static const bool preserves_trailing_dots = true;
63 static const bool filters_schemes = false; 63 static const bool filters_schemes = false;
64 static const bool has_path_prefix_bug = false; 64 static const bool has_path_prefix_bug = false;
65 static const int creation_time_granularity_in_ms = 0; 65 static const int creation_time_granularity_in_ms = 0;
66 static const int enforces_prefixes = true; 66 static const int enforces_prefixes = true;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 224 }
225 225
226 // Test fixture to exersize net::CookieStoreIOS created with 226 // Test fixture to exersize net::CookieStoreIOS created with
227 // TestPersistentCookieStore backend and not synchronized with 227 // TestPersistentCookieStore backend and not synchronized with
228 // NSHTTPCookieStorage. 228 // NSHTTPCookieStorage.
229 class NotSynchronizedCookieStoreIOSWithBackend : public testing::Test { 229 class NotSynchronizedCookieStoreIOSWithBackend : public testing::Test {
230 public: 230 public:
231 NotSynchronizedCookieStoreIOSWithBackend() 231 NotSynchronizedCookieStoreIOSWithBackend()
232 : kTestCookieURL("http://foo.google.com/bar"), 232 : kTestCookieURL("http://foo.google.com/bar"),
233 backend_(new TestPersistentCookieStore), 233 backend_(new TestPersistentCookieStore),
234 store_(new net::CookieStoreIOS(backend_.get())) { 234 store_(
235 base::MakeUnique<net::CookieStoreIOSPersistent>(backend_.get())) {
235 cookie_changed_callback_ = store_->AddCallbackForCookie( 236 cookie_changed_callback_ = store_->AddCallbackForCookie(
236 kTestCookieURL, "abc", 237 kTestCookieURL, "abc",
237 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_)); 238 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_));
238 } 239 }
239 240
240 ~NotSynchronizedCookieStoreIOSWithBackend() override {} 241 ~NotSynchronizedCookieStoreIOSWithBackend() override {}
241 242
242 // Gets the cookies. |callback| will be called on completion. 243 // Gets the cookies. |callback| will be called on completion.
243 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { 244 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) {
244 net::CookieOptions options; 245 net::CookieOptions options;
(...skipping 22 matching lines...) Expand all
267 // Test fixture to exersize net::CookieStoreIOS created without backend and 268 // Test fixture to exersize net::CookieStoreIOS created without backend and
268 // synchronized with |[NSHTTPCookieStorage sharedHTTPCookieStorage]|. 269 // synchronized with |[NSHTTPCookieStorage sharedHTTPCookieStorage]|.
269 class SynchronizedCookieStoreIOS : public testing::Test { 270 class SynchronizedCookieStoreIOS : public testing::Test {
270 public: 271 public:
271 SynchronizedCookieStoreIOS() 272 SynchronizedCookieStoreIOS()
272 : kTestCookieURL("http://foo.google.com/bar"), 273 : kTestCookieURL("http://foo.google.com/bar"),
273 kTestCookieURL2("http://foo.google.com/baz"), 274 kTestCookieURL2("http://foo.google.com/baz"),
274 kTestCookieURL3("http://foo.google.com"), 275 kTestCookieURL3("http://foo.google.com"),
275 kTestCookieURL4("http://bar.google.com/bar"), 276 kTestCookieURL4("http://bar.google.com/bar"),
276 backend_(new TestPersistentCookieStore), 277 backend_(new TestPersistentCookieStore),
277 store_(net::CookieStoreIOS::CreateCookieStore( 278 store_(base::MakeUnique<net::CookieStoreIOS>(
278 [NSHTTPCookieStorage sharedHTTPCookieStorage])) { 279 [NSHTTPCookieStorage sharedHTTPCookieStorage])) {
279 cookie_changed_callback_ = store_->AddCallbackForCookie( 280 cookie_changed_callback_ = store_->AddCallbackForCookie(
280 kTestCookieURL, "abc", 281 kTestCookieURL, "abc",
281 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_)); 282 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_));
282 } 283 }
283 284
284 ~SynchronizedCookieStoreIOS() override {} 285 ~SynchronizedCookieStoreIOS() override {}
285 286
286 // Gets the cookies. |callback| will be called on completion. 287 // Gets the cookies. |callback| will be called on completion.
287 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { 288 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 SetCookie("abc=def"); 412 SetCookie("abc=def");
412 EXPECT_EQ(1U, cookies_changed_.size()); 413 EXPECT_EQ(1U, cookies_changed_.size());
413 SetCookie("abc=def"); 414 SetCookie("abc=def");
414 EXPECT_EQ(1U, cookies_changed_.size()); 415 EXPECT_EQ(1U, cookies_changed_.size());
415 } 416 }
416 417
417 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) { 418 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) {
418 base::MessageLoop loop; 419 base::MessageLoop loop;
419 const GURL kTestCookieURL("http://foo.google.com/bar"); 420 const GURL kTestCookieURL("http://foo.google.com/bar");
420 ClearCookies(); 421 ClearCookies();
421 std::unique_ptr<CookieStoreIOS> cookie_store( 422 std::unique_ptr<CookieStoreIOS> cookie_store(base::MakeUnique<CookieStoreIOS>(
422 CookieStoreIOS::CreateCookieStore( 423 [NSHTTPCookieStorage sharedHTTPCookieStorage]));
423 [NSHTTPCookieStorage sharedHTTPCookieStorage])); 424
424 // Add a cookie. 425 // Add a cookie.
425 net::CookieOptions options; 426 net::CookieOptions options;
426 options.set_include_httponly(); 427 options.set_include_httponly();
427 cookie_store->SetCookieWithOptionsAsync( 428 cookie_store->SetCookieWithOptionsAsync(
428 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); 429 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback());
429 // Check we can get the cookie. 430 // Check we can get the cookie.
430 GetAllCookiesCallback callback; 431 GetAllCookiesCallback callback;
431 cookie_store->GetAllCookiesForURLAsync( 432 cookie_store->GetAllCookiesForURLAsync(
432 kTestCookieURL, 433 kTestCookieURL,
433 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback))); 434 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback)));
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 SetSystemCookie(kTestCookieURL, "abc", "ghi"); 634 SetSystemCookie(kTestCookieURL, "abc", "ghi");
634 EXPECT_EQ(2U, cookies.size()); 635 EXPECT_EQ(2U, cookies.size());
635 // this deletes the callback 636 // this deletes the callback
636 handle.reset(); 637 handle.reset();
637 SetSystemCookie(kTestCookieURL, "abc", "jkl"); 638 SetSystemCookie(kTestCookieURL, "abc", "jkl");
638 EXPECT_EQ(2U, cookies.size()); 639 EXPECT_EQ(2U, cookies.size());
639 DeleteSystemCookie(kTestCookieURL, "abc"); 640 DeleteSystemCookie(kTestCookieURL, "abc");
640 } 641 }
641 642
642 } // namespace net 643 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698