Commit e4330f81 authored by Yaron Friedman's avatar Yaron Friedman Committed by Commit Bot

Batch remaining JavaBridgeTests into one.

Also some cleanup unifying/simplifying the setup fixture.

Change-Id: I6cbbcb5cbbd01f548ac87f80a71cc2b8f656f7ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431450Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Yaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811708}
parent dd0b0ce9
......@@ -9,8 +9,6 @@ import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.chromium.base.Log;
import org.chromium.base.test.SetUpStatement;
import org.chromium.base.test.SetUpTestRule;
import org.chromium.base.test.params.ParameterProvider;
import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.util.UrlUtils;
......@@ -28,8 +26,10 @@ import java.util.List;
/**
* ActivityTestRule with common functionality for testing the Java Bridge.
*/
public class JavaBridgeActivityTestRule
extends ContentShellActivityTestRule implements SetUpTestRule<JavaBridgeActivityTestRule> {
public class JavaBridgeActivityTestRule extends ContentShellActivityTestRule {
/** Shared name for batched JavaBridge tests. */
public static final String BATCH = "JavaBridgeActivityTestRule";
/**
* {@link ParameterProvider} used for parameterized test that provides the Mojo usage state.
*/
......@@ -58,7 +58,6 @@ public class JavaBridgeActivityTestRule
}
private TestCallbackHelperContainer mTestCallbackHelperContainer;
private boolean mSetup;
private boolean mUseMojo;
public static class Controller {
......@@ -183,18 +182,7 @@ public class JavaBridgeActivityTestRule
@Override
public Statement apply(Statement base, Description desc) {
SetUpStatement setUpBase = new SetUpStatement(base, this, mSetup);
return super.apply(setUpBase, desc);
}
@Override
public JavaBridgeActivityTestRule shouldSetUp(boolean runSetUp) {
mSetup = runSetUp;
return this;
}
@Override
public void setUp() {
setUpContentView();
return super.apply(base, desc);
}
}
......@@ -17,6 +17,7 @@ import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
......@@ -33,12 +34,12 @@ import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
@Batch(JavaBridgeActivityTestRule.BATCH)
public class JavaBridgeArrayCoercionTest {
private static final double ASSERTION_DELTA = 0;
@Rule
public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(true);
public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
private static class TestObject extends Controller {
private final Object mObjectInstance;
......
......@@ -17,6 +17,7 @@ import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
......@@ -32,10 +33,10 @@ import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
@Batch(JavaBridgeActivityTestRule.BATCH)
public class JavaBridgeArrayTest {
@Rule
public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(true);
public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
private static class TestObject extends Controller {
private boolean mBooleanValue;
......
......@@ -7,7 +7,6 @@ package org.chromium.content.browser;
import androidx.test.filters.SmallTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
......@@ -17,22 +16,21 @@ import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer;
import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper;
import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer.OnPageFinishedHelper;
/**
* Common functionality for testing the Java Bridge.
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
@Batch(JavaBridgeActivityTestRule.BATCH)
public class JavaBridgeBareboneTest {
@Rule
public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(false);
public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
private TestCallbackHelperContainer mTestCallbackHelperContainer;
private boolean mUseMojo;
......@@ -43,15 +41,6 @@ public class JavaBridgeBareboneTest {
mActivityTestRule.setupMojoTest(useMojo);
}
@Before
public void setUp() {
mActivityTestRule.launchContentShellWithUrl(
UrlUtils.encodeHtmlDataUri("<html><head></head><body>test</body></html>"));
mActivityTestRule.waitForActiveShellToBeDoneLoading();
mTestCallbackHelperContainer =
new TestCallbackHelperContainer(mActivityTestRule.getWebContents());
}
private void injectDummyObject(final String name) throws Throwable {
mActivityTestRule.runOnUiThread(new Runnable() {
@Override
......@@ -69,19 +58,6 @@ public class JavaBridgeBareboneTest {
return javascriptHelper.getJsonResultAndClear();
}
private void reloadSync() throws Throwable {
OnPageFinishedHelper pageFinishedHelper =
mTestCallbackHelperContainer.getOnPageFinishedHelper();
int currentCallCount = pageFinishedHelper.getCallCount();
mActivityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
mActivityTestRule.getWebContents().getNavigationController().reload(true);
}
});
pageFinishedHelper.waitForCallback(currentCallCount);
}
// If inection happens before evaluating any JS code, then the first evaluation
// triggers the same condition as page reload, which causes Java Bridge to add
// a JS wrapper.
......@@ -121,7 +97,7 @@ public class JavaBridgeBareboneTest {
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
@DisabledTest(message = "Flaky - https://crbug.com/1117003")
public void testImmediateAdditionAfterReload(boolean useMojo) throws Throwable {
reloadSync();
mActivityTestRule.synchronousPageReload();
injectDummyObject("testObject");
Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
}
......@@ -132,7 +108,7 @@ public class JavaBridgeBareboneTest {
@UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testReloadAfterAddition(boolean useMojo) throws Throwable {
injectDummyObject("testObject");
reloadSync();
mActivityTestRule.synchronousPageReload();
Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
}
}
......@@ -10,7 +10,6 @@ import android.support.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
......@@ -51,11 +50,10 @@ import java.util.concurrent.CountDownLatch;
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(ContentJUnit4RunnerDelegate.class)
@Batch(Batch.PER_CLASS)
@Batch(JavaBridgeActivityTestRule.BATCH)
public class JavaBridgeBasicsTest {
@Rule
public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(false);
public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
private static class TestController extends Controller {
private int mIntValue;
......@@ -117,18 +115,10 @@ public class JavaBridgeBasicsTest {
@Before
public void setUp() {
mActivityTestRule.setUpContentView();
mTestController = new TestController();
mActivityTestRule.injectObjectAndReload(mTestController, "testController");
}
@After
public void tearDown() throws Exception {
// TODO(yfriedman): Instead of finishing the activity, re-use it and launch a new Shell to
// minimize overhead.
mActivityTestRule.getActivity().finish();
}
// Note that this requires that we can pass a JavaScript string to Java.
protected String executeJavaScriptAndGetStringResult(String script) throws Throwable {
mActivityTestRule.executeJavaScript("testController.setStringValue(" + script + ");");
......
......@@ -18,6 +18,7 @@ import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature;
......@@ -41,10 +42,10 @@ import java.util.concurrent.TimeoutException;
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(ContentJUnit4RunnerDelegate.class)
@Batch(JavaBridgeActivityTestRule.BATCH)
public class JavaBridgeChildFrameTest {
@Rule
public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(true);
public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
private static class TestController extends Controller {
private String mStringValue;
......
......@@ -19,6 +19,7 @@ import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
......@@ -39,12 +40,12 @@ import java.io.File;
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
@Batch(JavaBridgeActivityTestRule.BATCH)
public class JavaBridgeCoercionTest {
private static final double ASSERTION_DELTA = 0;
@Rule
public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(true);
public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
private static class TestObject extends Controller {
private Object mObjectInstance;
......
......@@ -17,6 +17,7 @@ import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
......@@ -26,10 +27,10 @@ import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
@Batch(JavaBridgeActivityTestRule.BATCH)
public class JavaBridgeFieldsTest {
@Rule
public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(true);
public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
private static class TestObject extends Controller {
private String mStringValue;
......
......@@ -17,6 +17,7 @@ import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameter;
import org.chromium.base.test.params.ParameterAnnotations.UseMethodParameterBefore;
import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate;
import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.Batch;
import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
......@@ -33,10 +34,10 @@ import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
@Batch(JavaBridgeActivityTestRule.BATCH)
public class JavaBridgeReturnValuesTest {
@Rule
public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(true);
public JavaBridgeActivityTestRule mActivityTestRule = new JavaBridgeActivityTestRule();
// An instance of this class is injected into the page to test returning
// Java values to JavaScript.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment