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.
5 #ifndef NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_
6 #define NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_
8 #include "net/cookies/cookie_monster.h"
13 #include "base/callback_forward.h"
14 #include "testing/gtest/include/gtest/gtest.h"
18 class DelayedCookieMonster
: public CookieStore
{
20 DelayedCookieMonster();
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.
26 virtual void SetCookieWithOptionsAsync(
28 const std::string
& cookie_line
,
29 const CookieOptions
& options
,
30 const CookieMonster::SetCookiesCallback
& callback
) OVERRIDE
;
32 virtual void GetCookiesWithOptionsAsync(
34 const CookieOptions
& options
,
35 const CookieMonster::GetCookiesCallback
& callback
) OVERRIDE
;
37 virtual bool SetCookieWithOptions(const GURL
& url
,
38 const std::string
& cookie_line
,
39 const CookieOptions
& options
);
41 virtual std::string
GetCookiesWithOptions(const GURL
& url
,
42 const CookieOptions
& options
);
44 virtual void DeleteCookie(const GURL
& url
,
45 const std::string
& cookie_name
);
47 virtual void DeleteCookieAsync(const GURL
& url
,
48 const std::string
& cookie_name
,
49 const base::Closure
& callback
) OVERRIDE
;
51 virtual void DeleteAllCreatedBetweenAsync(
52 const base::Time
& delete_begin
,
53 const base::Time
& delete_end
,
54 const DeleteCallback
& callback
) OVERRIDE
;
56 virtual void DeleteAllCreatedBetweenForHostAsync(
57 const base::Time delete_begin
,
58 const base::Time delete_end
,
60 const DeleteCallback
& callback
) OVERRIDE
;
62 virtual void DeleteSessionCookiesAsync(const DeleteCallback
&) OVERRIDE
;
64 virtual CookieMonster
* GetCookieMonster() OVERRIDE
;
68 // Be called immediately from CookieMonster.
70 void SetCookiesInternalCallback(bool result
);
72 void GetCookiesWithOptionsInternalCallback(const std::string
& cookie
);
74 // Invoke the original callbacks.
76 void InvokeSetCookiesCallback(
77 const CookieMonster::SetCookiesCallback
& callback
);
79 void InvokeGetCookieStringCallback(
80 const CookieMonster::GetCookiesCallback
& callback
);
82 friend class base::RefCountedThreadSafe
<DelayedCookieMonster
>;
83 virtual ~DelayedCookieMonster();
85 scoped_refptr
<CookieMonster
> cookie_monster_
;
90 std::string cookie_line_
;
95 #endif // NET_COOKIES_COOKIE_STORE_TEST_HELPERS_H_