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; | 7 import org.json.JSONException; |
8 import org.json.JSONObject; | |
8 | 9 |
9 import org.chromium.base.annotations.JNINamespace; | 10 import org.chromium.base.annotations.JNINamespace; |
10 import org.chromium.net.impl.CronetUrlRequest; | 11 import org.chromium.net.impl.CronetUrlRequest; |
11 import org.json.JSONException; | 12 import org.chromium.net.impl.CronetUrlRequestContext; |
12 import org.json.JSONObject; | |
13 | 13 |
14 /** | 14 /** |
15 * Utilities for Cronet testing | 15 * Utilities for Cronet testing |
16 */ | 16 */ |
17 @JNINamespace("cronet") | 17 @JNINamespace("cronet") |
18 public class CronetTestUtil { | 18 public class CronetTestUtil { |
19 private static final ConditionVariable sHostResolverBlock = new ConditionVar iable(); | |
20 | |
21 static final String SDCH_FAKE_HOST = "fake.sdch.domain"; | 19 static final String SDCH_FAKE_HOST = "fake.sdch.domain"; |
22 // QUIC test domain must match the certificate used | 20 // QUIC test domain must match the certificate used |
23 // (quic_test.example.com.crt and quic_test.example.com.key.pkcs8), and | 21 // (quic_test.example.com.crt and quic_test.example.com.key.pkcs8), and |
24 // the file served ( | 22 // the file served ( |
25 // components/cronet/android/test/assets/test/quic_data/simple.txt). | 23 // components/cronet/android/test/assets/test/quic_data/simple.txt). |
26 static final String QUIC_FAKE_HOST = "test.example.com"; | 24 static final String QUIC_FAKE_HOST = "test.example.com"; |
27 private static final String[] TEST_DOMAINS = {SDCH_FAKE_HOST, QUIC_FAKE_HOST }; | 25 private static final String[] TEST_DOMAINS = {SDCH_FAKE_HOST, QUIC_FAKE_HOST }; |
28 private static final String LOOPBACK_ADDRESS = "127.0.0.1"; | 26 private static final String LOOPBACK_ADDRESS = "127.0.0.1"; |
29 | 27 |
30 /** | 28 /** |
(...skipping 20 matching lines...) Expand all Loading... | |
51 */ | 49 */ |
52 public static JSONObject generateHostResolverRules(String destination) throw s JSONException { | 50 public static JSONObject generateHostResolverRules(String destination) throw s JSONException { |
53 StringBuilder rules = new StringBuilder(); | 51 StringBuilder rules = new StringBuilder(); |
54 for (String domain : TEST_DOMAINS) { | 52 for (String domain : TEST_DOMAINS) { |
55 rules.append("MAP " + domain + " " + destination + ","); | 53 rules.append("MAP " + domain + " " + destination + ","); |
56 } | 54 } |
57 return new JSONObject().put("host_resolver_rules", rules); | 55 return new JSONObject().put("host_resolver_rules", rules); |
58 } | 56 } |
59 | 57 |
60 /** | 58 /** |
59 * Prepare {@code cronetEngine}'s network thread so libcronet_test code can run on it. | |
60 */ | |
61 public static class PrepareNetworkThread { | |
mef
2016/11/16 20:01:27
I think the name is a bit confusing, maybe call it
pauljensen
2016/11/18 18:12:10
Done.
| |
62 private final CronetUrlRequestContext mRequestContext; | |
63 | |
64 public PrepareNetworkThread(CronetEngine cronetEngine) { | |
65 mRequestContext = (CronetUrlRequestContext) cronetEngine; | |
66 nativePrepareNetworkThread(mRequestContext.getUrlRequestContextAdapt er()); | |
67 } | |
68 | |
69 public void shutdown() { | |
70 nativeCleanupNetworkThread(mRequestContext.getUrlRequestContextAdapt er()); | |
71 } | |
72 } | |
73 | |
74 /** | |
61 * Returns the value of load flags in |urlRequest|. | 75 * Returns the value of load flags in |urlRequest|. |
62 * @param urlRequest is the UrlRequest object of interest. | 76 * @param urlRequest is the UrlRequest object of interest. |
63 */ | 77 */ |
64 public static int getLoadFlags(UrlRequest urlRequest) { | 78 public static int getLoadFlags(UrlRequest urlRequest) { |
65 return nativeGetLoadFlags(((CronetUrlRequest) urlRequest).getUrlRequestA dapterForTesting()); | 79 return nativeGetLoadFlags(((CronetUrlRequest) urlRequest).getUrlRequestA dapterForTesting()); |
66 } | 80 } |
67 | 81 |
68 private static native int nativeGetLoadFlags(long urlRequest); | 82 private static native int nativeGetLoadFlags(long urlRequestAdapter); |
83 | |
84 private static native void nativePrepareNetworkThread(long contextAdapter); | |
mef
2016/11/16 20:01:27
nit: maybe these should be class methods as oppose
pauljensen
2016/11/18 18:12:10
@NativeClassQualifiedName only works for non-stati
mef
2016/11/18 21:45:50
Acknowledged. Thanks for explanation!
| |
85 private static native void nativeCleanupNetworkThread(long contextAdapter); | |
69 } | 86 } |
OLD | NEW |