Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: net/url_request/url_request_test_util.cc

Issue 6995013: More progress towards removing content settings code from the content layer. We can't use Cookie... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments and sync Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_test_util.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/url_request/url_request_test_util.h" 5 #include "net/url_request/url_request_test_util.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/threading/thread.h" 10 #include "base/threading/thread.h"
11 #include "net/base/host_port_pair.h" 11 #include "net/base/host_port_pair.h"
12 #include "net/http/http_network_session.h" 12 #include "net/http/http_network_session.h"
13 13
14 TestCookiePolicy::TestCookiePolicy(int options_bit_mask)
15 : options_(options_bit_mask) {
16 }
17
18 TestCookiePolicy::~TestCookiePolicy() {}
19
20 int TestCookiePolicy::CanGetCookies(const GURL& url,
21 const GURL& first_party) const {
22 if (options_ & NO_GET_COOKIES)
23 return net::ERR_ACCESS_DENIED;
24
25 return net::OK;
26 }
27
28 int TestCookiePolicy::CanSetCookie(const GURL& url,
29 const GURL& first_party,
30 const std::string& cookie_line) const {
31 if (options_ & NO_SET_COOKIE)
32 return net::ERR_ACCESS_DENIED;
33
34 if (options_ & FORCE_SESSION)
35 return net::OK_FOR_SESSION_ONLY;
36
37 return net::OK;
38 }
39
40 TestURLRequestContext::TestURLRequestContext() 14 TestURLRequestContext::TestURLRequestContext()
41 : ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) { 15 : ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) {
42 context_storage_.set_host_resolver( 16 context_storage_.set_host_resolver(
43 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, 17 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism,
44 NULL)); 18 NULL));
45 context_storage_.set_proxy_service(net::ProxyService::CreateDirect()); 19 context_storage_.set_proxy_service(net::ProxyService::CreateDirect());
46 Init(); 20 Init();
47 } 21 }
48 22
49 TestURLRequestContext::TestURLRequestContext(const std::string& proxy) 23 TestURLRequestContext::TestURLRequestContext(const std::string& proxy)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 TestDelegate::TestDelegate() 80 TestDelegate::TestDelegate()
107 : cancel_in_rr_(false), 81 : cancel_in_rr_(false),
108 cancel_in_rs_(false), 82 cancel_in_rs_(false),
109 cancel_in_rd_(false), 83 cancel_in_rd_(false),
110 cancel_in_rd_pending_(false), 84 cancel_in_rd_pending_(false),
111 cancel_in_getcookiesblocked_(false), 85 cancel_in_getcookiesblocked_(false),
112 cancel_in_setcookieblocked_(false), 86 cancel_in_setcookieblocked_(false),
113 quit_on_complete_(true), 87 quit_on_complete_(true),
114 quit_on_redirect_(false), 88 quit_on_redirect_(false),
115 allow_certificate_errors_(false), 89 allow_certificate_errors_(false),
90 cookie_options_bit_mask_(0),
116 response_started_count_(0), 91 response_started_count_(0),
117 received_bytes_count_(0), 92 received_bytes_count_(0),
118 received_redirect_count_(0), 93 received_redirect_count_(0),
119 blocked_get_cookies_count_(0), 94 blocked_get_cookies_count_(0),
120 blocked_set_cookie_count_(0), 95 blocked_set_cookie_count_(0),
121 set_cookie_count_(0), 96 set_cookie_count_(0),
122 received_data_before_response_(false), 97 received_data_before_response_(false),
123 request_failed_(false), 98 request_failed_(false),
124 have_certificate_errors_(false), 99 have_certificate_errors_(false),
125 buf_(new net::IOBuffer(kBufferSize)) { 100 buf_(new net::IOBuffer(kBufferSize)) {
(...skipping 28 matching lines...) Expand all
154 // The caller can control whether it needs all SSL requests to go through, 129 // The caller can control whether it needs all SSL requests to go through,
155 // independent of any possible errors, or whether it wants SSL errors to 130 // independent of any possible errors, or whether it wants SSL errors to
156 // cancel the request. 131 // cancel the request.
157 have_certificate_errors_ = true; 132 have_certificate_errors_ = true;
158 if (allow_certificate_errors_) 133 if (allow_certificate_errors_)
159 request->ContinueDespiteLastError(); 134 request->ContinueDespiteLastError();
160 else 135 else
161 request->Cancel(); 136 request->Cancel();
162 } 137 }
163 138
164 void TestDelegate::OnGetCookies(net::URLRequest* request, 139 bool TestDelegate::CanGetCookies(net::URLRequest* request) {
165 bool blocked_by_policy) { 140 bool allow = true;
166 if (blocked_by_policy) { 141 if (cookie_options_bit_mask_ & NO_GET_COOKIES)
142 allow = false;
143
144 if (!allow) {
167 blocked_get_cookies_count_++; 145 blocked_get_cookies_count_++;
168 if (cancel_in_getcookiesblocked_) 146 if (cancel_in_getcookiesblocked_)
169 request->Cancel(); 147 request->Cancel();
170 } 148 }
149
150 return allow;
171 } 151 }
172 152
173 void TestDelegate::OnSetCookie(net::URLRequest* request, 153 bool TestDelegate::CanSetCookie(net::URLRequest* request,
174 const std::string& cookie_line, 154 const std::string& cookie_line,
175 const net::CookieOptions& options, 155 net::CookieOptions* options) {
176 bool blocked_by_policy) { 156 bool allow = true;
177 if (blocked_by_policy) { 157 if (cookie_options_bit_mask_ & NO_SET_COOKIE)
158 allow = false;
159
160 if (cookie_options_bit_mask_ & FORCE_SESSION)
161 options->set_force_session();
162
163
164 if (!allow) {
178 blocked_set_cookie_count_++; 165 blocked_set_cookie_count_++;
179 if (cancel_in_setcookieblocked_) 166 if (cancel_in_setcookieblocked_)
180 request->Cancel(); 167 request->Cancel();
181 } else { 168 } else {
182 set_cookie_count_++; 169 set_cookie_count_++;
183 } 170 }
171
172 return allow;
184 } 173 }
185 174
186 void TestDelegate::OnResponseStarted(net::URLRequest* request) { 175 void TestDelegate::OnResponseStarted(net::URLRequest* request) {
187 // It doesn't make sense for the request to have IO pending at this point. 176 // It doesn't make sense for the request to have IO pending at this point.
188 DCHECK(!request->status().is_io_pending()); 177 DCHECK(!request->status().is_io_pending());
189 178
190 response_started_count_++; 179 response_started_count_++;
191 if (cancel_in_rs_) { 180 if (cancel_in_rs_) {
192 request->Cancel(); 181 request->Cancel();
193 OnResponseCompleted(request); 182 OnResponseCompleted(request);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 291 }
303 292
304 net::URLRequestJob* TestNetworkDelegate::OnMaybeCreateURLRequestJob( 293 net::URLRequestJob* TestNetworkDelegate::OnMaybeCreateURLRequestJob(
305 net::URLRequest* request) { 294 net::URLRequest* request) {
306 return NULL; 295 return NULL;
307 } 296 }
308 297
309 void TestNetworkDelegate::OnPACScriptError(int line_number, 298 void TestNetworkDelegate::OnPACScriptError(int line_number,
310 const string16& error) { 299 const string16& error) {
311 } 300 }
OLDNEW
« no previous file with comments | « net/url_request/url_request_test_util.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698