• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /**
18  * Part of the test suite for the WebView's Java Bridge. This class tests that
19  * we correctly convert JavaScript arrays to Java arrays when passing them to
20  * the methods of injected Java objects.
21  *
22  * The conversions should follow
23  * http://jdk6.java.net/plugin2/liveconnect/#JS_JAVA_CONVERSIONS. Places in
24  * which the implementation differs from the spec are marked with
25  * LIVECONNECT_COMPLIANCE.
26  * FIXME: Consider making our implementation more compliant, if it will not
27  * break backwards-compatibility. See b/4408210.
28  *
29  * To run this test ...
30  *  adb shell am instrument -w -e class com.android.webviewtests.JavaBridgeArrayCoercionTest \
31  *     com.android.webviewtests/android.test.InstrumentationTestRunner
32  */
33 
34 package com.android.webviewtests;
35 
36 public class JavaBridgeArrayCoercionTest extends JavaBridgeTestBase {
37     private class TestObject extends Controller {
38         private Object mObjectInstance;
39         private CustomType mCustomTypeInstance;
40 
41         private boolean[] mBooleanArray;
42         private byte[] mByteArray;
43         private char[] mCharArray;
44         private short[] mShortArray;
45         private int[] mIntArray;
46         private long[] mLongArray;
47         private float[] mFloatArray;
48         private double[] mDoubleArray;
49         private String[] mStringArray;
50         private Object[] mObjectArray;
51         private CustomType[] mCustomTypeArray;
52 
TestObject()53         public TestObject() {
54             mObjectInstance = new Object();
55             mCustomTypeInstance = new CustomType();
56         }
57 
getObjectInstance()58         public Object getObjectInstance() {
59             return mObjectInstance;
60         }
getCustomTypeInstance()61         public CustomType getCustomTypeInstance() {
62             return mCustomTypeInstance;
63         }
64 
setBooleanArray(boolean[] x)65         public synchronized void setBooleanArray(boolean[] x) {
66             mBooleanArray = x;
67             notifyResultIsReady();
68         }
setByteArray(byte[] x)69         public synchronized void setByteArray(byte[] x) {
70             mByteArray = x;
71             notifyResultIsReady();
72         }
setCharArray(char[] x)73         public synchronized void setCharArray(char[] x) {
74             mCharArray = x;
75             notifyResultIsReady();
76         }
setShortArray(short[] x)77         public synchronized void setShortArray(short[] x) {
78             mShortArray = x;
79             notifyResultIsReady();
80         }
setIntArray(int[] x)81         public synchronized void setIntArray(int[] x) {
82             mIntArray = x;
83             notifyResultIsReady();
84         }
setLongArray(long[] x)85         public synchronized void setLongArray(long[] x) {
86             mLongArray = x;
87             notifyResultIsReady();
88         }
setFloatArray(float[] x)89         public synchronized void setFloatArray(float[] x) {
90             mFloatArray = x;
91             notifyResultIsReady();
92         }
setDoubleArray(double[] x)93         public synchronized void setDoubleArray(double[] x) {
94             mDoubleArray = x;
95             notifyResultIsReady();
96         }
setStringArray(String[] x)97         public synchronized void setStringArray(String[] x) {
98             mStringArray = x;
99             notifyResultIsReady();
100         }
setObjectArray(Object[] x)101         public synchronized void setObjectArray(Object[] x) {
102             mObjectArray = x;
103             notifyResultIsReady();
104         }
setCustomTypeArray(CustomType[] x)105         public synchronized void setCustomTypeArray(CustomType[] x) {
106             mCustomTypeArray = x;
107             notifyResultIsReady();
108         }
109 
waitForBooleanArray()110         public synchronized boolean[] waitForBooleanArray() {
111             waitForResult();
112             return mBooleanArray;
113         }
waitForByteArray()114         public synchronized byte[] waitForByteArray() {
115             waitForResult();
116             return mByteArray;
117         }
waitForCharArray()118         public synchronized char[] waitForCharArray() {
119             waitForResult();
120             return mCharArray;
121         }
waitForShortArray()122         public synchronized short[] waitForShortArray() {
123             waitForResult();
124             return mShortArray;
125         }
waitForIntArray()126         public synchronized int[] waitForIntArray() {
127             waitForResult();
128             return mIntArray;
129         }
waitForLongArray()130         public synchronized long[] waitForLongArray() {
131             waitForResult();
132             return mLongArray;
133         }
waitForFloatArray()134         public synchronized float[] waitForFloatArray() {
135             waitForResult();
136             return mFloatArray;
137         }
waitForDoubleArray()138         public synchronized double[] waitForDoubleArray() {
139             waitForResult();
140             return mDoubleArray;
141         }
waitForStringArray()142         public synchronized String[] waitForStringArray() {
143             waitForResult();
144             return mStringArray;
145         }
waitForObjectArray()146         public synchronized Object[] waitForObjectArray() {
147             waitForResult();
148             return mObjectArray;
149         }
waitForCustomTypeArray()150         public synchronized CustomType[] waitForCustomTypeArray() {
151             waitForResult();
152             return mCustomTypeArray;
153         }
154     }
155 
156     // Two custom types used when testing passing objects.
157     private class CustomType {
158     }
159 
160     private TestObject mTestObject;
161 
162     @Override
setUp()163     protected void setUp() throws Exception {
164         super.setUp();
165         mTestObject = new TestObject();
166         setUpWebView(mTestObject, "testObject");
167     }
168 
169     // Note that all tests use a single element array for simplicity. We test
170     // multiple elements elsewhere.
171 
172     // Test passing an array of JavaScript numbers in the int32 range to a
173     // method which takes a Java array.
testPassNumberInt32()174     public void testPassNumberInt32() throws Throwable {
175         executeJavaScript("testObject.setBooleanArray([0]);");
176         assertFalse(mTestObject.waitForBooleanArray()[0]);
177         // LIVECONNECT_COMPLIANCE: Should convert to boolean.
178         executeJavaScript("testObject.setBooleanArray([42]);");
179         assertFalse(mTestObject.waitForBooleanArray()[0]);
180 
181         executeJavaScript("testObject.setByteArray([42]);");
182         assertEquals(42, mTestObject.waitForByteArray()[0]);
183 
184         // LIVECONNECT_COMPLIANCE: Should convert to numeric char value.
185         executeJavaScript("testObject.setCharArray([42]);");
186         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
187 
188         executeJavaScript("testObject.setShortArray([42]);");
189         assertEquals(42, mTestObject.waitForShortArray()[0]);
190 
191         executeJavaScript("testObject.setIntArray([42]);");
192         assertEquals(42, mTestObject.waitForIntArray()[0]);
193 
194         executeJavaScript("testObject.setLongArray([42]);");
195         assertEquals(42L, mTestObject.waitForLongArray()[0]);
196 
197         executeJavaScript("testObject.setFloatArray([42]);");
198         assertEquals(42.0f, mTestObject.waitForFloatArray()[0]);
199 
200         executeJavaScript("testObject.setDoubleArray([42]);");
201         assertEquals(42.0, mTestObject.waitForDoubleArray()[0]);
202 
203         // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number.
204         executeJavaScript("testObject.setObjectArray([42]);");
205         assertNull(mTestObject.waitForObjectArray());
206 
207         // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String.
208         executeJavaScript("testObject.setStringArray([42]);");
209         assertNull(mTestObject.waitForStringArray()[0]);
210 
211         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
212         executeJavaScript("testObject.setCustomTypeArray([42]);");
213         assertNull(mTestObject.waitForCustomTypeArray());
214     }
215 
216     // Test passing an array of JavaScript numbers in the double range to a
217     // method which takes a Java array.
testPassNumberDouble()218     public void testPassNumberDouble() throws Throwable {
219         // LIVECONNECT_COMPLIANCE: Should convert to boolean.
220         executeJavaScript("testObject.setBooleanArray([42.1]);");
221         assertFalse(mTestObject.waitForBooleanArray()[0]);
222 
223         executeJavaScript("testObject.setByteArray([42.1]);");
224         assertEquals(42, mTestObject.waitForByteArray()[0]);
225 
226         // LIVECONNECT_COMPLIANCE: Should convert to numeric char value.
227         executeJavaScript("testObject.setCharArray([42.1]);");
228         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
229 
230         executeJavaScript("testObject.setShortArray([42.1]);");
231         assertEquals(42, mTestObject.waitForShortArray()[0]);
232 
233         executeJavaScript("testObject.setIntArray([42.1]);");
234         assertEquals(42, mTestObject.waitForIntArray()[0]);
235 
236         executeJavaScript("testObject.setLongArray([42.1]);");
237         assertEquals(42L, mTestObject.waitForLongArray()[0]);
238 
239         executeJavaScript("testObject.setFloatArray([42.1]);");
240         assertEquals(42.1f, mTestObject.waitForFloatArray()[0]);
241 
242         executeJavaScript("testObject.setDoubleArray([42.1]);");
243         assertEquals(42.1, mTestObject.waitForDoubleArray()[0]);
244 
245         // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number.
246         executeJavaScript("testObject.setObjectArray([42.1]);");
247         assertNull(mTestObject.waitForObjectArray());
248 
249         // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String.
250         executeJavaScript("testObject.setStringArray([42.1]);");
251         assertNull(mTestObject.waitForStringArray()[0]);
252 
253         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
254         executeJavaScript("testObject.setCustomTypeArray([42.1]);");
255         assertNull(mTestObject.waitForCustomTypeArray());
256     }
257 
258     // Test passing an array of JavaScript NaN values to a method which takes a
259     // Java array.
testPassNumberNaN()260     public void testPassNumberNaN() throws Throwable {
261         executeJavaScript("testObject.setBooleanArray([Number.NaN]);");
262         assertFalse(mTestObject.waitForBooleanArray()[0]);
263 
264         executeJavaScript("testObject.setByteArray([Number.NaN]);");
265         assertEquals(0, mTestObject.waitForByteArray()[0]);
266 
267         executeJavaScript("testObject.setCharArray([Number.NaN]);");
268         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
269 
270         executeJavaScript("testObject.setShortArray([Number.NaN]);");
271         assertEquals(0, mTestObject.waitForShortArray()[0]);
272 
273         executeJavaScript("testObject.setIntArray([Number.NaN]);");
274         assertEquals(0, mTestObject.waitForIntArray()[0]);
275 
276         executeJavaScript("testObject.setLongArray([Number.NaN]);");
277         assertEquals(0L, mTestObject.waitForLongArray()[0]);
278 
279         executeJavaScript("testObject.setFloatArray([Number.NaN]);");
280         assertEquals(Float.NaN, mTestObject.waitForFloatArray()[0]);
281 
282         executeJavaScript("testObject.setDoubleArray([Number.NaN]);");
283         assertEquals(Double.NaN, mTestObject.waitForDoubleArray()[0]);
284 
285         // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number.
286         executeJavaScript("testObject.setObjectArray([Number.NaN]);");
287         assertNull(mTestObject.waitForObjectArray());
288 
289         // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String.
290         executeJavaScript("testObject.setStringArray([Number.NaN]);");
291         assertNull(mTestObject.waitForStringArray()[0]);
292 
293         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
294         executeJavaScript("testObject.setCustomTypeArray([Number.NaN]);");
295         assertNull(mTestObject.waitForCustomTypeArray());
296     }
297 
298     // Test passing an array of JavaScript infinity values to a method which
299     // takes a Java array.
testPassNumberInfinity()300     public void testPassNumberInfinity() throws Throwable {
301         executeJavaScript("testObject.setBooleanArray([Infinity]);");
302         assertFalse(mTestObject.waitForBooleanArray()[0]);
303 
304         executeJavaScript("testObject.setByteArray([Infinity]);");
305         assertEquals(-1, mTestObject.waitForByteArray()[0]);
306 
307         // LIVECONNECT_COMPLIANCE: Should convert to maximum numeric char value.
308         executeJavaScript("testObject.setCharArray([Infinity]);");
309         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
310 
311         executeJavaScript("testObject.setShortArray([Infinity]);");
312         assertEquals(-1, mTestObject.waitForShortArray()[0]);
313 
314         executeJavaScript("testObject.setIntArray([Infinity]);");
315         assertEquals(Integer.MAX_VALUE, mTestObject.waitForIntArray()[0]);
316 
317         // LIVECONNECT_COMPLIANCE: Should be Long.MAX_VALUE.
318         executeJavaScript("testObject.setLongArray([Infinity]);");
319         assertEquals(-1L, mTestObject.waitForLongArray()[0]);
320 
321         executeJavaScript("testObject.setFloatArray([Infinity]);");
322         assertEquals(Float.POSITIVE_INFINITY, mTestObject.waitForFloatArray()[0]);
323 
324         executeJavaScript("testObject.setDoubleArray([Infinity]);");
325         assertEquals(Double.POSITIVE_INFINITY, mTestObject.waitForDoubleArray()[0]);
326 
327         // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number.
328         executeJavaScript("testObject.setObjectArray([Infinity]);");
329         assertNull(mTestObject.waitForObjectArray());
330 
331         // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String.
332         executeJavaScript("testObject.setStringArray([Infinity]);");
333         assertNull(mTestObject.waitForStringArray()[0]);
334 
335         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
336         executeJavaScript("testObject.setCustomTypeArray([Infinity]);");
337         assertNull(mTestObject.waitForCustomTypeArray());
338     }
339 
340     // Test passing an array of JavaScript boolean values to a method which
341     // takes a Java array.
testPassBoolean()342     public void testPassBoolean() throws Throwable {
343         executeJavaScript("testObject.setBooleanArray([true]);");
344         assertTrue(mTestObject.waitForBooleanArray()[0]);
345         executeJavaScript("testObject.setBooleanArray([false]);");
346         assertFalse(mTestObject.waitForBooleanArray()[0]);
347 
348         // LIVECONNECT_COMPLIANCE: Should be 1.
349         executeJavaScript("testObject.setByteArray([true]);");
350         assertEquals(0, mTestObject.waitForByteArray()[0]);
351         executeJavaScript("testObject.setByteArray([false]);");
352         assertEquals(0, mTestObject.waitForByteArray()[0]);
353 
354         // LIVECONNECT_COMPLIANCE: Should convert to numeric char value 1.
355         executeJavaScript("testObject.setCharArray([true]);");
356         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
357         executeJavaScript("testObject.setCharArray([false]);");
358         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
359 
360         // LIVECONNECT_COMPLIANCE: Should be 1.
361         executeJavaScript("testObject.setShortArray([true]);");
362         assertEquals(0, mTestObject.waitForShortArray()[0]);
363         executeJavaScript("testObject.setShortArray([false]);");
364         assertEquals(0, mTestObject.waitForShortArray()[0]);
365 
366         // LIVECONNECT_COMPLIANCE: Should be 1.
367         executeJavaScript("testObject.setIntArray([true]);");
368         assertEquals(0, mTestObject.waitForIntArray()[0]);
369         executeJavaScript("testObject.setIntArray([false]);");
370         assertEquals(0, mTestObject.waitForIntArray()[0]);
371 
372         // LIVECONNECT_COMPLIANCE: Should be 1.
373         executeJavaScript("testObject.setLongArray([true]);");
374         assertEquals(0L, mTestObject.waitForLongArray()[0]);
375         executeJavaScript("testObject.setLongArray([false]);");
376         assertEquals(0L, mTestObject.waitForLongArray()[0]);
377 
378         // LIVECONNECT_COMPLIANCE: Should be 1.0.
379         executeJavaScript("testObject.setFloatArray([true]);");
380         assertEquals(0.0f, mTestObject.waitForFloatArray()[0]);
381         executeJavaScript("testObject.setFloatArray([false]);");
382         assertEquals(0.0f, mTestObject.waitForFloatArray()[0]);
383 
384         // LIVECONNECT_COMPLIANCE: Should be 1.0.
385         executeJavaScript("testObject.setDoubleArray([true]);");
386         assertEquals(0.0, mTestObject.waitForDoubleArray()[0]);
387         executeJavaScript("testObject.setDoubleArray([false]);");
388         assertEquals(0.0, mTestObject.waitForDoubleArray()[0]);
389 
390         // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number.
391         executeJavaScript("testObject.setObjectArray([true]);");
392         assertNull(mTestObject.waitForObjectArray());
393 
394         // LIVECONNECT_COMPLIANCE: Should create instances of java.lang.String.
395         executeJavaScript("testObject.setStringArray([true]);");
396         assertNull(mTestObject.waitForStringArray()[0]);
397 
398         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
399         executeJavaScript("testObject.setCustomTypeArray([true]);");
400         assertNull(mTestObject.waitForCustomTypeArray());
401     }
402 
403     // Test passing an array of JavaScript strings to a method which takes a
404     // Java array.
testPassString()405     public void testPassString() throws Throwable {
406         // LIVECONNECT_COMPLIANCE: Non-empty string should convert to true.
407         executeJavaScript("testObject.setBooleanArray([\"+042.10\"]);");
408         assertFalse(mTestObject.waitForBooleanArray()[0]);
409 
410         // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type.
411         executeJavaScript("testObject.setByteArray([\"+042.10\"]);");
412         assertEquals(0, mTestObject.waitForByteArray()[0]);
413 
414         // LIVECONNECT_COMPLIANCE: Should decode and convert to numeric char value.
415         executeJavaScript("testObject.setCharArray([\"+042.10\"]);");
416         assertEquals(0, mTestObject.waitForCharArray()[0]);
417 
418         // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type.
419         executeJavaScript("testObject.setShortArray([\"+042.10\"]);");
420         assertEquals(0, mTestObject.waitForShortArray()[0]);
421 
422         // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type.
423         executeJavaScript("testObject.setIntArray([\"+042.10\"]);");
424         assertEquals(0, mTestObject.waitForIntArray()[0]);
425 
426         // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type.
427         executeJavaScript("testObject.setLongArray([\"+042.10\"]);");
428         assertEquals(0L, mTestObject.waitForLongArray()[0]);
429 
430         // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type.
431         executeJavaScript("testObject.setFloatArray([\"+042.10\"]);");
432         assertEquals(0.0f, mTestObject.waitForFloatArray()[0]);
433 
434         // LIVECONNECT_COMPLIANCE: Should use valueOf() of appropriate type.
435         executeJavaScript("testObject.setDoubleArray([\"+042.10\"]);");
436         assertEquals(0.0, mTestObject.waitForDoubleArray()[0]);
437 
438         // LIVECONNECT_COMPLIANCE: Should create array and create instances of java.lang.Number.
439         executeJavaScript("testObject.setObjectArray([\"+042.10\"]);");
440         assertNull(mTestObject.waitForObjectArray());
441 
442         executeJavaScript("testObject.setStringArray([\"+042.10\"]);");
443         assertEquals("+042.10", mTestObject.waitForStringArray()[0]);
444 
445         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
446         executeJavaScript("testObject.setCustomTypeArray([\"+042.10\"]);");
447         assertNull(mTestObject.waitForCustomTypeArray());
448     }
449 
450     // Test passing an array of JavaScript objects to a method which takes a
451     // Java array.
testPassJavaScriptObject()452     public void testPassJavaScriptObject() throws Throwable {
453         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
454         executeJavaScript("testObject.setBooleanArray([{foo: 42}]);");
455         assertFalse(mTestObject.waitForBooleanArray()[0]);
456 
457         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
458         executeJavaScript("testObject.setByteArray([{foo: 42}]);");
459         assertEquals(0, mTestObject.waitForByteArray()[0]);
460 
461         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
462         executeJavaScript("testObject.setCharArray([{foo: 42}]);");
463         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
464 
465         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
466         executeJavaScript("testObject.setShortArray([{foo: 42}]);");
467         assertEquals(0, mTestObject.waitForShortArray()[0]);
468 
469         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
470         executeJavaScript("testObject.setIntArray([{foo: 42}]);");
471         assertEquals(0, mTestObject.waitForIntArray()[0]);
472 
473         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
474         executeJavaScript("testObject.setLongArray([{foo: 42}]);");
475         assertEquals(0L, mTestObject.waitForLongArray()[0]);
476 
477         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
478         executeJavaScript("testObject.setFloatArray([{foo: 42}]);");
479         assertEquals(0.0f, mTestObject.waitForFloatArray()[0]);
480 
481         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
482         executeJavaScript("testObject.setDoubleArray([{foo: 42}]);");
483         assertEquals(0.0, mTestObject.waitForDoubleArray()[0]);
484 
485         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
486         executeJavaScript("testObject.setObjectArray([{foo: 42}]);");
487         assertNull(mTestObject.waitForObjectArray());
488 
489         // LIVECONNECT_COMPLIANCE: Should call toString() on object.
490         executeJavaScript("testObject.setStringArray([{foo: 42}]);");
491         assertNull(mTestObject.waitForStringArray()[0]);
492 
493         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
494         executeJavaScript("testObject.setCustomTypeArray([{foo: 42}]);");
495         assertNull(mTestObject.waitForCustomTypeArray());
496     }
497 
498     // Test passing an array of Java objects to a method which takes a Java
499     // array.
testPassJavaObject()500     public void testPassJavaObject() throws Throwable {
501         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
502         executeJavaScript("testObject.setBooleanArray([testObject.getObjectInstance()]);");
503         assertFalse(mTestObject.waitForBooleanArray()[0]);
504 
505         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
506         executeJavaScript("testObject.setByteArray([testObject.getObjectInstance()]);");
507         assertEquals(0, mTestObject.waitForByteArray()[0]);
508 
509         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
510         executeJavaScript("testObject.setCharArray([testObject.getObjectInstance()]);");
511         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
512 
513         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
514         executeJavaScript("testObject.setShortArray([testObject.getObjectInstance()]);");
515         assertEquals(0, mTestObject.waitForShortArray()[0]);
516 
517         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
518         executeJavaScript("testObject.setIntArray([testObject.getObjectInstance()]);");
519         assertEquals(0, mTestObject.waitForIntArray()[0]);
520 
521         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
522         executeJavaScript("testObject.setLongArray([testObject.getObjectInstance()]);");
523         assertEquals(0L, mTestObject.waitForLongArray()[0]);
524 
525         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
526         executeJavaScript("testObject.setFloatArray([testObject.getObjectInstance()]);");
527         assertEquals(0.0f, mTestObject.waitForFloatArray()[0]);
528 
529         // LIVECONNECT_COMPLIANCE: Should raise a JavaScript exception.
530         executeJavaScript("testObject.setDoubleArray([testObject.getObjectInstance()]);");
531         assertEquals(0.0, mTestObject.waitForDoubleArray()[0]);
532 
533         // LIVECONNECT_COMPLIANCE: Should create an array and pass Java object.
534         executeJavaScript("testObject.setObjectArray([testObject.getObjectInstance()]);");
535         assertNull(mTestObject.waitForObjectArray());
536 
537         // LIVECONNECT_COMPLIANCE: Should call toString() on object.
538         executeJavaScript("testObject.setStringArray([testObject.getObjectInstance()]);");
539         assertNull(mTestObject.waitForStringArray()[0]);
540 
541         // LIVECONNECT_COMPLIANCE: Should create array and pass Java object.
542         executeJavaScript("testObject.setCustomTypeArray([testObject.getObjectInstance()]);");
543         assertNull(mTestObject.waitForCustomTypeArray());
544         executeJavaScript("testObject.setCustomTypeArray([testObject.getCustomTypeInstance()]);");
545         assertNull(mTestObject.waitForCustomTypeArray());
546     }
547 
548     // Test passing an array of JavaScript null values to a method which takes
549     // a Java array.
testPassNull()550     public void testPassNull() throws Throwable {
551         executeJavaScript("testObject.setByteArray([null]);");
552         assertEquals(0, mTestObject.waitForByteArray()[0]);
553 
554         executeJavaScript("testObject.setCharArray([null]);");
555         assertEquals('\u0000', mTestObject.waitForCharArray()[0]);
556 
557         executeJavaScript("testObject.setShortArray([null]);");
558         assertEquals(0, mTestObject.waitForShortArray()[0]);
559 
560         executeJavaScript("testObject.setIntArray([null]);");
561         assertEquals(0, mTestObject.waitForIntArray()[0]);
562 
563         executeJavaScript("testObject.setLongArray([null]);");
564         assertEquals(0L, mTestObject.waitForLongArray()[0]);
565 
566         executeJavaScript("testObject.setFloatArray([null]);");
567         assertEquals(0.0f, mTestObject.waitForFloatArray()[0]);
568 
569         executeJavaScript("testObject.setDoubleArray([null]);");
570         assertEquals(0.0, mTestObject.waitForDoubleArray()[0]);
571 
572         executeJavaScript("testObject.setBooleanArray([null]);");
573         assertFalse(mTestObject.waitForBooleanArray()[0]);
574 
575         // LIVECONNECT_COMPLIANCE: Should create array and pass null.
576         executeJavaScript("testObject.setObjectArray([null]);");
577         assertNull(mTestObject.waitForObjectArray());
578 
579         executeJavaScript("testObject.setStringArray([null]);");
580         assertNull(mTestObject.waitForStringArray()[0]);
581 
582         // LIVECONNECT_COMPLIANCE: Should create array and pass null.
583         executeJavaScript("testObject.setCustomTypeArray([null]);");
584         assertNull(mTestObject.waitForCustomTypeArray());
585     }
586 
587     // Test passing an array of JavaScript undefined values to a method which
588     // takes a Java array.
testPassUndefined()589     public void testPassUndefined() throws Throwable {
590         executeJavaScript("testObject.setByteArray([undefined]);");
591         assertEquals(0, mTestObject.waitForByteArray()[0]);
592 
593         executeJavaScript("testObject.setCharArray([undefined]);");
594         assertEquals(0, mTestObject.waitForCharArray()[0]);
595 
596         executeJavaScript("testObject.setShortArray([undefined]);");
597         assertEquals(0, mTestObject.waitForShortArray()[0]);
598 
599         executeJavaScript("testObject.setIntArray([undefined]);");
600         assertEquals(0, mTestObject.waitForIntArray()[0]);
601 
602         executeJavaScript("testObject.setLongArray([undefined]);");
603         assertEquals(0L, mTestObject.waitForLongArray()[0]);
604 
605         executeJavaScript("testObject.setFloatArray([undefined]);");
606         assertEquals(0.0f, mTestObject.waitForFloatArray()[0]);
607 
608         executeJavaScript("testObject.setDoubleArray([undefined]);");
609         assertEquals(0.0, mTestObject.waitForDoubleArray()[0]);
610 
611         executeJavaScript("testObject.setBooleanArray([undefined]);");
612         assertEquals(false, mTestObject.waitForBooleanArray()[0]);
613 
614         // LIVECONNECT_COMPLIANCE: Should create array and pass null.
615         executeJavaScript("testObject.setObjectArray([undefined]);");
616         assertNull(mTestObject.waitForObjectArray());
617 
618         executeJavaScript("testObject.setStringArray([undefined]);");
619         assertNull(mTestObject.waitForStringArray()[0]);
620 
621         // LIVECONNECT_COMPLIANCE: Should create array and pass null.
622         executeJavaScript("testObject.setCustomTypeArray([undefined]);");
623         assertNull(mTestObject.waitForCustomTypeArray());
624     }
625 }
626