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( 33 const GURL& url, 34 const CookieOptions& options, 35 const CookieMonster::GetCookiesCallback& callback) OVERRIDE; 36 37 virtual bool SetCookieWithOptions(const GURL& url, 38 const std::string& cookie_line, 39 const CookieOptions& options); 40 41 virtual std::string GetCookiesWithOptions(const GURL& url, 42 const CookieOptions& options); 43 44 virtual void DeleteCookie(const GURL& url, 45 const std::string& cookie_name); 46 47 virtual void DeleteCookieAsync(const GURL& url, 48 const std::string& cookie_name, 49 const base::Closure& callback) OVERRIDE; 50 51 virtual void DeleteAllCreatedBetweenAsync( 52 const base::Time& delete_begin, 53 const base::Time& delete_end, 54 const DeleteCallback& callback) OVERRIDE; 55 56 virtual void DeleteSessionCookiesAsync(const DeleteCallback&) OVERRIDE; 57 58 virtual CookieMonster* GetCookieMonster() OVERRIDE; 59 60 private: 61 62 // Be called immediately from CookieMonster. 63 64 void SetCookiesInternalCallback(bool result); 65 66 void GetCookiesWithOptionsInternalCallback(const std::string& cookie); 67 68 // Invoke the original callbacks. 69 70 void InvokeSetCookiesCallback( 71 const CookieMonster::SetCookiesCallback& callback); 72 73 void InvokeGetCookieStringCallback( 74 const CookieMonster::GetCookiesCallback& callback); 75 76 friend class base::RefCountedThreadSafe<DelayedCookieMonster>; 77 virtual ~DelayedCookieMonster(); 78 79 scoped_refptr<CookieMonster> cookie_monster_; 80 81 bool did_run_; 82 bool result_; 83 std::string cookie_; 84 std::string cookie_line_; 85 }; 86 87 } // namespace net 88 89 #endif // NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_ 90