| 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 import org.chromium.base.test.util.UrlUtils; | |
| 14 | 13 |
| 15 /** | 14 /** |
| 16 * Wrapper class to start a Quic test server. | 15 * Wrapper class to start a Quic test server. |
| 17 */ | 16 */ |
| 18 @JNINamespace("cronet") | 17 @JNINamespace("cronet") |
| 19 public final class QuicTestServer { | 18 public final class QuicTestServer { |
| 20 private static final ConditionVariable sBlock = new ConditionVariable(); | 19 private static final ConditionVariable sBlock = new ConditionVariable(); |
| 21 private static final String TAG = "cr.QuicTestServer"; | 20 private static final String TAG = "cr.QuicTestServer"; |
| 22 | 21 |
| 23 private static final String CERT_USED = "quic_test.example.com.crt"; | 22 private static final String CERT_USED = "quic_test.example.com.crt"; |
| 24 private static final String KEY_USED = "quic_test.example.com.key"; | 23 private static final String KEY_USED = "quic_test.example.com.key"; |
| 25 private static final String[] CERTS_USED = {CERT_USED}; | 24 private static final String[] CERTS_USED = {CERT_USED}; |
| 26 | 25 |
| 27 private static boolean sServerRunning = false; | 26 private static boolean sServerRunning = false; |
| 28 | 27 |
| 29 /* | 28 /* |
| 30 * Starts the server. | 29 * Starts the server. |
| 31 */ | 30 */ |
| 32 public static void startQuicTestServer(Context context) { | 31 public static void startQuicTestServer(Context context) { |
| 33 if (sServerRunning) { | 32 if (sServerRunning) { |
| 34 throw new IllegalStateException("Quic server is already running"); | 33 throw new IllegalStateException("Quic server is already running"); |
| 35 } | 34 } |
| 36 TestFilesInstaller.installIfNeeded(context); | 35 TestFilesInstaller.installIfNeeded(context); |
| 37 nativeStartQuicTestServer( | 36 nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context)); |
| 38 TestFilesInstaller.getInstalledPath(context), UrlUtils.getIsolat
edTestRoot()); | |
| 39 sBlock.block(); | 37 sBlock.block(); |
| 40 sBlock.close(); | 38 sBlock.close(); |
| 41 sServerRunning = true; | 39 sServerRunning = true; |
| 42 } | 40 } |
| 43 | 41 |
| 44 /** | 42 /** |
| 45 * Shuts down the server. No-op if the server is already shut down. | 43 * Shuts down the server. No-op if the server is already shut down. |
| 46 */ | 44 */ |
| 47 public static void shutdownQuicTestServer() { | 45 public static void shutdownQuicTestServer() { |
| 48 if (!sServerRunning) { | 46 if (!sServerRunning) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 75 public static long createMockCertVerifier() { | 73 public static long createMockCertVerifier() { |
| 76 return MockCertVerifier.createMockCertVerifier(CERTS_USED); | 74 return MockCertVerifier.createMockCertVerifier(CERTS_USED); |
| 77 } | 75 } |
| 78 | 76 |
| 79 @CalledByNative | 77 @CalledByNative |
| 80 private static void onServerStarted() { | 78 private static void onServerStarted() { |
| 81 Log.i(TAG, "Quic server started."); | 79 Log.i(TAG, "Quic server started."); |
| 82 sBlock.open(); | 80 sBlock.open(); |
| 83 } | 81 } |
| 84 | 82 |
| 85 private static native void nativeStartQuicTestServer(String filePath, String
testDataDir); | 83 private static native void nativeStartQuicTestServer(String filePath); |
| 86 private static native void nativeShutdownQuicTestServer(); | 84 private static native void nativeShutdownQuicTestServer(); |
| 87 private static native String nativeGetServerHost(); | 85 private static native String nativeGetServerHost(); |
| 88 private static native int nativeGetServerPort(); | 86 private static native int nativeGetServerPort(); |
| 89 } | 87 } |
| OLD | NEW |