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 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // Test net::CookieMonster::PersistentCookieStore allowing to control when the | 242 // Test net::CookieMonster::PersistentCookieStore allowing to control when the |
243 // initialization completes. | 243 // initialization completes. |
244 class TestPersistentCookieStore | 244 class TestPersistentCookieStore |
245 : public net::CookieMonster::PersistentCookieStore { | 245 : public net::CookieMonster::PersistentCookieStore { |
246 public: | 246 public: |
247 TestPersistentCookieStore() | 247 TestPersistentCookieStore() |
248 : kTestCookieURL("http://foo.google.com/bar"), flushed_(false) {} | 248 : kTestCookieURL("http://foo.google.com/bar"), flushed_(false) {} |
249 | 249 |
250 // Runs the completion callback with a "a=b" cookie. | 250 // Runs the completion callback with a "a=b" cookie. |
251 void RunLoadedCallback() { | 251 void RunLoadedCallback() { |
252 std::vector<net::CanonicalCookie*> cookies; | 252 std::vector<std::unique_ptr<net::CanonicalCookie>> cookies; |
253 net::CookieOptions options; | 253 net::CookieOptions options; |
254 options.set_include_httponly(); | 254 options.set_include_httponly(); |
255 | 255 |
256 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( | 256 std::unique_ptr<net::CanonicalCookie> cookie(net::CanonicalCookie::Create( |
257 kTestCookieURL, "a=b", base::Time::Now(), options)); | 257 kTestCookieURL, "a=b", base::Time::Now(), options)); |
258 cookies.push_back(cookie.release()); | 258 cookies.push_back(std::move(cookie)); |
259 | 259 |
260 // Some canonical cookies cannot be converted into System cookies, for | 260 // Some canonical cookies cannot be converted into System cookies, for |
261 // example if value is not valid utf8. Such cookies are ignored. | 261 // example if value is not valid utf8. Such cookies are ignored. |
262 std::unique_ptr<net::CanonicalCookie> bad_canonical_cookie( | 262 std::unique_ptr<net::CanonicalCookie> bad_canonical_cookie( |
263 net::CanonicalCookie::Create(GURL("http://domain/"), "name", | 263 net::CanonicalCookie::Create(GURL("http://domain/"), "name", |
264 "\x81r\xe4\xbd\xa0\xe5\xa5\xbd", | 264 "\x81r\xe4\xbd\xa0\xe5\xa5\xbd", |
265 std::string(), "/path/", | 265 std::string(), "/path/", |
266 base::Time(), // creation | 266 base::Time(), // creation |
267 base::Time(), // expires | 267 base::Time(), // expires |
268 false, // secure | 268 false, // secure |
269 false, // httponly | 269 false, // httponly |
270 net::CookieSameSite::DEFAULT_MODE, false, | 270 net::CookieSameSite::DEFAULT_MODE, false, |
271 net::COOKIE_PRIORITY_DEFAULT)); | 271 net::COOKIE_PRIORITY_DEFAULT)); |
272 cookies.push_back(bad_canonical_cookie.release()); | 272 cookies.push_back(std::move(bad_canonical_cookie)); |
273 loaded_callback_.Run(cookies); | 273 loaded_callback_.Run(std::move(cookies)); |
274 } | 274 } |
275 | 275 |
276 bool flushed() { return flushed_; } | 276 bool flushed() { return flushed_; } |
277 | 277 |
278 private: | 278 private: |
279 // net::CookieMonster::PersistentCookieStore implementation: | 279 // net::CookieMonster::PersistentCookieStore implementation: |
280 void Load(const LoadedCallback& loaded_callback) override { | 280 void Load(const LoadedCallback& loaded_callback) override { |
281 loaded_callback_ = loaded_callback; | 281 loaded_callback_ = loaded_callback; |
282 } | 282 } |
283 | 283 |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 EXPECT_EQ(2U, cookies.size()); | 993 EXPECT_EQ(2U, cookies.size()); |
994 // this deletes the callback | 994 // this deletes the callback |
995 handle.reset(); | 995 handle.reset(); |
996 SetSystemCookie(kTestCookieURL, "abc", "jkl"); | 996 SetSystemCookie(kTestCookieURL, "abc", "jkl"); |
997 EXPECT_EQ(2U, cookies.size()); | 997 EXPECT_EQ(2U, cookies.size()); |
998 DeleteSystemCookie(kTestCookieURL, "abc"); | 998 DeleteSystemCookie(kTestCookieURL, "abc"); |
999 store_->UnSynchronize(); | 999 store_->UnSynchronize(); |
1000 } | 1000 } |
1001 | 1001 |
1002 } // namespace net | 1002 } // namespace net |
OLD | NEW |