| Index: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBareboneTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBareboneTest.java b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBareboneTest.java
|
| index 0261302b88c9aa1e2ef1cbf7373f291c0ef76321..ae2349ec0fcbdc4a80cd5b212fabb32f66c400f6 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBareboneTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBareboneTest.java
|
| @@ -6,33 +6,44 @@ package org.chromium.content.browser;
|
|
|
| import android.support.test.filters.SmallTest;
|
|
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +
|
| +import org.chromium.base.test.BaseJUnit4ClassRunner;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.UrlUtils;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
|
| import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
|
| -import org.chromium.content_shell_apk.ContentShellTestBase;
|
| +import org.chromium.content_shell_apk.ContentShellActivityTestRule;
|
|
|
| /**
|
| * Common functionality for testing the Java Bridge.
|
| */
|
| -public class JavaBridgeBareboneTest extends ContentShellTestBase {
|
| +@RunWith(BaseJUnit4ClassRunner.class)
|
| +public class JavaBridgeBareboneTest {
|
| + @Rule
|
| + public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule();
|
| +
|
| private TestCallbackHelperContainer mTestCallbackHelperContainer;
|
|
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - super.setUp();
|
| - launchContentShellWithUrl(
|
| + @Before
|
| + public void setUp() throws Exception {
|
| + mActivityTestRule.launchContentShellWithUrl(
|
| UrlUtils.encodeHtmlDataUri("<html><head></head><body>test</body></html>"));
|
| - waitForActiveShellToBeDoneLoading();
|
| - mTestCallbackHelperContainer = new TestCallbackHelperContainer(getContentViewCore());
|
| + mActivityTestRule.waitForActiveShellToBeDoneLoading();
|
| + mTestCallbackHelperContainer =
|
| + new TestCallbackHelperContainer(mActivityTestRule.getContentViewCore());
|
| }
|
|
|
| private void injectDummyObject(final String name) throws Throwable {
|
| - runTestOnUiThread(new Runnable() {
|
| + mActivityTestRule.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getContentViewCore().addPossiblyUnsafeJavascriptInterface(
|
| + mActivityTestRule.getContentViewCore().addPossiblyUnsafeJavascriptInterface(
|
| new Object(), name, null);
|
| }
|
| });
|
| @@ -40,7 +51,7 @@ public class JavaBridgeBareboneTest extends ContentShellTestBase {
|
|
|
| private String evaluateJsSync(String jsCode) throws Exception {
|
| OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaScriptResultHelper();
|
| - javascriptHelper.evaluateJavaScriptForTests(getWebContents(), jsCode);
|
| + javascriptHelper.evaluateJavaScriptForTests(mActivityTestRule.getWebContents(), jsCode);
|
| javascriptHelper.waitUntilHasValue();
|
| return javascriptHelper.getJsonResultAndClear();
|
| }
|
| @@ -49,10 +60,10 @@ public class JavaBridgeBareboneTest extends ContentShellTestBase {
|
| OnPageFinishedHelper pageFinishedHelper =
|
| mTestCallbackHelperContainer.getOnPageFinishedHelper();
|
| int currentCallCount = pageFinishedHelper.getCallCount();
|
| - runTestOnUiThread(new Runnable() {
|
| + mActivityTestRule.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getWebContents().getNavigationController().reload(true);
|
| + mActivityTestRule.getWebContents().getNavigationController().reload(true);
|
| }
|
| });
|
| pageFinishedHelper.waitForCallback(currentCallCount);
|
| @@ -69,36 +80,40 @@ public class JavaBridgeBareboneTest extends ContentShellTestBase {
|
| // webView.addJavascriptInterface(new Foo(), "foo");
|
| // webView.loadUrl("javascript:foo.bar();void(0);");
|
| //
|
| + @Test
|
| @SmallTest
|
| @Feature({"AndroidWebView", "Android-JavaBridge"})
|
| public void testImmediateAddition() throws Throwable {
|
| injectDummyObject("testObject");
|
| - assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
|
| + Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
|
| }
|
|
|
| // Now here, we evaluate some JS before injecting the object, and this behaves as
|
| // expected.
|
| + @Test
|
| @SmallTest
|
| @Feature({"AndroidWebView", "Android-JavaBridge"})
|
| public void testNoImmediateAdditionAfterJSEvaluation() throws Throwable {
|
| evaluateJsSync("true");
|
| injectDummyObject("testObject");
|
| - assertEquals("\"undefined\"", evaluateJsSync("typeof testObject"));
|
| + Assert.assertEquals("\"undefined\"", evaluateJsSync("typeof testObject"));
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"AndroidWebView", "Android-JavaBridge"})
|
| public void testImmediateAdditionAfterReload() throws Throwable {
|
| reloadSync();
|
| injectDummyObject("testObject");
|
| - assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
|
| + Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| @Feature({"AndroidWebView", "Android-JavaBridge"})
|
| public void testReloadAfterAddition() throws Throwable {
|
| injectDummyObject("testObject");
|
| reloadSync();
|
| - assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
|
| + Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
|
| }
|
| }
|
|
|