Chromium Code Reviews| 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 |
| 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 #include "ios/net/cookies/cookie_store_ios_persistent.h" | |
|
Eugene But (OOO till 7-30)
2017/01/23 17:37:48
s/include/import
maksims (do not use this acc)
2017/01/24 10:23:46
Done.
| |
| 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 Loading... | |
| 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_(new net::CookieStoreIOSPersistent(backend_.get())) { |
|
Eugene But (OOO till 7-30)
2017/01/23 17:37:48
Could you please use MakeUnique here and in other
maksims (do not use this acc)
2017/01/24 10:23:46
Done.
| |
| 235 cookie_changed_callback_ = store_->AddCallbackForCookie( | 235 cookie_changed_callback_ = store_->AddCallbackForCookie( |
| 236 kTestCookieURL, "abc", | 236 kTestCookieURL, "abc", |
| 237 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_)); | 237 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_)); |
| 238 } | 238 } |
| 239 | 239 |
| 240 ~NotSynchronizedCookieStoreIOSWithBackend() override {} | 240 ~NotSynchronizedCookieStoreIOSWithBackend() override {} |
| 241 | 241 |
| 242 // Gets the cookies. |callback| will be called on completion. | 242 // Gets the cookies. |callback| will be called on completion. |
| 243 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { | 243 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { |
| 244 net::CookieOptions options; | 244 net::CookieOptions options; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 267 // Test fixture to exersize net::CookieStoreIOS created without backend and | 267 // Test fixture to exersize net::CookieStoreIOS created without backend and |
| 268 // synchronized with |[NSHTTPCookieStorage sharedHTTPCookieStorage]|. | 268 // synchronized with |[NSHTTPCookieStorage sharedHTTPCookieStorage]|. |
| 269 class SynchronizedCookieStoreIOS : public testing::Test { | 269 class SynchronizedCookieStoreIOS : public testing::Test { |
| 270 public: | 270 public: |
| 271 SynchronizedCookieStoreIOS() | 271 SynchronizedCookieStoreIOS() |
| 272 : kTestCookieURL("http://foo.google.com/bar"), | 272 : kTestCookieURL("http://foo.google.com/bar"), |
| 273 kTestCookieURL2("http://foo.google.com/baz"), | 273 kTestCookieURL2("http://foo.google.com/baz"), |
| 274 kTestCookieURL3("http://foo.google.com"), | 274 kTestCookieURL3("http://foo.google.com"), |
| 275 kTestCookieURL4("http://bar.google.com/bar"), | 275 kTestCookieURL4("http://bar.google.com/bar"), |
| 276 backend_(new TestPersistentCookieStore), | 276 backend_(new TestPersistentCookieStore), |
| 277 store_(net::CookieStoreIOS::CreateCookieStore( | 277 store_(new net::CookieStoreIOS( |
| 278 [NSHTTPCookieStorage sharedHTTPCookieStorage])) { | 278 [NSHTTPCookieStorage sharedHTTPCookieStorage])) { |
| 279 cookie_changed_callback_ = store_->AddCallbackForCookie( | 279 cookie_changed_callback_ = store_->AddCallbackForCookie( |
| 280 kTestCookieURL, "abc", | 280 kTestCookieURL, "abc", |
| 281 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_)); | 281 base::Bind(&RecordCookieChanges, &cookies_changed_, &cookies_removed_)); |
| 282 } | 282 } |
| 283 | 283 |
| 284 ~SynchronizedCookieStoreIOS() override {} | 284 ~SynchronizedCookieStoreIOS() override {} |
| 285 | 285 |
| 286 // Gets the cookies. |callback| will be called on completion. | 286 // Gets the cookies. |callback| will be called on completion. |
| 287 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { | 287 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 EXPECT_EQ(1U, cookies_changed_.size()); | 412 EXPECT_EQ(1U, cookies_changed_.size()); |
| 413 SetCookie("abc=def"); | 413 SetCookie("abc=def"); |
| 414 EXPECT_EQ(1U, cookies_changed_.size()); | 414 EXPECT_EQ(1U, cookies_changed_.size()); |
| 415 } | 415 } |
| 416 | 416 |
| 417 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) { | 417 TEST(CookieStoreIOS, GetAllCookiesForURLAsync) { |
| 418 base::MessageLoop loop; | 418 base::MessageLoop loop; |
| 419 const GURL kTestCookieURL("http://foo.google.com/bar"); | 419 const GURL kTestCookieURL("http://foo.google.com/bar"); |
| 420 ClearCookies(); | 420 ClearCookies(); |
| 421 std::unique_ptr<CookieStoreIOS> cookie_store( | 421 std::unique_ptr<CookieStoreIOS> cookie_store( |
| 422 CookieStoreIOS::CreateCookieStore( | 422 new CookieStoreIOS([NSHTTPCookieStorage sharedHTTPCookieStorage])); |
| 423 [NSHTTPCookieStorage sharedHTTPCookieStorage])); | 423 |
| 424 // Add a cookie. | 424 // Add a cookie. |
| 425 net::CookieOptions options; | 425 net::CookieOptions options; |
| 426 options.set_include_httponly(); | 426 options.set_include_httponly(); |
| 427 cookie_store->SetCookieWithOptionsAsync( | 427 cookie_store->SetCookieWithOptionsAsync( |
| 428 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); | 428 kTestCookieURL, "a=b", options, net::CookieStore::SetCookiesCallback()); |
| 429 // Check we can get the cookie. | 429 // Check we can get the cookie. |
| 430 GetAllCookiesCallback callback; | 430 GetAllCookiesCallback callback; |
| 431 cookie_store->GetAllCookiesForURLAsync( | 431 cookie_store->GetAllCookiesForURLAsync( |
| 432 kTestCookieURL, | 432 kTestCookieURL, |
| 433 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback))); | 433 base::Bind(&GetAllCookiesCallback::Run, base::Unretained(&callback))); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 SetSystemCookie(kTestCookieURL, "abc", "ghi"); | 633 SetSystemCookie(kTestCookieURL, "abc", "ghi"); |
| 634 EXPECT_EQ(2U, cookies.size()); | 634 EXPECT_EQ(2U, cookies.size()); |
| 635 // this deletes the callback | 635 // this deletes the callback |
| 636 handle.reset(); | 636 handle.reset(); |
| 637 SetSystemCookie(kTestCookieURL, "abc", "jkl"); | 637 SetSystemCookie(kTestCookieURL, "abc", "jkl"); |
| 638 EXPECT_EQ(2U, cookies.size()); | 638 EXPECT_EQ(2U, cookies.size()); |
| 639 DeleteSystemCookie(kTestCookieURL, "abc"); | 639 DeleteSystemCookie(kTestCookieURL, "abc"); |
| 640 } | 640 } |
| 641 | 641 |
| 642 } // namespace net | 642 } // namespace net |
| OLD | NEW |