Commit c71a585c authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

[remoteobjects] Add a test that static methods can be found and invoked.

This doesn't require special support, since the java.lang.reflect API allows
calling static methods the same way as instance methods.

Bug: 794320
Change-Id: Id9064ec69b6cbdbe23576fa1f3e5d5e0e2c30677
Reviewed-on: https://chromium-review.googlesource.com/894465Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533063}
parent 156d069f
...@@ -179,6 +179,45 @@ public final class RemoteObjectImplTest { ...@@ -179,6 +179,45 @@ public final class RemoteObjectImplTest {
verify(response, times(2)).call(resultIsOk()); verify(response, times(2)).call(resultIsOk());
} }
/**
* Reports to the runnable it is given when its static method is called.
* Works around the fact that a static method cannot capture variables.
*/
static class ObjectWithStaticMethod {
static Runnable sRunnable;
@TestJavascriptInterface
public static void staticMethod() {
sRunnable.run();
}
}
@Test
public void testStaticMethod() {
// Static methods should work just like non-static ones.
Object target = new ObjectWithStaticMethod();
RemoteObject remoteObject = new RemoteObjectImpl(target, TestJavascriptInterface.class);
Runnable runnable = mock(Runnable.class);
ObjectWithStaticMethod.sRunnable = runnable;
RemoteObject.InvokeMethodResponse response = mock(RemoteObject.InvokeMethodResponse.class);
remoteObject.invokeMethod("staticMethod", new RemoteInvocationArgument[] {}, response);
ObjectWithStaticMethod.sRunnable = null;
verify(runnable).run();
verify(response).call(resultIsOk());
RemoteObject.HasMethodResponse hasMethodResponse =
mock(RemoteObject.HasMethodResponse.class);
remoteObject.hasMethod("staticMethod", hasMethodResponse);
verify(hasMethodResponse).call(true);
RemoteObject.GetMethodsResponse getMethodsResponse =
mock(RemoteObject.GetMethodsResponse.class);
remoteObject.getMethods(getMethodsResponse);
verify(getMethodsResponse).call(aryEq(new String[] {"staticMethod"}));
}
@Test @Test
public void testInvokeMethodNotFound() { public void testInvokeMethodNotFound() {
Object target = new Object() { Object target = new Object() {
......
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