| 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 attribute_changed_callback_test; |
| 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:unittest/html_config.dart'; |
| 8 import 'dart:html'; |
| 9 |
| 10 class A extends HtmlElement { |
| 11 static final tag = 'x-a'; |
| 12 factory A() => new Element.tag(tag); |
| 13 |
| 14 static var attributeChangedInvocations = 0; |
| 15 |
| 16 void onAttributeChanged(name, oldValue, newValue) { |
| 17 attributeChangedInvocations++; |
| 18 } |
| 19 } |
| 20 |
| 21 class B extends HtmlElement { |
| 22 static final tag = 'x-b'; |
| 23 factory B() => new Element.tag(tag); |
| 24 |
| 25 static var invocations = []; |
| 26 |
| 27 void onCreated() { |
| 28 invocations.add('created'); |
| 29 } |
| 30 |
| 31 void onAttributeChanged(name, oldValue, newValue) { |
| 32 invocations.add('$name: $oldValue => $newValue'); |
| 33 } |
| 34 } |
| 35 |
| 36 main() { |
| 37 useHtmlConfiguration(); |
| 38 |
| 39 // Adapted from Blink's fast/dom/custom/attribute-changed-callback test. |
| 40 |
| 41 test('transfer attribute changed callback', () { |
| 42 document.register(A.tag, A); |
| 43 var element = new A(); |
| 44 |
| 45 element.attributes['a'] = 'b'; |
| 46 expect(A.attributeChangedInvocations, 1); |
| 47 }); |
| 48 |
| 49 test('add, change and remove an attribute', () { |
| 50 document.register(B.tag, B); |
| 51 var b = new B(); |
| 52 b.id = 'x'; |
| 53 expect(B.invocations, ['created', 'id: null => x']); |
| 54 |
| 55 B.invocations = []; |
| 56 b.attributes.remove('id'); |
| 57 expect(B.invocations, ['id: x => null']); |
| 58 |
| 59 B.invocations = []; |
| 60 b.attributes['data-s'] = 't'; |
| 61 expect(B.invocations, ['data-s: null => t']); |
| 62 |
| 63 B.invocations = []; |
| 64 b.classList.toggle('u'); |
| 65 expect(B.invocations, ['class: null => u']); |
| 66 |
| 67 b.attributes['data-v'] = 'w'; |
| 68 B.invocations = []; |
| 69 b.attributes['data-v'] = 'x'; |
| 70 expect(B.invocations, ['data-v: w => x']); |
| 71 |
| 72 B.invocations = []; |
| 73 b.attributes['data-v'] = 'x'; |
| 74 expect(B.invocations, []); |
| 75 }); |
| 76 } |
| OLD | NEW |