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

remoteobjects: Ensure that null object return values map to null.

Bug: 794320
Change-Id: If5776962746a12481fd89426f5e13a3ab6b79214
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095779Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748563}
parent a58f4002
......@@ -400,6 +400,8 @@ class RemoteObjectImpl implements RemoteObject {
} else {
resultValue.setStringValue(javaStringToMojoString((String) result));
}
} else if (result == null) {
resultValue.setSingletonValue(SingletonJavaScriptValue.NULL);
} else {
int objectId = objectIdAllocator.getObjectId(result);
resultValue.setObjectId(objectId);
......
......@@ -750,6 +750,11 @@ public final class RemoteObjectImplTest {
public Object getFoo() {
return foo;
}
@TestJavascriptInterface
public Object getNull() {
return null;
}
};
when(mIdAllocator.getObjectId(foo)).thenReturn(42);
......@@ -757,8 +762,10 @@ public final class RemoteObjectImplTest {
RemoteObject remoteObject = newRemoteObjectImpl(target, TestJavascriptInterface.class);
RemoteObject.InvokeMethodResponse response = mock(RemoteObject.InvokeMethodResponse.class);
remoteObject.invokeMethod("getFoo", new RemoteInvocationArgument[] {}, response);
remoteObject.invokeMethod("getNull", new RemoteInvocationArgument[] {}, response);
verify(response).call(resultIsObject(42));
verify(response).call(resultIsNull());
}
private RemoteInvocationResult resultHasError(final int error) {
......@@ -777,6 +784,14 @@ public final class RemoteObjectImplTest {
}));
}
private RemoteInvocationResult resultIsNull() {
return and(resultIsOk(), ArgumentMatchers.argThat(result -> {
return result.value != null
&& result.value.which() == RemoteInvocationResultValue.Tag.SingletonValue
&& result.value.getSingletonValue() == SingletonJavaScriptValue.NULL;
}));
}
private RemoteInvocationResult resultIsNumber(final double numberValue) {
return and(resultIsOk(), ArgumentMatchers.argThat(result -> {
return result.value != null
......
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