Commit 2373806e authored by Miyoung Shin's avatar Miyoung Shin Committed by Chromium LUCI CQ

[remoteobjects] Pass all tests with MojoTestParams from JavaBridgeArrayTest

This CL update the codes so that all tests from JavaBridgeArrayTest
pass with MojoTestParams.

Bug: 1149011
Change-Id: Icc090585fa6cf95818ec9d5e1609f1791c5a9427
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2613084Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#844294}
parent f43e523b
...@@ -200,7 +200,7 @@ public class JavaBridgeArrayTest { ...@@ -200,7 +200,7 @@ public class JavaBridgeArrayTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class) @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testObjectWithLengthProperty(boolean useMojo) throws Throwable { public void testObjectWithLengthProperty(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("testObject.setIntArray({length: 3, 1: 42});"); mActivityTestRule.executeJavaScript("testObject.setIntArray({length: 3, 1: 42});");
int[] result = mTestObject.waitForIntArray(); int[] result = mTestObject.waitForIntArray();
...@@ -213,7 +213,7 @@ public class JavaBridgeArrayTest { ...@@ -213,7 +213,7 @@ public class JavaBridgeArrayTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class) @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testNonNumericLengthProperty(boolean useMojo) throws Throwable { public void testNonNumericLengthProperty(boolean useMojo) throws Throwable {
// LIVECONNECT_COMPLIANCE: This should not count as an array, so we // LIVECONNECT_COMPLIANCE: This should not count as an array, so we
// should raise a JavaScript exception. // should raise a JavaScript exception.
...@@ -224,7 +224,7 @@ public class JavaBridgeArrayTest { ...@@ -224,7 +224,7 @@ public class JavaBridgeArrayTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class) @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testLengthOutOfBounds(boolean useMojo) throws Throwable { public void testLengthOutOfBounds(boolean useMojo) throws Throwable {
// LIVECONNECT_COMPLIANCE: This should not count as an array, so we // LIVECONNECT_COMPLIANCE: This should not count as an array, so we
// should raise a JavaScript exception. // should raise a JavaScript exception.
...@@ -305,7 +305,7 @@ public class JavaBridgeArrayTest { ...@@ -305,7 +305,7 @@ public class JavaBridgeArrayTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class) @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassArrayBuffer(boolean useMojo) throws Throwable { public void testPassArrayBuffer(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(16);"); mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(16);");
mActivityTestRule.executeJavaScript("testObject.setIntArray(buffer);"); mActivityTestRule.executeJavaScript("testObject.setIntArray(buffer);");
...@@ -321,7 +321,7 @@ public class JavaBridgeArrayTest { ...@@ -321,7 +321,7 @@ public class JavaBridgeArrayTest {
@Test @Test
@SmallTest @SmallTest
@Feature({"AndroidWebView", "Android-JavaBridge"}) @Feature({"AndroidWebView", "Android-JavaBridge"})
@UseMethodParameter(JavaBridgeActivityTestRule.LegacyTestParams.class) @UseMethodParameter(JavaBridgeActivityTestRule.MojoTestParams.class)
public void testPassDataView(boolean useMojo) throws Throwable { public void testPassDataView(boolean useMojo) throws Throwable {
mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(16);"); mActivityTestRule.executeJavaScript("buffer = new ArrayBuffer(16);");
mActivityTestRule.executeJavaScript("testObject.setIntArray(new DataView(buffer));"); mActivityTestRule.executeJavaScript("testObject.setIntArray(new DataView(buffer));");
......
...@@ -165,6 +165,82 @@ mojom::blink::RemoteInvocationArgumentPtr JSValueToMojom( ...@@ -165,6 +165,82 @@ mojom::blink::RemoteInvocationArgumentPtr JSValueToMojom(
std::move(remote_typed_array)); std::move(remote_typed_array));
} }
if (js_value->IsObject()) {
v8::Local<v8::Object> object_val = js_value.As<v8::Object>();
v8::Local<v8::Value> length_value;
v8::TryCatch try_catch(isolate);
v8::MaybeLocal<v8::Value> maybe_length_value = object_val->Get(
isolate->GetCurrentContext(), V8AtomicString(isolate, "length"));
if (try_catch.HasCaught() || !maybe_length_value.ToLocal(&length_value)) {
length_value = v8::Null(isolate);
try_catch.Reset();
}
if (!length_value->IsNumber()) {
return mojom::blink::RemoteInvocationArgument::NewSingletonValue(
mojom::blink::SingletonJavaScriptValue::kNull);
}
double length = length_value.As<v8::Number>()->Value();
if (length < 0 || length > std::numeric_limits<int32_t>::max()) {
return mojom::blink::RemoteInvocationArgument::NewSingletonValue(
mojom::blink::SingletonJavaScriptValue::kNull);
}
v8::Local<v8::Array> property_names;
if (!object_val->GetOwnPropertyNames(isolate->GetCurrentContext())
.ToLocal(&property_names)) {
return mojom::blink::RemoteInvocationArgument::NewSingletonValue(
mojom::blink::SingletonJavaScriptValue::kNull);
}
WTF::Vector<mojom::blink::RemoteInvocationArgumentPtr> nested_arguments(
SafeCast<wtf_size_t>(length));
for (uint32_t i = 0; i < property_names->Length(); ++i) {
v8::Local<v8::Value> key;
if (!property_names->Get(isolate->GetCurrentContext(), i).ToLocal(&key) ||
key->IsString()) {
try_catch.Reset();
continue;
}
if (!key->IsNumber()) {
NOTREACHED() << "Key \"" << *v8::String::Utf8Value(isolate, key)
<< "\" is not a number";
continue;
}
uint32_t key_value;
if (!key->Uint32Value(isolate->GetCurrentContext()).To(&key_value))
continue;
v8::Local<v8::Value> value_v8;
v8::MaybeLocal<v8::Value> maybe_value =
object_val->Get(isolate->GetCurrentContext(), key);
if (try_catch.HasCaught() || !maybe_value.ToLocal(&value_v8)) {
value_v8 = v8::Null(isolate);
try_catch.Reset();
}
auto nested_argument = JSValueToMojom(value_v8, isolate);
if (!nested_argument)
continue;
nested_arguments[key_value] = std::move(nested_argument);
}
// Ensure that the vector has a null value.
for (wtf_size_t i = 0; i < nested_arguments.size(); i++) {
if (!nested_arguments[i]) {
nested_arguments[i] =
mojom::blink::RemoteInvocationArgument::NewSingletonValue(
mojom::blink::SingletonJavaScriptValue::kNull);
}
}
return mojom::blink::RemoteInvocationArgument::NewArrayValue(
std::move(nested_arguments));
}
return nullptr; return nullptr;
} }
......
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