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 library tests.html.mirrors_test; |
| 6 |
| 7 @MirrorsUsed(targets: const [A, B]) |
| 8 import 'dart:mirrors'; |
| 9 import 'dart:html'; |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'package:unittest/html_config.dart'; |
| 12 import '../utils.dart'; |
| 13 |
| 14 /// Regression test for a tricky mirrors+custom_elements issue: |
| 15 /// dart2js mirrors cache dispatch information on the Object's constructor. |
| 16 /// This was failing for custom elements on IE 10, because the constructor was |
| 17 /// HTMLUnknownElement for all of them. So mirrors called the wrong method. |
| 18 main() { |
| 19 useHtmlConfiguration(); |
| 20 |
| 21 var registered = false; |
| 22 setUp(() => customElementsReady.then((_) { |
| 23 if (!registered) { |
| 24 registered = true; |
| 25 document.registerElement(A.tag, A); |
| 26 document.registerElement(B.tag, B); |
| 27 } |
| 28 })); |
| 29 |
| 30 test('dynamic dispatch', () { |
| 31 var a = new A(); |
| 32 expect(a.fooBar, 1); |
| 33 reflect(a).setField(#fooBar, 123); |
| 34 expect(a.fooBar, 123); |
| 35 |
| 36 // Even though A was set first, B.fooBar= should dispatch to B. |
| 37 var b = new B(); |
| 38 expect(b.fooBar, 2); |
| 39 expect(b._fooBarSet, 0); |
| 40 reflect(b).setField(#fooBar, 123); |
| 41 expect(b.fooBar, 123); |
| 42 expect(b._fooBarSet, 1); |
| 43 }); |
| 44 } |
| 45 |
| 46 class A extends HtmlElement { |
| 47 static final tag = 'x-a'; |
| 48 factory A() => new Element.tag(tag); |
| 49 A.created() : super.created(); |
| 50 |
| 51 int fooBar = 1; |
| 52 } |
| 53 |
| 54 class B extends HtmlElement { |
| 55 static final tag = 'x-b'; |
| 56 factory B() => new Element.tag(tag); |
| 57 B.created() : super.created(); |
| 58 |
| 59 int _fooBar = 2; |
| 60 int _fooBarSet = 0; |
| 61 |
| 62 int get fooBar => _fooBar; |
| 63 set fooBar(value) { |
| 64 _fooBarSet++; |
| 65 _fooBar = value; |
| 66 } |
| 67 } |
OLD | NEW |