OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.content.Context; |
7 import android.os.ConditionVariable; | 8 import android.os.ConditionVariable; |
8 | 9 |
9 import junit.framework.Assert; | 10 import junit.framework.Assert; |
10 | 11 |
11 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
12 import org.chromium.base.annotations.JNINamespace; | 13 import org.chromium.base.annotations.JNINamespace; |
13 import org.chromium.base.annotations.NativeClassQualifiedName; | 14 import org.chromium.base.annotations.NativeClassQualifiedName; |
14 | 15 |
15 /** | 16 /** |
16 * A wrapper class on top of the native net::UploadDataStream. This class is | 17 * A wrapper class on top of the native net::UploadDataStream. This class is |
17 * used in tests to drive the native UploadDataStream directly. | 18 * used in tests to drive the native UploadDataStream directly. |
18 */ | 19 */ |
19 @JNINamespace("cronet") | 20 @JNINamespace("cronet") |
20 public final class TestUploadDataStreamHandler { | 21 public final class TestUploadDataStreamHandler { |
| 22 private CronetEngine mCronetEngine; |
21 private long mTestUploadDataStreamHandler; | 23 private long mTestUploadDataStreamHandler; |
22 private ConditionVariable mWaitInitCalled = new ConditionVariable(); | 24 private ConditionVariable mWaitInitCalled = new ConditionVariable(); |
23 private ConditionVariable mWaitInitComplete = new ConditionVariable(); | 25 private ConditionVariable mWaitInitComplete = new ConditionVariable(); |
24 private ConditionVariable mWaitReadComplete = new ConditionVariable(); | 26 private ConditionVariable mWaitReadComplete = new ConditionVariable(); |
25 private ConditionVariable mWaitResetComplete = new ConditionVariable(); | 27 private ConditionVariable mWaitResetComplete = new ConditionVariable(); |
26 // Waits for checkIfInitCallbackInvoked() returns result asynchronously. | 28 // Waits for checkIfInitCallbackInvoked() returns result asynchronously. |
27 private ConditionVariable mWaitCheckInit = new ConditionVariable(); | 29 private ConditionVariable mWaitCheckInit = new ConditionVariable(); |
28 // Waits for checkIfReadCallbackInvoked() returns result asynchronously. | 30 // Waits for checkIfReadCallbackInvoked() returns result asynchronously. |
29 private ConditionVariable mWaitCheckRead = new ConditionVariable(); | 31 private ConditionVariable mWaitCheckRead = new ConditionVariable(); |
30 // If true, init completes synchronously. | 32 // If true, init completes synchronously. |
31 private boolean mInitCompletedSynchronously = false; | 33 private boolean mInitCompletedSynchronously = false; |
32 private String mData = ""; | 34 private String mData = ""; |
33 | 35 |
34 public TestUploadDataStreamHandler(final long uploadDataStream) { | 36 public TestUploadDataStreamHandler(Context context, final long uploadDataStr
eam) { |
35 mTestUploadDataStreamHandler = | 37 mCronetEngine = new CronetEngine.Builder(context).build(); |
36 nativeCreateTestUploadDataStreamHandler(uploadDataStream); | 38 CronetTestUtil.prepareNetworkThreadForTesting(mCronetEngine); |
| 39 mTestUploadDataStreamHandler = nativeCreateTestUploadDataStreamHandler( |
| 40 uploadDataStream, CronetTestUtil.getNativeSingleThreadTaskRunner
()); |
37 } | 41 } |
38 | 42 |
39 public void destroyNativeObjects() { | 43 public void destroyNativeObjects() { |
40 if (mTestUploadDataStreamHandler != 0) { | 44 if (mTestUploadDataStreamHandler != 0) { |
41 nativeDestroy(mTestUploadDataStreamHandler); | 45 nativeDestroy(mTestUploadDataStreamHandler); |
42 mTestUploadDataStreamHandler = 0; | 46 mTestUploadDataStreamHandler = 0; |
| 47 CronetTestUtil.cleanupNetorkThreadForTesting(); |
| 48 mCronetEngine.shutdown(); |
43 } | 49 } |
44 } | 50 } |
45 | 51 |
46 /** | 52 /** |
47 * Init and returns whether init completes synchronously. | 53 * Init and returns whether init completes synchronously. |
48 */ | 54 */ |
49 public boolean init() { | 55 public boolean init() { |
50 mData = ""; | 56 mData = ""; |
51 nativeInit(mTestUploadDataStreamHandler); | 57 nativeInit(mTestUploadDataStreamHandler); |
52 mWaitInitCalled.block(); | 58 mWaitInitCalled.block(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 long nativePtr); | 167 long nativePtr); |
162 | 168 |
163 @NativeClassQualifiedName("TestUploadDataStreamHandler") | 169 @NativeClassQualifiedName("TestUploadDataStreamHandler") |
164 private native void nativeCheckReadCallbackNotInvoked( | 170 private native void nativeCheckReadCallbackNotInvoked( |
165 long nativePtr); | 171 long nativePtr); |
166 | 172 |
167 @NativeClassQualifiedName("TestUploadDataStreamHandler") | 173 @NativeClassQualifiedName("TestUploadDataStreamHandler") |
168 private native void nativeDestroy(long nativePtr); | 174 private native void nativeDestroy(long nativePtr); |
169 | 175 |
170 private native long nativeCreateTestUploadDataStreamHandler( | 176 private native long nativeCreateTestUploadDataStreamHandler( |
171 long uploadDataStream); | 177 long uploadDataStream, long singleThreadTaskRunner); |
172 } | 178 } |
OLD | NEW |