| 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; | 5 library jsTest; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:html'; | 8 import 'dart:html'; |
| 9 import 'dart:typed_data' show ByteBuffer, Int32List; | 9 import 'dart:typed_data' show ByteBuffer, Int32List; |
| 10 import 'dart:indexed_db' show IdbFactory, KeyRange; | 10 import 'dart:indexed_db' show IdbFactory, KeyRange; |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 ArgumentError outside of checked mode. In unchecked mode this should just | 443 ArgumentError outside of checked mode. In unchecked mode this should just |
| 444 return a NoSuchMethodError as the class lacks a method "true". | 444 return a NoSuchMethodError as the class lacks a method "true". |
| 445 | 445 |
| 446 test('callMethod throws if name is not a String or num', () { | 446 test('callMethod throws if name is not a String or num', () { |
| 447 expect(() => context.callMethod(true), | 447 expect(() => context.callMethod(true), |
| 448 throwsA(new isInstanceOf<ArgumentError>())); | 448 throwsA(new isInstanceOf<ArgumentError>())); |
| 449 }); | 449 }); |
| 450 */ | 450 */ |
| 451 }); | 451 }); |
| 452 | 452 |
| 453 group('JsArray', () { |
| 454 |
| 455 test('new JsArray()', () { |
| 456 var array = new JsArray(); |
| 457 var arrayType = context['Array']; |
| 458 expect(array.instanceof(arrayType), true); |
| 459 expect(array, []); |
| 460 // basic check that it behaves like a List |
| 461 array.addAll([1, 2, 3]); |
| 462 expect(array, [1, 2, 3]); |
| 463 }); |
| 464 |
| 465 test('new JsArray.from()', () { |
| 466 var array = new JsArray.from([1, 2, 3]); |
| 467 var arrayType = context['Array']; |
| 468 expect(array.instanceof(arrayType), true); |
| 469 expect(array, [1, 2, 3]); |
| 470 }); |
| 471 |
| 472 test('get Array from JS', () { |
| 473 context['a'] = [1, 2, 3]; |
| 474 var a = context['a']; |
| 475 expect(a is JsArray, true); |
| 476 expect(a, [1, 2, 3]); |
| 477 context.deleteProperty('a'); |
| 478 }); |
| 479 |
| 480 test('[]', () { |
| 481 var array = new JsArray.from([1, 2]); |
| 482 expect(array[0], 1); |
| 483 expect(array[1], 2); |
| 484 expect(() => array[-1], throwsA(isRangeError)); |
| 485 expect(() => array[2], throwsA(isRangeError)); |
| 486 }); |
| 487 |
| 488 test('[]=', () { |
| 489 var array = new JsArray.from([1, 2]); |
| 490 array[0] = 'd'; |
| 491 array[1] = 'e'; |
| 492 expect(array, ['d', 'e']); |
| 493 expect(() => array[-1] = 3, throwsA(isRangeError)); |
| 494 expect(() => array[2] = 3, throwsA(isRangeError)); |
| 495 }); |
| 496 |
| 497 test('length', () { |
| 498 var array = new JsArray.from([1, 2, 3]); |
| 499 expect(array.length, 3); |
| 500 array.add(4); |
| 501 expect(array.length, 4); |
| 502 array.length = 2; |
| 503 expect(array, [1, 2]); |
| 504 array.length = 3; |
| 505 expect(array, [1, 2, null]); |
| 506 }); |
| 507 |
| 508 test('add', () { |
| 509 var array = new JsArray(); |
| 510 array.add('a'); |
| 511 expect(array, ['a']); |
| 512 array.add('b'); |
| 513 expect(array, ['a', 'b']); |
| 514 }); |
| 515 |
| 516 test('addAll', () { |
| 517 var array = new JsArray(); |
| 518 array.addAll(['a', 'b']); |
| 519 expect(array, ['a', 'b']); |
| 520 // make sure addAll can handle Iterables |
| 521 array.addAll(new Set.from(['c'])); |
| 522 expect(array, ['a', 'b', 'c']); |
| 523 }); |
| 524 |
| 525 test('insert', () { |
| 526 var array = new JsArray.from([]); |
| 527 array.insert(0, 'b'); |
| 528 expect(array, ['b']); |
| 529 array.insert(0, 'a'); |
| 530 expect(array, ['a', 'b']); |
| 531 array.insert(2, 'c'); |
| 532 expect(array, ['a', 'b', 'c']); |
| 533 expect(() => array.insert(4, 'e'), throwsA(isRangeError)); |
| 534 expect(() => array.insert(-1, 'e'), throwsA(isRangeError)); |
| 535 }); |
| 536 |
| 537 test('removeAt', () { |
| 538 var array = new JsArray.from(['a', 'b', 'c']); |
| 539 expect(array.removeAt(1), 'b'); |
| 540 expect(array, ['a', 'c']); |
| 541 expect(() => array.removeAt(2), throwsA(isRangeError)); |
| 542 expect(() => array.removeAt(-1), throwsA(isRangeError)); |
| 543 }); |
| 544 |
| 545 test('removeLast', () { |
| 546 var array = new JsArray.from(['a', 'b', 'c']); |
| 547 expect(array.removeLast(), 'c'); |
| 548 expect(array, ['a', 'b']); |
| 549 array.length = 0; |
| 550 expect(() => array.removeLast(), throwsA(isRangeError)); |
| 551 }); |
| 552 |
| 553 test('removeRange', () { |
| 554 var array = new JsArray.from(['a', 'b', 'c', 'd']); |
| 555 array.removeRange(1, 3); |
| 556 expect(array, ['a', 'd']); |
| 557 expect(() => array.removeRange(-1, 2), throwsA(isRangeError)); |
| 558 expect(() => array.removeRange(0, 3), throwsA(isRangeError)); |
| 559 expect(() => array.removeRange(2, 1), throwsA(isRangeError)); |
| 560 }); |
| 561 |
| 562 test('setRange', () { |
| 563 var array = new JsArray.from(['a', 'b', 'c', 'd']); |
| 564 array.setRange(1, 3, ['e', 'f']); |
| 565 expect(array, ['a', 'e', 'f', 'd']); |
| 566 array.setRange(3, 4, ['g', 'h', 'i'], 1); |
| 567 expect(array, ['a', 'e', 'f', 'h']); |
| 568 }); |
| 569 |
| 570 test('sort', () { |
| 571 var array = new JsArray.from(['c', 'a', 'b']); |
| 572 array.sort(); |
| 573 expect(array, ['a', 'b', 'c']); |
| 574 }); |
| 575 |
| 576 test('sort with a Comparator', () { |
| 577 var array = new JsArray.from(['c', 'a', 'b']); |
| 578 array.sort((a, b) => -(a.compareTo(b))); |
| 579 expect(array, ['c', 'b', 'a']); |
| 580 }); |
| 581 |
| 582 }); |
| 583 |
| 453 group('JsObject.fromBrowserObject()', () { | 584 group('JsObject.fromBrowserObject()', () { |
| 454 | 585 |
| 455 test('Nodes are proxied', () { | 586 test('Nodes are proxied', () { |
| 456 var node = new JsObject.fromBrowserObject(new DivElement()); | 587 var node = new JsObject.fromBrowserObject(new DivElement()); |
| 457 context.callMethod('addTestProperty', [node]); | 588 context.callMethod('addTestProperty', [node]); |
| 458 expect(node is JsObject, isTrue); | 589 expect(node is JsObject, isTrue); |
| 459 // TODO(justinfagnani): make this work in IE9 | 590 // TODO(justinfagnani): make this work in IE9 |
| 460 // expect(node.instanceof(context['HTMLDivElement']), isTrue); | 591 // expect(node.instanceof(context['HTMLDivElement']), isTrue); |
| 461 expect(node['testProperty'], 'test'); | 592 expect(node['testProperty'], 'test'); |
| 462 }); | 593 }); |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 // is lost when typed arrays are passed between JS and Dart. | 909 // is lost when typed arrays are passed between JS and Dart. |
| 779 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), | 910 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), |
| 780 // isTrue); | 911 // isTrue); |
| 781 context.deleteProperty('o'); | 912 context.deleteProperty('o'); |
| 782 } | 913 } |
| 783 }); | 914 }); |
| 784 | 915 |
| 785 }); | 916 }); |
| 786 }); | 917 }); |
| 787 } | 918 } |
| OLD | NEW |