OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // TODO(sigmund): delete this file after issue 19322 is resolved. |
| 6 // This test is a trimmed down version of interop_test. interop_test is |
| 7 // currently failing in dart2js because of bug/19322, so we have this copy |
| 8 // that excludes the causes of failure to get some test coverage in .js. |
| 9 library web_components.interop2_test; |
| 10 |
| 11 import 'dart:html'; |
| 12 import 'dart:async'; |
| 13 import 'dart:js' show context, JsObject; |
| 14 import 'package:unittest/html_config.dart'; |
| 15 import 'package:unittest/unittest.dart'; |
| 16 import 'package:web_components/interop.dart'; |
| 17 |
| 18 main() { |
| 19 useHtmlConfiguration(); |
| 20 registerDartType('x-a', XAWrapper); |
| 21 registerDartType('x-b', XBWrapper, extendsTag: 'div'); |
| 22 registerDartType('x-c', XCWrapper); |
| 23 |
| 24 test('interop is supported', () { |
| 25 expect(isSupported, isTrue); |
| 26 }); |
| 27 |
| 28 test('previously created elements are not upgraded', () { |
| 29 var a = document.querySelector('x-a'); |
| 30 expect(a is HtmlElement, isTrue, reason: 'x-a is HtmlElement'); |
| 31 expect(a is XAWrapper, isFalse, reason: 'x-a should not be upgraded yet'); |
| 32 expect(_readX(a), 0); |
| 33 |
| 34 var c = document.querySelector('x-c'); |
| 35 expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement'); |
| 36 expect(c is XCWrapper, isFalse, reason: 'x-c should not be upgraded yet'); |
| 37 expect(_readX(c), null, reason: 'x-c has not been registered in JS yet'); |
| 38 }); |
| 39 |
| 40 test('events seen for anything created after registering Dart type', () { |
| 41 context.callMethod('addA'); |
| 42 var list = document.querySelectorAll('x-a'); |
| 43 expect(list.length, 2); |
| 44 var a = list[1]; |
| 45 expect(a is HtmlElement, isTrue, reason: 'x-a is HtmlElement'); |
| 46 expect(a is XAWrapper, isTrue, reason: 'x-a is upgraded to XAWrapper'); |
| 47 expect(a.x, 2); |
| 48 expect(a.wrapperCount, 0); |
| 49 }); |
| 50 |
| 51 test('events seen if Dart type is registered before registerElement', () { |
| 52 var c = document.querySelector('x-c'); |
| 53 expect(c is XCWrapper, isFalse); |
| 54 expect(_readX(c), null, reason: 'x-c has not been registered in JS yet'); |
| 55 |
| 56 context.callMethod('registerC'); |
| 57 c = document.querySelector('x-c'); |
| 58 expect(c is XCWrapper, isTrue); |
| 59 expect(c.x, 3); |
| 60 expect(c.wrapperCount, 1); |
| 61 |
| 62 context.callMethod('addC'); |
| 63 var list = document.querySelectorAll('x-c'); |
| 64 expect(list.length, 2); |
| 65 expect(list[0], c); |
| 66 c = list[1]; |
| 67 expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement'); |
| 68 expect(c is XCWrapper, isTrue, reason: 'x-c is upgraded to XCWrapper'); |
| 69 expect(c.x, 4); |
| 70 expect(c.wrapperCount, 2); |
| 71 }); |
| 72 } |
| 73 int _count = 0; |
| 74 |
| 75 abstract class Wrapper { |
| 76 int wrapperCount = _count++; |
| 77 int get x => _readX(this); |
| 78 } |
| 79 |
| 80 _readX(e) => new JsObject.fromBrowserObject(e)['x']; |
| 81 |
| 82 class XAWrapper extends HtmlElement with Wrapper { |
| 83 XAWrapper.created() : super.created(); |
| 84 } |
| 85 |
| 86 class XBWrapper extends DivElement with Wrapper { |
| 87 XBWrapper.created() : super.created(); |
| 88 } |
| 89 |
| 90 class XCWrapper extends HtmlElement with Wrapper { |
| 91 XCWrapper.created() : super.created(); |
| 92 } |
OLD | NEW |