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/message_loop.h"
12 const int kDelayedTime
= 0;
14 DelayedCookieMonster::DelayedCookieMonster()
15 : cookie_monster_(new CookieMonster(NULL
, NULL
)),
20 DelayedCookieMonster::~DelayedCookieMonster() {
23 void DelayedCookieMonster::SetCookiesInternalCallback(bool result
) {
28 void DelayedCookieMonster::GetCookiesWithOptionsInternalCallback(
29 const std::string
& cookie
) {
34 void DelayedCookieMonster::SetCookieWithOptionsAsync(
36 const std::string
& cookie_line
,
37 const CookieOptions
& options
,
38 const CookieMonster::SetCookiesCallback
& callback
) {
40 cookie_monster_
->SetCookieWithOptionsAsync(
41 url
, cookie_line
, options
,
42 base::Bind(&DelayedCookieMonster::SetCookiesInternalCallback
,
43 base::Unretained(this)));
44 DCHECK_EQ(did_run_
, true);
45 base::MessageLoop::current()->PostDelayedTask(
47 base::Bind(&DelayedCookieMonster::InvokeSetCookiesCallback
,
48 base::Unretained(this),
50 base::TimeDelta::FromMilliseconds(kDelayedTime
));
53 void DelayedCookieMonster::GetCookiesWithOptionsAsync(
55 const CookieOptions
& options
,
56 const CookieMonster::GetCookiesCallback
& callback
) {
58 cookie_monster_
->GetCookiesWithOptionsAsync(
60 base::Bind(&DelayedCookieMonster::GetCookiesWithOptionsInternalCallback
,
61 base::Unretained(this)));
62 DCHECK_EQ(did_run_
, true);
63 base::MessageLoop::current()->PostDelayedTask(
65 base::Bind(&DelayedCookieMonster::InvokeGetCookieStringCallback
,
66 base::Unretained(this),
68 base::TimeDelta::FromMilliseconds(kDelayedTime
));
71 void DelayedCookieMonster::GetAllCookiesForURLAsync(
73 const GetCookieListCallback
& callback
) {
74 cookie_monster_
->GetAllCookiesForURLAsync(url
, callback
);
77 void DelayedCookieMonster::InvokeSetCookiesCallback(
78 const CookieMonster::SetCookiesCallback
& callback
) {
79 if (!callback
.is_null())
80 callback
.Run(result_
);
83 void DelayedCookieMonster::InvokeGetCookieStringCallback(
84 const CookieMonster::GetCookiesCallback
& callback
) {
85 if (!callback
.is_null())
86 callback
.Run(cookie_
);
89 bool DelayedCookieMonster::SetCookieWithOptions(
91 const std::string
& cookie_line
,
92 const CookieOptions
& options
) {
97 std::string
DelayedCookieMonster::GetCookiesWithOptions(
99 const CookieOptions
& options
) {
101 return std::string();
104 void DelayedCookieMonster::DeleteCookie(const GURL
& url
,
105 const std::string
& cookie_name
) {
109 void DelayedCookieMonster::DeleteCookieAsync(const GURL
& url
,
110 const std::string
& cookie_name
,
111 const base::Closure
& callback
) {
115 void DelayedCookieMonster::DeleteAllCreatedBetweenAsync(
116 const base::Time
& delete_begin
,
117 const base::Time
& delete_end
,
118 const DeleteCallback
& callback
) {
122 void DelayedCookieMonster::DeleteAllCreatedBetweenForHostAsync(
123 const base::Time delete_begin
,
124 const base::Time delete_end
,
126 const DeleteCallback
& callback
) {
130 void DelayedCookieMonster::DeleteSessionCookiesAsync(const DeleteCallback
&) {
134 CookieMonster
* DelayedCookieMonster::GetCookieMonster() {
135 return cookie_monster_
.get();
138 scoped_ptr
<CookieStore::CookieChangedSubscription
>
139 DelayedCookieMonster::AddCallbackForCookie(
141 const std::string
& name
,
142 const CookieChangedCallback
& callback
) {
144 return scoped_ptr
<CookieStore::CookieChangedSubscription
>();