OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.net; | 5 package org.chromium.net; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.os.ConditionVariable; | 8 import android.os.ConditionVariable; |
9 | 9 |
10 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
11 import org.chromium.base.annotations.CalledByNative; | 11 import org.chromium.base.annotations.CalledByNative; |
12 import org.chromium.base.annotations.JNINamespace; | 12 import org.chromium.base.annotations.JNINamespace; |
13 | 13 |
14 /** | 14 /** |
15 * Wrapper class to start a Quic test server. | 15 * Wrapper class to start a Quic test server. |
16 */ | 16 */ |
17 @JNINamespace("cronet") | 17 @JNINamespace("cronet") |
18 public final class QuicTestServer { | 18 public final class QuicTestServer { |
19 private static final ConditionVariable sBlock = new ConditionVariable(); | 19 private static final ConditionVariable sBlock = new ConditionVariable(); |
20 private static final String TAG = "cr.QuicTestServer"; | 20 private static final String TAG = "cr.QuicTestServer"; |
21 | 21 |
| 22 private static final String CERT_USED = "quic_test.example.com.crt"; |
| 23 private static final String KEY_USED = "quic_test.example.com.key"; |
| 24 private static final String[] CERTS_USED = {CERT_USED}; |
| 25 |
22 public static void startQuicTestServer(Context context) { | 26 public static void startQuicTestServer(Context context) { |
23 TestFilesInstaller.installIfNeeded(context); | 27 TestFilesInstaller.installIfNeeded(context); |
24 nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context)); | 28 nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context)); |
25 sBlock.block(); | 29 sBlock.block(); |
26 } | 30 } |
27 | 31 |
28 public static void shutdownQuicTestServer() { | 32 public static void shutdownQuicTestServer() { |
29 nativeShutdownQuicTestServer(); | 33 nativeShutdownQuicTestServer(); |
30 sBlock.close(); | 34 sBlock.close(); |
31 } | 35 } |
32 | 36 |
33 public static String getServerURL() { | 37 public static String getServerURL() { |
34 return "https://" + getServerHost() + ":" + getServerPort(); | 38 return "https://" + getServerHost() + ":" + getServerPort(); |
35 } | 39 } |
36 | 40 |
37 public static String getServerHost() { | 41 public static String getServerHost() { |
38 return nativeGetServerHost(); | 42 return nativeGetServerHost(); |
39 } | 43 } |
40 | 44 |
41 public static int getServerPort() { | 45 public static int getServerPort() { |
42 return nativeGetServerPort(); | 46 return nativeGetServerPort(); |
43 } | 47 } |
44 | 48 |
| 49 public static final String getServerCert() { |
| 50 return CERT_USED; |
| 51 } |
| 52 |
| 53 public static final String getServerCertKey() { |
| 54 return KEY_USED; |
| 55 } |
| 56 |
| 57 public static long createMockCertVerifier() { |
| 58 return MockCertVerifier.createMockCertVerifier(CERTS_USED); |
| 59 } |
| 60 |
45 @CalledByNative | 61 @CalledByNative |
46 private static void onServerStarted() { | 62 private static void onServerStarted() { |
47 Log.i(TAG, "Quic server started."); | 63 Log.i(TAG, "Quic server started."); |
48 sBlock.open(); | 64 sBlock.open(); |
49 } | 65 } |
50 | 66 |
51 private static native void nativeStartQuicTestServer(String filePath); | 67 private static native void nativeStartQuicTestServer(String filePath); |
52 private static native void nativeShutdownQuicTestServer(); | 68 private static native void nativeShutdownQuicTestServer(); |
53 private static native String nativeGetServerHost(); | 69 private static native String nativeGetServerHost(); |
54 private static native int nativeGetServerPort(); | 70 private static native int nativeGetServerPort(); |
55 } | 71 } |
OLD | NEW |