| 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 import 'package:web_components/polyfill.dart'; | |
| 18 | |
| 19 final globalSetup = customElementsReady.then((_) { | |
| 20 registerDartType('x-a', XAWrapper); | |
| 21 registerDartType('x-b', XBWrapper, extendsTag: 'div'); | |
| 22 registerDartType('x-c', XCWrapper); | |
| 23 }); | |
| 24 | |
| 25 main() { | |
| 26 useHtmlConfiguration(); | |
| 27 setUp(() => globalSetup); | |
| 28 | |
| 29 test('interop is supported', () { | |
| 30 expect(isSupported, isTrue); | |
| 31 }); | |
| 32 | |
| 33 test('previously created elements are not upgraded', () { | |
| 34 var a = document.querySelector('x-a'); | |
| 35 expect(a is HtmlElement, isTrue, reason: 'x-a is HtmlElement'); | |
| 36 expect(a is XAWrapper, isFalse, reason: 'x-a should not be upgraded yet'); | |
| 37 expect(_readX(a), 0); | |
| 38 | |
| 39 var c = document.querySelector('x-c'); | |
| 40 expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement'); | |
| 41 expect(c is XCWrapper, isFalse, reason: 'x-c should not be upgraded yet'); | |
| 42 expect(_readX(c), null, reason: 'x-c has not been registered in JS yet'); | |
| 43 }); | |
| 44 | |
| 45 test('events seen for anything created after registering Dart type', () { | |
| 46 context.callMethod('addA'); | |
| 47 var list = document.querySelectorAll('x-a'); | |
| 48 expect(list.length, 2); | |
| 49 var a = list[1]; | |
| 50 expect(a is HtmlElement, isTrue, reason: 'x-a is HtmlElement'); | |
| 51 expect(a is XAWrapper, isTrue, reason: 'x-a is upgraded to XAWrapper'); | |
| 52 expect(a.x, 2); | |
| 53 expect(a.wrapperCount, 0); | |
| 54 }); | |
| 55 | |
| 56 test('events seen if Dart type is registered before registerElement', () { | |
| 57 var c = document.querySelector('x-c'); | |
| 58 expect(c is XCWrapper, isFalse); | |
| 59 expect(_readX(c), null, reason: 'x-c has not been registered in JS yet'); | |
| 60 | |
| 61 context.callMethod('registerC'); | |
| 62 c = document.querySelector('x-c'); | |
| 63 expect(c is XCWrapper, isTrue); | |
| 64 expect(c.x, 3); | |
| 65 expect(c.wrapperCount, 1); | |
| 66 | |
| 67 context.callMethod('addC'); | |
| 68 var list = document.querySelectorAll('x-c'); | |
| 69 expect(list.length, 2); | |
| 70 expect(list[0], c); | |
| 71 c = list[1]; | |
| 72 expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement'); | |
| 73 expect(c is XCWrapper, isTrue, reason: 'x-c is upgraded to XCWrapper'); | |
| 74 expect(c.x, 4); | |
| 75 expect(c.wrapperCount, 2); | |
| 76 }); | |
| 77 } | |
| 78 int _count = 0; | |
| 79 | |
| 80 abstract class Wrapper { | |
| 81 int wrapperCount = _count++; | |
| 82 int get x => _readX(this); | |
| 83 } | |
| 84 | |
| 85 _readX(e) => new JsObject.fromBrowserObject(e)['x']; | |
| 86 | |
| 87 class XAWrapper extends HtmlElement with Wrapper { | |
| 88 XAWrapper.created() : super.created(); | |
| 89 } | |
| 90 | |
| 91 class XBWrapper extends DivElement with Wrapper { | |
| 92 XBWrapper.created() : super.created(); | |
| 93 } | |
| 94 | |
| 95 class XCWrapper extends HtmlElement with Wrapper { | |
| 96 XCWrapper.created() : super.created(); | |
| 97 } | |
| OLD | NEW |