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

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: address Helen's comments 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.PrepareNetworkThread mPrepareNetworkThread;
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) {
25 mPrepareNetworkThread = new CronetTestUtil.PrepareNetworkThread(cronetEn gine);
26
21 nativeAddUrlInterceptors(); 27 nativeAddUrlInterceptors();
28 mInterceptorHandle = nativeAddUrlInterceptorJobFactory(
29 ((CronetUrlRequestContext) cronetEngine).getUrlRequestContextAda pter());
22 } 30 }
23 31
24 /** 32 /**
33 * Remove URL Interceptors.
34 */
35 public void shutdown() {
36 nativeRemoveUrlInterceptorJobFactory(mInterceptorHandle);
37 mPrepareNetworkThread.shutdown();
38 }
39
40 /**
25 * Constructs a mock URL that hangs or fails at certain phase. 41 * Constructs a mock URL that hangs or fails at certain phase.
26 * 42 *
27 * @param phase at which request fails. It should be a value in 43 * @param phase at which request fails. It should be a value in
28 * org.chromium.net.test.FailurePhase. 44 * org.chromium.net.test.FailurePhase.
29 * @param netError reported by UrlRequestJob. Passing -1, results in hang. 45 * @param netError reported by UrlRequestJob. Passing -1, results in hang.
30 */ 46 */
31 public static String getMockUrlWithFailure(int phase, int netError) { 47 public static String getMockUrlWithFailure(int phase, int netError) {
32 assertTrue(netError < 0); 48 assertTrue(netError < 0);
33 switch (phase) { 49 switch (phase) {
34 case FailurePhase.START: 50 case FailurePhase.START:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 86
71 /** 87 /**
72 * Constructs a mock URL that will hang when try to read response body from the remote. 88 * Constructs a mock URL that will hang when try to read response body from the remote.
73 */ 89 */
74 public static String getMockUrlForHangingRead() { 90 public static String getMockUrlForHangingRead() {
75 return nativeGetMockUrlForHangingRead(); 91 return nativeGetMockUrlForHangingRead();
76 } 92 }
77 93
78 private static native void nativeAddUrlInterceptors(); 94 private static native void nativeAddUrlInterceptors();
79 95
96 private static native long nativeAddUrlInterceptorJobFactory(long requestCon textAdapter);
97
98 private static native void nativeRemoveUrlInterceptorJobFactory(long interce ptorHandle);
99
80 private static native String nativeGetMockUrlWithFailure(int phase, int netE rror); 100 private static native String nativeGetMockUrlWithFailure(int phase, int netE rror);
81 101
82 private static native String nativeGetMockUrlForData(String data, 102 private static native String nativeGetMockUrlForData(String data,
83 int dataRepeatCount); 103 int dataRepeatCount);
84 104
85 private static native String nativeGetMockUrlForClientCertificateRequest(); 105 private static native String nativeGetMockUrlForClientCertificateRequest();
86 106
87 private static native String nativeGetMockUrlForSSLCertificateError(); 107 private static native String nativeGetMockUrlForSSLCertificateError();
88 108
89 private static native String nativeGetMockUrlForHangingRead(); 109 private static native String nativeGetMockUrlForHangingRead();
90 } 110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698