From c353abba95771ce28f1536fe36c1c705693232a8 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Mon, 14 Nov 2011 18:26:03 +0000 Subject: 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 --- .../android/webviewtests/JavaBridgeArrayTest.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'tests/WebViewTests/src') diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java index 5497990..98f2391 100644 --- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java +++ b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java @@ -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]); + } } -- cgit v1.1