| 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 template_wrappers_test; | 5 library template_wrappers_test; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:js' show context, JsObject; | 9 import 'dart:js' show context, JsObject; |
| 10 import 'package:unittest/html_config.dart'; | 10 import 'package:unittest/html_config.dart'; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 context.callMethod('addC'); | 113 context.callMethod('addC'); |
| 114 var list = document.querySelectorAll('x-c'); | 114 var list = document.querySelectorAll('x-c'); |
| 115 expect(list.length, 2); | 115 expect(list.length, 2); |
| 116 expect(list[0], c); | 116 expect(list[0], c); |
| 117 c = list[1]; | 117 c = list[1]; |
| 118 expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement'); | 118 expect(c is HtmlElement, isTrue, reason: 'x-c is HtmlElement'); |
| 119 expect(c is XCWrapper, isTrue, reason: 'x-c is upgraded to XCWrapper'); | 119 expect(c is XCWrapper, isTrue, reason: 'x-c is upgraded to XCWrapper'); |
| 120 expect(c.x, 7); | 120 expect(c.x, 7); |
| 121 expect(c.wrapperCount, 6); | 121 expect(c.wrapperCount, 6); |
| 122 }); | 122 }); |
| 123 |
| 124 test('element can extend another element', () { |
| 125 registerDartType('x-e', XEWrapper); |
| 126 context.callMethod('addE'); |
| 127 |
| 128 var e = document.querySelector('x-e'); |
| 129 expect(e is XEWrapper, isTrue); |
| 130 expect(e.x, 8); |
| 131 expect(e.y, 9); |
| 132 }); |
| 123 } | 133 } |
| 124 int _count = 0; | 134 int _count = 0; |
| 125 | 135 |
| 126 abstract class Wrapper { | 136 abstract class Wrapper { |
| 127 int wrapperCount = _count++; | 137 int wrapperCount = _count++; |
| 128 int get x => _readX(this); | 138 int get x => _readX(this); |
| 129 } | 139 } |
| 130 | 140 |
| 131 _readX(e) => new JsObject.fromBrowserObject(e)['x']; | 141 _readX(e) => new JsObject.fromBrowserObject(e)['x']; |
| 132 | 142 |
| 133 class XAWrapper extends HtmlElement with Wrapper { | 143 class XAWrapper extends HtmlElement with Wrapper { |
| 134 XAWrapper.created() : super.created(); | 144 XAWrapper.created() : super.created(); |
| 135 } | 145 } |
| 136 | 146 |
| 137 class XBWrapper extends DivElement with Wrapper { | 147 class XBWrapper extends DivElement with Wrapper { |
| 138 XBWrapper.created() : super.created(); | 148 XBWrapper.created() : super.created(); |
| 139 } | 149 } |
| 140 | 150 |
| 141 class XCWrapper extends HtmlElement with Wrapper { | 151 class XCWrapper extends HtmlElement with Wrapper { |
| 142 XCWrapper.created() : super.created(); | 152 XCWrapper.created() : super.created(); |
| 143 } | 153 } |
| 144 | 154 |
| 145 class XDWrapper extends HtmlElement with Wrapper { | 155 class XDWrapper extends HtmlElement with Wrapper { |
| 146 XDWrapper.created() : super.created(); | 156 XDWrapper.created() : super.created(); |
| 147 } | 157 } |
| 158 |
| 159 class XEWrapper extends HtmlElement with Wrapper { |
| 160 XEWrapper.created() : super.created(); |
| 161 |
| 162 int get y => new JsObject.fromBrowserObject(this)['y']; |
| 163 } |
| OLD | NEW |