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

Unified Diff: net/test/url_request/ssl_certificate_error_job.cc

Issue 1239543003: [Cronet] Surface SSL cert error through CronetURLRequestAdapter::OnSSLCertificateError (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add include Created 5 years, 5 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 | « net/test/url_request/ssl_certificate_error_job.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/test/url_request/ssl_certificate_error_job.cc
diff --git a/net/test/url_request/ssl_certificate_error_job.cc b/net/test/url_request/ssl_certificate_error_job.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8f2a12bef1020f2314e20ace117c73f0a7928744
--- /dev/null
+++ b/net/test/url_request/ssl_certificate_error_job.cc
@@ -0,0 +1,73 @@
+// Copyright 2015 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 "net/test/url_request/ssl_certificate_error_job.h"
+
+#include <string>
+
+#include "base/bind.h"
+#include "base/strings/stringprintf.h"
+#include "base/thread_task_runner_handle.h"
+#include "net/ssl/ssl_info.h"
+#include "net/url_request/url_request.h"
+#include "net/url_request/url_request_filter.h"
+#include "net/url_request/url_request_interceptor.h"
+
+namespace net {
+
+namespace {
+
+const char kMockHostname[] = "mock.ssl.cert.error.request";
+
+class MockJobInterceptor : public URLRequestInterceptor {
+ public:
+ MockJobInterceptor() {}
+ ~MockJobInterceptor() override {}
+
+ // URLRequestJobFactory::ProtocolHandler implementation:
+ URLRequestJob* MaybeInterceptRequest(
+ URLRequest* request,
+ NetworkDelegate* network_delegate) const override {
+ return new SSLCertificateErrorJob(request, network_delegate);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor);
+};
+
+} // namespace
+
+SSLCertificateErrorJob::SSLCertificateErrorJob(
+ URLRequest* request,
+ NetworkDelegate* network_delegate)
+ : URLRequestJob(request, network_delegate), weak_factory_(this) {
+}
+
+void SSLCertificateErrorJob::Start() {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&SSLCertificateErrorJob::NotifyError,
+ weak_factory_.GetWeakPtr()));
+}
+
+void SSLCertificateErrorJob::AddUrlHandler() {
+ URLRequestFilter* filter = URLRequestFilter::GetInstance();
+ filter->AddHostnameInterceptor(
+ "https", kMockHostname,
+ scoped_ptr<URLRequestInterceptor>(new MockJobInterceptor()));
+}
+
+GURL SSLCertificateErrorJob::GetMockUrl() {
+ return GURL(base::StringPrintf("https://%s", kMockHostname));
+}
+
+SSLCertificateErrorJob::~SSLCertificateErrorJob() {
+}
+
+void SSLCertificateErrorJob::NotifyError() {
+ SSLInfo info;
+ info.cert_status = CERT_STATUS_DATE_INVALID;
+ NotifySSLCertificateError(info, true);
+}
+
+} // namespace net
« no previous file with comments | « net/test/url_request/ssl_certificate_error_job.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698