blob: 2edb7ea289614a25898ed6ced7db10f24493dfa6 [file] [log] [blame]
estarkb1ee1672015-08-06 01:15:241// 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.
4
5#ifndef CHROME_BROWSER_SSL_CERT_VERIFIER_BROWSER_TEST_H_
6#define CHROME_BROWSER_SSL_CERT_VERIFIER_BROWSER_TEST_H_
7
dcheng4af48582016-04-19 00:29:358#include <memory>
9
estarkb1ee1672015-08-06 01:15:2410#include "chrome/test/base/in_process_browser_test.h"
John Abd-El-Malek96721282018-01-09 01:35:1711#include "content/public/common/network_service_test.mojom.h"
12#include "net/cert/mock_cert_verifier.h"
estarkb1ee1672015-08-06 01:15:2413
14namespace net {
15class MockCertVerifier;
16} // namespace net
17
18// CertVerifierBrowserTest allows tests to force certificate
19// verification results for requests made with any profile's main
20// request context (such as navigations). To do so, tests can use the
21// MockCertVerifier exposed via
22// CertVerifierBrowserTest::mock_cert_verifier().
23class CertVerifierBrowserTest : public InProcessBrowserTest {
24 public:
25 CertVerifierBrowserTest();
26 ~CertVerifierBrowserTest() override;
27
28 // InProcessBrowserTest:
John Abd-El-Maleke9cf2882018-01-17 16:59:0629 void SetUpCommandLine(base::CommandLine* command_line) override;
estarkb1ee1672015-08-06 01:15:2430 void SetUpInProcessBrowserTestFixture() override;
31 void TearDownInProcessBrowserTestFixture() override;
32
John Abd-El-Malek96721282018-01-09 01:35:1733 // Has the same methods as net::MockCertVerifier and updates the network
34 // service as well if it's in use. See the documentation of the net class
35 // for documentation on the methods.
36 // Once all requests use the NetworkContext even when network service is not
37 // enabled, we can stop also updating net::MockCertVerifier here and always
38 // go through the NetworkServiceTest mojo interface.
39 class CertVerifier {
40 public:
41 explicit CertVerifier(net::MockCertVerifier* verifier);
42 ~CertVerifier();
43 void set_default_result(int default_result);
44 void AddResultForCert(scoped_refptr<net::X509Certificate> cert,
45 const net::CertVerifyResult& verify_result,
46 int rv);
47 void AddResultForCertAndHost(scoped_refptr<net::X509Certificate> cert,
48 const std::string& host_pattern,
49 const net::CertVerifyResult& verify_result,
50 int rv);
51
52 private:
53 void EnsureNetworkServiceTestInitialized();
54
55 net::MockCertVerifier* verifier_;
56 content::mojom::NetworkServiceTestPtr network_service_test_;
57 };
58
estarkb1ee1672015-08-06 01:15:2459 // Returns a pointer to the MockCertVerifier used by all profiles in
60 // this test.
John Abd-El-Malek96721282018-01-09 01:35:1761 CertVerifier* mock_cert_verifier();
estarkb1ee1672015-08-06 01:15:2462
63 private:
dcheng4af48582016-04-19 00:29:3564 std::unique_ptr<net::MockCertVerifier> mock_cert_verifier_;
John Abd-El-Malek96721282018-01-09 01:35:1765
66 CertVerifier cert_verifier_;
estarkb1ee1672015-08-06 01:15:2467};
68
69#endif // CHROME_BROWSER_SSL_CERT_VERIFIER_BROWSER_TEST_H_