OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #import "ios/net/cookies/cookie_store_ios_persistent.h" | 5 #import "ios/net/cookies/cookie_store_ios_persistent.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 base::MakeUnique<net::CookieStoreIOSPersistent>(backend_.get())) { | 56 base::MakeUnique<net::CookieStoreIOSPersistent>(backend_.get())) { |
57 cookie_changed_callback_ = store_->AddCallbackForCookie( | 57 cookie_changed_callback_ = store_->AddCallbackForCookie( |
58 kTestCookieURL, "abc", | 58 kTestCookieURL, "abc", |
59 base::Bind(&net::RecordCookieChanges, &cookies_changed_, | 59 base::Bind(&net::RecordCookieChanges, &cookies_changed_, |
60 &cookies_removed_)); | 60 &cookies_removed_)); |
61 } | 61 } |
62 | 62 |
63 ~CookieStoreIOSPersistentTest() override {} | 63 ~CookieStoreIOSPersistentTest() override {} |
64 | 64 |
65 // Gets the cookies. |callback| will be called on completion. | 65 // Gets the cookies. |callback| will be called on completion. |
66 void GetCookies(const net::CookieStore::GetCookiesCallback& callback) { | 66 void GetCookies(net::CookieStore::GetCookiesCallback callback) { |
67 net::CookieOptions options; | 67 net::CookieOptions options; |
68 options.set_include_httponly(); | 68 options.set_include_httponly(); |
69 store_->GetCookiesWithOptionsAsync(kTestCookieURL, options, callback); | 69 store_->GetCookiesWithOptionsAsync(kTestCookieURL, options, |
| 70 std::move(callback)); |
70 } | 71 } |
71 | 72 |
72 // Sets a cookie. | 73 // Sets a cookie. |
73 void SetCookie(const std::string& cookie_line) { | 74 void SetCookie(const std::string& cookie_line) { |
74 net::SetCookie(cookie_line, kTestCookieURL, store_.get()); | 75 net::SetCookie(cookie_line, kTestCookieURL, store_.get()); |
75 } | 76 } |
76 | 77 |
77 private: | 78 private: |
78 const GURL kTestCookieURL; | 79 const GURL kTestCookieURL; |
79 | 80 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 EXPECT_TRUE(cookies_removed_[1]); | 113 EXPECT_TRUE(cookies_removed_[1]); |
113 EXPECT_EQ("abc", cookies_changed_[2].Name()); | 114 EXPECT_EQ("abc", cookies_changed_[2].Name()); |
114 EXPECT_EQ("ghi", cookies_changed_[2].Value()); | 115 EXPECT_EQ("ghi", cookies_changed_[2].Value()); |
115 EXPECT_FALSE(cookies_removed_[2]); | 116 EXPECT_FALSE(cookies_removed_[2]); |
116 } | 117 } |
117 | 118 |
118 // Tests that cookies can be read before the backend is loaded. | 119 // Tests that cookies can be read before the backend is loaded. |
119 TEST_F(CookieStoreIOSPersistentTest, NotSynchronized) { | 120 TEST_F(CookieStoreIOSPersistentTest, NotSynchronized) { |
120 // Start fetching the cookie. | 121 // Start fetching the cookie. |
121 GetCookieCallback callback; | 122 GetCookieCallback callback; |
122 GetCookies(base::Bind(&GetCookieCallback::Run, base::Unretained(&callback))); | 123 GetCookies( |
| 124 base::BindOnce(&GetCookieCallback::Run, base::Unretained(&callback))); |
123 // Backend loading completes. | 125 // Backend loading completes. |
124 backend_->RunLoadedCallback(); | 126 backend_->RunLoadedCallback(); |
125 EXPECT_TRUE(callback.did_run()); | 127 EXPECT_TRUE(callback.did_run()); |
126 EXPECT_EQ("a=b", callback.cookie_line()); | 128 EXPECT_EQ("a=b", callback.cookie_line()); |
127 } | 129 } |
128 | 130 |
129 } // namespace net | 131 } // namespace net |
OLD | NEW |