| 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 import java.util.ArrayList; |
| 15 import java.util.List; |
| 16 |
| 14 /** | 17 /** |
| 15 * Wrapper class to start a Quic test server. | 18 * Wrapper class to start a Quic test server. |
| 16 */ | 19 */ |
| 17 @JNINamespace("cronet") | 20 @JNINamespace("cronet") |
| 18 public final class QuicTestServer { | 21 public final class QuicTestServer { |
| 19 private static final ConditionVariable sBlock = new ConditionVariable(); | 22 private static final ConditionVariable sBlock = new ConditionVariable(); |
| 20 private static final String TAG = "cr.QuicTestServer"; | 23 private static final String TAG = "cr.QuicTestServer"; |
| 21 | 24 |
| 22 private static final String CERT_USED = "quic_test.example.com.crt"; | 25 private static final String CERT_USED = "quic_test.example.com.crt"; |
| 23 private static final String KEY_USED = "quic_test.example.com.key"; | 26 private static final String KEY_USED = "quic_test.example.com.key"; |
| 24 private static final String[] CERTS_USED = {CERT_USED}; | 27 private static final String[] CERTS_USED = {CERT_USED}; |
| 25 | 28 |
| 29 private static final List<Response> sResponses = new ArrayList<Response>(); |
| 30 |
| 31 /** |
| 32 * Represents a response returned by the server. |
| 33 */ |
| 34 public static class Response { |
| 35 private final String mPath; |
| 36 private final String[] mBodyChunks; |
| 37 private final String[] mTrailers; |
| 38 |
| 39 /** |
| 40 * Constructs a Response. |
| 41 * @param path path of the request url |
| 42 * @param bodyChunks multipart response body |
| 43 * @param trailers an array of response headers with keys at the even in
dices |
| 44 * followed by the corresponding values at the odd indices. |
| 45 */ |
| 46 public Response(String path, String[] bodyChunks, String[] trailers) { |
| 47 mPath = path; |
| 48 mBodyChunks = bodyChunks.clone(); |
| 49 mTrailers = trailers.clone(); |
| 50 } |
| 51 |
| 52 public final String getPath() { |
| 53 return mPath; |
| 54 } |
| 55 |
| 56 public final String[] getBodyChunks() { |
| 57 return mBodyChunks.clone(); |
| 58 } |
| 59 |
| 60 public final String[] getTrailers() { |
| 61 return mTrailers.clone(); |
| 62 } |
| 63 } |
| 64 |
| 65 public static void addResponse(Response response) { |
| 66 sResponses.add(response); |
| 67 } |
| 68 |
| 26 public static void startQuicTestServer(Context context) { | 69 public static void startQuicTestServer(Context context) { |
| 27 TestFilesInstaller.installIfNeeded(context); | 70 TestFilesInstaller.installIfNeeded(context); |
| 71 for (Response r : sResponses) { |
| 72 nativeAddResponse(r.getPath(), r.getBodyChunks(), r.getTrailers()); |
| 73 } |
| 28 nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context)); | 74 nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context)); |
| 29 sBlock.block(); | 75 sBlock.block(); |
| 30 } | 76 } |
| 31 | 77 |
| 32 public static void shutdownQuicTestServer() { | 78 public static void shutdownQuicTestServer() { |
| 33 nativeShutdownQuicTestServer(); | 79 nativeShutdownQuicTestServer(); |
| 34 sBlock.close(); | 80 sBlock.close(); |
| 35 } | 81 } |
| 36 | 82 |
| 37 public static String getServerURL() { | 83 public static String getServerURL() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 57 public static long createMockCertVerifier() { | 103 public static long createMockCertVerifier() { |
| 58 return MockCertVerifier.createMockCertVerifier(CERTS_USED); | 104 return MockCertVerifier.createMockCertVerifier(CERTS_USED); |
| 59 } | 105 } |
| 60 | 106 |
| 61 @CalledByNative | 107 @CalledByNative |
| 62 private static void onServerStarted() { | 108 private static void onServerStarted() { |
| 63 Log.i(TAG, "Quic server started."); | 109 Log.i(TAG, "Quic server started."); |
| 64 sBlock.open(); | 110 sBlock.open(); |
| 65 } | 111 } |
| 66 | 112 |
| 113 private static native void nativeAddResponse( |
| 114 String path, String[] bodyChunks, String[] trailers); |
| 67 private static native void nativeStartQuicTestServer(String filePath); | 115 private static native void nativeStartQuicTestServer(String filePath); |
| 68 private static native void nativeShutdownQuicTestServer(); | 116 private static native void nativeShutdownQuicTestServer(); |
| 69 private static native String nativeGetServerHost(); | 117 private static native String nativeGetServerHost(); |
| 70 private static native int nativeGetServerPort(); | 118 private static native int nativeGetServerPort(); |
| 71 } | 119 } |
| OLD | NEW |