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