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

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

Issue 145213003: Initial upload of cronet for Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changed copyright year on sample code back to 2012 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/content/shell/android/javatests/src/org/chromium/content_shell_apk/ContentShellTestBase.java b/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java
similarity index 56%
copy from content/shell/android/javatests/src/org/chromium/content_shell_apk/ContentShellTestBase.java
copy to net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java
index 0d3196cc96c1280ec5caa48bd125a62b2b7ac1b9..936dd43ca664e7edb3b730f8373ea774bf02589e 100644
--- a/content/shell/android/javatests/src/org/chromium/content_shell_apk/ContentShellTestBase.java
+++ b/net/cronet/android/sample/javatests/src/org/chromium/cronet_sample_apk/CronetSampleTestBase.java
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package org.chromium.content_shell_apk;
+package org.chromium.cronet_sample_apk;
import android.content.ComponentName;
import android.content.Intent;
@@ -13,62 +13,53 @@ import android.text.TextUtils;
import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import org.chromium.base.test.util.UrlUtils;
-import org.chromium.content.browser.ContentView;
-import org.chromium.content.browser.ContentViewCore;
-import org.chromium.content.browser.LoadUrlParams;
-import org.chromium.content.browser.test.util.CallbackHelper;
-import org.chromium.content.browser.test.util.Criteria;
-import org.chromium.content.browser.test.util.CriteriaHelper;
-import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
-import org.chromium.content_shell.Shell;
-
-import java.util.concurrent.TimeUnit;
+
import java.util.concurrent.atomic.AtomicBoolean;
/**
- * Base test class for all ContentShell based tests.
+ * Base test class for all CronetSample based tests.
*/
-public class ContentShellTestBase extends ActivityInstrumentationTestCase2<ContentShellActivity> {
+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);
protected static final long WAIT_PAGE_LOADING_TIMEOUT_SECONDS = scaleTimeout(15);
- public ContentShellTestBase() {
- super(ContentShellActivity.class);
+ public CronetSampleTestBase() {
+ super(CronetSampleActivity.class);
}
/**
- * Starts the ContentShell activity and loads the given URL.
- * The URL can be null, in which case will default to ContentShellActivity.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 ContentShellActivity launchContentShellWithUrl(String url) {
- return launchContentShellWithUrlAndCommandLineArgs(url, null);
+ protected CronetSampleActivity launchCronetSampleWithUrl(String url) {
+ return launchCronetSampleWithUrlAndCommandLineArgs(url, null);
}
/**
- * Starts the ContentShell activity appending the provided command line arguments
+ * 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
- * ContentShellActivity.DEFAULT_SHELL_URL.
+ * CronetSampleActivity.DEFAULT_SHELL_URL.
*/
- protected ContentShellActivity launchContentShellWithUrlAndCommandLineArgs(String url,
+ 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(),
- ContentShellActivity.class));
+ CronetSampleActivity.class));
if (commandLineArgs != null) {
- intent.putExtra(ContentShellActivity.COMMAND_LINE_ARGS_KEY, commandLineArgs);
+ intent.putExtra(CronetSampleActivity.COMMAND_LINE_ARGS_KEY, commandLineArgs);
}
setActivityIntent(intent);
return getActivity();
}
- // TODO(cjhopman): These functions are inconsistent with launchContentShell***. Should be
- // startContentShell*** and should use the url exactly without the getTestFileUrl call. Possibly
+ // 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.
@@ -76,10 +67,10 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
* @param url Test url to load.
*/
protected void startActivityWithTestUrl(String url) throws Throwable {
- launchContentShellWithUrl(UrlUtils.getTestFileUrl(url));
+ launchCronetSampleWithUrl(UrlUtils.getTestFileUrl(url));
assertNotNull(getActivity());
assertTrue(waitForActiveShellToBeDoneLoading());
- assertEquals(UrlUtils.getTestFileUrl(url), getContentView().getUrl());
+ assertEquals(UrlUtils.getTestFileUrl(url), getActivity().getUrl());
}
/**
@@ -91,27 +82,13 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
*/
protected void startActivityWithTestUrlAndCommandLineArgs(
String url, String[] commandLineArgs) throws Throwable {
- launchContentShellWithUrlAndCommandLineArgs(
+ launchCronetSampleWithUrlAndCommandLineArgs(
UrlUtils.getTestFileUrl(url), commandLineArgs);
assertNotNull(getActivity());
assertTrue(waitForActiveShellToBeDoneLoading());
}
/**
- * Returns the current ContentView.
- */
- protected ContentView getContentView() {
- return getActivity().getActiveShell().getContentView();
- }
-
- /**
- * Returns the current ContentViewCore or null if there is no ContentView.
- */
- protected ContentViewCore getContentViewCore() {
- return getContentView() == null ? null : getContentView().getContentViewCore();
- }
-
- /**
* 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
@@ -120,7 +97,7 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
* @throws InterruptedException
*/
protected boolean waitForActiveShellToBeDoneLoading() throws InterruptedException {
- final ContentShellActivity activity = getActivity();
+ final CronetSampleActivity activity = getActivity();
// Wait for the Content Shell to be initialized.
return CriteriaHelper.pollForCriteria(new Criteria() {
@@ -131,14 +108,13 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
runTestOnUiThread(new Runnable() {
@Override
public void run() {
- Shell shell = activity.getActiveShell();
- if (shell != null) {
+ 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
// we've set a URL and it actually is loading.
- isLoaded.set(!shell.isLoading()
- && !TextUtils.isEmpty(shell.getContentView().getUrl()));
+ isLoaded.set(!activity.isLoading()
+ && !TextUtils.isEmpty(activity.getUrl()));
} else {
isLoaded.set(false);
}
@@ -154,32 +130,13 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
}
/**
- * Loads a URL in the specified content view.
- *
- * @param contentView The content view to load the URL in.
- * @param callbackHelperContainer The callback helper container used to monitor progress.
- * @param params The URL params to use.
- */
- protected void loadUrl(
- final ContentView contentView, TestCallbackHelperContainer callbackHelperContainer,
- final LoadUrlParams params) throws Throwable {
- handleBlockingCallbackAction(
- callbackHelperContainer.getOnPageFinishedHelper(),
- new Runnable() {
- @Override
- public void run() {
- contentView.loadUrl(params);
- }
- });
- }
-
- /**
* 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();
@@ -187,20 +144,5 @@ public class ContentShellTestBase extends ActivityInstrumentationTestCase2<Conte
callbackHelper.waitForCallback(
currentCallCount, 1, WAIT_PAGE_LOADING_TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
-
- // TODO(aelias): This method needs to be removed once http://crbug.com/179511 is fixed.
- // Meanwhile, we have to wait if the page has the <meta viewport> tag.
- /**
- * Waits till the ContentViewCore receives the expected page scale factor
- * from the compositor and asserts that this happens.
- */
- protected void assertWaitForPageScaleFactorMatch(final float expectedScale)
- throws InterruptedException {
- assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
- @Override
- public boolean isSatisfied() {
- return getContentViewCore().getScale() == expectedScale;
- }
- }));
- }
+ */
}

Powered by Google App Engine
This is Rietveld 408576698