| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // Provides a temporary redirection while clients are updated to use the new |
| 6 // path. |
| 7 |
| 5 #ifndef NET_BASE_COOKIE_STORE_TEST_HELPERS_H_ | 8 #ifndef NET_BASE_COOKIE_STORE_TEST_HELPERS_H_ |
| 6 #define NET_BASE_COOKIE_STORE_TEST_HELPERS_H_ | 9 #define NET_BASE_COOKIE_STORE_TEST_HELPERS_H_ |
| 7 #pragma once | 10 #pragma once |
| 8 | 11 |
| 9 #include "net/base/cookie_monster.h" | 12 #include "net/cookies/cookie_store_test_helpers.h" |
| 10 | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/callback_forward.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 namespace net { | |
| 18 | |
| 19 class DelayedCookieMonster : public CookieStore { | |
| 20 public: | |
| 21 DelayedCookieMonster(); | |
| 22 | |
| 23 // Call the asynchronous CookieMonster function, expect it to immediately | |
| 24 // invoke the internal callback. | |
| 25 // Post a delayed task to invoke the original callback with the results. | |
| 26 | |
| 27 virtual void SetCookieWithOptionsAsync( | |
| 28 const GURL& url, | |
| 29 const std::string& cookie_line, | |
| 30 const CookieOptions& options, | |
| 31 const CookieMonster::SetCookiesCallback& callback) OVERRIDE; | |
| 32 | |
| 33 virtual void GetCookiesWithOptionsAsync( | |
| 34 const GURL& url, const CookieOptions& options, | |
| 35 const CookieMonster::GetCookiesCallback& callback) OVERRIDE; | |
| 36 | |
| 37 virtual void GetCookiesWithInfoAsync( | |
| 38 const GURL& url, | |
| 39 const CookieOptions& options, | |
| 40 const CookieMonster::GetCookieInfoCallback& callback) OVERRIDE; | |
| 41 | |
| 42 virtual bool SetCookieWithOptions(const GURL& url, | |
| 43 const std::string& cookie_line, | |
| 44 const CookieOptions& options); | |
| 45 | |
| 46 virtual std::string GetCookiesWithOptions(const GURL& url, | |
| 47 const CookieOptions& options); | |
| 48 | |
| 49 virtual void GetCookiesWithInfo(const GURL& url, | |
| 50 const CookieOptions& options, | |
| 51 std::string* cookie_line, | |
| 52 std::vector<CookieInfo>* cookie_infos); | |
| 53 | |
| 54 virtual void DeleteCookie(const GURL& url, | |
| 55 const std::string& cookie_name); | |
| 56 | |
| 57 virtual void DeleteCookieAsync(const GURL& url, | |
| 58 const std::string& cookie_name, | |
| 59 const base::Closure& callback) OVERRIDE; | |
| 60 | |
| 61 virtual void DeleteAllCreatedBetweenAsync( | |
| 62 const base::Time& delete_begin, | |
| 63 const base::Time& delete_end, | |
| 64 const DeleteCallback& callback) OVERRIDE; | |
| 65 | |
| 66 virtual CookieMonster* GetCookieMonster() OVERRIDE; | |
| 67 | |
| 68 private: | |
| 69 | |
| 70 // Be called immediately from CookieMonster. | |
| 71 | |
| 72 void GetCookiesInternalCallback( | |
| 73 const std::string& cookie_line, | |
| 74 const std::vector<CookieStore::CookieInfo>& cookie_info); | |
| 75 | |
| 76 void SetCookiesInternalCallback(bool result); | |
| 77 | |
| 78 void GetCookiesWithOptionsInternalCallback(const std::string& cookie); | |
| 79 | |
| 80 // Invoke the original callbacks. | |
| 81 | |
| 82 void InvokeGetCookiesCallback( | |
| 83 const CookieMonster::GetCookieInfoCallback& callback); | |
| 84 | |
| 85 void InvokeSetCookiesCallback( | |
| 86 const CookieMonster::SetCookiesCallback& callback); | |
| 87 | |
| 88 void InvokeGetCookieStringCallback( | |
| 89 const CookieMonster::GetCookiesCallback& callback); | |
| 90 | |
| 91 friend class base::RefCountedThreadSafe<DelayedCookieMonster>; | |
| 92 virtual ~DelayedCookieMonster(); | |
| 93 | |
| 94 scoped_refptr<CookieMonster> cookie_monster_; | |
| 95 | |
| 96 bool did_run_; | |
| 97 bool result_; | |
| 98 std::string cookie_; | |
| 99 std::string cookie_line_; | |
| 100 std::vector<CookieStore::CookieInfo> cookie_info_; | |
| 101 }; | |
| 102 | |
| 103 } // namespace net | |
| 104 | 13 |
| 105 #endif // NET_BASE_COOKIE_STORE_TEST_HELPERS_H_ | 14 #endif // NET_BASE_COOKIE_STORE_TEST_HELPERS_H_ |
| OLD | NEW |