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

Unified Diff: android_webview/javatests/src/org/chromium/android_webview/test/AwTestCommon.java

Issue 2933623002: Create AwJUnit4ClassRunner AwActivityTestRule and convert AwContentsTest (Closed)
Patch Set: rebase + fix errors Created 3 years, 5 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: android_webview/javatests/src/org/chromium/android_webview/test/AwTestCommon.java
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestCommon.java
similarity index 57%
copy from android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java
copy to android_webview/javatests/src/org/chromium/android_webview/test/AwTestCommon.java
index f67a27263ea1230c3ae0952687fae0ef1db43199..46eaa8e921cba3b60f73c27a95d71d96c308a36c 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AwTestBase.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwTestCommon.java
@@ -1,4 +1,4 @@
-// Copyright 2012 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,28 +8,23 @@ import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
import android.app.Instrumentation;
import android.content.Context;
-import android.os.Build;
import android.util.AndroidRuntimeException;
-import android.util.Log;
-import android.view.ViewGroup;
+
+import org.junit.Assert;
import org.chromium.android_webview.AwBrowserContext;
import org.chromium.android_webview.AwBrowserProcess;
import org.chromium.android_webview.AwContents;
-import org.chromium.android_webview.AwContents.DependencyFactory;
-import org.chromium.android_webview.AwContents.InternalAccessDelegate;
-import org.chromium.android_webview.AwContents.NativeDrawGLFunctorFactory;
import org.chromium.android_webview.AwContentsClient;
import org.chromium.android_webview.AwSettings;
-import org.chromium.android_webview.AwSwitches;
+import org.chromium.android_webview.test.AwTestBase.PopupInfo;
+import org.chromium.android_webview.test.AwTestBase.TestDependencyFactory;
import org.chromium.android_webview.test.util.GraphicsTestUtils;
import org.chromium.android_webview.test.util.JSUtils;
+import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
-import org.chromium.base.test.BaseActivityInstrumentationTestCase;
import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.InMemorySharedPreferences;
-import org.chromium.base.test.util.MinAndroidSdkLevel;
-import org.chromium.base.test.util.parameter.CommandLineParameter;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
@@ -37,8 +32,6 @@ import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.net.test.util.TestWebServer;
import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
@@ -46,51 +39,43 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-/**
- * A base class for android_webview tests. WebView only runs on KitKat and later,
- * so make sure no one attempts to run the tests on earlier OS releases.
- *
- * By default, all tests run both in single-process mode, and with sandboxed renderer.
- * If a test doesn't yet work with sandboxed renderer, an entire class, or an individual test
- * method can be marked for single-process testing only by adding the following annotation:
- *
- * @SkipCommandLineParameterization
- */
-@MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT)
-@CommandLineParameter({"", AwSwitches.WEBVIEW_SANDBOXED_RENDERER})
-public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunnerActivity> {
+// TODO(yolandyan): move this class to its test rule once JUnit4 migration is over
+final class AwTestCommon {
public static final long WAIT_TIMEOUT_MS = scaleTimeout(15000);
+
public static final int CHECK_INTERVAL = 100;
- private static final String TAG = "AwTestBase";
+
+ private static final String TAG = "AwTestCommon";
+
private static final Pattern MAYBE_QUOTED_STRING = Pattern.compile("^(\"?)(.*)\\1$");
// The browser context needs to be a process-wide singleton.
private AwBrowserContext mBrowserContext;
- public AwTestBase() {
- super(AwTestRunnerActivity.class);
+ private final AwTestCommonCallback mCallback;
+
+ AwTestCommon(AwTestCommonCallback callback) {
+ mCallback = callback;
}
- @Override
- protected void setUp() throws Exception {
+ void setUp() throws Exception {
if (needsAwBrowserContextCreated()) {
createAwBrowserContext();
}
-
- super.setUp();
if (needsBrowserProcessStarted()) {
startBrowserProcess();
}
}
- protected void createAwBrowserContext() {
+ void createAwBrowserContext() {
if (mBrowserContext != null) {
throw new AndroidRuntimeException("There should only be one browser context.");
}
- getActivity(); // The Activity must be launched in order to load native code
+ mCallback.getActivity(); // The Activity must be launched in order to load native code
final InMemorySharedPreferences prefs = new InMemorySharedPreferences();
- final Context appContext = getInstrumentation().getTargetContext().getApplicationContext();
- getInstrumentation().runOnMainSync(new Runnable() {
+ final Context appContext =
+ mCallback.getInstrumentation().getTargetContext().getApplicationContext();
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
mBrowserContext = createAwBrowserContextOnUiThread(prefs, appContext);
@@ -98,15 +83,15 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- protected AwBrowserContext createAwBrowserContextOnUiThread(
+ AwBrowserContext createAwBrowserContextOnUiThread(
InMemorySharedPreferences prefs, Context appContext) {
return new AwBrowserContext(prefs, appContext);
}
- protected void startBrowserProcess() throws Exception {
+ void startBrowserProcess() throws Exception {
// The Activity must be launched in order for proper webview statics to be setup.
- getActivity();
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getActivity();
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
AwBrowserProcess.start();
@@ -114,40 +99,22 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Override this to return false if the test doesn't want to create an AwBrowserContext
- * automatically.
- */
- protected boolean needsAwBrowserContextCreated() {
+ boolean needsAwBrowserContextCreated() {
return true;
}
- /**
- * Override this to return false if the test doesn't want the browser startup sequence to
- * be run automatically.
- * @return Whether the instrumentation test requires the browser process to already be started.
- */
- protected boolean needsBrowserProcessStarted() {
+ boolean needsBrowserProcessStarted() {
return true;
}
- /**
- * Runs a {@link Callable} on the main thread, blocking until it is
- * complete, and returns the result. Calls
- * {@link Instrumentation#waitForIdleSync()} first to help avoid certain
- * race conditions.
- *
- * @param <R> Type of result to return
- */
- public <R> R runTestOnUiThreadAndGetResult(Callable<R> callable)
- throws Exception {
+ public <R> R runTestOnUiThreadAndGetResult(Callable<R> callable) throws Exception {
FutureTask<R> task = new FutureTask<R>(callable);
- getInstrumentation().runOnMainSync(task);
+ mCallback.getInstrumentation().runOnMainSync(task);
return task.get();
}
public void enableJavaScriptOnUiThread(final AwContents awContents) {
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.getSettings().setJavaScriptEnabled(true);
@@ -155,9 +122,9 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- public void setNetworkAvailableOnUiThread(final AwContents awContents,
- final boolean networkUp) {
- getInstrumentation().runOnMainSync(new Runnable() {
+ public void setNetworkAvailableOnUiThread(
+ final AwContents awContents, final boolean networkUp) {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.setNetworkAvailable(networkUp);
@@ -165,50 +132,38 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Loads url on the UI thread and blocks until onPageFinished is called.
- */
- public void loadUrlSync(final AwContents awContents,
- CallbackHelper onPageFinishedHelper,
+ public void loadUrlSync(final AwContents awContents, CallbackHelper onPageFinishedHelper,
final String url) throws Exception {
loadUrlSync(awContents, onPageFinishedHelper, url, null);
}
- public void loadUrlSync(final AwContents awContents,
- CallbackHelper onPageFinishedHelper,
- final String url,
- final Map<String, String> extraHeaders) throws Exception {
+ public void loadUrlSync(final AwContents awContents, CallbackHelper onPageFinishedHelper,
+ final String url, final Map<String, String> extraHeaders) throws Exception {
int currentCallCount = onPageFinishedHelper.getCallCount();
loadUrlAsync(awContents, url, extraHeaders);
- onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
+ onPageFinishedHelper.waitForCallback(
+ currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
public void loadUrlSyncAndExpectError(final AwContents awContents,
- CallbackHelper onPageFinishedHelper,
- CallbackHelper onReceivedErrorHelper,
+ CallbackHelper onPageFinishedHelper, CallbackHelper onReceivedErrorHelper,
final String url) throws Exception {
int onErrorCallCount = onReceivedErrorHelper.getCallCount();
int onFinishedCallCount = onPageFinishedHelper.getCallCount();
loadUrlAsync(awContents, url);
- onReceivedErrorHelper.waitForCallback(onErrorCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
- onPageFinishedHelper.waitForCallback(onFinishedCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
+ onReceivedErrorHelper.waitForCallback(
+ onErrorCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+ onPageFinishedHelper.waitForCallback(
+ onFinishedCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
- /**
- * Loads url on the UI thread but does not block.
- */
- public void loadUrlAsync(final AwContents awContents,
- final String url) throws Exception {
+ public void loadUrlAsync(final AwContents awContents, final String url) throws Exception {
loadUrlAsync(awContents, url, null);
}
- public void loadUrlAsync(final AwContents awContents,
- final String url,
- final Map<String, String> extraHeaders) {
- getInstrumentation().runOnMainSync(new Runnable() {
+ public void loadUrlAsync(
+ final AwContents awContents, final String url, final Map<String, String> extraHeaders) {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.loadUrl(url, extraHeaders);
@@ -216,23 +171,16 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Posts url on the UI thread and blocks until onPageFinished is called.
- */
- public void postUrlSync(final AwContents awContents,
- CallbackHelper onPageFinishedHelper, final String url,
- byte[] postData) throws Exception {
+ public void postUrlSync(final AwContents awContents, CallbackHelper onPageFinishedHelper,
+ final String url, byte[] postData) throws Exception {
int currentCallCount = onPageFinishedHelper.getCallCount();
postUrlAsync(awContents, url, postData);
- onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
+ onPageFinishedHelper.waitForCallback(
+ currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
- /**
- * Loads url on the UI thread but does not block.
- */
- public void postUrlAsync(final AwContents awContents,
- final String url, byte[] postData) throws Exception {
+ public void postUrlAsync(final AwContents awContents, final String url, byte[] postData)
+ throws Exception {
class PostUrl implements Runnable {
byte[] mPostData;
public PostUrl(byte[] postData) {
@@ -243,46 +191,36 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
awContents.postUrl(url, mPostData);
}
}
- getInstrumentation().runOnMainSync(new PostUrl(postData));
+ mCallback.getInstrumentation().runOnMainSync(new PostUrl(postData));
}
- /**
- * Loads data on the UI thread and blocks until onPageFinished is called.
- */
- public void loadDataSync(final AwContents awContents,
- CallbackHelper onPageFinishedHelper,
- final String data, final String mimeType,
- final boolean isBase64Encoded) throws Exception {
+ public void loadDataSync(final AwContents awContents, CallbackHelper onPageFinishedHelper,
+ final String data, final String mimeType, final boolean isBase64Encoded)
+ throws Exception {
int currentCallCount = onPageFinishedHelper.getCallCount();
loadDataAsync(awContents, data, mimeType, isBase64Encoded);
- onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
+ onPageFinishedHelper.waitForCallback(
+ currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
public void loadDataSyncWithCharset(final AwContents awContents,
- CallbackHelper onPageFinishedHelper,
- final String data, final String mimeType,
- final boolean isBase64Encoded, final String charset)
- throws Exception {
+ CallbackHelper onPageFinishedHelper, final String data, final String mimeType,
+ final boolean isBase64Encoded, final String charset) throws Exception {
int currentCallCount = onPageFinishedHelper.getCallCount();
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.loadUrl(LoadUrlParams.createLoadDataParams(
data, mimeType, isBase64Encoded, charset));
}
});
- onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
+ onPageFinishedHelper.waitForCallback(
+ currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
- /**
- * Loads data on the UI thread but does not block.
- */
- public void loadDataAsync(final AwContents awContents, final String data,
- final String mimeType, final boolean isBase64Encoded)
- throws Exception {
- getInstrumentation().runOnMainSync(new Runnable() {
+ public void loadDataAsync(final AwContents awContents, final String data, final String mimeType,
+ final boolean isBase64Encoded) throws Exception {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.loadData(data, mimeType, isBase64Encoded ? "base64" : null);
@@ -292,18 +230,18 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
public void loadDataWithBaseUrlSync(final AwContents awContents,
CallbackHelper onPageFinishedHelper, final String data, final String mimeType,
- final boolean isBase64Encoded, final String baseUrl,
- final String historyUrl) throws Throwable {
+ final boolean isBase64Encoded, final String baseUrl, final String historyUrl)
+ throws Throwable {
int currentCallCount = onPageFinishedHelper.getCallCount();
loadDataWithBaseUrlAsync(awContents, data, mimeType, isBase64Encoded, baseUrl, historyUrl);
- onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
+ onPageFinishedHelper.waitForCallback(
+ currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
- public void loadDataWithBaseUrlAsync(final AwContents awContents,
- final String data, final String mimeType, final boolean isBase64Encoded,
- final String baseUrl, final String historyUrl) throws Throwable {
- runTestOnUiThread(new Runnable() {
+ public void loadDataWithBaseUrlAsync(final AwContents awContents, final String data,
+ final String mimeType, final boolean isBase64Encoded, final String baseUrl,
+ final String historyUrl) throws Throwable {
+ mCallback.runOnUiThread(new Runnable() {
@Override
public void run() {
awContents.loadDataWithBaseURL(
@@ -312,27 +250,21 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Reloads the current page synchronously.
- */
- public void reloadSync(final AwContents awContents,
- CallbackHelper onPageFinishedHelper) throws Exception {
+ public void reloadSync(final AwContents awContents, CallbackHelper onPageFinishedHelper)
+ throws Exception {
int currentCallCount = onPageFinishedHelper.getCallCount();
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.getNavigationController().reload(true);
}
});
- onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
+ onPageFinishedHelper.waitForCallback(
+ currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
- /**
- * Stops loading on the UI thread.
- */
public void stopLoading(final AwContents awContents) {
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.stopLoading();
@@ -343,15 +275,15 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
public void waitForVisualStateCallback(final AwContents awContents) throws Exception {
final CallbackHelper ch = new CallbackHelper();
final int chCount = ch.getCallCount();
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
final long requestId = 666;
- awContents.insertVisualStateCallback(requestId,
- new AwContents.VisualStateCallback() {
+ awContents.insertVisualStateCallback(
+ requestId, new AwContents.VisualStateCallback() {
@Override
public void onComplete(long id) {
- assertEquals(requestId, id);
+ Assert.assertEquals(requestId, id);
ch.notifyCalled();
}
});
@@ -362,7 +294,7 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
public void insertVisualStateCallbackOnUIThread(final AwContents awContents,
final long requestId, final AwContents.VisualStateCallback callback) {
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.insertVisualStateCallback(requestId, callback);
@@ -370,9 +302,6 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- // Waits for the pixel at the center of AwContents to color up into expectedColor.
- // Note that this is a stricter condition that waiting for a visual state callback,
- // as visual state callback only indicates that *something* has appeared in WebView.
public void waitForPixelColorAtCenterOfView(final AwContents awContents,
final AwTestContainerView testContainerView, final int expectedColor) throws Exception {
pollUiThread(new Callable<Boolean>() {
@@ -384,60 +313,11 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Checks the current test has |clazz| annotation. Note this swallows NoSuchMethodException
- * and returns false in that case.
- */
- private boolean testMethodHasAnnotation(Class<? extends Annotation> clazz) {
- String testName = getName();
- Method method = null;
- try {
- method = getClass().getMethod(testName);
- } catch (NoSuchMethodException e) {
- Log.w(TAG, "Test method name not found.", e);
- return false;
- }
-
- // Cast to AnnotatedElement to work around a compilation failure.
- // Method.isAnnotationPresent() was removed in Java 8 (which is used by the Android N SDK),
- // so compilation with Java 7 fails. See crbug.com/608792.
- return ((AnnotatedElement) method).isAnnotationPresent(clazz);
- }
-
- /**
- * Factory class used in creation of test AwContents instances.
- *
- * Test cases can provide subclass instances to the createAwTest* methods in order to create an
- * AwContents instance with injected test dependencies.
- */
- public static class TestDependencyFactory extends AwContents.DependencyFactory {
- public AwTestContainerView createAwTestContainerView(AwTestRunnerActivity activity,
- boolean allowHardwareAcceleration) {
- return new AwTestContainerView(activity, allowHardwareAcceleration);
- }
- public AwSettings createAwSettings(Context context, boolean supportsLegacyQuirks) {
- return new AwSettings(context, false /* isAccessFromFileURLsGrantedByDefault */,
- supportsLegacyQuirks, false /* allowEmptyDocumentPersistence */,
- true /* allowGeolocationOnInsecureOrigins */,
- false /* doNotUpdateSelectionOnMutatingSelectionRange */);
- }
-
- public AwContents createAwContents(AwBrowserContext browserContext, ViewGroup containerView,
- Context context, InternalAccessDelegate internalAccessAdapter,
- NativeDrawGLFunctorFactory nativeDrawGLFunctorFactory,
- AwContentsClient contentsClient, AwSettings settings,
- DependencyFactory dependencyFactory) {
- return new AwContents(browserContext, containerView, context, internalAccessAdapter,
- nativeDrawGLFunctorFactory, contentsClient, settings, dependencyFactory);
- }
- }
-
- protected TestDependencyFactory createTestDependencyFactory() {
+ TestDependencyFactory createTestDependencyFactory() {
return new TestDependencyFactory();
}
- public AwTestContainerView createAwTestContainerView(
- final AwContentsClient awContentsClient) {
+ public AwTestContainerView createAwTestContainerView(final AwContentsClient awContentsClient) {
return createAwTestContainerView(awContentsClient, false, null);
}
@@ -445,7 +325,7 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
boolean supportsLegacyQuirks, final TestDependencyFactory testDependencyFactory) {
AwTestContainerView testContainerView = createDetachedAwTestContainerView(
awContentsClient, supportsLegacyQuirks, testDependencyFactory);
- getActivity().addView(testContainerView);
+ mCallback.getActivity().addView(testContainerView);
testContainerView.requestFocus();
return testContainerView;
}
@@ -468,10 +348,10 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
boolean allowHardwareAcceleration = isHardwareAcceleratedTest();
final AwTestContainerView testContainerView =
testDependencyFactory.createAwTestContainerView(
- getActivity(), allowHardwareAcceleration);
+ mCallback.getActivity(), allowHardwareAcceleration);
- AwSettings awSettings =
- testDependencyFactory.createAwSettings(getActivity(), supportsLegacyQuirks);
+ AwSettings awSettings = testDependencyFactory.createAwSettings(
+ mCallback.getActivity(), supportsLegacyQuirks);
AwContents awContents = testDependencyFactory.createAwContents(mBrowserContext,
testContainerView, testContainerView.getContext(),
testContainerView.getInternalAccessDelegate(),
@@ -481,12 +361,12 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
return testContainerView;
}
- protected boolean isHardwareAcceleratedTest() {
- return !testMethodHasAnnotation(DisableHardwareAccelerationForTest.class);
+ boolean isHardwareAcceleratedTest() {
+ return !mCallback.testMethodHasAnnotation(DisableHardwareAccelerationForTest.class);
}
- public AwTestContainerView createAwTestContainerViewOnMainSync(
- final AwContentsClient client) throws Exception {
+ public AwTestContainerView createAwTestContainerViewOnMainSync(final AwContentsClient client)
+ throws Exception {
return createAwTestContainerViewOnMainSync(client, false, null);
}
@@ -508,7 +388,7 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
public void destroyAwContentsOnMainSync(final AwContents awContents) {
if (awContents == null) return;
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.destroy();
@@ -525,8 +405,7 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- public AwSettings getAwSettingsOnUiThread(
- final AwContents awContents) throws Exception {
+ public AwSettings getAwSettingsOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<AwSettings>() {
@Override
public AwSettings call() throws Exception {
@@ -535,43 +414,30 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Verify double quotes in both sides of the raw string. Strip the double quotes and
- * returns rest of the string.
- */
- protected String maybeStripDoubleQuotes(String raw) {
- assertNotNull(raw);
+ String maybeStripDoubleQuotes(String raw) {
+ Assert.assertNotNull(raw);
Matcher m = MAYBE_QUOTED_STRING.matcher(raw);
- assertTrue(m.matches());
+ Assert.assertTrue(m.matches());
return m.group(2);
}
- /**
- * Executes the given snippet of JavaScript code within the given ContentView. Returns the
- * result of its execution in JSON format.
- */
public String executeJavaScriptAndWaitForResult(final AwContents awContents,
TestAwContentsClient viewClient, final String code) throws Exception {
- return JSUtils.executeJavaScriptAndWaitForResult(this, awContents,
- viewClient.getOnEvaluateJavaScriptResultHelper(),
- code);
+ return JSUtils.executeJavaScriptAndWaitForResult(mCallback.getInstrumentation(), awContents,
+ viewClient.getOnEvaluateJavaScriptResultHelper(), code);
}
/**
* Executes JavaScript code within the given ContentView to get the text content in
* document body. Returns the result string without double quotes.
*/
- protected String getJavaScriptResultBodyTextContent(
+ String getJavaScriptResultBodyTextContent(
final AwContents awContents, final TestAwContentsClient viewClient) throws Exception {
String raw = executeJavaScriptAndWaitForResult(
awContents, viewClient, "document.body.textContent");
return maybeStripDoubleQuotes(raw);
}
- /**
- * Wrapper around CriteriaHelper.pollInstrumentationThread. This uses AwTestBase-specifc
- * timeouts and treats timeouts and exceptions as test failures automatically.
- */
public static void pollInstrumentationThread(final Callable<Boolean> callable)
throws Exception {
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@@ -587,9 +453,6 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
}, WAIT_TIMEOUT_MS, CHECK_INTERVAL);
}
- /**
- * Wrapper around {@link AwTestBase#poll()} but runs the callable on the UI thread.
- */
public void pollUiThread(final Callable<Boolean> callable) throws Exception {
pollInstrumentationThread(new Callable<Boolean>() {
@Override
@@ -599,14 +462,9 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Clears the resource cache. Note that the cache is per-application, so this will clear the
- * cache for all WebViews used.
- */
- public void clearCacheOnUiThread(
- final AwContents awContents,
- final boolean includeDiskFiles) throws Exception {
- getInstrumentation().runOnMainSync(new Runnable() {
+ public void clearCacheOnUiThread(final AwContents awContents, final boolean includeDiskFiles)
+ throws Exception {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.clearCache(includeDiskFiles);
@@ -614,9 +472,6 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Returns pure page scale.
- */
public float getScaleOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
@@ -626,9 +481,6 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Returns page scale multiplied by the screen density.
- */
public float getPixelScaleOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Float>() {
@Override
@@ -638,9 +490,6 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Returns whether a user can zoom the page in.
- */
public boolean canZoomInOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
@Override
@@ -650,9 +499,6 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Returns whether a user can zoom the page out.
- */
public boolean canZoomOutOnUiThread(final AwContents awContents) throws Exception {
return runTestOnUiThreadAndGetResult(new Callable<Boolean>() {
@Override
@@ -663,7 +509,7 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
}
public void killRenderProcessOnUiThreadAsync(final AwContents awContents) throws Exception {
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
awContents.killRenderProcess();
@@ -671,15 +517,12 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
});
}
- /**
- * Loads the main html then triggers the popup window.
- */
public void triggerPopup(final AwContents parentAwContents,
TestAwContentsClient parentAwContentsClient, TestWebServer testWebServer,
String mainHtml, String popupHtml, String popupPath, String triggerScript)
throws Exception {
enableJavaScriptOnUiThread(parentAwContents);
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
parentAwContents.getSettings().setSupportMultipleWindows(true);
@@ -705,24 +548,6 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
}
- /**
- * POD object for holding references to helper objects of a popup window.
- */
- public static class PopupInfo {
- public final TestAwContentsClient popupContentsClient;
- public final AwTestContainerView popupContainerView;
- public final AwContents popupContents;
- public PopupInfo(TestAwContentsClient popupContentsClient,
- AwTestContainerView popupContainerView, AwContents popupContents) {
- this.popupContentsClient = popupContentsClient;
- this.popupContainerView = popupContainerView;
- this.popupContents = popupContents;
- }
- }
-
- /**
- * Supplies the popup window with AwContents then waits for the popup window to finish loading.
- */
public PopupInfo connectPendingPopup(final AwContents parentAwContents) throws Exception {
TestAwContentsClient popupContentsClient;
AwTestContainerView popupContainerView;
@@ -732,7 +557,7 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
popupContents = popupContainerView.getAwContents();
enableJavaScriptOnUiThread(popupContents);
- getInstrumentation().runOnMainSync(new Runnable() {
+ mCallback.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
parentAwContents.supplyContentsForPopup(popupContents);
@@ -745,11 +570,18 @@ public class AwTestBase extends BaseActivityInstrumentationTestCase<AwTestRunner
popupContentsClient.getOnReceivedTitleHelper();
int titleCallCount = onReceivedTitleHelper.getCallCount();
- onPageFinishedHelper.waitForCallback(finishCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
- onReceivedTitleHelper.waitForCallback(titleCallCount, 1, WAIT_TIMEOUT_MS,
- TimeUnit.MILLISECONDS);
+ onPageFinishedHelper.waitForCallback(
+ finishCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
+ onReceivedTitleHelper.waitForCallback(
+ titleCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
return new PopupInfo(popupContentsClient, popupContainerView, popupContents);
}
+
+ public interface AwTestCommonCallback {
+ Instrumentation getInstrumentation();
+ AwTestRunnerActivity getActivity();
+ void runOnUiThread(Runnable runnable) throws Throwable;
+ boolean testMethodHasAnnotation(Class<? extends Annotation> clazz);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698