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

Unified Diff: net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java

Issue 183333002: Cronet Java wrappers to fallback to HttpUrlConnection if Cronet is not available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address formatting comments. Created 6 years, 9 months 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 side-by-side diff with in-line comments
Download patch
Index: net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java
diff --git a/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java b/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java
index 3a7d14c9b173a9c657bc93c3ab6eaca479212337..eb44b56edd1666b5e3ea2ab8f43a17b95eb56e77 100644
--- a/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java
+++ b/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java
@@ -19,51 +19,62 @@ import java.util.concurrent.atomic.AtomicBoolean;
/**
* Base test class for all CronetSample based tests.
*/
-public class CronetSampleTestBase extends ActivityInstrumentationTestCase2<CronetSampleActivity> {
+public class CronetSampleTestBase extends
+ ActivityInstrumentationTestCase2<CronetSampleActivity> {
- /** The maximum time the waitForActiveShellToBeDoneLoading method will wait. */
- private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeout(10000);
+ /**
+ * 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);
+ protected static final long
+ WAIT_PAGE_LOADING_TIMEOUT_SECONDS = scaleTimeout(15);
public CronetSampleTestBase() {
super(CronetSampleActivity.class);
}
/**
- * Starts the CronetSample activity and loads the given URL.
- * The URL can be null, in which case will default to CronetSampleActivity.DEFAULT_SHELL_URL.
+ * Starts the CronetSample activity and loads the given URL. The URL can be
+ * null, in which case will default to
+ * CronetSampleActivity.DEFAULT_SHELL_URL.
*/
protected CronetSampleActivity launchCronetSampleWithUrl(String url) {
return launchCronetSampleWithUrlAndCommandLineArgs(url, null);
}
/**
- * Starts the CronetSample activity appending the provided command line arguments
- * and loads the given URL. The URL can be null, in which case will default to
- * CronetSampleActivity.DEFAULT_SHELL_URL.
+ * Starts the CronetSample activity appending the provided command line
+ * arguments and loads the given URL. The URL can be null, in which case
+ * will default to CronetSampleActivity.DEFAULT_SHELL_URL.
*/
- protected CronetSampleActivity launchCronetSampleWithUrlAndCommandLineArgs(String url,
- String[] commandLineArgs) {
+ protected CronetSampleActivity launchCronetSampleWithUrlAndCommandLineArgs(
+ 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(),
- CronetSampleActivity.class));
+ if (url != null)
+ intent.setData(Uri.parse(url));
+ intent.setComponent(new ComponentName(
+ getInstrumentation().getTargetContext(),
+ CronetSampleActivity.class));
if (commandLineArgs != null) {
- intent.putExtra(CronetSampleActivity.COMMAND_LINE_ARGS_KEY, commandLineArgs);
+ intent.putExtra(CronetSampleActivity.COMMAND_LINE_ARGS_KEY,
+ commandLineArgs);
}
setActivityIntent(intent);
return getActivity();
}
- // TODO(cjhopman): These functions are inconsistent with launchCronetSample***. Should be
- // startCronetSample*** and should use the url exactly without the getTestFileUrl call. Possibly
- // these two ways of starting the activity (launch* and start*) should be merged into one.
+ // TODO(cjhopman): These functions are inconsistent with
+ // launchCronetSample***. Should be startCronetSample*** and should use the
+ // url exactly without the getTestFileUrl call. Possibly these two ways of
+ // starting the activity (launch* and start*) should be merged into one.
/**
- * Starts the content shell activity with the provided test url.
- * The url is synchronously loaded.
+ * Starts the content shell activity with the provided test url. The url is
+ * synchronously loaded.
+ *
* @param url Test url to load.
*/
protected void startActivityWithTestUrl(String url) throws Throwable {
@@ -74,14 +85,15 @@ public class CronetSampleTestBase extends ActivityInstrumentationTestCase2<Crone
}
/**
- * Starts the content shell activity with the provided test url and optional command line
- * arguments to append.
- * The url is synchronously loaded.
+ * Starts the content shell activity with the provided test url and optional
+ * command line arguments to append. The url is synchronously loaded.
+ *
* @param url Test url to load.
- * @param commandLineArgs Optional command line args to append when launching the activity.
+ * @param commandLineArgs Optional command line args to append when
+ * launching the activity.
*/
- protected void startActivityWithTestUrlAndCommandLineArgs(
- String url, String[] commandLineArgs) throws Throwable {
+ protected void startActivityWithTestUrlAndCommandLineArgs(String url,
+ String[] commandLineArgs) throws Throwable {
launchCronetSampleWithUrlAndCommandLineArgs(
UrlUtils.getTestFileUrl(url), commandLineArgs);
assertNotNull(getActivity());
@@ -89,32 +101,38 @@ public class CronetSampleTestBase extends ActivityInstrumentationTestCase2<Crone
}
/**
- * Waits for the Active shell to finish loading. This times out after
- * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be used for long
- * loading pages. Instead it should be used more for test initialization. The proper way
- * to wait is to use a TestCallbackHelperContainer after the initial load is completed.
+ * Waits for the Active shell to finish loading. This times out after
+ * WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT milliseconds and it shouldn't be
+ * used for long loading pages. Instead it should be used more for test
+ * initialization. The proper way to wait is to use a
+ * TestCallbackHelperContainer after the initial load is completed.
+ *
* @return Whether or not the Shell was actually finished loading.
* @throws InterruptedException
*/
- protected boolean waitForActiveShellToBeDoneLoading() throws InterruptedException {
+ protected boolean waitForActiveShellToBeDoneLoading()
+ throws InterruptedException {
final CronetSampleActivity activity = getActivity();
// Wait for the Content Shell to be initialized.
return CriteriaHelper.pollForCriteria(new Criteria() {
- @Override
+ @Override
public boolean isSatisfied() {
try {
final AtomicBoolean isLoaded = new AtomicBoolean(false);
runTestOnUiThread(new Runnable() {
- @Override
+ @Override
public void run() {
if (activity != null) {
- // There are two cases here that need to be accounted for.
- // The first is that we've just created a Shell and it isn't
- // loading because it has no URL set yet. The second is that
+ // There are two cases here that need to be
+ // accounted for.
+ // The first is that we've just created a Shell
+ // and it isn't
+ // loading because it has no URL set yet. The
+ // second is that
// we've set a URL and it actually is loading.
- isLoaded.set(!activity.isLoading()
- && !TextUtils.isEmpty(activity.getUrl()));
+ isLoaded.set(!activity.isLoading() && !TextUtils
+ .isEmpty(activity.getUrl()));
} else {
isLoaded.set(false);
}
@@ -126,23 +144,7 @@ public class CronetSampleTestBase extends ActivityInstrumentationTestCase2<Crone
return false;
}
}
- }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
- }
-
- /**
- * Handles performing an action on the UI thread that will return when the specified callback
- * is incremented.
- *
- * @param callbackHelper The callback helper that will be blocked on.
- * @param action The action to be performed on the UI thread.
- */
- /*
- protected void handleBlockingCallbackAction(
- CallbackHelper callbackHelper, Runnable action) throws Throwable {
- int currentCallCount = callbackHelper.getCallCount();
- runTestOnUiThread(action);
- callbackHelper.waitForCallback(
- currentCallCount, 1, WAIT_PAGE_LOADING_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ }, WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT,
+ CriteriaHelper.DEFAULT_POLLING_INTERVAL);
}
- */
}

Powered by Google App Engine
This is Rietveld 408576698