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