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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java

Issue 1102753002: [Android] Refactor Java Bridge tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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: content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
index 4e9729a2a940c4dce2980721c25461de98b2792b..97f91a1ee336d9e122fc2e6dc264e16f56277637 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/JavaBridgeBasicsTest.java
@@ -16,7 +16,6 @@ import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content_public.browser.LoadUrlParams;
-import java.lang.annotation.Annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -96,7 +95,7 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
protected void setUp() throws Exception {
super.setUp();
mTestController = new TestController();
- setUpContentView(mTestController, "testController");
+ injectObjectAndReload(mTestController, "testController");
}
// Note that this requires that we can pass a JavaScript string to Java.
@@ -105,26 +104,6 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
return mTestController.waitForStringValue();
}
- protected void injectObjectAndReload(final Object object, final String name) throws Throwable {
- injectObjectAndReload(object, name, null);
- }
-
- protected void injectObjectAndReload(final Object object, final String name,
- final Class<? extends Annotation> requiredAnnotation) throws Throwable {
- TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
- mTestCallbackHelperContainer.getOnPageFinishedHelper();
- int currentCallCount = onPageFinishedHelper.getCallCount();
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- getContentViewCore().addPossiblyUnsafeJavascriptInterface(object,
- name, requiredAnnotation);
- getContentViewCore().getWebContents().getNavigationController().reload(true);
- }
- });
- onPageFinishedHelper.waitForCallback(currentCallCount);
- }
-
protected void synchronousPageReload() throws Throwable {
TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
mTestCallbackHelperContainer.getOnPageFinishedHelper();
@@ -410,20 +389,7 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
}
}
final TestObject testObject = new TestObject();
- TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
- mTestCallbackHelperContainer.getOnPageFinishedHelper();
- int currentCallCount = onPageFinishedHelper.getCallCount();
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- getContentViewCore().addPossiblyUnsafeJavascriptInterface(
- testObject, "testObject1", null);
- getContentViewCore().addPossiblyUnsafeJavascriptInterface(
- testObject, "testObject2", null);
- getContentViewCore().getWebContents().getNavigationController().reload(true);
- }
- });
- onPageFinishedHelper.waitForCallback(currentCallCount);
+ injectObjectsAndReload(testObject, "testObject1", testObject, "testObject2", null);
executeJavaScript("testObject1.method()");
assertEquals(1, mTestController.waitForIntValue());
executeJavaScript("testObject2.method()");
@@ -462,20 +428,7 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
return innerObject;
}
};
- TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
- mTestCallbackHelperContainer.getOnPageFinishedHelper();
- int currentCallCount = onPageFinishedHelper.getCallCount();
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- getContentViewCore().addPossiblyUnsafeJavascriptInterface(
- object, "testObject", null);
- getContentViewCore().addPossiblyUnsafeJavascriptInterface(
- innerObject, "innerObject", null);
- getContentViewCore().getWebContents().getNavigationController().reload(true);
- }
- });
- onPageFinishedHelper.waitForCallback(currentCallCount);
+ injectObjectsAndReload(object, "testObject", innerObject, "innerObject", null);
executeJavaScript("testObject.getInnerObject().method()");
assertEquals(1, mTestController.waitForIntValue());
executeJavaScript("innerObject.method()");
@@ -1039,16 +992,7 @@ public class JavaBridgeBasicsTest extends JavaBridgeTestBase {
}
final TestObject testObject1 = new TestObject(1);
final TestObject testObject2 = new TestObject(2);
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- getContentViewCore().addPossiblyUnsafeJavascriptInterface(
- testObject1, "testObject1", null);
- getContentViewCore().addPossiblyUnsafeJavascriptInterface(
- testObject2, "testObject2", null);
- getContentViewCore().getWebContents().getNavigationController().reload(true);
- }
- });
+ injectObjectsAndReload(testObject1, "testObject1", testObject2, "testObject2", null);
executeJavaScript("testObject1.method()");
assertEquals(1, mTestController.waitForIntValue());
executeJavaScript("testObject2.method()");

Powered by Google App Engine
This is Rietveld 408576698