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/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
14 const int kDelayedTime
= 0;
16 DelayedCookieMonster::DelayedCookieMonster()
17 : cookie_monster_(new CookieMonster(NULL
, NULL
)),
22 DelayedCookieMonster::~DelayedCookieMonster() {
25 void DelayedCookieMonster::SetCookiesInternalCallback(bool result
) {
30 void DelayedCookieMonster::GetCookiesWithOptionsInternalCallback(
31 const std::string
& cookie
) {
36 void DelayedCookieMonster::SetCookieWithOptionsAsync(
38 const std::string
& cookie_line
,
39 const CookieOptions
& options
,
40 const CookieMonster::SetCookiesCallback
& callback
) {
42 cookie_monster_
->SetCookieWithOptionsAsync(
43 url
, cookie_line
, options
,
44 base::Bind(&DelayedCookieMonster::SetCookiesInternalCallback
,
45 base::Unretained(this)));
46 DCHECK_EQ(did_run_
, true);
47 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
48 FROM_HERE
, base::Bind(&DelayedCookieMonster::InvokeSetCookiesCallback
,
49 base::Unretained(this), callback
),
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::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
65 base::Bind(&DelayedCookieMonster::InvokeGetCookieStringCallback
,
66 base::Unretained(this), callback
),
67 base::TimeDelta::FromMilliseconds(kDelayedTime
));
70 void DelayedCookieMonster::GetAllCookiesForURLAsync(
72 const GetCookieListCallback
& callback
) {
73 cookie_monster_
->GetAllCookiesForURLAsync(url
, callback
);
76 void DelayedCookieMonster::InvokeSetCookiesCallback(
77 const CookieMonster::SetCookiesCallback
& callback
) {
78 if (!callback
.is_null())
79 callback
.Run(result_
);
82 void DelayedCookieMonster::InvokeGetCookieStringCallback(
83 const CookieMonster::GetCookiesCallback
& callback
) {
84 if (!callback
.is_null())
85 callback
.Run(cookie_
);
88 bool DelayedCookieMonster::SetCookieWithOptions(
90 const std::string
& cookie_line
,
91 const CookieOptions
& options
) {
96 std::string
DelayedCookieMonster::GetCookiesWithOptions(
98 const CookieOptions
& options
) {
100 return std::string();
103 void DelayedCookieMonster::DeleteCookie(const GURL
& url
,
104 const std::string
& cookie_name
) {
108 void DelayedCookieMonster::DeleteCookieAsync(const GURL
& url
,
109 const std::string
& cookie_name
,
110 const base::Closure
& callback
) {
114 void DelayedCookieMonster::DeleteAllCreatedBetweenAsync(
115 const base::Time
& delete_begin
,
116 const base::Time
& delete_end
,
117 const DeleteCallback
& callback
) {
121 void DelayedCookieMonster::DeleteAllCreatedBetweenForHostAsync(
122 const base::Time delete_begin
,
123 const base::Time delete_end
,
125 const DeleteCallback
& callback
) {
129 void DelayedCookieMonster::DeleteSessionCookiesAsync(const DeleteCallback
&) {
133 CookieMonster
* DelayedCookieMonster::GetCookieMonster() {
134 return cookie_monster_
.get();
137 scoped_ptr
<CookieStore::CookieChangedSubscription
>
138 DelayedCookieMonster::AddCallbackForCookie(
140 const std::string
& name
,
141 const CookieChangedCallback
& callback
) {
143 return scoped_ptr
<CookieStore::CookieChangedSubscription
>();