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..68431da184db8d1dee60e47cc87e952917d216fa 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 |
@@ -1,4 +1,4 @@ |
-// Copyright 2015 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. |
@@ -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")); |
} |
} |