| OLD | NEW |
| 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/http/http_network_session.h" | 11 #include "net/http/http_network_session.h" |
| 12 | 12 |
| 13 TestCookiePolicy::TestCookiePolicy(int options_bit_mask) | 13 TestCookiePolicy::TestCookiePolicy(int options_bit_mask) |
| 14 : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), | 14 : options_(options_bit_mask) { |
| 15 options_(options_bit_mask), | |
| 16 callback_(NULL) { | |
| 17 } | 15 } |
| 18 | 16 |
| 19 TestCookiePolicy::~TestCookiePolicy() {} | 17 TestCookiePolicy::~TestCookiePolicy() {} |
| 20 | 18 |
| 21 int TestCookiePolicy::CanGetCookies(const GURL& url, | 19 int TestCookiePolicy::CanGetCookies(const GURL& url, |
| 22 const GURL& first_party, | 20 const GURL& first_party) const { |
| 23 net::CompletionCallback* callback) { | |
| 24 if ((options_ & ASYNC) && callback) { | |
| 25 callback_ = callback; | |
| 26 MessageLoop::current()->PostTask(FROM_HERE, | |
| 27 method_factory_.NewRunnableMethod( | |
| 28 &TestCookiePolicy::DoGetCookiesPolicy, url, first_party)); | |
| 29 return net::ERR_IO_PENDING; | |
| 30 } | |
| 31 | |
| 32 if (options_ & NO_GET_COOKIES) | 21 if (options_ & NO_GET_COOKIES) |
| 33 return net::ERR_ACCESS_DENIED; | 22 return net::ERR_ACCESS_DENIED; |
| 34 | 23 |
| 35 return net::OK; | 24 return net::OK; |
| 36 } | 25 } |
| 37 | 26 |
| 38 int TestCookiePolicy::CanSetCookie(const GURL& url, | 27 int TestCookiePolicy::CanSetCookie(const GURL& url, |
| 39 const GURL& first_party, | 28 const GURL& first_party, |
| 40 const std::string& cookie_line, | 29 const std::string& cookie_line) const { |
| 41 net::CompletionCallback* callback) { | |
| 42 if ((options_ & ASYNC) && callback) { | |
| 43 callback_ = callback; | |
| 44 MessageLoop::current()->PostTask(FROM_HERE, | |
| 45 method_factory_.NewRunnableMethod( | |
| 46 &TestCookiePolicy::DoSetCookiePolicy, url, first_party, | |
| 47 cookie_line)); | |
| 48 return net::ERR_IO_PENDING; | |
| 49 } | |
| 50 | |
| 51 if (options_ & NO_SET_COOKIE) | 30 if (options_ & NO_SET_COOKIE) |
| 52 return net::ERR_ACCESS_DENIED; | 31 return net::ERR_ACCESS_DENIED; |
| 53 | 32 |
| 54 if (options_ & FORCE_SESSION) | 33 if (options_ & FORCE_SESSION) |
| 55 return net::OK_FOR_SESSION_ONLY; | 34 return net::OK_FOR_SESSION_ONLY; |
| 56 | 35 |
| 57 return net::OK; | 36 return net::OK; |
| 58 } | 37 } |
| 59 | 38 |
| 60 void TestCookiePolicy::DoGetCookiesPolicy(const GURL& url, | |
| 61 const GURL& first_party) { | |
| 62 int policy = CanGetCookies(url, first_party, NULL); | |
| 63 | |
| 64 DCHECK(callback_); | |
| 65 net::CompletionCallback* callback = callback_; | |
| 66 callback_ = NULL; | |
| 67 callback->Run(policy); | |
| 68 } | |
| 69 | |
| 70 void TestCookiePolicy::DoSetCookiePolicy(const GURL& url, | |
| 71 const GURL& first_party, | |
| 72 const std::string& cookie_line) { | |
| 73 int policy = CanSetCookie(url, first_party, cookie_line, NULL); | |
| 74 | |
| 75 DCHECK(callback_); | |
| 76 net::CompletionCallback* callback = callback_; | |
| 77 callback_ = NULL; | |
| 78 callback->Run(policy); | |
| 79 } | |
| 80 | |
| 81 | |
| 82 TestURLRequestContext::TestURLRequestContext() | 39 TestURLRequestContext::TestURLRequestContext() |
| 83 : ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) { | 40 : ALLOW_THIS_IN_INITIALIZER_LIST(context_storage_(this)) { |
| 84 context_storage_.set_host_resolver( | 41 context_storage_.set_host_resolver( |
| 85 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, | 42 net::CreateSystemHostResolver(net::HostResolver::kDefaultParallelism, |
| 86 NULL, NULL)); | 43 NULL, NULL)); |
| 87 context_storage_.set_proxy_service(net::ProxyService::CreateDirect()); | 44 context_storage_.set_proxy_service(net::ProxyService::CreateDirect()); |
| 88 Init(); | 45 Init(); |
| 89 } | 46 } |
| 90 | 47 |
| 91 TestURLRequestContext::TestURLRequestContext(const std::string& proxy) | 48 TestURLRequestContext::TestURLRequestContext(const std::string& proxy) |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 280 } |
| 324 } | 281 } |
| 325 | 282 |
| 326 void TestNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { | 283 void TestNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { |
| 327 } | 284 } |
| 328 | 285 |
| 329 net::URLRequestJob* TestNetworkDelegate::OnMaybeCreateURLRequestJob( | 286 net::URLRequestJob* TestNetworkDelegate::OnMaybeCreateURLRequestJob( |
| 330 net::URLRequest* request) { | 287 net::URLRequest* request) { |
| 331 return NULL; | 288 return NULL; |
| 332 } | 289 } |
| OLD | NEW |