| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | 8 |
| 9 import org.chromium.base.annotations.JNINamespace; | 9 import org.chromium.base.annotations.JNINamespace; |
| 10 import org.chromium.base.test.util.UrlUtils; | 10 import org.chromium.base.test.util.UrlUtils; |
| 11 | 11 |
| 12 import java.net.MalformedURLException; |
| 13 import java.net.URL; |
| 14 |
| 12 /** | 15 /** |
| 13 * Wrapper class to start an in-process native test server, and get URLs | 16 * Wrapper class to start an in-process native test server, and get URLs |
| 14 * needed to talk to it. | 17 * needed to talk to it. |
| 15 */ | 18 */ |
| 16 @JNINamespace("cronet") | 19 @JNINamespace("cronet") |
| 17 public final class NativeTestServer { | 20 public final class NativeTestServer { |
| 18 // This variable contains the response body of a request to getSuccessURL(). | 21 // This variable contains the response body of a request to getSuccessURL(). |
| 19 public static final String SUCCESS_BODY = "this is a text file\n"; | 22 public static final String SUCCESS_BODY = "this is a text file\n"; |
| 20 | 23 |
| 21 public static boolean startNativeTestServer(Context context) { | 24 public static boolean startNativeTestServer(Context context) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 45 } | 48 } |
| 46 | 49 |
| 47 public static String getRedirectToEchoBody() { | 50 public static String getRedirectToEchoBody() { |
| 48 return nativeGetRedirectToEchoBody(); | 51 return nativeGetRedirectToEchoBody(); |
| 49 } | 52 } |
| 50 | 53 |
| 51 public static String getFileURL(String filePath) { | 54 public static String getFileURL(String filePath) { |
| 52 return nativeGetFileURL(filePath); | 55 return nativeGetFileURL(filePath); |
| 53 } | 56 } |
| 54 | 57 |
| 55 public static String getSdchURL() { | 58 public static String getSdchURL() throws MalformedURLException { |
| 56 return nativeGetSdchURL(); | 59 return new URL("http", CronetTestUtil.SDCH_FAKE_HOST, getPort(), "").toS
tring(); |
| 57 } | 60 } |
| 58 | 61 |
| 59 // Returns a URL that the server will return an Exabyte of data | 62 // Returns a URL that the server will return an Exabyte of data |
| 60 public static String getExabyteResponseURL() { | 63 public static String getExabyteResponseURL() { |
| 61 return nativeGetExabyteResponseURL(); | 64 return nativeGetExabyteResponseURL(); |
| 62 } | 65 } |
| 63 | 66 |
| 64 // The following URLs will make NativeTestServer serve a response based on | 67 // The following URLs will make NativeTestServer serve a response based on |
| 65 // the contents of the corresponding file and its mock-http-headers file. | 68 // the contents of the corresponding file and its mock-http-headers file. |
| 66 | 69 |
| 67 public static String getSuccessURL() { | 70 public static String getSuccessURL() { |
| 68 return nativeGetFileURL("/success.txt"); | 71 return nativeGetFileURL("/success.txt"); |
| 69 } | 72 } |
| 70 | 73 |
| 71 public static String getRedirectURL() { | 74 public static String getRedirectURL() { |
| 72 return nativeGetFileURL("/redirect.html"); | 75 return nativeGetFileURL("/redirect.html"); |
| 73 } | 76 } |
| 74 | 77 |
| 75 public static String getMultiRedirectURL() { | 78 public static String getMultiRedirectURL() { |
| 76 return nativeGetFileURL("/multiredirect.html"); | 79 return nativeGetFileURL("/multiredirect.html"); |
| 77 } | 80 } |
| 78 | 81 |
| 79 public static String getNotFoundURL() { | 82 public static String getNotFoundURL() { |
| 80 return nativeGetFileURL("/notfound.html"); | 83 return nativeGetFileURL("/notfound.html"); |
| 81 } | 84 } |
| 82 | 85 |
| 86 public static int getPort() { |
| 87 return nativeGetPort(); |
| 88 } |
| 89 |
| 83 public static String getHostPort() { | 90 public static String getHostPort() { |
| 84 return nativeGetHostPort(); | 91 return nativeGetHostPort(); |
| 85 } | 92 } |
| 86 | 93 |
| 87 public static boolean isDataReductionProxySupported() { | 94 public static boolean isDataReductionProxySupported() { |
| 88 return nativeIsDataReductionProxySupported(); | 95 return nativeIsDataReductionProxySupported(); |
| 89 } | 96 } |
| 90 | 97 |
| 91 private static native boolean nativeStartNativeTestServer(String filePath, S
tring testDataDir); | 98 private static native boolean nativeStartNativeTestServer(String filePath, S
tring testDataDir); |
| 92 private static native void nativeShutdownNativeTestServer(); | 99 private static native void nativeShutdownNativeTestServer(); |
| 93 private static native String nativeGetEchoBodyURL(); | 100 private static native String nativeGetEchoBodyURL(); |
| 94 private static native String nativeGetEchoHeaderURL(String header); | 101 private static native String nativeGetEchoHeaderURL(String header); |
| 95 private static native String nativeGetEchoAllHeadersURL(); | 102 private static native String nativeGetEchoAllHeadersURL(); |
| 96 private static native String nativeGetEchoMethodURL(); | 103 private static native String nativeGetEchoMethodURL(); |
| 97 private static native String nativeGetRedirectToEchoBody(); | 104 private static native String nativeGetRedirectToEchoBody(); |
| 98 private static native String nativeGetFileURL(String filePath); | 105 private static native String nativeGetFileURL(String filePath); |
| 99 private static native String nativeGetSdchURL(); | |
| 100 private static native String nativeGetExabyteResponseURL(); | 106 private static native String nativeGetExabyteResponseURL(); |
| 101 private static native String nativeGetHostPort(); | 107 private static native String nativeGetHostPort(); |
| 108 private static native int nativeGetPort(); |
| 102 private static native boolean nativeIsDataReductionProxySupported(); | 109 private static native boolean nativeIsDataReductionProxySupported(); |
| 103 } | 110 } |
| OLD | NEW |