OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library jsTest; | |
6 | |
7 import 'dart:async'; | |
8 import 'dart:html'; | 5 import 'dart:html'; |
9 import 'dart:typed_data' show ByteBuffer, Int32List; | 6 import 'dart:typed_data' show ByteBuffer, Int32List; |
10 import 'dart:indexed_db' show IdbFactory, KeyRange; | 7 import 'dart:indexed_db' show IdbFactory, KeyRange; |
11 import 'dart:js'; | 8 import 'dart:js'; |
12 | 9 |
13 import 'package:unittest/unittest.dart'; | 10 import 'package:minitest/minitest.dart'; |
14 import 'package:unittest/html_individual_config.dart'; | |
15 | 11 |
16 _injectJs() { | 12 _injectJs() { |
17 final script = new ScriptElement(); | 13 final script = new ScriptElement(); |
18 script.type = 'text/javascript'; | 14 script.type = 'text/javascript'; |
19 script.innerHtml = r""" | 15 script.innerHtml = r""" |
20 var x = 42; | 16 var x = 42; |
21 | 17 |
22 var _x = 123; | 18 var _x = 123; |
23 | 19 |
24 var myArray = ["value1"]; | 20 var myArray = ["value1"]; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 219 } |
224 | 220 |
225 class TestDartObject {} | 221 class TestDartObject {} |
226 | 222 |
227 class Callable { | 223 class Callable { |
228 call() => 'called'; | 224 call() => 'called'; |
229 } | 225 } |
230 | 226 |
231 main() { | 227 main() { |
232 _injectJs(); | 228 _injectJs(); |
233 useHtmlIndividualConfiguration(); | |
234 | 229 |
235 group('identity', () { | 230 group('identity', () { |
236 | 231 |
237 test('context instances should be identical', () { | 232 test('context instances should be identical', () { |
238 var c1 = context; | 233 var c1 = context; |
239 var c2 = context; | 234 var c2 = context; |
240 expect(identical(c1, c2), isTrue); | 235 expect(identical(c1, c2), isTrue); |
241 }); | 236 }); |
242 | 237 |
243 test('identical JS objects should have identical proxies', () { | 238 test('identical JS objects should have identical proxies', () { |
(...skipping 23 matching lines...) Expand all Loading... |
267 expect(identical(f1, f2), isTrue); | 262 expect(identical(f1, f2), isTrue); |
268 }); | 263 }); |
269 | 264 |
270 // TODO(justinfagnani): old tests duplicate checks above, remove | 265 // TODO(justinfagnani): old tests duplicate checks above, remove |
271 // on test next cleanup pass | 266 // on test next cleanup pass |
272 test('test proxy equality', () { | 267 test('test proxy equality', () { |
273 var foo1 = new JsObject(context['Foo'], [1]); | 268 var foo1 = new JsObject(context['Foo'], [1]); |
274 var foo2 = new JsObject(context['Foo'], [2]); | 269 var foo2 = new JsObject(context['Foo'], [2]); |
275 context['foo1'] = foo1; | 270 context['foo1'] = foo1; |
276 context['foo2'] = foo2; | 271 context['foo2'] = foo2; |
277 expect(foo1, isNot(equals(context['foo2']))); | 272 expect(foo1, notEquals(context['foo2'])); |
278 expect(foo2, equals(context['foo2'])); | 273 expect(foo2, equals(context['foo2'])); |
279 context.deleteProperty('foo1'); | 274 context.deleteProperty('foo1'); |
280 context.deleteProperty('foo2'); | 275 context.deleteProperty('foo2'); |
281 }); | 276 }); |
282 | 277 |
283 test('retrieve same dart Object', () { | 278 test('retrieve same dart Object', () { |
284 final obj = new Object(); | 279 final obj = new Object(); |
285 context['obj'] = obj; | 280 context['obj'] = obj; |
286 expect(context['obj'], same(obj)); | 281 expect(context['obj'], same(obj)); |
287 context.deleteProperty('obj'); | 282 context.deleteProperty('obj'); |
(...skipping 30 matching lines...) Expand all Loading... |
318 }); | 313 }); |
319 | 314 |
320 }); | 315 }); |
321 | 316 |
322 group('new_JsObject', () { | 317 group('new_JsObject', () { |
323 | 318 |
324 test('new Foo()', () { | 319 test('new Foo()', () { |
325 var foo = new JsObject(context['Foo'], [42]); | 320 var foo = new JsObject(context['Foo'], [42]); |
326 expect(foo['a'], equals(42)); | 321 expect(foo['a'], equals(42)); |
327 expect(foo.callMethod('bar'), equals(42)); | 322 expect(foo.callMethod('bar'), equals(42)); |
328 expect(() => foo.callMethod('baz'), throwsA(isNoSuchMethodError)); | 323 expect(() => foo.callMethod('baz'), throwsNoSuchMethodError); |
329 }); | 324 }); |
330 | 325 |
331 test('new container.Foo()', () { | 326 test('new container.Foo()', () { |
332 final Foo2 = context['container']['Foo']; | 327 final Foo2 = context['container']['Foo']; |
333 final foo = new JsObject(Foo2, [42]); | 328 final foo = new JsObject(Foo2, [42]); |
334 expect(foo['a'], 42); | 329 expect(foo['a'], 42); |
335 expect(Foo2['b'], 38); | 330 expect(Foo2['b'], 38); |
336 }); | 331 }); |
337 | 332 |
338 test('new Array()', () { | 333 test('new Array()', () { |
339 var a = new JsObject(context['Array']); | 334 var a = new JsObject(context['Array']); |
340 expect(a, new isInstanceOf<JsArray>()); | 335 expect(a is JsArray, isTrue); |
341 | 336 |
342 // Test that the object still behaves via the base JsObject interface. | 337 // Test that the object still behaves via the base JsObject interface. |
343 // JsArray specific tests are below. | 338 // JsArray specific tests are below. |
344 expect(a['length'], 0); | 339 expect(a['length'], 0); |
345 | 340 |
346 a.callMethod('push', ["value 1"]); | 341 a.callMethod('push', ["value 1"]); |
347 expect(a['length'], 1); | 342 expect(a['length'], 1); |
348 expect(a[0], "value 1"); | 343 expect(a[0], "value 1"); |
349 | 344 |
350 a.callMethod('pop'); | 345 a.callMethod('pop'); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 expect(o["f$i"], i); | 432 expect(o["f$i"], i); |
438 } | 433 } |
439 expect(o['constructor'], equals(context['Baz'])); | 434 expect(o['constructor'], equals(context['Baz'])); |
440 }); | 435 }); |
441 }); | 436 }); |
442 | 437 |
443 group('JsFunction and callMethod', () { | 438 group('JsFunction and callMethod', () { |
444 | 439 |
445 test('new JsObject can return a JsFunction', () { | 440 test('new JsObject can return a JsFunction', () { |
446 var f = new JsObject(context['Function']); | 441 var f = new JsObject(context['Function']); |
447 expect(f, new isInstanceOf<JsFunction>()); | 442 expect(f is JsFunction, isTrue); |
448 }); | 443 }); |
449 | 444 |
450 test('JsFunction.apply on a function defined in JS', () { | 445 test('JsFunction.apply on a function defined in JS', () { |
451 expect(context['razzle'].apply([]), equals(42)); | 446 expect(context['razzle'].apply([]), equals(42)); |
452 }); | 447 }); |
453 | 448 |
454 test('JsFunction.apply on a function that uses this', () { | 449 test('JsFunction.apply on a function that uses this', () { |
455 var object = new Object(); | 450 var object = new Object(); |
456 expect(context['returnThis'].apply([], thisArg: object), same(object)); | 451 expect(context['returnThis'].apply([], thisArg: object), same(object)); |
457 }); | 452 }); |
458 | 453 |
459 test('JsObject.callMethod on a function defined in JS', () { | 454 test('JsObject.callMethod on a function defined in JS', () { |
460 expect(context.callMethod('razzle'), equals(42)); | 455 expect(context.callMethod('razzle'), equals(42)); |
461 expect(() => context.callMethod('dazzle'), throwsA(isNoSuchMethodError)); | 456 expect(() => context.callMethod('dazzle'), throwsNoSuchMethodError); |
462 }); | 457 }); |
463 | 458 |
464 test('callMethod with many arguments', () { | 459 test('callMethod with many arguments', () { |
465 expect(context.callMethod('varArgs', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), | 460 expect(context.callMethod('varArgs', [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), |
466 equals(55)); | 461 equals(55)); |
467 }); | 462 }); |
468 | 463 |
469 test('access a property of a function', () { | 464 test('access a property of a function', () { |
470 expect(context.callMethod('Bar'), "ret_value"); | 465 expect(context.callMethod('Bar'), "ret_value"); |
471 expect(context['Bar']['foo'], "property_value"); | 466 expect(context['Bar']['foo'], "property_value"); |
472 }); | 467 }); |
473 /* | 468 /* |
474 TODO(jacobr): evaluate whether we should be in the business of throwing | 469 TODO(jacobr): evaluate whether we should be in the business of throwing |
475 ArgumentError outside of checked mode. In unchecked mode this should just | 470 ArgumentError outside of checked mode. In unchecked mode this should just |
476 return a NoSuchMethodError as the class lacks a method "true". | 471 return a NoSuchMethodError as the class lacks a method "true". |
477 | 472 |
478 test('callMethod throws if name is not a String or num', () { | 473 test('callMethod throws if name is not a String or num', () { |
479 expect(() => context.callMethod(true), | 474 expect(() => context.callMethod(true), |
480 throwsA(new isInstanceOf<ArgumentError>())); | 475 throwsArgumentError); |
481 }); | 476 }); |
482 */ | 477 */ |
483 }); | 478 }); |
484 | 479 |
485 group('JsArray', () { | 480 group('JsArray', () { |
486 | 481 |
487 test('new JsArray()', () { | 482 test('new JsArray()', () { |
488 var array = new JsArray(); | 483 var array = new JsArray(); |
489 var arrayType = context['Array']; | 484 var arrayType = context['Array']; |
490 expect(array.instanceof(arrayType), true); | 485 expect(array.instanceof(arrayType), true); |
491 expect(array, []); | 486 expect(array, []); |
492 // basic check that it behaves like a List | 487 // basic check that it behaves like a List |
493 array.addAll([1, 2, 3]); | 488 array.addAll([1, 2, 3]); |
494 expect(array, [1, 2, 3]); | 489 expect(array, [1, 2, 3]); |
495 }); | 490 }); |
496 | 491 |
497 test('new JsArray.from()', () { | 492 test('new JsArray.from()', () { |
498 var array = new JsArray.from([1, 2, 3]); | 493 var array = new JsArray.from([1, 2, 3]); |
499 var arrayType = context['Array']; | 494 var arrayType = context['Array']; |
500 expect(array.instanceof(arrayType), true); | 495 expect(array.instanceof(arrayType), true); |
501 expect(array, [1, 2, 3]); | 496 expect(array, [1, 2, 3]); |
502 }); | 497 }); |
503 | 498 |
504 test('get Array from JS', () { | 499 test('get Array from JS', () { |
505 context['a'] = new JsObject(context['Array'], [1, 2, 3]); | 500 context['a'] = new JsObject(context['Array'], [1, 2, 3]); |
506 expect(context.callMethod('isPropertyInstanceOf', | 501 expect(context.callMethod('isPropertyInstanceOf', |
507 ['a', context['Array']]), isTrue); | 502 ['a', context['Array']]), isTrue); |
508 var a = context['a']; | 503 var a = context['a']; |
509 expect(a, new isInstanceOf<JsArray>()); | 504 expect(a is JsArray, isTrue); |
510 expect(a, [1, 2, 3]); | 505 expect(a, [1, 2, 3]); |
511 context.deleteProperty('a'); | 506 context.deleteProperty('a'); |
512 }); | 507 }); |
513 | 508 |
514 test('pass Array to JS', () { | 509 test('pass Array to JS', () { |
515 context['a'] = [1, 2, 3]; | 510 context['a'] = [1, 2, 3]; |
516 expect(context.callMethod('isPropertyInstanceOf', | 511 expect(context.callMethod('isPropertyInstanceOf', |
517 ['a', context['Array']]), isTrue); | 512 ['a', context['Array']]), isTrue); |
518 var a = context['a']; | 513 var a = context['a']; |
519 expect(a, new isInstanceOf<List>()); | 514 expect(a is List, isTrue); |
520 expect(a, isNot(new isInstanceOf<JsArray>())); | 515 expect(a is JsArray, isFalse); |
521 expect(a, [1, 2, 3]); | 516 expect(a, [1, 2, 3]); |
522 context.deleteProperty('a'); | 517 context.deleteProperty('a'); |
523 }); | 518 }); |
524 | 519 |
525 test('[]', () { | 520 test('[]', () { |
526 var array = new JsArray.from([1, 2]); | 521 var array = new JsArray.from([1, 2]); |
527 expect(array[0], 1); | 522 expect(array[0], 1); |
528 expect(array[1], 2); | 523 expect(array[1], 2); |
529 expect(() => array[-1], throwsA(isRangeError)); | 524 expect(() => array[-1], throwsRangeError); |
530 expect(() => array[2], throwsA(isRangeError)); | 525 expect(() => array[2], throwsRangeError); |
531 }); | 526 }); |
532 | 527 |
533 test('[]=', () { | 528 test('[]=', () { |
534 var array = new JsArray.from([1, 2]); | 529 var array = new JsArray<Object>.from([1, 2]); |
535 array[0] = 'd'; | 530 array[0] = 'd'; |
536 array[1] = 'e'; | 531 array[1] = 'e'; |
537 expect(array, ['d', 'e']); | 532 expect(array, ['d', 'e']); |
538 expect(() => array[-1] = 3, throwsA(isRangeError)); | 533 expect(() => array[-1] = 3, throwsRangeError); |
539 expect(() => array[2] = 3, throwsA(isRangeError)); | 534 expect(() => array[2] = 3, throwsRangeError); |
540 }); | 535 }); |
541 | 536 |
542 test('length', () { | 537 test('length', () { |
543 var array = new JsArray.from([1, 2, 3]); | 538 var array = new JsArray.from([1, 2, 3]); |
544 expect(array.length, 3); | 539 expect(array.length, 3); |
545 array.add(4); | 540 array.add(4); |
546 expect(array.length, 4); | 541 expect(array.length, 4); |
547 array.length = 2; | 542 array.length = 2; |
548 expect(array, [1, 2]); | 543 expect(array, [1, 2]); |
549 array.length = 3; | 544 array.length = 3; |
(...skipping 18 matching lines...) Expand all Loading... |
568 }); | 563 }); |
569 | 564 |
570 test('insert', () { | 565 test('insert', () { |
571 var array = new JsArray.from([]); | 566 var array = new JsArray.from([]); |
572 array.insert(0, 'b'); | 567 array.insert(0, 'b'); |
573 expect(array, ['b']); | 568 expect(array, ['b']); |
574 array.insert(0, 'a'); | 569 array.insert(0, 'a'); |
575 expect(array, ['a', 'b']); | 570 expect(array, ['a', 'b']); |
576 array.insert(2, 'c'); | 571 array.insert(2, 'c'); |
577 expect(array, ['a', 'b', 'c']); | 572 expect(array, ['a', 'b', 'c']); |
578 expect(() => array.insert(4, 'e'), throwsA(isRangeError)); | 573 expect(() => array.insert(4, 'e'), throwsRangeError); |
579 expect(() => array.insert(-1, 'e'), throwsA(isRangeError)); | 574 expect(() => array.insert(-1, 'e'), throwsRangeError); |
580 }); | 575 }); |
581 | 576 |
582 test('removeAt', () { | 577 test('removeAt', () { |
583 var array = new JsArray.from(['a', 'b', 'c']); | 578 var array = new JsArray.from(['a', 'b', 'c']); |
584 expect(array.removeAt(1), 'b'); | 579 expect(array.removeAt(1), 'b'); |
585 expect(array, ['a', 'c']); | 580 expect(array, ['a', 'c']); |
586 expect(() => array.removeAt(2), throwsA(isRangeError)); | 581 expect(() => array.removeAt(2), throwsRangeError); |
587 expect(() => array.removeAt(-1), throwsA(isRangeError)); | 582 expect(() => array.removeAt(-1), throwsRangeError); |
588 }); | 583 }); |
589 | 584 |
590 test('removeLast', () { | 585 test('removeLast', () { |
591 var array = new JsArray.from(['a', 'b', 'c']); | 586 var array = new JsArray.from(['a', 'b', 'c']); |
592 expect(array.removeLast(), 'c'); | 587 expect(array.removeLast(), 'c'); |
593 expect(array, ['a', 'b']); | 588 expect(array, ['a', 'b']); |
594 array.length = 0; | 589 array.length = 0; |
595 expect(() => array.removeLast(), throwsA(isRangeError)); | 590 expect(() => array.removeLast(), throwsRangeError); |
596 }); | 591 }); |
597 | 592 |
598 test('removeRange', () { | 593 test('removeRange', () { |
599 var array = new JsArray.from(['a', 'b', 'c', 'd']); | 594 var array = new JsArray.from(['a', 'b', 'c', 'd']); |
600 array.removeRange(1, 3); | 595 array.removeRange(1, 3); |
601 expect(array, ['a', 'd']); | 596 expect(array, ['a', 'd']); |
602 expect(() => array.removeRange(-1, 2), throwsA(isRangeError)); | 597 expect(() => array.removeRange(-1, 2), throwsRangeError); |
603 expect(() => array.removeRange(0, 3), throwsA(isRangeError)); | 598 expect(() => array.removeRange(0, 3), throwsRangeError); |
604 expect(() => array.removeRange(2, 1), throwsA(isRangeError)); | 599 expect(() => array.removeRange(2, 1), throwsRangeError); |
605 }); | 600 }); |
606 | 601 |
607 test('setRange', () { | 602 test('setRange', () { |
608 var array = new JsArray.from(['a', 'b', 'c', 'd']); | 603 var array = new JsArray.from(['a', 'b', 'c', 'd']); |
609 array.setRange(1, 3, ['e', 'f']); | 604 array.setRange(1, 3, ['e', 'f']); |
610 expect(array, ['a', 'e', 'f', 'd']); | 605 expect(array, ['a', 'e', 'f', 'd']); |
611 array.setRange(3, 4, ['g', 'h', 'i'], 1); | 606 array.setRange(3, 4, ['g', 'h', 'i'], 1); |
612 expect(array, ['a', 'e', 'f', 'h']); | 607 expect(array, ['a', 'e', 'f', 'h']); |
613 }); | 608 }); |
614 | 609 |
(...skipping 17 matching lines...) Expand all Loading... |
632 var node = new JsObject.fromBrowserObject(new DivElement()); | 627 var node = new JsObject.fromBrowserObject(new DivElement()); |
633 context.callMethod('addTestProperty', [node]); | 628 context.callMethod('addTestProperty', [node]); |
634 expect(node is JsObject, isTrue); | 629 expect(node is JsObject, isTrue); |
635 // TODO(justinfagnani): make this work in IE9 | 630 // TODO(justinfagnani): make this work in IE9 |
636 // expect(node.instanceof(context['HTMLDivElement']), isTrue); | 631 // expect(node.instanceof(context['HTMLDivElement']), isTrue); |
637 expect(node['testProperty'], 'test'); | 632 expect(node['testProperty'], 'test'); |
638 }); | 633 }); |
639 | 634 |
640 test('primitives and null throw ArgumentError', () { | 635 test('primitives and null throw ArgumentError', () { |
641 for (var v in ['a', 1, 2.0, true, null]) { | 636 for (var v in ['a', 1, 2.0, true, null]) { |
642 expect(() => new JsObject.fromBrowserObject(v), | 637 expect(() => new JsObject.fromBrowserObject(v), throwsArgumentError); |
643 throwsA(new isInstanceOf<ArgumentError>())); | |
644 } | 638 } |
645 }); | 639 }); |
646 | 640 |
647 }); | 641 }); |
648 | 642 |
649 group('Dart_functions', () { | 643 group('Dart_functions', () { |
650 test('invoke Dart callback from JS', () { | 644 test('invoke Dart callback from JS', () { |
651 expect(() => context.callMethod('invokeCallback'), throws); | 645 expect(() => context.callMethod('invokeCallback'), throws); |
652 | 646 |
653 context['callback'] = () => 42; | 647 context['callback'] = () => 42; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 test('convert a Map', () { | 712 test('convert a Map', () { |
719 var map = {'a': 1, 'b': 2, 'c': 3}; | 713 var map = {'a': 1, 'b': 2, 'c': 3}; |
720 var jsMap = new JsObject.jsify(map); | 714 var jsMap = new JsObject.jsify(map); |
721 expect(!context.callMethod('isArray', [jsMap]), isTrue); | 715 expect(!context.callMethod('isArray', [jsMap]), isTrue); |
722 for (final key in map.keys) { | 716 for (final key in map.keys) { |
723 expect(context.callMethod('checkMap', [jsMap, key, map[key]]), isTrue); | 717 expect(context.callMethod('checkMap', [jsMap, key, map[key]]), isTrue); |
724 } | 718 } |
725 }); | 719 }); |
726 | 720 |
727 test('deep convert a complex object', () { | 721 test('deep convert a complex object', () { |
728 final object = { | 722 dynamic object = { |
729 'a': [1, [2, 3]], | 723 'a': [1, [2, 3]], |
730 'b': { | 724 'b': { |
731 'c': 3, | 725 'c': 3, |
732 'd': new JsObject(context['Foo'], [42]) | 726 'd': new JsObject(context['Foo'], [42]) |
733 }, | 727 }, |
734 'e': null | 728 'e': null |
735 }; | 729 }; |
736 var jsObject = new JsObject.jsify(object); | 730 var jsObject = new JsObject.jsify(object); |
737 expect(jsObject['a'][0], equals(object['a'][0])); | 731 expect(jsObject['a'][0], equals(object['a'][0])); |
738 expect(jsObject['a'][1][0], equals(object['a'][1][0])); | 732 expect(jsObject['a'][1][0], equals(object['a'][1][0])); |
739 expect(jsObject['a'][1][1], equals(object['a'][1][1])); | 733 expect(jsObject['a'][1][1], equals(object['a'][1][1])); |
740 expect(jsObject['b']['c'], equals(object['b']['c'])); | 734 expect(jsObject['b']['c'], equals(object['b']['c'])); |
741 expect(jsObject['b']['d'], equals(object['b']['d'])); | 735 expect(jsObject['b']['d'], equals(object['b']['d'])); |
742 expect(jsObject['b']['d'].callMethod('bar'), equals(42)); | 736 expect(jsObject['b']['d'].callMethod('bar'), equals(42)); |
743 expect(jsObject['e'], isNull); | 737 expect(jsObject['e'], isNull); |
744 }); | 738 }); |
745 | 739 |
746 test('throws if object is not a Map or Iterable', () { | 740 test('throws if object is not a Map or Iterable', () { |
747 expect(() => new JsObject.jsify('a'), | 741 expect(() => new JsObject.jsify('a'), throwsArgumentError); |
748 throwsA(new isInstanceOf<ArgumentError>())); | |
749 }); | 742 }); |
750 }); | 743 }); |
751 | 744 |
752 group('JsObject_methods', () { | 745 group('JsObject_methods', () { |
753 | 746 |
754 test('hashCode and ==', () { | 747 test('hashCode and ==', () { |
755 final o1 = context['Object']; | 748 final o1 = context['Object']; |
756 final o2 = context['Object']; | 749 final o2 = context['Object']; |
757 expect(o1 == o2, isTrue); | 750 expect(o1 == o2, isTrue); |
758 expect(o1.hashCode == o2.hashCode, isTrue); | 751 expect(o1.hashCode == o2.hashCode, isTrue); |
(...skipping 27 matching lines...) Expand all Loading... |
786 expect(context['Object'].callMethod('keys', [object])['length'], 1); | 779 expect(context['Object'].callMethod('keys', [object])['length'], 1); |
787 expect(context['Object'].callMethod('keys', [object])[0], "a"); | 780 expect(context['Object'].callMethod('keys', [object])[0], "a"); |
788 object.deleteProperty("a"); | 781 object.deleteProperty("a"); |
789 expect(context['Object'].callMethod('keys', [object])['length'], 0); | 782 expect(context['Object'].callMethod('keys', [object])['length'], 0); |
790 }); | 783 }); |
791 | 784 |
792 /* TODO(jacobr): this is another test that is inconsistent with JS semantics. | 785 /* TODO(jacobr): this is another test that is inconsistent with JS semantics. |
793 test('deleteProperty throws if name is not a String or num', () { | 786 test('deleteProperty throws if name is not a String or num', () { |
794 var object = new JsObject.jsify({}); | 787 var object = new JsObject.jsify({}); |
795 expect(() => object.deleteProperty(true), | 788 expect(() => object.deleteProperty(true), |
796 throwsA(new isInstanceOf<ArgumentError>())); | 789 throwsArgumentError); |
797 }); | 790 }); |
798 */ | 791 */ |
799 | 792 |
800 test('hasProperty', () { | 793 test('hasProperty', () { |
801 var object = new JsObject.jsify({}); | 794 var object = new JsObject.jsify({}); |
802 object['a'] = 1; | 795 object['a'] = 1; |
803 expect(object.hasProperty('a'), isTrue); | 796 expect(object.hasProperty('a'), isTrue); |
804 expect(object.hasProperty('b'), isFalse); | 797 expect(object.hasProperty('b'), isFalse); |
805 }); | 798 }); |
806 | 799 |
807 /* TODO(jacobr): is this really the correct unchecked mode behavior? | 800 /* TODO(jacobr): is this really the correct unchecked mode behavior? |
808 test('hasProperty throws if name is not a String or num', () { | 801 test('hasProperty throws if name is not a String or num', () { |
809 var object = new JsObject.jsify({}); | 802 var object = new JsObject.jsify({}); |
810 expect(() => object.hasProperty(true), | 803 expect(() => object.hasProperty(true), |
811 throwsA(new isInstanceOf<ArgumentError>())); | 804 throwsArgumentError); |
812 }); | 805 }); |
813 */ | 806 */ |
814 | 807 |
815 test('[] and []=', () { | 808 test('[] and []=', () { |
816 final myArray = context['myArray']; | 809 final myArray = context['myArray']; |
817 expect(myArray['length'], equals(1)); | 810 expect(myArray['length'], equals(1)); |
818 expect(myArray[0], equals("value1")); | 811 expect(myArray[0], equals("value1")); |
819 myArray[0] = "value2"; | 812 myArray[0] = "value2"; |
820 expect(myArray['length'], equals(1)); | 813 expect(myArray['length'], equals(1)); |
821 expect(myArray[0], equals("value2")); | 814 expect(myArray[0], equals("value2")); |
822 | 815 |
823 final foo = new JsObject(context['Foo'], [1]); | 816 final foo = new JsObject(context['Foo'], [1]); |
824 foo["getAge"] = () => 10; | 817 foo["getAge"] = () => 10; |
825 expect(foo.callMethod('getAge'), equals(10)); | 818 expect(foo.callMethod('getAge'), equals(10)); |
826 }); | 819 }); |
827 | 820 |
828 /* TODO(jacobr): remove as we should only throw this in checked mode. | 821 /* TODO(jacobr): remove as we should only throw this in checked mode. |
829 test('[] and []= throw if name is not a String or num', () { | 822 test('[] and []= throw if name is not a String or num', () { |
830 var object = new JsObject.jsify({}); | 823 var object = new JsObject.jsify({}); |
831 expect(() => object[true], | 824 expect(() => object[true], |
832 throwsA(new isInstanceOf<ArgumentError>())); | 825 throwsArgumentError); |
833 expect(() => object[true] = 1, | 826 expect(() => object[true] = 1, |
834 throwsA(new isInstanceOf<ArgumentError>())); | 827 throwsArgumentError); |
835 }); | 828 }); |
836 */ | 829 */ |
837 }); | 830 }); |
838 | 831 |
839 group('transferrables', () { | 832 group('transferrables', () { |
840 | 833 |
841 group('JS->Dart', () { | 834 group('JS->Dart', () { |
842 | 835 |
843 test('DateTime', () { | 836 test('DateTime', () { |
844 var date = context.callMethod('getNewDate'); | 837 var date = context.callMethod('getNewDate'); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 test('ImageData', () { | 902 test('ImageData', () { |
910 var node = context.callMethod('getNewImageData'); | 903 var node = context.callMethod('getNewImageData'); |
911 expect(node is ImageData, isTrue); | 904 expect(node is ImageData, isTrue); |
912 }); | 905 }); |
913 | 906 |
914 test('typed data: Int32Array', () { | 907 test('typed data: Int32Array', () { |
915 if (Platform.supportsTypedData) { | 908 if (Platform.supportsTypedData) { |
916 var list = context.callMethod('getNewInt32Array'); | 909 var list = context.callMethod('getNewInt32Array'); |
917 print(list); | 910 print(list); |
918 expect(list is Int32List, isTrue); | 911 expect(list is Int32List, isTrue); |
919 expect(list, orderedEquals([1, 2, 3, 4, 5, 6, 7, 8])); | 912 expect(list, equals([1, 2, 3, 4, 5, 6, 7, 8])); |
920 } | 913 } |
921 }); | 914 }); |
922 | 915 |
923 }); | 916 }); |
924 | 917 |
925 group('Dart->JS', () { | 918 group('Dart->JS', () { |
926 | 919 |
927 test('Date', () { | 920 test('Date', () { |
928 context['o'] = new DateTime(1995, 12, 17); | 921 context['o'] = new DateTime(1995, 12, 17); |
929 var dateType = context['Date']; | 922 var dateType = context['Date']; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 isTrue); | 974 isTrue); |
982 context.deleteProperty('o'); | 975 context.deleteProperty('o'); |
983 } | 976 } |
984 }); | 977 }); |
985 | 978 |
986 // this test fails in IE9 for very weird, but unknown, reasons | 979 // this test fails in IE9 for very weird, but unknown, reasons |
987 // the expression context['ImageData'] fails if useHtmlConfiguration() | 980 // the expression context['ImageData'] fails if useHtmlConfiguration() |
988 // is called, or if the other tests in this file are enabled | 981 // is called, or if the other tests in this file are enabled |
989 skipIE9_test('ImageData', () { | 982 skipIE9_test('ImageData', () { |
990 var canvas = new CanvasElement(); | 983 var canvas = new CanvasElement(); |
991 var ctx = canvas.getContext('2d'); | 984 var ctx = canvas.getContext('2d') as CanvasRenderingContext2D; |
992 context['o'] = ctx.createImageData(1, 1); | 985 context['o'] = ctx.createImageData(1, 1); |
993 var imageDataType = context['ImageData']; | 986 var imageDataType = context['ImageData']; |
994 expect(context.callMethod('isPropertyInstanceOf', ['o', imageDataType]), | 987 expect(context.callMethod('isPropertyInstanceOf', ['o', imageDataType]), |
995 isTrue); | 988 isTrue); |
996 context.deleteProperty('o'); | 989 context.deleteProperty('o'); |
997 }); | 990 }); |
998 | 991 |
999 test('typed data: Int32List', () { | 992 test('typed data: Int32List', () { |
1000 if (Platform.supportsTypedData) { | 993 if (Platform.supportsTypedData) { |
1001 context['o'] = new Int32List.fromList([1, 2, 3, 4]); | 994 context['o'] = new Int32List.fromList([1, 2, 3, 4]); |
1002 var listType = context['Int32Array']; | 995 var listType = context['Int32Array']; |
1003 // TODO(jacobr): make this test pass. Currently some type information | 996 // TODO(jacobr): make this test pass. Currently some type information |
1004 // is lost when typed arrays are passed between JS and Dart. | 997 // is lost when typed arrays are passed between JS and Dart. |
1005 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), | 998 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), |
1006 // isTrue); | 999 // isTrue); |
1007 context.deleteProperty('o'); | 1000 context.deleteProperty('o'); |
1008 } | 1001 } |
1009 }); | 1002 }); |
1010 | 1003 |
1011 }); | 1004 }); |
1012 }); | 1005 }); |
1013 | 1006 |
1014 } | 1007 } |
OLD | NEW |