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

Unified Diff: components/cronet/android/test/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: Added a test 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
Index: components/cronet/android/test/ssl_certificate_error_job.cc
diff --git a/components/cronet/android/test/ssl_certificate_error_job.cc b/components/cronet/android/test/ssl_certificate_error_job.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5e1dca509bd8337f099c8ae0f3a6749ee4c63246
--- /dev/null
+++ b/components/cronet/android/test/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 "ssl_certificate_error_job.h"
+
+#include "base/bind.h"
+#include "base/strings/stringprintf.h"
+#include "base/thread_task_runner_handle.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 cronet {
+
+namespace {
+
+const char kMockHostname[] = "mock.ssl.cert.error.request";
+
+class MockJobInterceptor : public net::URLRequestInterceptor {
+ public:
+ MockJobInterceptor() {}
+ ~MockJobInterceptor() override {}
+
+ // net::URLRequestJobFactory::ProtocolHandler implementation:
+ net::URLRequestJob* MaybeInterceptRequest(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate) const override {
+ return new SSLCertificateErrorJob(request, network_delegate);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor);
+};
+
+} // namespace
+
+SSLCertificateErrorJob::SSLCertificateErrorJob(
+ net::URLRequest* request,
+ net::NetworkDelegate* network_delegate)
+ : net::URLRequestTestJob(request, network_delegate, "", "", true),
+ weak_factory_(this) {
+}
+
+void SSLCertificateErrorJob::Start() {
+ base::ThreadTaskRunnerHandle::Get()->PostTask(
+ FROM_HERE, base::Bind(&SSLCertificateErrorJob::NotifyError,
+ weak_factory_.GetWeakPtr()));
+}
+
+void SSLCertificateErrorJob::NotifyError() {
+ net::SSLInfo info;
+ info.cert_status = net::CERT_STATUS_DATE_INVALID;
+ NotifySSLCertificateError(info, true);
+}
+
+// static
+void SSLCertificateErrorJob::AddUrlHandler() {
+ net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance();
+ filter->AddHostnameInterceptor(
+ "https", kMockHostname,
+ scoped_ptr<net::URLRequestInterceptor>(new MockJobInterceptor()));
+}
+
+// static
mmenke 2015/07/17 19:29:59 "// static" is no longer needed before static meth
xunjieli 2015/07/17 20:15:20 Done.
+GURL SSLCertificateErrorJob::GetMockUrl() {
+ return GURL(base::StringPrintf("https://%s", kMockHostname));
+}
+
+SSLCertificateErrorJob::~SSLCertificateErrorJob() {
mmenke 2015/07/17 19:29:59 nit: Definition order should match the declaratio
xunjieli 2015/07/17 20:15:20 Done.
+}
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698