Add tests for array length bounds in WebView's Java Bridge

Tests for https://android-git.corp.google.com/g/150320.

We test that when the legnth property of a JavaScript object is out of the
bounds for a Java array, we convert to null.

Also update a test in the case that the length property is not numeric.

Bug: 5626284
Change-Id: If41acb117eb4b786d671b5ffece2704c6f045d52
diff --git a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java
index 98f2391..2fd42a74d 100644
--- a/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java
+++ b/tests/WebViewTests/src/com/android/webviewtests/JavaBridgeArrayTest.java
@@ -165,7 +165,26 @@
         // 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);
+        assertNull(mTestObject.waitForIntArray());
+    }
+
+    public void testLengthOutOfBounds() throws Throwable {
+        // LIVECONNECT_COMPLIANCE: This should not count as an array, so we
+        // should raise a JavaScript exception.
+        executeJavaScript("testObject.setIntArray({length: -1});");
+        assertNull(mTestObject.waitForIntArray());
+
+        // LIVECONNECT_COMPLIANCE: This should not count as an array, so we
+        // should raise a JavaScript exception.
+        long length = (long)Integer.MAX_VALUE + 1L;
+        executeJavaScript("testObject.setIntArray({length: " + length + "});");
+        assertNull(mTestObject.waitForIntArray());
+
+        // LIVECONNECT_COMPLIANCE: This should not count as an array, so we
+        // should raise a JavaScript exception.
+        length = (long)Integer.MAX_VALUE + 1L - (long)Integer.MIN_VALUE + 1L;
+        executeJavaScript("testObject.setIntArray({length: " + length + "});");
+        assertNull(mTestObject.waitForIntArray());
     }
 
     public void testSparseArray() throws Throwable {