Index: components/cronet/android/test/src/org/chromium/net/QuicTestServer.java |
diff --git a/components/cronet/android/test/src/org/chromium/net/QuicTestServer.java b/components/cronet/android/test/src/org/chromium/net/QuicTestServer.java |
index 1344cc4d5c8114ae573571c4cdcc8ed0a5223f22..2f0648e48486f88b4992a893a8d7611fba80fb52 100644 |
--- a/components/cronet/android/test/src/org/chromium/net/QuicTestServer.java |
+++ b/components/cronet/android/test/src/org/chromium/net/QuicTestServer.java |
@@ -11,6 +11,9 @@ import org.chromium.base.Log; |
import org.chromium.base.annotations.CalledByNative; |
import org.chromium.base.annotations.JNINamespace; |
+import java.util.ArrayList; |
+import java.util.List; |
+ |
/** |
* Wrapper class to start a Quic test server. |
*/ |
@@ -23,8 +26,51 @@ public final class QuicTestServer { |
private static final String KEY_USED = "quic_test.example.com.key"; |
private static final String[] CERTS_USED = {CERT_USED}; |
+ private static final List<Response> sResponses = new ArrayList<Response>(); |
+ |
+ /** |
+ * Represents a response returned by the server. |
+ */ |
+ public static class Response { |
+ private final String mPath; |
+ private final String[] mBodyChunks; |
+ private final String[] mTrailers; |
+ |
+ /** |
+ * Constructs a Response. |
+ * @param path path of the request url |
+ * @param bodyChunks multipart response body |
+ * @param trailers an array of response headers with keys at the even indices |
+ * followed by the corresponding values at the odd indices. |
+ */ |
+ public Response(String path, String[] bodyChunks, String[] trailers) { |
+ mPath = path; |
+ mBodyChunks = bodyChunks.clone(); |
+ mTrailers = trailers.clone(); |
+ } |
+ |
+ public final String getPath() { |
+ return mPath; |
+ } |
+ |
+ public final String[] getBodyChunks() { |
+ return mBodyChunks.clone(); |
+ } |
+ |
+ public final String[] getTrailers() { |
+ return mTrailers.clone(); |
+ } |
+ } |
+ |
+ public static void addResponse(Response response) { |
+ sResponses.add(response); |
+ } |
+ |
public static void startQuicTestServer(Context context) { |
TestFilesInstaller.installIfNeeded(context); |
+ for (Response r : sResponses) { |
+ nativeAddResponse(r.getPath(), r.getBodyChunks(), r.getTrailers()); |
+ } |
nativeStartQuicTestServer(TestFilesInstaller.getInstalledPath(context)); |
sBlock.block(); |
} |
@@ -64,6 +110,8 @@ public final class QuicTestServer { |
sBlock.open(); |
} |
+ private static native void nativeAddResponse( |
+ String path, String[] bodyChunks, String[] trailers); |
private static native void nativeStartQuicTestServer(String filePath); |
private static native void nativeShutdownQuicTestServer(); |
private static native String nativeGetServerHost(); |