Don't force SPDY2 (hence we will use the default SPDY3).
[chromium-blink-merge.git] / net / cookies / cookie_store_test_helpers.cc
blob3f19d8d1273166a1228e1bbe1ec973ff649c6cd1
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"
7 #include "base/bind.h"
8 #include "base/message_loop.h"
10 namespace net {
12 const int kDelayedTime = 0;
14 DelayedCookieMonster::DelayedCookieMonster()
15 : cookie_monster_(new CookieMonster(NULL, NULL)),
16 did_run_(false),
17 result_(false) {
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;
28 did_run_ = true;
31 void DelayedCookieMonster::SetCookiesInternalCallback(bool result) {
32 result_ = result;
33 did_run_ = true;
36 void DelayedCookieMonster::GetCookiesWithOptionsInternalCallback(
37 const std::string& cookie) {
38 cookie_ = cookie;
39 did_run_ = true;
42 void DelayedCookieMonster::GetCookiesWithInfoAsync(
43 const GURL& url,
44 const CookieOptions& options,
45 const CookieMonster::GetCookieInfoCallback& callback) {
46 did_run_ = false;
47 cookie_monster_->GetCookiesWithInfoAsync(
48 url, options,
49 base::Bind(&DelayedCookieMonster::GetCookiesInternalCallback,
50 base::Unretained(this)));
51 DCHECK_EQ(did_run_, true);
52 MessageLoop::current()->PostDelayedTask(
53 FROM_HERE,
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) {
63 did_run_ = false;
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(
70 FROM_HERE,
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) {
79 did_run_ = false;
80 cookie_monster_->GetCookiesWithOptionsAsync(
81 url, options,
82 base::Bind(&DelayedCookieMonster::GetCookiesWithOptionsInternalCallback,
83 base::Unretained(this)));
84 DCHECK_EQ(did_run_, true);
85 MessageLoop::current()->PostDelayedTask(
86 FROM_HERE,
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(
111 const GURL& url,
112 const std::string& cookie_line,
113 const CookieOptions& options) {
114 ADD_FAILURE();
115 return false;
118 std::string DelayedCookieMonster::GetCookiesWithOptions(
119 const GURL& url,
120 const CookieOptions& options) {
121 ADD_FAILURE();
122 return "";
125 void DelayedCookieMonster::GetCookiesWithInfo(
126 const GURL& url,
127 const CookieOptions& options,
128 std::string* cookie_line,
129 std::vector<CookieInfo>* cookie_infos) {
130 ADD_FAILURE();
133 void DelayedCookieMonster::DeleteCookie(const GURL& url,
134 const std::string& cookie_name) {
135 ADD_FAILURE();
138 void DelayedCookieMonster::DeleteCookieAsync(const GURL& url,
139 const std::string& cookie_name,
140 const base::Closure& callback) {
141 ADD_FAILURE();
144 void DelayedCookieMonster::DeleteAllCreatedBetweenAsync(
145 const base::Time& delete_begin,
146 const base::Time& delete_end,
147 const DeleteCallback& callback) {
148 ADD_FAILURE();
151 void DelayedCookieMonster::DeleteSessionCookiesAsync(const DeleteCallback&) {
152 ADD_FAILURE();
155 CookieMonster* DelayedCookieMonster::GetCookieMonster() {
156 return cookie_monster_;
159 } // namespace net