Commit 2ea849e2 authored by Miyoung Shin's avatar Miyoung Shin Committed by Commit Bot

[remoteobjects] Use new codepath for Java bridge in instrumentation tests

This CL is parameterizing the Java bridge instrumentation tests to
run with and without using Mojo in JavascriptInjector, running all
the relevant tests and using
JavaBridgeActivityTestRule#MojoTestParams for the ones that pass
and JavaBridgeActivityTestRule#LegacyTestParams for the ones that
fails. So, all tests still run for the old codepath.

Bug: 1105928
Change-Id: Idb3ee3ed4d1cb49fa0fc37d7609ac2e8ef166177
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2348488Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#798370}
parent ef690472
...@@ -11,6 +11,8 @@ import org.junit.runners.model.Statement; ...@@ -11,6 +11,8 @@ import org.junit.runners.model.Statement;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.test.SetUpStatement; import org.chromium.base.test.SetUpStatement;
import org.chromium.base.test.SetUpTestRule; 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; import org.chromium.base.test.util.UrlUtils;
import org.chromium.content_public.browser.JavascriptInjector; import org.chromium.content_public.browser.JavascriptInjector;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
...@@ -20,14 +22,44 @@ import org.chromium.content_shell_apk.ContentShellActivity; ...@@ -20,14 +22,44 @@ import org.chromium.content_shell_apk.ContentShellActivity;
import org.chromium.content_shell_apk.ContentShellActivityTestRule; import org.chromium.content_shell_apk.ContentShellActivityTestRule;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.util.Arrays;
import java.util.List;
/** /**
* ActivityTestRule with common functionality for testing the Java Bridge. * ActivityTestRule with common functionality for testing the Java Bridge.
*/ */
public class JavaBridgeActivityTestRule public class JavaBridgeActivityTestRule
extends ContentShellActivityTestRule implements SetUpTestRule<JavaBridgeActivityTestRule> { extends ContentShellActivityTestRule implements SetUpTestRule<JavaBridgeActivityTestRule> {
/**
* {@link ParameterProvider} used for parameterized test that provides the Mojo usage state.
*/
public static class MojoTestParams implements ParameterProvider {
private static List<ParameterSet> sMojoTestParams =
Arrays.asList(new ParameterSet().value(false).name("MojoUnused"),
new ParameterSet().value(true).name("MojoUsed"));
@Override
public List<ParameterSet> getParameters() {
return sMojoTestParams;
}
}
/**
* {@link ParameterProvider} used for parameterized test that keeps the legacy tests.
*/
public static class LegacyTestParams implements ParameterProvider {
private static List<ParameterSet> sLegacyTestParams =
Arrays.asList(new ParameterSet().value(false));
@Override
public List<ParameterSet> getParameters() {
return sLegacyTestParams;
}
}
private TestCallbackHelperContainer mTestCallbackHelperContainer; private TestCallbackHelperContainer mTestCallbackHelperContainer;
private boolean mSetup; private boolean mSetup;
private boolean mUseMojo;
public static class Controller { public static class Controller {
private static final int RESULT_WAIT_TIME = 5000; private static final int RESULT_WAIT_TIME = 5000;
...@@ -116,7 +148,8 @@ public class JavaBridgeActivityTestRule ...@@ -116,7 +148,8 @@ public class JavaBridgeActivityTestRule
@Override @Override
public void run() { public void run() {
WebContents webContents = getWebContents(); WebContents webContents = getWebContents();
JavascriptInjector injector = JavascriptInjector.fromWebContents(webContents); JavascriptInjector injector =
JavascriptInjector.fromWebContents(webContents, mUseMojo);
injector.addPossiblyUnsafeInterface(object1, name1, requiredAnnotation); injector.addPossiblyUnsafeInterface(object1, name1, requiredAnnotation);
if (object2 != null && name2 != null) { if (object2 != null && name2 != null) {
injector.addPossiblyUnsafeInterface(object2, name2, requiredAnnotation); injector.addPossiblyUnsafeInterface(object2, name2, requiredAnnotation);
...@@ -130,6 +163,9 @@ public class JavaBridgeActivityTestRule ...@@ -130,6 +163,9 @@ public class JavaBridgeActivityTestRule
"Failed to injectObjectsAndReload: " + Log.getStackTraceString(e)); "Failed to injectObjectsAndReload: " + Log.getStackTraceString(e));
} }
} }
public void setupMojoTest(boolean useMojo) {
mUseMojo = useMojo;
}
public void synchronousPageReload() throws Throwable { public void synchronousPageReload() throws Throwable {
TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper = TestCallbackHelperContainer.OnPageFinishedHelper onPageFinishedHelper =
......
...@@ -12,7 +12,11 @@ import org.junit.Rule; ...@@ -12,7 +12,11 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.params.BaseJUnit4RunnerDelegate;
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.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.UrlUtils; 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;
...@@ -22,13 +26,21 @@ import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer ...@@ -22,13 +26,21 @@ import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer
/** /**
* Common functionality for testing the Java Bridge. * Common functionality for testing the Java Bridge.
*/ */
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
public class JavaBridgeBareboneTest { public class JavaBridgeBareboneTest {
@Rule @Rule
public JavaBridgeActivityTestRule mActivityTestRule = public JavaBridgeActivityTestRule mActivityTestRule =
new JavaBridgeActivityTestRule().shouldSetUp(false); new JavaBridgeActivityTestRule().shouldSetUp(false);
private TestCallbackHelperContainer mTestCallbackHelperContainer; private TestCallbackHelperContainer mTestCallbackHelperContainer;
private boolean mUseMojo;
@UseMethodParameterBefore(JavaBridgeActivityTestRule.MojoTestParams.class)
public void setupMojoTest(boolean useMojo) {
mUseMojo = useMojo;
mActivityTestRule.setupMojoTest(useMojo);
}
@Before @Before
public void setUp() { public void setUp() {
...@@ -43,7 +55,7 @@ public class JavaBridgeBareboneTest { ...@@ -43,7 +55,7 @@ public class JavaBridgeBareboneTest {
mActivityTestRule.runOnUiThread(new Runnable() { mActivityTestRule.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
mActivityTestRule.getJavascriptInjector().addPossiblyUnsafeInterface( mActivityTestRule.getJavascriptInjector(mUseMojo).addPossiblyUnsafeInterface(
new Object(), name, null); new Object(), name, null);
} }
}); });
...@@ -83,7 +95,8 @@ public class JavaBridgeBareboneTest { ...@@ -83,7 +95,8 @@ public class JavaBridgeBareboneTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testImmediateAddition() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testImmediateAddition(boolean useMojo) throws Throwable {
injectDummyObject("testObject"); injectDummyObject("testObject");
Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject")); Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
} }
...@@ -93,7 +106,8 @@ public class JavaBridgeBareboneTest { ...@@ -93,7 +106,8 @@ public class JavaBridgeBareboneTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testNoImmediateAdditionAfterJSEvaluation() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testNoImmediateAdditionAfterJSEvaluation(boolean useMojo) throws Throwable {
evaluateJsSync("true"); evaluateJsSync("true");
injectDummyObject("testObject"); injectDummyObject("testObject");
Assert.assertEquals("\"undefined\"", evaluateJsSync("typeof testObject")); Assert.assertEquals("\"undefined\"", evaluateJsSync("typeof testObject"));
...@@ -102,7 +116,8 @@ public class JavaBridgeBareboneTest { ...@@ -102,7 +116,8 @@ public class JavaBridgeBareboneTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testImmediateAdditionAfterReload() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testImmediateAdditionAfterReload(boolean useMojo) throws Throwable {
reloadSync(); reloadSync();
injectDummyObject("testObject"); injectDummyObject("testObject");
Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject")); Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
...@@ -111,7 +126,8 @@ public class JavaBridgeBareboneTest { ...@@ -111,7 +126,8 @@ public class JavaBridgeBareboneTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testReloadAfterAddition() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testReloadAfterAddition(boolean useMojo) throws Throwable {
injectDummyObject("testObject"); injectDummyObject("testObject");
reloadSync(); reloadSync();
Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject")); Assert.assertEquals("\"object\"", evaluateJsSync("typeof testObject"));
......
...@@ -14,6 +14,10 @@ import org.junit.Rule; ...@@ -14,6 +14,10 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
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.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
...@@ -22,7 +26,7 @@ import org.chromium.content_public.browser.JavaScriptCallback; ...@@ -22,7 +26,7 @@ import org.chromium.content_public.browser.JavaScriptCallback;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.NavigationController; import org.chromium.content_public.browser.NavigationController;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.test.ContentJUnit4ClassRunner; import org.chromium.content_public.browser.test.ContentJUnit4RunnerDelegate;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
...@@ -35,7 +39,8 @@ import java.util.concurrent.TimeoutException; ...@@ -35,7 +39,8 @@ import java.util.concurrent.TimeoutException;
* Ensures that injected objects are exposed to child frames as well as the * Ensures that injected objects are exposed to child frames as well as the
* main frame. * main frame.
*/ */
@RunWith(ContentJUnit4ClassRunner.class) @RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(ContentJUnit4RunnerDelegate.class)
public class JavaBridgeChildFrameTest { public class JavaBridgeChildFrameTest {
@Rule @Rule
public JavaBridgeActivityTestRule mActivityTestRule = public JavaBridgeActivityTestRule mActivityTestRule =
...@@ -56,6 +61,11 @@ public class JavaBridgeChildFrameTest { ...@@ -56,6 +61,11 @@ public class JavaBridgeChildFrameTest {
} }
} }
@UseMethodParameterBefore(JavaBridgeActivityTestRule.MojoTestParams.class)
public void setupMojoTest(boolean useMojo) {
mActivityTestRule.setupMojoTest(useMojo);
}
TestController mTestController; TestController mTestController;
@Before @Before
...@@ -67,7 +77,8 @@ public class JavaBridgeChildFrameTest { ...@@ -67,7 +77,8 @@ public class JavaBridgeChildFrameTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testInjectedObjectPresentInChildFrame() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
public void testInjectedObjectPresentInChildFrame(boolean useMojo) throws Throwable {
loadDataSync(mActivityTestRule.getWebContents().getNavigationController(), loadDataSync(mActivityTestRule.getWebContents().getNavigationController(),
"<html><body><iframe></iframe></body></html>", "text/html", false); "<html><body><iframe></iframe></body></html>", "text/html", false);
// We are not executing this code as a part of page loading routine to avoid races // We are not executing this code as a part of page loading routine to avoid races
...@@ -85,7 +96,8 @@ public class JavaBridgeChildFrameTest { ...@@ -85,7 +96,8 @@ public class JavaBridgeChildFrameTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testMainPageWrapperIsNotBrokenByChildFrame() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testMainPageWrapperIsNotBrokenByChildFrame(boolean useMojo) throws Throwable {
loadDataSync(mActivityTestRule.getWebContents().getNavigationController(), loadDataSync(mActivityTestRule.getWebContents().getNavigationController(),
"<html><body><iframe></iframe></body></html>", "text/html", false); "<html><body><iframe></iframe></body></html>", "text/html", false);
// In case there is anything wrong with the JS wrapper, an attempt // In case there is anything wrong with the JS wrapper, an attempt
...@@ -108,7 +120,8 @@ public class JavaBridgeChildFrameTest { ...@@ -108,7 +120,8 @@ public class JavaBridgeChildFrameTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testWrapperIsNotSharedWithChildFrame() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class)
public void testWrapperIsNotSharedWithChildFrame(boolean useMojo) throws Throwable {
// Test by setting a custom property on the parent page's injected // Test by setting a custom property on the parent page's injected
// object and then checking that child frame doesn't see the property. // object and then checking that child frame doesn't see the property.
loadDataSync(mActivityTestRule.getWebContents().getNavigationController(), loadDataSync(mActivityTestRule.getWebContents().getNavigationController(),
...@@ -137,7 +150,8 @@ public class JavaBridgeChildFrameTest { ...@@ -137,7 +150,8 @@ public class JavaBridgeChildFrameTest {
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@DisabledTest(message = "https://crbug.com/677182") @DisabledTest(message = "https://crbug.com/677182")
public void testRemovingTransientObjectHolders() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testRemovingTransientObjectHolders(boolean useMojo) throws Throwable {
class Test { class Test {
private Object mInner = new Object(); private Object mInner = new Object();
// Expecting the inner object to be retrieved twice. // Expecting the inner object to be retrieved twice.
...@@ -199,7 +213,8 @@ public class JavaBridgeChildFrameTest { ...@@ -199,7 +213,8 @@ public class JavaBridgeChildFrameTest {
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@CommandLineFlags.Add("js-flags=--expose-gc") @CommandLineFlags.Add("js-flags=--expose-gc")
@DisabledTest(message = "https://crbug.com/646843") @DisabledTest(message = "https://crbug.com/646843")
public void testHolderFrame() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testHolderFrame(boolean useMojo) throws Throwable {
class Test { class Test {
WeakReference<Object> mWeakRefForInner; WeakReference<Object> mWeakRefForInner;
private CountDownLatch mLatch = new CountDownLatch(1); private CountDownLatch mLatch = new CountDownLatch(1);
......
...@@ -12,7 +12,11 @@ import org.junit.Rule; ...@@ -12,7 +12,11 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.params.BaseJUnit4RunnerDelegate;
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.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller; import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
...@@ -20,7 +24,8 @@ import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller; ...@@ -20,7 +24,8 @@ import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
* Part of the test suite for the Java Bridge. This test tests the * Part of the test suite for the Java Bridge. This test tests the
* use of fields. * use of fields.
*/ */
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
public class JavaBridgeFieldsTest { public class JavaBridgeFieldsTest {
@Rule @Rule
public JavaBridgeActivityTestRule mActivityTestRule = public JavaBridgeActivityTestRule mActivityTestRule =
...@@ -56,6 +61,11 @@ public class JavaBridgeFieldsTest { ...@@ -56,6 +61,11 @@ public class JavaBridgeFieldsTest {
private static class CustomType { private static class CustomType {
} }
@UseMethodParameterBefore(JavaBridgeActivityTestRule.MojoTestParams.class)
public void setupMojoTest(boolean useMojo) {
mActivityTestRule.setupMojoTest(useMojo);
}
TestObject mTestObject; TestObject mTestObject;
@Before @Before
...@@ -75,7 +85,8 @@ public class JavaBridgeFieldsTest { ...@@ -75,7 +85,8 @@ public class JavaBridgeFieldsTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testFieldTypes() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testFieldTypes(boolean useMojo) throws Throwable {
Assert.assertEquals( Assert.assertEquals(
"undefined", executeJavaScriptAndGetStringResult("typeof testObject.booleanField")); "undefined", executeJavaScriptAndGetStringResult("typeof testObject.booleanField"));
Assert.assertEquals( Assert.assertEquals(
......
...@@ -12,7 +12,11 @@ import org.junit.Rule; ...@@ -12,7 +12,11 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.test.BaseJUnit4ClassRunner; import org.chromium.base.test.params.BaseJUnit4RunnerDelegate;
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.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller; import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
...@@ -27,7 +31,8 @@ import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller; ...@@ -27,7 +31,8 @@ import org.chromium.content.browser.JavaBridgeActivityTestRule.Controller;
* FIXME: Consider making our implementation more compliant, if it will not * FIXME: Consider making our implementation more compliant, if it will not
* break backwards-compatibility. See b/4408210. * break backwards-compatibility. See b/4408210.
*/ */
@RunWith(BaseJUnit4ClassRunner.class) @RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class)
public class JavaBridgeReturnValuesTest { public class JavaBridgeReturnValuesTest {
@Rule @Rule
public JavaBridgeActivityTestRule mActivityTestRule = public JavaBridgeActivityTestRule mActivityTestRule =
...@@ -113,6 +118,11 @@ public class JavaBridgeReturnValuesTest { ...@@ -113,6 +118,11 @@ public class JavaBridgeReturnValuesTest {
private static class CustomType { private static class CustomType {
} }
@UseMethodParameterBefore(JavaBridgeActivityTestRule.MojoTestParams.class)
public void setupMojoTest(boolean useMojo) {
mActivityTestRule.setupMojoTest(useMojo);
}
TestObject mTestObject; TestObject mTestObject;
@Before @Before
...@@ -136,7 +146,8 @@ public class JavaBridgeReturnValuesTest { ...@@ -136,7 +146,8 @@ public class JavaBridgeReturnValuesTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testMethodReturnTypes() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testMethodReturnTypes(boolean useMojo) throws Throwable {
Assert.assertEquals("boolean", Assert.assertEquals("boolean",
executeJavaScriptAndGetStringResult("typeof testObject.getBooleanValue()")); executeJavaScriptAndGetStringResult("typeof testObject.getBooleanValue()"));
Assert.assertEquals( Assert.assertEquals(
...@@ -178,7 +189,8 @@ public class JavaBridgeReturnValuesTest { ...@@ -178,7 +189,8 @@ public class JavaBridgeReturnValuesTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
public void testMethodReturnValues() throws Throwable { @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testMethodReturnValues(boolean useMojo) throws Throwable {
// We do the string comparison in JavaScript, to avoid relying on the // We do the string comparison in JavaScript, to avoid relying on the
// coercion algorithm from JavaScript to Java. // coercion algorithm from JavaScript to Java.
Assert.assertTrue(executeJavaScriptAndGetBooleanResult("testObject.getBooleanValue()")); Assert.assertTrue(executeJavaScriptAndGetBooleanResult("testObject.getBooleanValue()"));
......
...@@ -34,6 +34,7 @@ android_library("content_java_test_support") { ...@@ -34,6 +34,7 @@ android_library("content_java_test_support") {
"javatests/src/org/chromium/content_public/browser/test/ChildProcessAllocatorSettings.java", "javatests/src/org/chromium/content_public/browser/test/ChildProcessAllocatorSettings.java",
"javatests/src/org/chromium/content_public/browser/test/ChildProcessAllocatorSettingsHook.java", "javatests/src/org/chromium/content_public/browser/test/ChildProcessAllocatorSettingsHook.java",
"javatests/src/org/chromium/content_public/browser/test/ContentJUnit4ClassRunner.java", "javatests/src/org/chromium/content_public/browser/test/ContentJUnit4ClassRunner.java",
"javatests/src/org/chromium/content_public/browser/test/ContentJUnit4RunnerDelegate.java",
"javatests/src/org/chromium/content_public/browser/test/NativeLibraryTestUtils.java", "javatests/src/org/chromium/content_public/browser/test/NativeLibraryTestUtils.java",
"javatests/src/org/chromium/content_public/browser/test/RenderFrameHostTestExt.java", "javatests/src/org/chromium/content_public/browser/test/RenderFrameHostTestExt.java",
"javatests/src/org/chromium/content_public/browser/test/mock/MockNavigationController.java", "javatests/src/org/chromium/content_public/browser/test/mock/MockNavigationController.java",
......
// Copyright 2020 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.
package org.chromium.content_public.browser.test;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
import org.chromium.base.test.params.ParameterizedRunner.ParameterizedTestInstantiationException;
import org.chromium.base.test.params.ParameterizedRunnerDelegate;
import org.chromium.base.test.params.ParameterizedRunnerDelegateCommon;
import java.util.List;
/**
* A custom runner delegate for running //content JUnit4 parameterized tests.
*/
public final class ContentJUnit4RunnerDelegate
extends ContentJUnit4ClassRunner implements ParameterizedRunnerDelegate {
private final ParameterizedRunnerDelegateCommon mDelegateCommon;
public ContentJUnit4RunnerDelegate(Class<?> klass,
ParameterizedRunnerDelegateCommon delegateCommon) throws InitializationError {
super(klass);
mDelegateCommon = delegateCommon;
}
@Override
public void collectInitializationErrors(List<Throwable> errors) {
ParameterizedRunnerDelegateCommon.collectInitializationErrors(errors);
}
@Override
public List<FrameworkMethod> computeTestMethods() {
return mDelegateCommon.computeTestMethods();
}
@Override
public Object createTest() throws ParameterizedTestInstantiationException {
return mDelegateCommon.createTest();
}
}
...@@ -226,7 +226,11 @@ public class ContentShellActivityTestRule extends ActivityTestRule<ContentShellA ...@@ -226,7 +226,11 @@ public class ContentShellActivityTestRule extends ActivityTestRule<ContentShellA
} }
public JavascriptInjector getJavascriptInjector() { public JavascriptInjector getJavascriptInjector() {
return JavascriptInjector.fromWebContents(getWebContents()); return getJavascriptInjector(false);
}
public JavascriptInjector getJavascriptInjector(boolean useMojo) {
return JavascriptInjector.fromWebContents(getWebContents(), useMojo);
} }
/** /**
......
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