Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / net / test / url_request / ssl_certificate_error_job.cc
blob8f2a12bef1020f2314e20ace117c73f0a7928744
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/test/url_request/ssl_certificate_error_job.h"
7 #include <string>
9 #include "base/bind.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "net/ssl/ssl_info.h"
13 #include "net/url_request/url_request.h"
14 #include "net/url_request/url_request_filter.h"
15 #include "net/url_request/url_request_interceptor.h"
17 namespace net {
19 namespace {
21 const char kMockHostname[] = "mock.ssl.cert.error.request";
23 class MockJobInterceptor : public URLRequestInterceptor {
24 public:
25 MockJobInterceptor() {}
26 ~MockJobInterceptor() override {}
28 // URLRequestJobFactory::ProtocolHandler implementation:
29 URLRequestJob* MaybeInterceptRequest(
30 URLRequest* request,
31 NetworkDelegate* network_delegate) const override {
32 return new SSLCertificateErrorJob(request, network_delegate);
35 private:
36 DISALLOW_COPY_AND_ASSIGN(MockJobInterceptor);
39 } // namespace
41 SSLCertificateErrorJob::SSLCertificateErrorJob(
42 URLRequest* request,
43 NetworkDelegate* network_delegate)
44 : URLRequestJob(request, network_delegate), weak_factory_(this) {
47 void SSLCertificateErrorJob::Start() {
48 base::ThreadTaskRunnerHandle::Get()->PostTask(
49 FROM_HERE, base::Bind(&SSLCertificateErrorJob::NotifyError,
50 weak_factory_.GetWeakPtr()));
53 void SSLCertificateErrorJob::AddUrlHandler() {
54 URLRequestFilter* filter = URLRequestFilter::GetInstance();
55 filter->AddHostnameInterceptor(
56 "https", kMockHostname,
57 scoped_ptr<URLRequestInterceptor>(new MockJobInterceptor()));
60 GURL SSLCertificateErrorJob::GetMockUrl() {
61 return GURL(base::StringPrintf("https://%s", kMockHostname));
64 SSLCertificateErrorJob::~SSLCertificateErrorJob() {
67 void SSLCertificateErrorJob::NotifyError() {
68 SSLInfo info;
69 info.cert_status = CERT_STATUS_DATE_INVALID;
70 NotifySSLCertificateError(info, true);
73 } // namespace net