• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package org.chromium.net;
6 
7 import org.chromium.base.ContextUtils;
8 import org.chromium.base.annotations.JNINamespace;
9 import org.chromium.base.annotations.NativeMethods;
10 import org.chromium.base.test.util.UrlUtils;
11 
12 /**
13  * A Java wrapper to supply a net::MockCertVerifier which can be then passed
14  * into {@link CronetEngine.Builder#setMockCertVerifierForTesting}.
15  * The native pointer will be freed when the CronetEngine is torn down.
16  */
17 @JNINamespace("cronet")
18 public class MockCertVerifier {
MockCertVerifier()19     private MockCertVerifier() {}
20 
21     /**
22      * Creates a new net::MockCertVerifier, and returns a pointer to it.
23      * @param certs a String array of certificate filenames in
24      *         net::GetTestCertsDirectory() to accept in testing.
25      * @return a pointer to the newly created net::MockCertVerifier.
26      */
createMockCertVerifier(String[] certs, boolean knownRoot)27     public static long createMockCertVerifier(String[] certs, boolean knownRoot) {
28         return MockCertVerifierJni.get().createMockCertVerifier(certs, knownRoot,
29                 TestFilesInstaller.getInstalledPath(ContextUtils.getApplicationContext()));
30     }
31 
32     /**
33      * Creates a new free-for-all net::MockCertVerifier and returns a pointer to it.
34      *
35      * @return a pointer to the newly created net::MockCertVerifier.
36      */
createFreeForAllMockCertVerifier()37     public static long createFreeForAllMockCertVerifier() {
38         return MockCertVerifierJni.get().createFreeForAllMockCertVerifier();
39     }
40 
41     @NativeMethods("cronet_tests")
42     public interface Natives {
createMockCertVerifier(String[] certs, boolean knownRoot, String testDataDir)43         long createMockCertVerifier(String[] certs, boolean knownRoot, String testDataDir);
createFreeForAllMockCertVerifier()44         long createFreeForAllMockCertVerifier();
45     }
46 }
47