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 #include "net/cookies/cookie_store_test_helpers.h"
8 #include "base/message_loop.h"
12 const int kDelayedTime
= 0;
14 DelayedCookieMonster::DelayedCookieMonster()
15 : cookie_monster_(new CookieMonster(NULL
, NULL
)),
20 DelayedCookieMonster::~DelayedCookieMonster() {
23 void DelayedCookieMonster::GetCookiesInternalCallback(
24 const std::string
& cookie_line
,
25 const std::vector
<CookieStore::CookieInfo
>& cookie_info
) {
26 cookie_line_
= cookie_line
;
27 cookie_info_
= cookie_info
;
31 void DelayedCookieMonster::SetCookiesInternalCallback(bool result
) {
36 void DelayedCookieMonster::GetCookiesWithOptionsInternalCallback(
37 const std::string
& cookie
) {
42 void DelayedCookieMonster::GetCookiesWithInfoAsync(
44 const CookieOptions
& options
,
45 const CookieMonster::GetCookieInfoCallback
& callback
) {
47 cookie_monster_
->GetCookiesWithInfoAsync(
49 base::Bind(&DelayedCookieMonster::GetCookiesInternalCallback
,
50 base::Unretained(this)));
51 DCHECK_EQ(did_run_
, true);
52 MessageLoop::current()->PostDelayedTask(
54 base::Bind(&DelayedCookieMonster::InvokeGetCookiesCallback
,
55 base::Unretained(this), callback
),
56 base::TimeDelta::FromMilliseconds(kDelayedTime
));
59 void DelayedCookieMonster::SetCookieWithOptionsAsync(
60 const GURL
& url
, const std::string
& cookie_line
,
61 const CookieOptions
& options
,
62 const CookieMonster::SetCookiesCallback
& callback
) {
64 cookie_monster_
->SetCookieWithOptionsAsync(
65 url
, cookie_line
, options
,
66 base::Bind(&DelayedCookieMonster::SetCookiesInternalCallback
,
67 base::Unretained(this)));
68 DCHECK_EQ(did_run_
, true);
69 MessageLoop::current()->PostDelayedTask(
71 base::Bind(&DelayedCookieMonster::InvokeSetCookiesCallback
,
72 base::Unretained(this), callback
),
73 base::TimeDelta::FromMilliseconds(kDelayedTime
));
76 void DelayedCookieMonster::GetCookiesWithOptionsAsync(
77 const GURL
& url
, const CookieOptions
& options
,
78 const CookieMonster::GetCookiesCallback
& callback
) {
80 cookie_monster_
->GetCookiesWithOptionsAsync(
82 base::Bind(&DelayedCookieMonster::GetCookiesWithOptionsInternalCallback
,
83 base::Unretained(this)));
84 DCHECK_EQ(did_run_
, true);
85 MessageLoop::current()->PostDelayedTask(
87 base::Bind(&DelayedCookieMonster::InvokeGetCookieStringCallback
,
88 base::Unretained(this), callback
),
89 base::TimeDelta::FromMilliseconds(kDelayedTime
));
92 void DelayedCookieMonster::InvokeGetCookiesCallback(
93 const CookieMonster::GetCookieInfoCallback
& callback
) {
94 if (!callback
.is_null())
95 callback
.Run(cookie_line_
, cookie_info_
);
98 void DelayedCookieMonster::InvokeSetCookiesCallback(
99 const CookieMonster::SetCookiesCallback
& callback
) {
100 if (!callback
.is_null())
101 callback
.Run(result_
);
104 void DelayedCookieMonster::InvokeGetCookieStringCallback(
105 const CookieMonster::GetCookiesCallback
& callback
) {
106 if (!callback
.is_null())
107 callback
.Run(cookie_
);
110 bool DelayedCookieMonster::SetCookieWithOptions(
112 const std::string
& cookie_line
,
113 const CookieOptions
& options
) {
118 std::string
DelayedCookieMonster::GetCookiesWithOptions(
120 const CookieOptions
& options
) {
125 void DelayedCookieMonster::GetCookiesWithInfo(
127 const CookieOptions
& options
,
128 std::string
* cookie_line
,
129 std::vector
<CookieInfo
>* cookie_infos
) {
133 void DelayedCookieMonster::DeleteCookie(const GURL
& url
,
134 const std::string
& cookie_name
) {
138 void DelayedCookieMonster::DeleteCookieAsync(const GURL
& url
,
139 const std::string
& cookie_name
,
140 const base::Closure
& callback
) {
144 void DelayedCookieMonster::DeleteAllCreatedBetweenAsync(
145 const base::Time
& delete_begin
,
146 const base::Time
& delete_end
,
147 const DeleteCallback
& callback
) {
151 void DelayedCookieMonster::DeleteSessionCookiesAsync(const DeleteCallback
&) {
155 CookieMonster
* DelayedCookieMonster::GetCookieMonster() {
156 return cookie_monster_
;