| Index: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeTestBase.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeTestBase.java b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeTestBase.java
|
| index 592e6f9db44871834678e47a89c5c404fa0ba888..d7907c689c46a77a872f533d7d3b71e3d0962eb9 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeTestBase.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeTestBase.java
|
| @@ -4,92 +4,39 @@
|
|
|
| package org.chromium.content.browser;
|
|
|
| -import android.util.Log;
|
| -
|
| -import junit.framework.Assert;
|
| -
|
| -import org.chromium.base.annotations.SuppressFBWarnings;
|
| -import org.chromium.base.test.util.UrlUtils;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
|
| -import org.chromium.content_public.browser.LoadUrlParams;
|
| import org.chromium.content_shell_apk.ContentShellActivity;
|
| import org.chromium.content_shell_apk.ContentShellTestBase;
|
| +import org.chromium.content_shell_apk.ContentShellTestCommon.TestCommonCallback;
|
|
|
| import java.lang.annotation.Annotation;
|
|
|
| /**
|
| * Common functionality for testing the Java Bridge.
|
| */
|
| -public class JavaBridgeTestBase extends ContentShellTestBase {
|
| -
|
| - protected TestCallbackHelperContainer mTestCallbackHelperContainer;
|
| +public class JavaBridgeTestBase
|
| + extends ContentShellTestBase implements TestCommonCallback<ContentShellActivity> {
|
| + private final JavaBridgeTestCommon mTestCommon = new JavaBridgeTestCommon(this);
|
|
|
| /**
|
| * Sets up the ContentView. Intended to be called from setUp().
|
| */
|
| private void setUpContentView() throws Exception {
|
| - // This starts the activity, so must be called on the test thread.
|
| - final ContentShellActivity activity = launchContentShellWithUrl(
|
| - UrlUtils.encodeHtmlDataUri("<html><head></head><body>test</body></html>"));
|
| -
|
| - waitForActiveShellToBeDoneLoading();
|
| -
|
| - try {
|
| - runTestOnUiThread(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - mTestCallbackHelperContainer = new TestCallbackHelperContainer(
|
| - activity.getActiveContentViewCore());
|
| - }
|
| - });
|
| - } catch (Throwable e) {
|
| - throw new RuntimeException(
|
| - "Failed to set up ContentView: " + Log.getStackTraceString(e));
|
| - }
|
| + mTestCommon.setUpContentView();
|
| }
|
|
|
| @Override
|
| protected void setUp() throws Exception {
|
| super.setUp();
|
| - setUpContentView();
|
| + mTestCommon.setUpContentView();
|
| }
|
|
|
| - @SuppressFBWarnings("CHROMIUM_SYNCHRONIZED_METHOD")
|
| - protected static class Controller {
|
| - private boolean mIsResultReady;
|
| -
|
| - protected synchronized void notifyResultIsReady() {
|
| - mIsResultReady = true;
|
| - notify();
|
| - }
|
| - protected synchronized void waitForResult() {
|
| - while (!mIsResultReady) {
|
| - try {
|
| - wait(5000);
|
| - } catch (Exception e) {
|
| - continue;
|
| - }
|
| - if (!mIsResultReady) {
|
| - Assert.fail("Wait timed out");
|
| - }
|
| - }
|
| - mIsResultReady = false;
|
| - }
|
| + public TestCallbackHelperContainer getTestCallBackHelperContainer() {
|
| + return mTestCommon.getTestCallBackHelperContainer();
|
| }
|
|
|
| protected void executeJavaScript(final String script) throws Throwable {
|
| - runTestOnUiThread(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - // When a JavaScript URL is executed, if the value of the last
|
| - // expression evaluated is not 'undefined', this value is
|
| - // converted to a string and used as the new document for the
|
| - // frame. We don't want this behaviour, so wrap the script in
|
| - // an anonymous function.
|
| - getWebContents().getNavigationController().loadUrl(
|
| - new LoadUrlParams("javascript:(function() { " + script + " })()"));
|
| - }
|
| - });
|
| + mTestCommon.executeJavaScript(script);
|
| }
|
|
|
| protected void injectObjectAndReload(final Object object, final String name) throws Exception {
|
| @@ -104,39 +51,10 @@ public class JavaBridgeTestBase extends ContentShellTestBase {
|
| protected void injectObjectsAndReload(final Object object1, final String name1,
|
| final Object object2, final String name2,
|
| final Class<? extends Annotation> requiredAnnotation) throws Exception {
|
| - TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
|
| - mTestCallbackHelperContainer.getOnPageFinishedHelper();
|
| - int currentCallCount = onPageFinishedHelper.getCallCount();
|
| - try {
|
| - runTestOnUiThread(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - getContentViewCore().addPossiblyUnsafeJavascriptInterface(object1,
|
| - name1, requiredAnnotation);
|
| - if (object2 != null && name2 != null) {
|
| - getContentViewCore().addPossiblyUnsafeJavascriptInterface(object2,
|
| - name2, requiredAnnotation);
|
| - }
|
| - getContentViewCore().getWebContents().getNavigationController().reload(true);
|
| - }
|
| - });
|
| - onPageFinishedHelper.waitForCallback(currentCallCount);
|
| - } catch (Throwable e) {
|
| - throw new RuntimeException(
|
| - "Failed to injectObjectsAndReload: " + Log.getStackTraceString(e));
|
| - }
|
| + mTestCommon.injectObjectsAndReload(object1, name1, object2, name2, requiredAnnotation);
|
| }
|
|
|
| protected void synchronousPageReload() throws Throwable {
|
| - TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
|
| - mTestCallbackHelperContainer.getOnPageFinishedHelper();
|
| - int currentCallCount = onPageFinishedHelper.getCallCount();
|
| - runTestOnUiThread(new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - getContentViewCore().getWebContents().getNavigationController().reload(true);
|
| - }
|
| - });
|
| - onPageFinishedHelper.waitForCallback(currentCallCount);
|
| + mTestCommon.synchronousPageReload();
|
| }
|
| }
|
|
|