| Index: components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java
|
| diff --git a/components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java b/components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java
|
| index 9eda8e515025d05833a6b82d60bbae2b6801e764..65c346a7b7f4eae2909cae5e7e82314949b6dccf 100644
|
| --- a/components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java
|
| +++ b/components/cronet/android/test/src/org/chromium/net/CronetTestFramework.java
|
| @@ -5,7 +5,6 @@
|
| package org.chromium.net;
|
|
|
| import android.content.Context;
|
| -import android.os.ConditionVariable;
|
| import android.os.Environment;
|
|
|
| import static junit.framework.Assert.assertEquals;
|
| @@ -14,14 +13,10 @@ import static junit.framework.Assert.assertTrue;
|
| import org.chromium.base.Log;
|
| import org.chromium.base.PathUtils;
|
| import org.chromium.base.annotations.SuppressFBWarnings;
|
| +import org.chromium.net.impl.CronetEngineBase;
|
|
|
| -import java.io.ByteArrayInputStream;
|
| import java.io.File;
|
| -import java.io.InputStream;
|
| import java.net.URLStreamHandlerFactory;
|
| -import java.nio.channels.Channels;
|
| -import java.nio.channels.ReadableByteChannel;
|
| -import java.util.HashMap;
|
|
|
| /**
|
| * Framework for testing Cronet.
|
| @@ -49,8 +44,8 @@ public class CronetTestFramework {
|
| public static final String SDCH_ENABLE = "enable";
|
|
|
| /**
|
| - * Library init type strings to use along with {@link LIBRARY_INIT_KEY}.
|
| - * If unspecified, {@link LibraryInitType.CRONET} will be used.
|
| + * Library init type strings to use along with {@link #LIBRARY_INIT_KEY}.
|
| + * If unspecified, {@link LibraryInitType#CRONET} will be used.
|
| */
|
| public static final class LibraryInitType {
|
| // Initializes Cronet Async API.
|
| @@ -66,44 +61,20 @@ public class CronetTestFramework {
|
| }
|
|
|
| public URLStreamHandlerFactory mStreamHandlerFactory;
|
| - public CronetEngine mCronetEngine;
|
| - @SuppressWarnings("deprecation")
|
| - HttpUrlRequestFactory mRequestFactory;
|
| + public CronetEngineBase mCronetEngine;
|
|
|
| private final String[] mCommandLine;
|
| private final Context mContext;
|
|
|
| - private String mUrl;
|
| private int mHttpStatusCode = 0;
|
|
|
| // CronetEngine.Builder used for this activity.
|
| - private CronetEngine.Builder mCronetEngineBuilder;
|
| -
|
| - @SuppressWarnings("deprecation")
|
| - private class TestHttpUrlRequestListener implements HttpUrlRequestListener {
|
| - private final ConditionVariable mComplete = new ConditionVariable();
|
| -
|
| - public TestHttpUrlRequestListener() {}
|
| -
|
| - @Override
|
| - public void onResponseStarted(HttpUrlRequest request) {
|
| - mHttpStatusCode = request.getHttpStatusCode();
|
| - }
|
| -
|
| - @Override
|
| - public void onRequestComplete(HttpUrlRequest request) {
|
| - mComplete.open();
|
| - }
|
| -
|
| - public void blockForComplete() {
|
| - mComplete.block();
|
| - }
|
| - }
|
| + private ExperimentalCronetEngine.Builder mCronetEngineBuilder;
|
|
|
| // TODO(crbug.com/547160): Fix this findbugs error and remove the suppression.
|
| @SuppressFBWarnings("EI_EXPOSE_REP2")
|
| - public CronetTestFramework(
|
| - String appUrl, String[] commandLine, Context context, CronetEngine.Builder builder) {
|
| + public CronetTestFramework(String appUrl, String[] commandLine, Context context,
|
| + ExperimentalCronetEngine.Builder builder) {
|
| mCommandLine = commandLine;
|
| mContext = context;
|
|
|
| @@ -128,12 +99,6 @@ public class CronetTestFramework {
|
| switch (initString) {
|
| case LibraryInitType.NONE:
|
| break;
|
| - case LibraryInitType.LEGACY:
|
| - mRequestFactory = initRequestFactory();
|
| - if (appUrl != null) {
|
| - startWithURL(appUrl);
|
| - }
|
| - break;
|
| case LibraryInitType.HTTP_URL_CONNECTION:
|
| mCronetEngine = initCronetEngine();
|
| mStreamHandlerFactory = mCronetEngine.createURLStreamHandlerFactory();
|
| @@ -196,23 +161,23 @@ public class CronetTestFramework {
|
| return path.delete();
|
| }
|
|
|
| - CronetEngine.Builder getCronetEngineBuilder() {
|
| + ExperimentalCronetEngine.Builder getCronetEngineBuilder() {
|
| return mCronetEngineBuilder;
|
| }
|
|
|
| - private CronetEngine.Builder initializeCronetEngineBuilderWithPresuppliedBuilder(
|
| - CronetEngine.Builder builder) {
|
| + private ExperimentalCronetEngine.Builder initializeCronetEngineBuilderWithPresuppliedBuilder(
|
| + ExperimentalCronetEngine.Builder builder) {
|
| return createCronetEngineBuilderWithPresuppliedBuilder(mContext, builder);
|
| }
|
|
|
| - CronetEngine.Builder createCronetEngineBuilder(Context context) {
|
| + ExperimentalCronetEngine.Builder createCronetEngineBuilder(Context context) {
|
| return createCronetEngineBuilderWithPresuppliedBuilder(context, null);
|
| }
|
|
|
| - private CronetEngine.Builder createCronetEngineBuilderWithPresuppliedBuilder(
|
| - Context context, CronetEngine.Builder cronetEngineBuilder) {
|
| + private ExperimentalCronetEngine.Builder createCronetEngineBuilderWithPresuppliedBuilder(
|
| + Context context, ExperimentalCronetEngine.Builder cronetEngineBuilder) {
|
| if (cronetEngineBuilder == null) {
|
| - cronetEngineBuilder = new CronetEngine.Builder(context);
|
| + cronetEngineBuilder = new ExperimentalCronetEngine.Builder(context);
|
| cronetEngineBuilder.enableHttp2(true).enableQuic(true);
|
| }
|
|
|
| @@ -235,19 +200,13 @@ public class CronetTestFramework {
|
| }
|
|
|
| // Setting this here so it isn't overridden on the command line
|
| - cronetEngineBuilder.setLibraryName("cronet_tests");
|
| + CronetTestUtil.setLibraryName(cronetEngineBuilder, "cronet_tests");
|
| return cronetEngineBuilder;
|
| }
|
|
|
| // Helper function to initialize Cronet engine. Also used in testing.
|
| - public CronetEngine initCronetEngine() {
|
| - return mCronetEngineBuilder.build();
|
| - }
|
| -
|
| - // Helper function to initialize request factory. Also used in testing.
|
| - @SuppressWarnings("deprecation")
|
| - public HttpUrlRequestFactory initRequestFactory() {
|
| - return HttpUrlRequestFactory.createFactory(mContext, mCronetEngineBuilder);
|
| + public CronetEngineBase initCronetEngine() {
|
| + return (CronetEngineBase) mCronetEngineBuilder.build();
|
| }
|
|
|
| private String getCommandLineArg(String key) {
|
| @@ -261,45 +220,11 @@ public class CronetTestFramework {
|
| return null;
|
| }
|
|
|
| - @SuppressWarnings("deprecation")
|
| - private void applyCommandLineToHttpUrlRequest(HttpUrlRequest request) {
|
| - String postData = getCommandLineArg(POST_DATA_KEY);
|
| - if (postData != null) {
|
| - InputStream dataStream = new ByteArrayInputStream(postData.getBytes());
|
| - ReadableByteChannel dataChannel = Channels.newChannel(dataStream);
|
| - request.setUploadChannel("text/plain", dataChannel, postData.length());
|
| - request.setHttpMethod("POST");
|
| - }
|
| - }
|
| -
|
| - @SuppressWarnings("deprecation")
|
| - public void startWithURL(String url) {
|
| - Log.i(TAG, "Cronet started: %s", url);
|
| - mUrl = url;
|
| -
|
| - HashMap<String, String> headers = new HashMap<String, String>();
|
| - TestHttpUrlRequestListener listener = new TestHttpUrlRequestListener();
|
| - HttpUrlRequest request = mRequestFactory.createRequest(
|
| - url, HttpUrlRequest.REQUEST_PRIORITY_MEDIUM, headers, listener);
|
| - applyCommandLineToHttpUrlRequest(request);
|
| - request.start();
|
| - listener.blockForComplete();
|
| - }
|
| -
|
| - public String getUrl() {
|
| - return mUrl;
|
| - }
|
| -
|
| public int getHttpStatusCode() {
|
| return mHttpStatusCode;
|
| }
|
|
|
| public void startNetLog() {
|
| - if (mRequestFactory != null) {
|
| - mRequestFactory.startNetLogToFile(Environment.getExternalStorageDirectory().getPath()
|
| - + "/cronet_sample_netlog_old_api.json",
|
| - false);
|
| - }
|
| if (mCronetEngine != null) {
|
| mCronetEngine.startNetLogToFile(Environment.getExternalStorageDirectory().getPath()
|
| + "/cronet_sample_netlog_new_api.json",
|
| @@ -308,9 +233,6 @@ public class CronetTestFramework {
|
| }
|
|
|
| public void stopNetLog() {
|
| - if (mRequestFactory != null) {
|
| - mRequestFactory.stopNetLog();
|
| - }
|
| if (mCronetEngine != null) {
|
| mCronetEngine.stopNetLog();
|
| }
|
|
|