Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc6cf288 authored by Steve Block's avatar Steve Block
Browse files

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
parent 38bc7318
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -165,7 +165,26 @@ public class JavaBridgeArrayTest extends JavaBridgeTestBase {
        // 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 {