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