Chromium Code Reviews| 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 custom_element_attribute_changed_test; | |
| 6 import '../../pkg/unittest/lib/unittest.dart'; | |
|
blois
2013/08/16 23:37:48
we should use package: imports for new tests.
vsm
2013/08/19 17:00:10
Done.
| |
| 7 import '../../pkg/unittest/lib/html_individual_config.dart'; | |
| 8 import 'dart:html'; | |
| 9 | |
| 10 class CustomA extends HtmlElement { | |
|
Siggi Cherem (dart-lang)
2013/08/16 23:02:19
so so so awesome!
| |
| 11 static final tag = 'x-a'; | |
| 12 factory CustomA() => new Element.tag(tag); | |
| 13 | |
| 14 static var attributeChangedInvocations = 0; | |
| 15 | |
| 16 void onAttributeChanged(name, oldValue, newValue) { | |
| 17 attributeChangedInvocations++; | |
| 18 } | |
| 19 } | |
| 20 | |
| 21 class CustomB extends HtmlElement { | |
| 22 static final tag = 'x-b'; | |
| 23 factory CustomB() => 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 useHtmlIndividualConfiguration(); | |
| 38 | |
| 39 // Adapted from Blink's fast/dom/custom/attribute-changed-callback test. | |
| 40 group('callback', () { | |
| 41 test('transfer attribute changed callback', () { | |
| 42 document.register(CustomA.tag, CustomA); | |
| 43 var element = new CustomA(); | |
| 44 | |
| 45 element.attributes['a'] = 'b'; | |
| 46 expect(CustomA.attributeChangedInvocations, 1); | |
| 47 }); | |
| 48 | |
| 49 test('add, change and remove an attribute', () { | |
| 50 document.register(CustomB.tag, CustomB); | |
| 51 var b = new CustomB(); | |
| 52 b.id = 'x'; | |
| 53 expect(CustomB.invocations, ['created', 'id: null => x']); | |
| 54 | |
| 55 CustomB.invocations = []; | |
| 56 b.attributes.remove('id'); | |
| 57 expect(CustomB.invocations, ['id: x => null']); | |
| 58 | |
| 59 CustomB.invocations = []; | |
| 60 b.attributes['data-s'] = 't'; | |
| 61 expect(CustomB.invocations, ['data-s: null => t']); | |
| 62 | |
| 63 CustomB.invocations = []; | |
| 64 b.classList.toggle('u'); | |
| 65 expect(CustomB.invocations, ['class: null => u']); | |
| 66 | |
| 67 b.attributes['data-v'] = 'w'; | |
| 68 CustomB.invocations = []; | |
| 69 b.attributes['data-v'] = 'x'; | |
| 70 expect(CustomB.invocations, ['data-v: w => x']); | |
| 71 | |
| 72 CustomB.invocations = []; | |
| 73 b.attributes['data-v'] = 'x'; | |
| 74 expect(CustomB.invocations, []); | |
| 75 }); | |
| 76 }); | |
| 77 } | |
| OLD | NEW |