Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: components/cronet/android/test/src/org/chromium/net/MockUrlRequestJobFactory.java

Issue 2406273002: [Cronet] Test the libcronet that's shipped, not libcronet_test (Closed)
Patch Set: fix shutdown race Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 static junit.framework.Assert.assertTrue; 7 import static junit.framework.Assert.assertTrue;
8 8
9 import org.chromium.base.annotations.JNINamespace; 9 import org.chromium.base.annotations.JNINamespace;
10 import org.chromium.net.impl.CronetUrlRequestContext;
10 import org.chromium.net.test.FailurePhase; 11 import org.chromium.net.test.FailurePhase;
11 12
12 /** 13 /**
13 * Helper class to set up url interceptors for testing purposes. 14 * Helper class to set up url interceptors for testing purposes.
14 */ 15 */
15 @JNINamespace("cronet") 16 @JNINamespace("cronet")
16 public final class MockUrlRequestJobFactory { 17 public final class MockUrlRequestJobFactory {
18 private final long mInterceptorHandle;
19 private final CronetTestUtil.NetworkThreadTestConnector mNetworkThreadTestCo nnector;
20
17 /** 21 /**
18 * Sets up URL interceptors. 22 * Sets up URL interceptors.
19 */ 23 */
20 public static void setUp() { 24 public MockUrlRequestJobFactory(CronetEngine cronetEngine) {
21 nativeAddUrlInterceptors(); 25 mNetworkThreadTestConnector = new CronetTestUtil.NetworkThreadTestConnec tor(cronetEngine);
26
27 mInterceptorHandle = nativeAddUrlInterceptors(
28 ((CronetUrlRequestContext) cronetEngine).getUrlRequestContextAda pter());
22 } 29 }
23 30
24 /** 31 /**
32 * Remove URL Interceptors.
33 */
34 public void shutdown() {
35 nativeRemoveUrlInterceptorJobFactory(mInterceptorHandle);
36 mNetworkThreadTestConnector.shutdown();
37 }
38
39 /**
25 * Constructs a mock URL that hangs or fails at certain phase. 40 * Constructs a mock URL that hangs or fails at certain phase.
26 * 41 *
27 * @param phase at which request fails. It should be a value in 42 * @param phase at which request fails. It should be a value in
28 * org.chromium.net.test.FailurePhase. 43 * org.chromium.net.test.FailurePhase.
29 * @param netError reported by UrlRequestJob. Passing -1, results in hang. 44 * @param netError reported by UrlRequestJob. Passing -1, results in hang.
30 */ 45 */
31 public static String getMockUrlWithFailure(int phase, int netError) { 46 public static String getMockUrlWithFailure(int phase, int netError) {
32 assertTrue(netError < 0); 47 assertTrue(netError < 0);
33 switch (phase) { 48 switch (phase) {
34 case FailurePhase.START: 49 case FailurePhase.START:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 return nativeGetMockUrlForSSLCertificateError(); 83 return nativeGetMockUrlForSSLCertificateError();
69 } 84 }
70 85
71 /** 86 /**
72 * Constructs a mock URL that will hang when try to read response body from the remote. 87 * Constructs a mock URL that will hang when try to read response body from the remote.
73 */ 88 */
74 public static String getMockUrlForHangingRead() { 89 public static String getMockUrlForHangingRead() {
75 return nativeGetMockUrlForHangingRead(); 90 return nativeGetMockUrlForHangingRead();
76 } 91 }
77 92
78 private static native void nativeAddUrlInterceptors(); 93 private static native long nativeAddUrlInterceptors(long requestContextAdapt er);
94
95 private static native void nativeRemoveUrlInterceptorJobFactory(long interce ptorHandle);
79 96
80 private static native String nativeGetMockUrlWithFailure(int phase, int netE rror); 97 private static native String nativeGetMockUrlWithFailure(int phase, int netE rror);
81 98
82 private static native String nativeGetMockUrlForData(String data, 99 private static native String nativeGetMockUrlForData(String data,
83 int dataRepeatCount); 100 int dataRepeatCount);
84 101
85 private static native String nativeGetMockUrlForClientCertificateRequest(); 102 private static native String nativeGetMockUrlForClientCertificateRequest();
86 103
87 private static native String nativeGetMockUrlForSSLCertificateError(); 104 private static native String nativeGetMockUrlForSSLCertificateError();
88 105
89 private static native String nativeGetMockUrlForHangingRead(); 106 private static native String nativeGetMockUrlForHangingRead();
90 } 107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698