Commit 8a18697e authored by Miyoung Shin's avatar Miyoung Shin Committed by Chromium LUCI CQ

[remoteobjects] Use @JavascriptInterface explicitly for the tests

This CL uses @JavascriptInterface explicitly instead of passing
null for JavaBridge* tests unless the tests are specifically
testing the case of no annotations.

Bug: 1105935
Change-Id: Ib1a7fb5e69bd1899f3a56278dc9599030f697eb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569012
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835098}
parent 8619269a
......@@ -4,6 +4,8 @@
package org.chromium.content.browser;
import android.webkit.JavascriptInterface;
import org.junit.Assert;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
......@@ -128,7 +130,8 @@ public class JavaBridgeActivityTestRule extends ContentShellActivityTestRule {
}
public void injectObjectAndReload(Object object, String name) {
injectObjectAndReload(object, name, null);
Class<? extends Annotation> requiredAnnotation = JavascriptInterface.class;
injectObjectAndReload(object, name, requiredAnnotation);
}
public void injectObjectAndReload(
......
......@@ -4,6 +4,8 @@
package org.chromium.content.browser;
import android.webkit.JavascriptInterface;
import androidx.test.filters.SmallTest;
import org.junit.Assert;
......@@ -62,53 +64,66 @@ public class JavaBridgeArrayCoercionTest {
mCustomTypeInstance = new CustomType();
}
@JavascriptInterface
public Object getObjectInstance() {
return mObjectInstance;
}
@JavascriptInterface
public CustomType getCustomTypeInstance() {
return mCustomTypeInstance;
}
@JavascriptInterface
public synchronized void setBooleanArray(boolean[] x) {
mBooleanArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setByteArray(byte[] x) {
mByteArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setCharArray(char[] x) {
mCharArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setShortArray(short[] x) {
mShortArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setIntArray(int[] x) {
mIntArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setLongArray(long[] x) {
mLongArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setFloatArray(float[] x) {
mFloatArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setDoubleArray(double[] x) {
mDoubleArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setStringArray(String[] x) {
mStringArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setObjectArray(Object[] x) {
mObjectArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setCustomTypeArray(CustomType[] x) {
mCustomTypeArray = x;
notifyResultIsReady();
......
......@@ -4,6 +4,8 @@
package org.chromium.content.browser;
import android.webkit.JavascriptInterface;
import androidx.test.filters.SmallTest;
import org.junit.Assert;
......@@ -48,14 +50,17 @@ public class JavaBridgeArrayTest {
private boolean mWasArrayMethodCalled;
@JavascriptInterface
public synchronized void setBooleanValue(boolean x) {
mBooleanValue = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setIntValue(int x) {
mIntValue = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setStringValue(String x) {
mStringValue = x;
notifyResultIsReady();
......@@ -74,10 +79,12 @@ public class JavaBridgeArrayTest {
return mStringValue;
}
@JavascriptInterface
public synchronized void setIntArray(int[] x) {
mIntArray = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized void setIntIntArray(int[][] x) {
mIntIntArray = x;
notifyResultIsReady();
......@@ -92,6 +99,7 @@ public class JavaBridgeArrayTest {
return mIntIntArray;
}
@JavascriptInterface
public synchronized int[] arrayMethod() {
mWasArrayMethodCalled = true;
return new int[] {42, 43, 44};
......
......@@ -5,6 +5,7 @@
package org.chromium.content.browser;
import android.support.test.InstrumentationRegistry;
import android.webkit.JavascriptInterface;
import androidx.test.filters.SmallTest;
......@@ -51,6 +52,7 @@ public class JavaBridgeChildFrameTest {
private String mStringValue;
@SuppressWarnings("unused") // Called via reflection
@JavascriptInterface
public synchronized void setStringValue(String x) {
mStringValue = x;
notifyResultIsReady();
......
......@@ -4,6 +4,8 @@
package org.chromium.content.browser;
import android.webkit.JavascriptInterface;
import androidx.test.filters.SmallTest;
import org.junit.Assert;
......@@ -35,11 +37,13 @@ public class JavaBridgeFieldsTest {
private static class TestObject extends Controller {
private String mStringValue;
@JavascriptInterface
// These methods are used to control the test.
public synchronized void setStringValue(String x) {
mStringValue = x;
notifyResultIsReady();
}
@JavascriptInterface
public synchronized String waitForStringValue() {
waitForResult();
return mStringValue;
......
......@@ -4,6 +4,8 @@
package org.chromium.content.browser;
import android.webkit.JavascriptInterface;
import androidx.test.filters.SmallTest;
import org.junit.Assert;
......@@ -46,6 +48,7 @@ public class JavaBridgeReturnValuesTest {
private boolean mBooleanResult;
// These four methods are used to control the test.
@JavascriptInterface
public synchronized void setStringResult(String x) {
mStringResult = x;
notifyResultIsReady();
......@@ -54,6 +57,7 @@ public class JavaBridgeReturnValuesTest {
waitForResult();
return mStringResult;
}
@JavascriptInterface
public synchronized void setBooleanResult(boolean x) {
mBooleanResult = x;
notifyResultIsReady();
......@@ -63,56 +67,72 @@ public class JavaBridgeReturnValuesTest {
return mBooleanResult;
}
@JavascriptInterface
public boolean getBooleanValue() {
return true;
}
@JavascriptInterface
public byte getByteValue() {
return 42;
}
@JavascriptInterface
public char getCharValue() {
return '\u002A';
}
@JavascriptInterface
public short getShortValue() {
return 42;
}
@JavascriptInterface
public int getIntValue() {
return 42;
}
@JavascriptInterface
public long getLongValue() {
return 42L;
}
@JavascriptInterface
public float getFloatValue() {
return 42.1f;
}
@JavascriptInterface
public float getFloatValueNoDecimal() {
return 42.0f;
}
@JavascriptInterface
public double getDoubleValue() {
return 42.1;
}
@JavascriptInterface
public double getDoubleValueNoDecimal() {
return 42.0;
}
@JavascriptInterface
public String getStringValue() {
return "foo";
}
@JavascriptInterface
public String getEmptyStringValue() {
return "";
}
@JavascriptInterface
public String getNullStringValue() {
return null;
}
@JavascriptInterface
public Object getObjectValue() {
return new Object();
}
@JavascriptInterface
public Object getNullObjectValue() {
return null;
}
@JavascriptInterface
public CustomType getCustomTypeValue() {
return new CustomType();
}
public void getVoidValue() {
}
@JavascriptInterface
public void getVoidValue() {}
}
// A custom type used when testing passing objects.
......
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