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.os.ConditionVariable; | |
8 | |
9 import org.json.JSONException; | 7 import org.json.JSONException; |
10 import org.json.JSONObject; | 8 import org.json.JSONObject; |
11 | 9 |
12 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
13 import org.chromium.net.impl.CronetEngineBuilderImpl; | 11 import org.chromium.net.impl.CronetEngineBuilderImpl; |
14 import org.chromium.net.impl.CronetUrlRequest; | 12 import org.chromium.net.impl.CronetUrlRequest; |
| 13 import org.chromium.net.impl.CronetUrlRequestContext; |
15 | 14 |
16 /** | 15 /** |
17 * Utilities for Cronet testing | 16 * Utilities for Cronet testing |
18 */ | 17 */ |
19 @JNINamespace("cronet") | 18 @JNINamespace("cronet") |
20 public class CronetTestUtil { | 19 public class CronetTestUtil { |
21 private static final ConditionVariable sHostResolverBlock = new ConditionVar
iable(); | |
22 | |
23 static final String SDCH_FAKE_HOST = "fake.sdch.domain"; | 20 static final String SDCH_FAKE_HOST = "fake.sdch.domain"; |
24 // QUIC test domain must match the certificate used | 21 // QUIC test domain must match the certificate used |
25 // (quic_test.example.com.crt and quic_test.example.com.key.pkcs8), and | 22 // (quic_test.example.com.crt and quic_test.example.com.key.pkcs8), and |
26 // the file served ( | 23 // the file served ( |
27 // components/cronet/android/test/assets/test/quic_data/simple.txt). | 24 // components/cronet/android/test/assets/test/quic_data/simple.txt). |
28 static final String QUIC_FAKE_HOST = "test.example.com"; | 25 static final String QUIC_FAKE_HOST = "test.example.com"; |
29 private static final String[] TEST_DOMAINS = {SDCH_FAKE_HOST, QUIC_FAKE_HOST
}; | 26 private static final String[] TEST_DOMAINS = {SDCH_FAKE_HOST, QUIC_FAKE_HOST
}; |
30 private static final String LOOPBACK_ADDRESS = "127.0.0.1"; | 27 private static final String LOOPBACK_ADDRESS = "127.0.0.1"; |
31 | 28 |
32 /** | 29 /** |
(...skipping 20 matching lines...) Expand all Loading... |
53 */ | 50 */ |
54 public static JSONObject generateHostResolverRules(String destination) throw
s JSONException { | 51 public static JSONObject generateHostResolverRules(String destination) throw
s JSONException { |
55 StringBuilder rules = new StringBuilder(); | 52 StringBuilder rules = new StringBuilder(); |
56 for (String domain : TEST_DOMAINS) { | 53 for (String domain : TEST_DOMAINS) { |
57 rules.append("MAP " + domain + " " + destination + ","); | 54 rules.append("MAP " + domain + " " + destination + ","); |
58 } | 55 } |
59 return new JSONObject().put("host_resolver_rules", rules); | 56 return new JSONObject().put("host_resolver_rules", rules); |
60 } | 57 } |
61 | 58 |
62 /** | 59 /** |
| 60 * Prepare {@code cronetEngine}'s network thread so libcronet_test code can
run on it. |
| 61 */ |
| 62 public static class NetworkThreadTestConnector { |
| 63 private final CronetUrlRequestContext mRequestContext; |
| 64 |
| 65 public NetworkThreadTestConnector(CronetEngine cronetEngine) { |
| 66 mRequestContext = (CronetUrlRequestContext) cronetEngine; |
| 67 nativePrepareNetworkThread(mRequestContext.getUrlRequestContextAdapt
er()); |
| 68 } |
| 69 |
| 70 public void shutdown() { |
| 71 nativeCleanupNetworkThread(mRequestContext.getUrlRequestContextAdapt
er()); |
| 72 } |
| 73 } |
| 74 |
| 75 /** |
63 * Returns the value of load flags in |urlRequest|. | 76 * Returns the value of load flags in |urlRequest|. |
64 * @param urlRequest is the UrlRequest object of interest. | 77 * @param urlRequest is the UrlRequest object of interest. |
65 */ | 78 */ |
66 public static int getLoadFlags(UrlRequest urlRequest) { | 79 public static int getLoadFlags(UrlRequest urlRequest) { |
67 return nativeGetLoadFlags(((CronetUrlRequest) urlRequest).getUrlRequestA
dapterForTesting()); | 80 return nativeGetLoadFlags(((CronetUrlRequest) urlRequest).getUrlRequestA
dapterForTesting()); |
68 } | 81 } |
69 | 82 |
70 public static void setMockCertVerifierForTesting( | 83 public static void setMockCertVerifierForTesting( |
71 ExperimentalCronetEngine.Builder builder, long mockCertVerifier) { | 84 ExperimentalCronetEngine.Builder builder, long mockCertVerifier) { |
72 getCronetEngineBuilderImpl(builder).setMockCertVerifierForTesting(mockCe
rtVerifier); | 85 getCronetEngineBuilderImpl(builder).setMockCertVerifierForTesting(mockCe
rtVerifier); |
73 } | 86 } |
74 | 87 |
75 public static void setLibraryName(ExperimentalCronetEngine.Builder builder,
String libName) { | |
76 getCronetEngineBuilderImpl(builder).setLibraryName(libName); | |
77 } | |
78 | |
79 public static CronetEngineBuilderImpl getCronetEngineBuilderImpl( | 88 public static CronetEngineBuilderImpl getCronetEngineBuilderImpl( |
80 ExperimentalCronetEngine.Builder builder) { | 89 ExperimentalCronetEngine.Builder builder) { |
81 return (CronetEngineBuilderImpl) builder.getBuilderDelegate(); | 90 return (CronetEngineBuilderImpl) builder.getBuilderDelegate(); |
82 } | 91 } |
83 | 92 |
84 private static native int nativeGetLoadFlags(long urlRequest); | 93 private static native int nativeGetLoadFlags(long urlRequestAdapter); |
| 94 |
| 95 private static native void nativePrepareNetworkThread(long contextAdapter); |
| 96 private static native void nativeCleanupNetworkThread(long contextAdapter); |
85 } | 97 } |
OLD | NEW |