summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_test_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'net/url_request/url_request_test_util.cc')
-rw-r--r--net/url_request/url_request_test_util.cc159
1 files changed, 78 insertions, 81 deletions
diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc
index 9648b78..34335ae 100644
--- a/net/url_request/url_request_test_util.cc
+++ b/net/url_request/url_request_test_util.cc
@@ -20,11 +20,9 @@
#include "net/url_request/url_request_job_factory_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace net {
-
namespace {
-// These constants put the NetworkDelegate events of TestNetworkDelegate
+// These constants put the net::NetworkDelegate events of TestNetworkDelegate
// into an order. They are used in conjunction with
// |TestNetworkDelegate::next_states_| to check that we do not send
// events in the wrong order.
@@ -65,34 +63,34 @@ void TestURLRequestContext::Init() {
if (!host_resolver())
context_storage_.set_host_resolver(
- scoped_ptr<HostResolver>(new MockCachingHostResolver()));
+ scoped_ptr<net::HostResolver>(new net::MockCachingHostResolver()));
if (!proxy_service())
- context_storage_.set_proxy_service(ProxyService::CreateDirect());
+ context_storage_.set_proxy_service(net::ProxyService::CreateDirect());
if (!cert_verifier())
- context_storage_.set_cert_verifier(CertVerifier::CreateDefault());
+ context_storage_.set_cert_verifier(net::CertVerifier::CreateDefault());
if (!ftp_transaction_factory()) {
#if !defined(DISABLE_FTP_SUPPORT)
context_storage_.set_ftp_transaction_factory(
- new FtpNetworkLayer(host_resolver()));
+ new net::FtpNetworkLayer(host_resolver()));
#else
context_storage_.set_ftp_transaction_factory(NULL);
#endif // !defined(DISABLE_FTP_SUPPORT)
}
if (!ssl_config_service())
- context_storage_.set_ssl_config_service(new SSLConfigServiceDefaults);
+ context_storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults);
if (!http_auth_handler_factory()) {
context_storage_.set_http_auth_handler_factory(
- HttpAuthHandlerFactory::CreateDefault(host_resolver()));
+ net::HttpAuthHandlerFactory::CreateDefault(host_resolver()));
}
if (!http_server_properties()) {
context_storage_.set_http_server_properties(
- new HttpServerPropertiesImpl);
+ new net::HttpServerPropertiesImpl);
}
if (!transport_security_state()) {
context_storage_.set_transport_security_state(
- new TransportSecurityState());
+ new net::TransportSecurityState());
}
- HttpNetworkSession::Params params;
+ net::HttpNetworkSession::Params params;
params.host_resolver = host_resolver();
params.cert_verifier = cert_verifier();
params.proxy_service = proxy_service();
@@ -102,33 +100,33 @@ void TestURLRequestContext::Init() {
params.http_server_properties = http_server_properties();
if (!http_transaction_factory()) {
- context_storage_.set_http_transaction_factory(new HttpCache(
- new HttpNetworkSession(params),
- HttpCache::DefaultBackend::InMemory(0)));
+ context_storage_.set_http_transaction_factory(new net::HttpCache(
+ new net::HttpNetworkSession(params),
+ net::HttpCache::DefaultBackend::InMemory(0)));
}
// In-memory cookie store.
if (!cookie_store())
- context_storage_.set_cookie_store(new CookieMonster(NULL, NULL));
+ context_storage_.set_cookie_store(new net::CookieMonster(NULL, NULL));
// In-memory origin bound cert service.
if (!server_bound_cert_service()) {
context_storage_.set_server_bound_cert_service(
- new ServerBoundCertService(
- new DefaultServerBoundCertStore(NULL),
+ new net::ServerBoundCertService(
+ new net::DefaultServerBoundCertStore(NULL),
base::WorkerPool::GetTaskRunner(true)));
}
if (!http_user_agent_settings()) {
context_storage_.set_http_user_agent_settings(
- new StaticHttpUserAgentSettings(
+ new net::StaticHttpUserAgentSettings(
"en-us,fr", "iso-8859-1,*,utf-8", EmptyString()));
}
if (!job_factory())
- context_storage_.set_job_factory(new URLRequestJobFactoryImpl);
+ context_storage_.set_job_factory(new net::URLRequestJobFactoryImpl);
}
TestURLRequest::TestURLRequest(const GURL& url,
Delegate* delegate,
TestURLRequestContext* context)
- : URLRequest(url, delegate, context) {
+ : net::URLRequest(url, delegate, context) {
}
TestURLRequest::~TestURLRequest() {
@@ -176,12 +174,12 @@ TestDelegate::TestDelegate()
have_certificate_errors_(false),
certificate_errors_are_fatal_(false),
auth_required_(false),
- buf_(new IOBuffer(kBufferSize)) {
+ buf_(new net::IOBuffer(kBufferSize)) {
}
TestDelegate::~TestDelegate() {}
-void TestDelegate::OnReceivedRedirect(URLRequest* request,
+void TestDelegate::OnReceivedRedirect(net::URLRequest* request,
const GURL& new_url,
bool* defer_redirect) {
EXPECT_TRUE(request->is_redirecting());
@@ -194,8 +192,8 @@ void TestDelegate::OnReceivedRedirect(URLRequest* request,
}
}
-void TestDelegate::OnAuthRequired(URLRequest* request,
- AuthChallengeInfo* auth_info) {
+void TestDelegate::OnAuthRequired(net::URLRequest* request,
+ net::AuthChallengeInfo* auth_info) {
auth_required_ = true;
if (!credentials_.Empty()) {
request->SetAuth(credentials_);
@@ -204,8 +202,8 @@ void TestDelegate::OnAuthRequired(URLRequest* request,
}
}
-void TestDelegate::OnSSLCertificateError(URLRequest* request,
- const SSLInfo& ssl_info,
+void TestDelegate::OnSSLCertificateError(net::URLRequest* request,
+ const net::SSLInfo& ssl_info,
bool fatal) {
// The caller can control whether it needs all SSL requests to go through,
// independent of any possible errors, or whether it wants SSL errors to
@@ -218,7 +216,7 @@ void TestDelegate::OnSSLCertificateError(URLRequest* request,
request->Cancel();
}
-void TestDelegate::OnResponseStarted(URLRequest* request) {
+void TestDelegate::OnResponseStarted(net::URLRequest* request) {
// It doesn't make sense for the request to have IO pending at this point.
DCHECK(!request->status().is_io_pending());
EXPECT_FALSE(request->is_redirecting());
@@ -228,8 +226,8 @@ void TestDelegate::OnResponseStarted(URLRequest* request) {
request->Cancel();
OnResponseCompleted(request);
} else if (!request->status().is_success()) {
- DCHECK(request->status().status() == URLRequestStatus::FAILED ||
- request->status().status() == URLRequestStatus::CANCELED);
+ DCHECK(request->status().status() == net::URLRequestStatus::FAILED ||
+ request->status().status() == net::URLRequestStatus::CANCELED);
request_failed_ = true;
OnResponseCompleted(request);
} else {
@@ -242,7 +240,7 @@ void TestDelegate::OnResponseStarted(URLRequest* request) {
}
}
-void TestDelegate::OnReadCompleted(URLRequest* request, int bytes_read) {
+void TestDelegate::OnReadCompleted(net::URLRequest* request, int bytes_read) {
// It doesn't make sense for the request to have IO pending at this point.
DCHECK(!request->status().is_io_pending());
@@ -278,7 +276,7 @@ void TestDelegate::OnReadCompleted(URLRequest* request, int bytes_read) {
request->Cancel();
}
-void TestDelegate::OnResponseCompleted(URLRequest* request) {
+void TestDelegate::OnResponseCompleted(net::URLRequest* request) {
if (quit_on_complete_)
MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
}
@@ -311,8 +309,8 @@ void TestNetworkDelegate::InitRequestStatesIfNew(int request_id) {
}
int TestNetworkDelegate::OnBeforeURLRequest(
- URLRequest* request,
- const CompletionCallback& callback,
+ net::URLRequest* request,
+ const net::CompletionCallback& callback,
GURL* new_url ) {
int req_id = request->identifier();
InitRequestStatesIfNew(req_id);
@@ -326,13 +324,13 @@ int TestNetworkDelegate::OnBeforeURLRequest(
kStageCompletedError | // request canceled by delegate
kStageAuthRequired; // Auth can come next for FTP requests
created_requests_++;
- return OK;
+ return net::OK;
}
int TestNetworkDelegate::OnBeforeSendHeaders(
- URLRequest* request,
- const CompletionCallback& callback,
- HttpRequestHeaders* headers) {
+ net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ net::HttpRequestHeaders* headers) {
int req_id = request->identifier();
InitRequestStatesIfNew(req_id);
event_order_[req_id] += "OnBeforeSendHeaders\n";
@@ -342,12 +340,12 @@ int TestNetworkDelegate::OnBeforeSendHeaders(
kStageSendHeaders |
kStageCompletedError; // request canceled by delegate
- return OK;
+ return net::OK;
}
void TestNetworkDelegate::OnSendHeaders(
- URLRequest* request,
- const HttpRequestHeaders& headers) {
+ net::URLRequest* request,
+ const net::HttpRequestHeaders& headers) {
int req_id = request->identifier();
InitRequestStatesIfNew(req_id);
event_order_[req_id] += "OnSendHeaders\n";
@@ -359,10 +357,10 @@ void TestNetworkDelegate::OnSendHeaders(
}
int TestNetworkDelegate::OnHeadersReceived(
- URLRequest* request,
- const CompletionCallback& callback,
- const HttpResponseHeaders* original_response_headers,
- scoped_refptr<HttpResponseHeaders>* override_response_headers) {
+ net::URLRequest* request,
+ const net::CompletionCallback& callback,
+ const net::HttpResponseHeaders* original_response_headers,
+ scoped_refptr<net::HttpResponseHeaders>* override_response_headers) {
int req_id = request->identifier();
event_order_[req_id] += "OnHeadersReceived\n";
InitRequestStatesIfNew(req_id);
@@ -378,10 +376,10 @@ int TestNetworkDelegate::OnHeadersReceived(
// layer before the URLRequest reports that a response has started.
next_states_[req_id] |= kStageBeforeSendHeaders;
- return OK;
+ return net::OK;
}
-void TestNetworkDelegate::OnBeforeRedirect(URLRequest* request,
+void TestNetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
const GURL& new_location) {
int req_id = request->identifier();
InitRequestStatesIfNew(req_id);
@@ -399,24 +397,24 @@ void TestNetworkDelegate::OnBeforeRedirect(URLRequest* request,
next_states_[req_id] |= kStageResponseStarted;
}
-void TestNetworkDelegate::OnResponseStarted(URLRequest* request) {
+void TestNetworkDelegate::OnResponseStarted(net::URLRequest* request) {
int req_id = request->identifier();
InitRequestStatesIfNew(req_id);
event_order_[req_id] += "OnResponseStarted\n";
EXPECT_TRUE(next_states_[req_id] & kStageResponseStarted) <<
event_order_[req_id];
next_states_[req_id] = kStageCompletedSuccess | kStageCompletedError;
- if (request->status().status() == URLRequestStatus::FAILED) {
+ if (request->status().status() == net::URLRequestStatus::FAILED) {
error_count_++;
last_error_ = request->status().error();
}
}
-void TestNetworkDelegate::OnRawBytesRead(const URLRequest& request,
+void TestNetworkDelegate::OnRawBytesRead(const net::URLRequest& request,
int bytes_read) {
}
-void TestNetworkDelegate::OnCompleted(URLRequest* request, bool started) {
+void TestNetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
int req_id = request->identifier();
InitRequestStatesIfNew(req_id);
event_order_[req_id] += "OnCompleted\n";
@@ -431,13 +429,14 @@ void TestNetworkDelegate::OnCompleted(URLRequest* request, bool started) {
event_order_[req_id];
next_states_[req_id] = kStageURLRequestDestroyed;
completed_requests_++;
- if (request->status().status() == URLRequestStatus::FAILED) {
+ if (request->status().status() == net::URLRequestStatus::FAILED) {
error_count_++;
last_error_ = request->status().error();
}
}
-void TestNetworkDelegate::OnURLRequestDestroyed(URLRequest* request) {
+void TestNetworkDelegate::OnURLRequestDestroyed(
+ net::URLRequest* request) {
int req_id = request->identifier();
InitRequestStatesIfNew(req_id);
event_order_[req_id] += "OnURLRequestDestroyed\n";
@@ -451,11 +450,11 @@ void TestNetworkDelegate::OnPACScriptError(int line_number,
const string16& error) {
}
-NetworkDelegate::AuthRequiredResponse TestNetworkDelegate::OnAuthRequired(
- URLRequest* request,
- const AuthChallengeInfo& auth_info,
+net::NetworkDelegate::AuthRequiredResponse TestNetworkDelegate::OnAuthRequired(
+ net::URLRequest* request,
+ const net::AuthChallengeInfo& auth_info,
const AuthCallback& callback,
- AuthCredentials* credentials) {
+ net::AuthCredentials* credentials) {
int req_id = request->identifier();
InitRequestStatesIfNew(req_id);
event_order_[req_id] += "OnAuthRequired\n";
@@ -467,11 +466,11 @@ NetworkDelegate::AuthRequiredResponse TestNetworkDelegate::OnAuthRequired(
kStageResponseStarted | // data: URLs do not trigger sending headers
kStageBeforeRedirect | // a delegate can trigger a redirection
kStageCompletedError; // request cancelled before callback
- return NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
+ return net::NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
}
-bool TestNetworkDelegate::OnCanGetCookies(const URLRequest& request,
- const CookieList& cookie_list) {
+bool TestNetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
+ const net::CookieList& cookie_list) {
bool allow = true;
if (cookie_options_bit_mask_ & NO_GET_COOKIES)
allow = false;
@@ -483,9 +482,9 @@ bool TestNetworkDelegate::OnCanGetCookies(const URLRequest& request,
return allow;
}
-bool TestNetworkDelegate::OnCanSetCookie(const URLRequest& request,
+bool TestNetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
const std::string& cookie_line,
- CookieOptions* options) {
+ net::CookieOptions* options) {
bool allow = true;
if (cookie_options_bit_mask_ & NO_SET_COOKIE)
allow = false;
@@ -499,24 +498,24 @@ bool TestNetworkDelegate::OnCanSetCookie(const URLRequest& request,
return allow;
}
-bool TestNetworkDelegate::OnCanAccessFile(const URLRequest& request,
+bool TestNetworkDelegate::OnCanAccessFile(const net::URLRequest& request,
const FilePath& path) const {
return true;
}
bool TestNetworkDelegate::OnCanThrottleRequest(
- const URLRequest& request) const {
+ const net::URLRequest& request) const {
return true;
}
int TestNetworkDelegate::OnBeforeSocketStreamConnect(
- SocketStream* socket,
- const CompletionCallback& callback) {
- return OK;
+ net::SocketStream* socket,
+ const net::CompletionCallback& callback) {
+ return net::OK;
}
void TestNetworkDelegate::OnRequestWaitStateChange(
- const URLRequest& request,
+ const net::URLRequest& request,
RequestWaitState state) {
}
@@ -543,29 +542,27 @@ const std::string& ScopedCustomUrlRequestTestHttpHost::value() {
TestJobInterceptor::TestJobInterceptor() : main_intercept_job_(NULL) {
}
-URLRequestJob* TestJobInterceptor::MaybeIntercept(
- URLRequest* request,
- NetworkDelegate* network_delegate) const {
- URLRequestJob* job = main_intercept_job_;
+net::URLRequestJob* TestJobInterceptor::MaybeIntercept(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const {
+ net::URLRequestJob* job = main_intercept_job_;
main_intercept_job_ = NULL;
return job;
}
-URLRequestJob* TestJobInterceptor::MaybeInterceptRedirect(
+net::URLRequestJob* TestJobInterceptor::MaybeInterceptRedirect(
const GURL& location,
- URLRequest* request,
- NetworkDelegate* network_delegate) const {
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const {
return NULL;
}
-URLRequestJob* TestJobInterceptor::MaybeInterceptResponse(
- URLRequest* request,
- NetworkDelegate* network_delegate) const {
+net::URLRequestJob* TestJobInterceptor::MaybeInterceptResponse(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const {
return NULL;
}
-void TestJobInterceptor::set_main_intercept_job(URLRequestJob* job) {
+void TestJobInterceptor::set_main_intercept_job(net::URLRequestJob* job) {
main_intercept_job_ = job;
}
-
-} // namespace net