Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_ |
| 6 | #define NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_ |
| 7 | |
| 8 | #include "net/cookies/cookie_monster.h" |
| 9 | |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include "base/callback_forward.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
| 16 | namespace net { |
| 17 | |
| 18 | class DelayedCookieMonster : public CookieStore { |
| 19 | public: |
| 20 | DelayedCookieMonster(); |
| 21 | |
| 22 | // Call the asynchronous CookieMonster function, expect it to immediately |
| 23 | // invoke the internal callback. |
| 24 | // Post a delayed task to invoke the original callback with the results. |
| 25 | |
| 26 | virtual void SetCookieWithOptionsAsync( |
| 27 | const GURL& url, |
| 28 | const std::string& cookie_line, |
| 29 | const CookieOptions& options, |
| 30 | const CookieMonster::SetCookiesCallback& callback) OVERRIDE; |
| 31 | |
| 32 | virtual void GetCookiesWithOptionsAsync( |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 33 | const GURL& url, |
| 34 | const CookieOptions& options, |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 35 | const CookieMonster::GetCookiesCallback& callback) OVERRIDE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 36 | |
Ben Murdoch | effb81e | 2014-03-31 11:51:25 +0100 | [diff] [blame] | 37 | virtual void GetAllCookiesForURLAsync( |
| 38 | const GURL& url, |
| 39 | const GetCookieListCallback& callback) OVERRIDE; |
| 40 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 41 | virtual bool SetCookieWithOptions(const GURL& url, |
| 42 | const std::string& cookie_line, |
| 43 | const CookieOptions& options); |
| 44 | |
| 45 | virtual std::string GetCookiesWithOptions(const GURL& url, |
| 46 | const CookieOptions& options); |
| 47 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 48 | virtual void DeleteCookie(const GURL& url, |
| 49 | const std::string& cookie_name); |
| 50 | |
| 51 | virtual void DeleteCookieAsync(const GURL& url, |
| 52 | const std::string& cookie_name, |
| 53 | const base::Closure& callback) OVERRIDE; |
| 54 | |
| 55 | virtual void DeleteAllCreatedBetweenAsync( |
| 56 | const base::Time& delete_begin, |
| 57 | const base::Time& delete_end, |
| 58 | const DeleteCallback& callback) OVERRIDE; |
| 59 | |
Torne (Richard Coles) | 5d1f7b1 | 2014-02-21 12:16:55 +0000 | [diff] [blame] | 60 | virtual void DeleteAllCreatedBetweenForHostAsync( |
| 61 | const base::Time delete_begin, |
| 62 | const base::Time delete_end, |
| 63 | const GURL& url, |
| 64 | const DeleteCallback& callback) OVERRIDE; |
| 65 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 66 | virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE; |
| 67 | |
| 68 | virtual CookieMonster* GetCookieMonster() OVERRIDE; |
| 69 | |
| 70 | private: |
| 71 | |
| 72 | // Be called immediately from CookieMonster. |
| 73 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 74 | void SetCookiesInternalCallback(bool result); |
| 75 | |
| 76 | void GetCookiesWithOptionsInternalCallback(const std::string& cookie); |
| 77 | |
| 78 | // Invoke the original callbacks. |
| 79 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 80 | void InvokeSetCookiesCallback( |
| 81 | const CookieMonster::SetCookiesCallback& callback); |
| 82 | |
| 83 | void InvokeGetCookieStringCallback( |
| 84 | const CookieMonster::GetCookiesCallback& callback); |
| 85 | |
| 86 | friend class base::RefCountedThreadSafe<DelayedCookieMonster>; |
| 87 | virtual ~DelayedCookieMonster(); |
| 88 | |
| 89 | scoped_refptr<CookieMonster> cookie_monster_; |
| 90 | |
| 91 | bool did_run_; |
| 92 | bool result_; |
| 93 | std::string cookie_; |
| 94 | std::string cookie_line_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | } // namespace net |
| 98 | |
| 99 | #endif // NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_ |