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

Unified Diff: content/test/net/url_request_failed_job.cc

Issue 9704023: Replace URLRequestFailedDnsJob with URLRequestFailedJob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix weak ptr factory usage Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/net/url_request_failed_job.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/net/url_request_failed_job.cc
===================================================================
--- content/test/net/url_request_failed_job.cc (revision 126703)
+++ content/test/net/url_request_failed_job.cc (working copy)
@@ -1,47 +1,87 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/test/net/url_request_failed_dns_job.h"
+#include "content/test/net/url_request_failed_job.h"
#include "base/bind.h"
-#include "base/compiler_specific.h"
+#include "base/logging.h"
#include "base/message_loop.h"
-#include "googleurl/src/gurl.h"
+#include "base/string_number_conversions.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_filter.h"
-const char URLRequestFailedDnsJob::kTestUrl[] =
- "http://url.handled.by.fake.dns/";
+namespace {
-URLRequestFailedDnsJob::URLRequestFailedDnsJob(net::URLRequest* request)
+const char kMockHostname[] = "mock.failed.request";
+
+// Gets the numeric net error code from URL of the form:
+// scheme://kMockHostname/error_code. The error code must be a valid
+// net error code, and not net::OK or net::ERR_IO_PENDING.
+int GetErrorCode(net::URLRequest* request) {
+ int net_error;
+ std::string path = request->url().path();
+ if (path[0] == '/' && base::StringToInt(path.c_str() + 1, &net_error)) {
+ CHECK_LT(net_error, 0);
+ CHECK_NE(net_error, net::ERR_IO_PENDING);
+ return net_error;
+ }
+ NOTREACHED();
+ return net::ERR_UNEXPECTED;
+}
+
+GURL GetMockUrl(const std::string& scheme, int net_error) {
+ CHECK_LT(net_error, 0);
+ CHECK_NE(net_error, net::ERR_IO_PENDING);
+ return GURL(scheme + "://" + kMockHostname + "/" +
+ base::IntToString(net_error));
+}
+
+} // namespace
+
+URLRequestFailedJob::URLRequestFailedJob(net::URLRequest* request,
+ int net_error)
: net::URLRequestJob(request),
+ net_error_(net_error),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {}
-URLRequestFailedDnsJob::~URLRequestFailedDnsJob() {}
+URLRequestFailedJob::~URLRequestFailedJob() {}
-void URLRequestFailedDnsJob::Start() {
+void URLRequestFailedJob::Start() {
MessageLoop::current()->PostTask(
FROM_HERE,
- base::Bind(&URLRequestFailedDnsJob::StartAsync,
+ base::Bind(&URLRequestFailedJob::StartAsync,
weak_factory_.GetWeakPtr()));
}
// static
-void URLRequestFailedDnsJob::AddUrlHandler() {
+void URLRequestFailedJob::AddUrlHandler() {
+ // Add kMockHostname to net::URLRequestFilter for HTTP and HTTPS.
net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
- filter->AddUrlHandler(GURL(kTestUrl),
- &URLRequestFailedDnsJob::Factory);
+ filter->AddHostnameHandler("http", kMockHostname,
+ URLRequestFailedJob::Factory);
+ filter->AddHostnameHandler("https", kMockHostname,
+ URLRequestFailedJob::Factory);
}
-/*static */
-net::URLRequestJob* URLRequestFailedDnsJob::Factory(net::URLRequest* request,
+// static
+GURL URLRequestFailedJob::GetMockHttpUrl(int net_error) {
+ return GetMockUrl("http", net_error);
+}
+
+// static
+GURL URLRequestFailedJob::GetMockHttpsUrl(int net_error) {
+ return GetMockUrl("https", net_error);
+}
+
+// static
+net::URLRequestJob* URLRequestFailedJob::Factory(net::URLRequest* request,
const std::string& scheme) {
- return new URLRequestFailedDnsJob(request);
+ return new URLRequestFailedJob(request, GetErrorCode(request));
}
-void URLRequestFailedDnsJob::StartAsync() {
+void URLRequestFailedJob::StartAsync() {
NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED,
- net::ERR_NAME_NOT_RESOLVED));
+ net_error_));
}
« no previous file with comments | « content/test/net/url_request_failed_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698