| Index: components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java
|
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java b/components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java
|
| index 2c044fa977a21eae13f00fe04ed51ea1a5dfbc68..a7c5856d2ad50302720bd1bd624e40f55153c1d2 100644
|
| --- a/components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java
|
| +++ b/components/cronet/android/test/javatests/src/org/chromium/net/CronetTestBase.java
|
| @@ -4,12 +4,7 @@
|
|
|
| package org.chromium.net;
|
|
|
| -import android.content.ComponentName;
|
| -import android.content.Intent;
|
| -import android.net.Uri;
|
| -import android.test.ActivityInstrumentationTestCase2;
|
| -
|
| -import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
|
| +import android.test.AndroidTestCase;
|
|
|
| import java.lang.annotation.ElementType;
|
| import java.lang.annotation.Retention;
|
| @@ -17,109 +12,45 @@ import java.lang.annotation.RetentionPolicy;
|
| import java.lang.annotation.Target;
|
| import java.lang.reflect.Method;
|
| import java.net.URL;
|
| -import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
| /**
|
| * Base test class for all CronetTest based tests.
|
| */
|
| -public class CronetTestBase extends
|
| - ActivityInstrumentationTestCase2<CronetTestActivity> {
|
| - /**
|
| - * The maximum time the waitForActiveShellToBeDoneLoading method will wait.
|
| - */
|
| - private static final long
|
| - WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeout(10000);
|
| -
|
| - protected static final long
|
| - WAIT_PAGE_LOADING_TIMEOUT_SECONDS = scaleTimeout(15);
|
| -
|
| - public CronetTestBase() {
|
| - super(CronetTestActivity.class);
|
| - }
|
| +public class CronetTestBase extends AndroidTestCase {
|
| + private CronetTestFramework mCronetTestFramework;
|
|
|
| /**
|
| - * Starts the CronetTest activity.
|
| + * Starts the CronetTest framework.
|
| */
|
| - protected CronetTestActivity launchCronetTestApp() {
|
| - return launchCronetTestAppWithUrlAndCommandLineArgs(null, null);
|
| + protected CronetTestFramework startCronetTestFramework() {
|
| + return startCronetTestFrameworkWithUrlAndCommandLineArgs(null, null);
|
| }
|
|
|
| /**
|
| - * Starts the CronetTest activity and loads the given URL. The URL can be
|
| + * Starts the CronetTest framework and loads the given URL. The URL can be
|
| * null.
|
| */
|
| - protected CronetTestActivity launchCronetTestAppWithUrl(String url) {
|
| - return launchCronetTestAppWithUrlAndCommandLineArgs(url, null);
|
| + protected CronetTestFramework startCronetTestFrameworkWithUrl(String url) {
|
| + return startCronetTestFrameworkWithUrlAndCommandLineArgs(url, null);
|
| }
|
|
|
| /**
|
| - * Starts the CronetTest activity appending the provided command line
|
| + * Starts the CronetTest framework appending the provided command line
|
| * arguments and loads the given URL. The URL can be null.
|
| */
|
| - protected CronetTestActivity launchCronetTestAppWithUrlAndCommandLineArgs(
|
| + protected CronetTestFramework startCronetTestFrameworkWithUrlAndCommandLineArgs(
|
| String url, String[] commandLineArgs) {
|
| - Intent intent = new Intent(Intent.ACTION_MAIN);
|
| - intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
| - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
| - if (url != null) intent.setData(Uri.parse(url));
|
| - intent.setComponent(new ComponentName(
|
| - getInstrumentation().getTargetContext(),
|
| - CronetTestActivity.class));
|
| - if (commandLineArgs != null) {
|
| - intent.putExtra(CronetTestActivity.COMMAND_LINE_ARGS_KEY,
|
| - commandLineArgs);
|
| - }
|
| - setActivityIntent(intent);
|
| - // Make sure the activity was created as expected.
|
| - assertNotNull(getActivity());
|
| - try {
|
| - waitForActivityToBeDoneLoading();
|
| - } catch (Throwable e) {
|
| - fail("Test activity has failed to load.");
|
| - }
|
| - return getActivity();
|
| + mCronetTestFramework = new CronetTestFramework(url, commandLineArgs, getContext());
|
| + return mCronetTestFramework;
|
| }
|
|
|
| - // Helper method to tell the activity to skip factory init in onCreate().
|
| - protected CronetTestActivity launchCronetTestAppAndSkipFactoryInit() {
|
| + // Helper method to tell the framework to skip factory init during construction.
|
| + protected CronetTestFramework startCronetTestFrameworkAndSkipFactoryInit() {
|
| String[] commandLineArgs = {
|
| - CronetTestActivity.LIBRARY_INIT_KEY, CronetTestActivity.LIBRARY_INIT_SKIP};
|
| - CronetTestActivity activity =
|
| - launchCronetTestAppWithUrlAndCommandLineArgs(null, commandLineArgs);
|
| - return activity;
|
| - }
|
| -
|
| - /**
|
| - * Waits for the Activity to finish loading. This times out after
|
| - * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds.
|
| - *
|
| - * @return Whether or not the Shell was actually finished loading.
|
| - * @throws InterruptedException
|
| - */
|
| - private boolean waitForActivityToBeDoneLoading()
|
| - throws InterruptedException {
|
| - final CronetTestActivity activity = getActivity();
|
| -
|
| - // Wait for the Activity to load.
|
| - return CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - try {
|
| - final AtomicBoolean isLoaded = new AtomicBoolean(false);
|
| - runTestOnUiThread(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - isLoaded.set(activity != null && !activity.isLoading());
|
| - }
|
| - });
|
| -
|
| - return isLoaded.get();
|
| - } catch (Throwable e) {
|
| - return false;
|
| - }
|
| - }
|
| - }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT,
|
| - CriteriaHelper.DEFAULT_POLLING_INTERVAL);
|
| + CronetTestFramework.LIBRARY_INIT_KEY, CronetTestFramework.LIBRARY_INIT_SKIP};
|
| + mCronetTestFramework =
|
| + startCronetTestFrameworkWithUrlAndCommandLineArgs(null, commandLineArgs);
|
| + return mCronetTestFramework;
|
| }
|
|
|
| @Override
|
| @@ -135,14 +66,12 @@ public class CronetTestBase extends
|
| // Run with the default HttpURLConnection implementation first.
|
| super.runTest();
|
| // Use Cronet's implementation, and run the same test.
|
| - URL.setURLStreamHandlerFactory(
|
| - getActivity().mStreamHandlerFactory);
|
| + URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandlerFactory);
|
| super.runTest();
|
| } else if (method.isAnnotationPresent(
|
| OnlyRunCronetHttpURLConnection.class)) {
|
| // Run only with Cronet's implementation.
|
| - URL.setURLStreamHandlerFactory(
|
| - getActivity().mStreamHandlerFactory);
|
| + URL.setURLStreamHandlerFactory(mCronetTestFramework.mStreamHandlerFactory);
|
| super.runTest();
|
| } else {
|
| // For all other tests.
|
|
|