Add tests for multidimensional arrays in WebView's Java Bridge
Also add a test for objects with a non-numeric length property being passed to a method expecting an array. Change-Id: Ic04bbd691c55744472cab9fb732e504997c62434
This commit is contained in:
@@ -39,6 +39,7 @@ public class JavaBridgeArrayTest extends JavaBridgeTestBase {
|
||||
private String mStringValue;
|
||||
|
||||
private int[] mIntArray;
|
||||
private int[][] mIntIntArray;
|
||||
|
||||
private boolean mWasArrayMethodCalled;
|
||||
|
||||
@@ -72,11 +73,19 @@ public class JavaBridgeArrayTest extends JavaBridgeTestBase {
|
||||
mIntArray = x;
|
||||
notifyResultIsReady();
|
||||
}
|
||||
public synchronized void setIntIntArray(int[][] x) {
|
||||
mIntIntArray = x;
|
||||
notifyResultIsReady();
|
||||
}
|
||||
|
||||
public synchronized int[] waitForIntArray() {
|
||||
waitForResult();
|
||||
return mIntArray;
|
||||
}
|
||||
public synchronized int[][] waitForIntIntArray() {
|
||||
waitForResult();
|
||||
return mIntIntArray;
|
||||
}
|
||||
|
||||
public synchronized int[] arrayMethod() {
|
||||
mWasArrayMethodCalled = true;
|
||||
@@ -152,6 +161,13 @@ public class JavaBridgeArrayTest extends JavaBridgeTestBase {
|
||||
assertEquals(0, result[2]);
|
||||
}
|
||||
|
||||
public void testNonNumericLengthProperty() throws Throwable {
|
||||
// LIVECONNECT_COMPLIANCE: This should not count as an array, so we
|
||||
// should raise a JavaScript exception.
|
||||
executeJavaScript("testObject.setIntArray({length: \"foo\"});");
|
||||
assertEquals(0, mTestObject.waitForIntArray().length);
|
||||
}
|
||||
|
||||
public void testSparseArray() throws Throwable {
|
||||
executeJavaScript("var x = [42, 43]; x[3] = 45; testObject.setIntArray(x);");
|
||||
int[] result = mTestObject.waitForIntArray();
|
||||
@@ -173,4 +189,19 @@ public class JavaBridgeArrayTest extends JavaBridgeTestBase {
|
||||
assertTrue(mTestObject.waitForBooleanValue());
|
||||
assertFalse(mTestObject.wasArrayMethodCalled());
|
||||
}
|
||||
|
||||
public void testMultiDimensionalArrayMethod() throws Throwable {
|
||||
// LIVECONNECT_COMPLIANCE: Should handle multi-dimensional arrays.
|
||||
executeJavaScript("testObject.setIntIntArray([ [42, 43], [44, 45] ]);");
|
||||
assertNull(mTestObject.waitForIntIntArray());
|
||||
}
|
||||
|
||||
public void testPassMultiDimensionalArray() throws Throwable {
|
||||
// LIVECONNECT_COMPLIANCE: Should handle multi-dimensional arrays.
|
||||
executeJavaScript("testObject.setIntArray([ [42, 43], [44, 45] ]);");
|
||||
int[] result = mTestObject.waitForIntArray();
|
||||
assertEquals(2, result.length);
|
||||
assertEquals(0, result[0]);
|
||||
assertEquals(0, result[1]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user