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 attribute_changed_callback_test; | 5 library attribute_changed_callback_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:html'; | 8 import 'dart:html'; |
9 import 'dart:js' as js; | 9 import 'dart:js' as js; |
10 import 'package:unittest/html_individual_config.dart'; | 10 import 'package:unittest/html_individual_config.dart'; |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 class B extends HtmlElement { | 26 class B extends HtmlElement { |
27 static final tag = 'x-b'; | 27 static final tag = 'x-b'; |
28 factory B() => new Element.tag(tag); | 28 factory B() => new Element.tag(tag); |
29 B.created() : super.created() { | 29 B.created() : super.created() { |
30 invocations.add('created'); | 30 invocations.add('created'); |
31 } | 31 } |
32 | 32 |
33 static var invocations = []; | 33 static var invocations = []; |
34 | 34 |
| 35 Completer completer; |
| 36 |
35 void attributeChanged(name, oldValue, newValue) { | 37 void attributeChanged(name, oldValue, newValue) { |
36 invocations.add('$name: $oldValue => $newValue'); | 38 invocations.add('$name: $oldValue => $newValue'); |
| 39 if (completer != null) { |
| 40 completer.complete('value changed to $newValue'); |
| 41 completer = null; |
| 42 } |
37 } | 43 } |
38 } | 44 } |
39 | 45 |
40 // Pump custom events polyfill events. | 46 // Pump custom events polyfill events. |
41 void customElementsTakeRecords() { | 47 void customElementsTakeRecords() { |
42 if (js.context.hasProperty('CustomElements')) { | 48 if (js.context.hasProperty('CustomElements')) { |
43 js.context['CustomElements'].callMethod('takeRecords'); | 49 js.context['CustomElements'].callMethod('takeRecords'); |
44 } | 50 } |
45 } | 51 } |
46 | 52 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 expect(B.invocations, []); | 89 expect(B.invocations, []); |
84 | 90 |
85 b.attributes.remove('data-v'); | 91 b.attributes.remove('data-v'); |
86 expect(B.invocations, ['data-v: x => null']); | 92 expect(B.invocations, ['data-v: x => null']); |
87 }); | 93 }); |
88 | 94 |
89 test('add, change ID', () { | 95 test('add, change ID', () { |
90 B.invocations = []; | 96 B.invocations = []; |
91 | 97 |
92 var b = new B(); | 98 var b = new B(); |
| 99 var completer = new Completer(); |
| 100 b.completer = completer; |
93 b.id = 'x'; | 101 b.id = 'x'; |
94 | 102 return completer.future |
95 return new Future.delayed(new Duration(milliseconds: 1)) | |
96 .then((_) => expect(B.invocations, ['created', 'id: null => x'])) | 103 .then((_) => expect(B.invocations, ['created', 'id: null => x'])) |
97 .then((_) { | 104 .then((_) { |
98 B.invocations = []; | 105 B.invocations = []; |
99 b.attributes.remove('id'); | 106 var secondCompleter = new Completer(); |
100 }) | 107 b.completer = secondCompleter; |
101 .then((_) => new Future.delayed(new Duration(milliseconds: 1))) | 108 b.attributes.remove('id'); |
102 .then((_) => expect(B.invocations, ['id: x => null'])); | 109 return secondCompleter.future; |
| 110 }) |
| 111 .then((_) => expect(B.invocations, ['id: x => null'])); |
103 }); | 112 }); |
104 }); | 113 }); |
105 | 114 |
106 group('unsupported_on_polyfill', () { | 115 group('unsupported_on_polyfill', () { |
107 | 116 |
108 // If these tests start passing, don't remove the status suppression. Move | 117 // If these tests start passing, don't remove the status suppression. Move |
109 // the tests to the fullYy_supported group. | 118 // the tests to the fullYy_supported group. |
110 | 119 |
111 test('add, change classes', () { | 120 test('add, change classes', () { |
112 var b = new B(); | 121 var b = new B(); |
113 | 122 |
114 B.invocations = []; | 123 B.invocations = []; |
115 b.classes.toggle('u'); | 124 b.classes.toggle('u'); |
116 expect(B.invocations, ['class: null => u']); | 125 expect(B.invocations, ['class: null => u']); |
117 }); | 126 }); |
118 }); | 127 }); |
119 } | 128 } |
OLD | NEW |