Index: components/cronet/android/test/src/org/chromium/net/CronetTestUtil.java |
diff --git a/components/cronet/android/test/src/org/chromium/net/CronetTestUtil.java b/components/cronet/android/test/src/org/chromium/net/CronetTestUtil.java |
index efd61ea6460cb2697486238d9c1bbc004884b692..fc83eda4f670025a57b0ebbcc176f4784902b5a7 100644 |
--- a/components/cronet/android/test/src/org/chromium/net/CronetTestUtil.java |
+++ b/components/cronet/android/test/src/org/chromium/net/CronetTestUtil.java |
@@ -6,8 +6,9 @@ package org.chromium.net; |
import android.os.ConditionVariable; |
-import org.chromium.base.annotations.CalledByNative; |
import org.chromium.base.annotations.JNINamespace; |
+import org.json.JSONException; |
+import org.json.JSONObject; |
/** |
* Utilities for Cronet testing |
@@ -16,36 +17,43 @@ import org.chromium.base.annotations.JNINamespace; |
public class CronetTestUtil { |
private static final ConditionVariable sHostResolverBlock = new ConditionVariable(); |
+ static final String SDCH_FAKE_HOST = "fake.sdch.domain"; |
+ // QUIC test domain must match the certificate used |
+ // (quic_test.example.com.crt and quic_test.example.com.key.pkcs8), and |
+ // the file served ( |
+ // components/cronet/android/test/assets/test/quic_data/simple.txt). |
+ static final String QUIC_FAKE_HOST = "test.example.com"; |
+ private static final String[] TEST_DOMAINS = {SDCH_FAKE_HOST, QUIC_FAKE_HOST}; |
+ private static final String LOOPBACK_ADDRESS = "127.0.0.1"; |
+ |
/** |
- * Registers customized DNS mapping for testing host names used by test servers, namely: |
+ * Generates rules for customized DNS mapping for testing hostnames used by test servers, |
+ * namely: |
* <ul> |
* <li>{@link QuicTestServer#getServerHost}</li> |
* <li>{@link NativeTestServer#getSdchURL}</li>'s host |
* </ul> |
- * @param cronetEngine {@link CronetEngine} that this mapping should apply to. |
- * @param destination host to map to (e.g. 127.0.0.1) |
+ * Maps the test hostnames to 127.0.0.1. |
*/ |
- public static void registerHostResolverProc(CronetEngine cronetEngine, String destination) { |
- long contextAdapter = |
- ((CronetUrlRequestContext) cronetEngine).getUrlRequestContextAdapter(); |
- nativeRegisterHostResolverProc(contextAdapter, false, destination); |
- sHostResolverBlock.block(); |
- sHostResolverBlock.close(); |
+ public static JSONObject generateHostResolverRules() throws JSONException { |
+ return generateHostResolverRules(LOOPBACK_ADDRESS); |
} |
/** |
- * Registers customized DNS mapping for testing host names used by test servers. |
- * @param requestFactory {@link HttpUrlRequestFactory} that this mapping should apply to. |
- * @param destination host to map to (e.g. 127.0.0.1) |
+ * Generates rules for customized DNS mapping for testing hostnames used by test servers, |
+ * namely: |
+ * <ul> |
+ * <li>{@link QuicTestServer#getServerHost}</li> |
+ * <li>{@link NativeTestServer#getSdchURL}</li>'s host |
+ * </ul> |
+ * @param destination host to map to |
*/ |
- public static void registerHostResolverProc( |
- HttpUrlRequestFactory requestFactory, String destination) { |
- long contextAdapter = ((ChromiumUrlRequestFactory) requestFactory) |
- .getRequestContext() |
- .getUrlRequestContextAdapter(); |
- nativeRegisterHostResolverProc(contextAdapter, true, destination); |
- sHostResolverBlock.block(); |
- sHostResolverBlock.close(); |
+ public static JSONObject generateHostResolverRules(String destination) throws JSONException { |
+ StringBuilder rules = new StringBuilder(); |
+ for (String domain : TEST_DOMAINS) { |
+ rules.append("MAP " + domain + " " + destination + ","); |
+ } |
+ return new JSONObject().put("host_resolver_rules", rules); |
} |
/** |
@@ -56,13 +64,5 @@ public class CronetTestUtil { |
return nativeGetLoadFlags(((CronetUrlRequest) urlRequest).getUrlRequestAdapterForTesting()); |
} |
- @CalledByNative |
- private static void onHostResolverProcRegistered() { |
- sHostResolverBlock.open(); |
- } |
- |
- private static native void nativeRegisterHostResolverProc( |
- long contextAdapter, boolean isLegacyAPI, String destination); |
- |
private static native int nativeGetLoadFlags(long urlRequest); |
} |