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
3 // found in the LICENSE file.
5 #ifndef NET_BASE_COOKIE_STORE_TEST_HELPERS_H_
6 #define NET_BASE_COOKIE_STORE_TEST_HELPERS_H_
9 #include "net/base/cookie_monster.h"
14 #include "base/callback_forward.h"
15 #include "testing/gtest/include/gtest/gtest.h"
19 class DelayedCookieMonster
: public CookieStore
{
21 DelayedCookieMonster();
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.
27 virtual void SetCookieWithOptionsAsync(
29 const std::string
& cookie_line
,
30 const CookieOptions
& options
,
31 const CookieMonster::SetCookiesCallback
& callback
) OVERRIDE
;
33 virtual void GetCookiesWithOptionsAsync(
34 const GURL
& url
, const CookieOptions
& options
,
35 const CookieMonster::GetCookiesCallback
& callback
) OVERRIDE
;
37 virtual void GetCookiesWithInfoAsync(
39 const CookieOptions
& options
,
40 const CookieMonster::GetCookieInfoCallback
& callback
) OVERRIDE
;
42 virtual bool SetCookieWithOptions(const GURL
& url
,
43 const std::string
& cookie_line
,
44 const CookieOptions
& options
);
46 virtual std::string
GetCookiesWithOptions(const GURL
& url
,
47 const CookieOptions
& options
);
49 virtual void GetCookiesWithInfo(const GURL
& url
,
50 const CookieOptions
& options
,
51 std::string
* cookie_line
,
52 std::vector
<CookieInfo
>* cookie_infos
);
54 virtual void DeleteCookie(const GURL
& url
,
55 const std::string
& cookie_name
);
57 virtual void DeleteCookieAsync(const GURL
& url
,
58 const std::string
& cookie_name
,
59 const base::Closure
& callback
) OVERRIDE
;
61 virtual void DeleteAllCreatedBetweenAsync(
62 const base::Time
& delete_begin
,
63 const base::Time
& delete_end
,
64 const DeleteCallback
& callback
) OVERRIDE
;
66 virtual CookieMonster
* GetCookieMonster() OVERRIDE
;
70 // Be called immediately from CookieMonster.
72 void GetCookiesInternalCallback(
73 const std::string
& cookie_line
,
74 const std::vector
<CookieStore::CookieInfo
>& cookie_info
);
76 void SetCookiesInternalCallback(bool result
);
78 void GetCookiesWithOptionsInternalCallback(const std::string
& cookie
);
80 // Invoke the original callbacks.
82 void InvokeGetCookiesCallback(
83 const CookieMonster::GetCookieInfoCallback
& callback
);
85 void InvokeSetCookiesCallback(
86 const CookieMonster::SetCookiesCallback
& callback
);
88 void InvokeGetCookieStringCallback(
89 const CookieMonster::GetCookiesCallback
& callback
);
91 friend class base::RefCountedThreadSafe
<DelayedCookieMonster
>;
92 virtual ~DelayedCookieMonster();
94 scoped_refptr
<CookieMonster
> cookie_monster_
;
99 std::string cookie_line_
;
100 std::vector
<CookieStore::CookieInfo
> cookie_info_
;
105 #endif // NET_BASE_COOKIE_STORE_TEST_HELPERS_H_