| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 useHtmlIndividualConfiguration(); | 233 useHtmlIndividualConfiguration(); |
| 234 | 234 |
| 235 group('identity', () { | 235 group('identity', () { |
| 236 | 236 |
| 237 test('context instances should be identical', () { | 237 test('context instances should be identical', () { |
| 238 var c1 = context; | 238 var c1 = context; |
| 239 var c2 = context; | 239 var c2 = context; |
| 240 expect(identical(c1, c2), isTrue); | 240 expect(identical(c1, c2), isTrue); |
| 241 }); | 241 }); |
| 242 | 242 |
| 243 /* | |
| 244 TODO(jacobr): enable this test when dartium supports maintaining proxy | |
| 245 equality. | |
| 246 | |
| 247 test('identical JS objects should have identical proxies', () { | 243 test('identical JS objects should have identical proxies', () { |
| 248 var o1 = new JsObject(context['Foo'], [1]); | 244 var o1 = new JsObject(context['Foo'], [1]); |
| 249 context['f1'] = o1; | 245 context['f1'] = o1; |
| 250 var o2 = context['f1']; | 246 var o2 = context['f1']; |
| 251 expect(equals(o1, o2), isTrue); | 247 expect(identical(o1, o2), isTrue); |
| 252 }); | 248 }); |
| 253 | 249 |
| 250 /* |
| 251 TODO(jacobr): enable this test when dartium supports maintaining proxy |
| 252 equality. |
| 254 test('identical Dart objects should have identical proxies', () { | 253 test('identical Dart objects should have identical proxies', () { |
| 255 var o1 = new TestDartObject(); | 254 var o1 = new TestDartObject(); |
| 256 expect(context.callMethod('identical', [o1, o1]), isTrue); | 255 expect(context.callMethod('identical', [o1, o1]), isTrue); |
| 257 }); | 256 }); |
| 257 */ |
| 258 | 258 |
| 259 test('identical Dart functions should have identical proxies', () { | 259 test('identical Dart functions should have identical proxies', () { |
| 260 var f1 = () => print("I'm a Function!"); | 260 var f1 = allowInterop(() => print("I'm a Function!")); |
| 261 expect(context.callMethod('identical', [f1, f1]), isTrue); | 261 expect(context.callMethod('identical', [f1, f1]), isTrue); |
| 262 }); | 262 }); |
| 263 */ | |
| 264 | 263 |
| 265 // TODO(jacobr): switch from equals to indentical when dartium supports | 264 test('identical JS functions should have identical proxies', () { |
| 266 // maintaining proxy equality. | |
| 267 test('identical JS functions should have equal proxies', () { | |
| 268 var f1 = context['Object']; | 265 var f1 = context['Object']; |
| 269 var f2 = context['Object']; | 266 var f2 = context['Object']; |
| 270 expect(f1, equals(f2)); | 267 expect(identical(f1, f2), isTrue); |
| 271 }); | 268 }); |
| 272 | 269 |
| 273 // TODO(justinfagnani): old tests duplicate checks above, remove | 270 // TODO(justinfagnani): old tests duplicate checks above, remove |
| 274 // on test next cleanup pass | 271 // on test next cleanup pass |
| 275 test('test proxy equality', () { | 272 test('test proxy equality', () { |
| 276 var foo1 = new JsObject(context['Foo'], [1]); | 273 var foo1 = new JsObject(context['Foo'], [1]); |
| 277 var foo2 = new JsObject(context['Foo'], [2]); | 274 var foo2 = new JsObject(context['Foo'], [2]); |
| 278 context['foo1'] = foo1; | 275 context['foo1'] = foo1; |
| 279 context['foo2'] = foo2; | 276 context['foo2'] = foo2; |
| 280 expect(foo1, isNot(equals(context['foo2']))); | 277 expect(foo1, isNot(equals(context['foo2']))); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 444 |
| 448 test('new JsObject can return a JsFunction', () { | 445 test('new JsObject can return a JsFunction', () { |
| 449 var f = new JsObject(context['Function']); | 446 var f = new JsObject(context['Function']); |
| 450 expect(f, new isInstanceOf<JsFunction>()); | 447 expect(f, new isInstanceOf<JsFunction>()); |
| 451 }); | 448 }); |
| 452 | 449 |
| 453 test('JsFunction.apply on a function defined in JS', () { | 450 test('JsFunction.apply on a function defined in JS', () { |
| 454 expect(context['razzle'].apply([]), equals(42)); | 451 expect(context['razzle'].apply([]), equals(42)); |
| 455 }); | 452 }); |
| 456 | 453 |
| 457 test('JsFunction.apply on a function that uses "this"', () { | 454 test('JsFunction.apply on a function that uses this', () { |
| 458 var object = new Object(); | 455 var object = new Object(); |
| 459 expect(context['returnThis'].apply([], thisArg: object), same(object)); | 456 expect(context['returnThis'].apply([], thisArg: object), same(object)); |
| 460 }); | 457 }); |
| 461 | 458 |
| 462 test('JsObject.callMethod on a function defined in JS', () { | 459 test('JsObject.callMethod on a function defined in JS', () { |
| 463 expect(context.callMethod('razzle'), equals(42)); | 460 expect(context.callMethod('razzle'), equals(42)); |
| 464 expect(() => context.callMethod('dazzle'), throwsA(isNoSuchMethodError)); | 461 expect(() => context.callMethod('dazzle'), throwsA(isNoSuchMethodError)); |
| 465 }); | 462 }); |
| 466 | 463 |
| 467 test('callMethod with many arguments', () { | 464 test('callMethod with many arguments', () { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 ['a', context['Array']]), isTrue); | 507 ['a', context['Array']]), isTrue); |
| 511 var a = context['a']; | 508 var a = context['a']; |
| 512 expect(a, new isInstanceOf<JsArray>()); | 509 expect(a, new isInstanceOf<JsArray>()); |
| 513 expect(a, [1, 2, 3]); | 510 expect(a, [1, 2, 3]); |
| 514 context.deleteProperty('a'); | 511 context.deleteProperty('a'); |
| 515 }); | 512 }); |
| 516 | 513 |
| 517 test('pass Array to JS', () { | 514 test('pass Array to JS', () { |
| 518 context['a'] = [1, 2, 3]; | 515 context['a'] = [1, 2, 3]; |
| 519 expect(context.callMethod('isPropertyInstanceOf', | 516 expect(context.callMethod('isPropertyInstanceOf', |
| 520 ['a', context['Array']]), isFalse); | 517 ['a', context['Array']]), isTrue); |
| 521 var a = context['a']; | 518 var a = context['a']; |
| 522 expect(a, new isInstanceOf<List>()); | 519 expect(a, new isInstanceOf<List>()); |
| 523 expect(a, isNot(new isInstanceOf<JsArray>())); | 520 expect(a, isNot(new isInstanceOf<JsArray>())); |
| 524 expect(a, [1, 2, 3]); | 521 expect(a, [1, 2, 3]); |
| 525 context.deleteProperty('a'); | 522 context.deleteProperty('a'); |
| 526 }); | 523 }); |
| 527 | 524 |
| 528 test('[]', () { | 525 test('[]', () { |
| 529 var array = new JsArray.from([1, 2]); | 526 var array = new JsArray.from([1, 2]); |
| 530 expect(array[0], 1); | 527 expect(array[0], 1); |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), | 1005 // expect(context.callMethod('isPropertyInstanceOf', ['o', listType]), |
| 1009 // isTrue); | 1006 // isTrue); |
| 1010 context.deleteProperty('o'); | 1007 context.deleteProperty('o'); |
| 1011 } | 1008 } |
| 1012 }); | 1009 }); |
| 1013 | 1010 |
| 1014 }); | 1011 }); |
| 1015 }); | 1012 }); |
| 1016 | 1013 |
| 1017 } | 1014 } |
| OLD | NEW |