Chromium Code Reviews| Index: tests/html/custom_element_attribute_changed_test.dart |
| diff --git a/tests/html/custom_element_attribute_changed_test.dart b/tests/html/custom_element_attribute_changed_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..94901c5599c3ed9752536e5e493844e415280396 |
| --- /dev/null |
| +++ b/tests/html/custom_element_attribute_changed_test.dart |
| @@ -0,0 +1,77 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library custom_element_attribute_changed_test; |
| +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.
|
| +import '../../pkg/unittest/lib/html_individual_config.dart'; |
| +import 'dart:html'; |
| + |
| +class CustomA extends HtmlElement { |
|
Siggi Cherem (dart-lang)
2013/08/16 23:02:19
so so so awesome!
|
| + static final tag = 'x-a'; |
| + factory CustomA() => new Element.tag(tag); |
| + |
| + static var attributeChangedInvocations = 0; |
| + |
| + void onAttributeChanged(name, oldValue, newValue) { |
| + attributeChangedInvocations++; |
| + } |
| +} |
| + |
| +class CustomB extends HtmlElement { |
| + static final tag = 'x-b'; |
| + factory CustomB() => new Element.tag(tag); |
| + |
| + static var invocations = []; |
| + |
| + void onCreated() { |
| + invocations.add('created'); |
| + } |
| + |
| + void onAttributeChanged(name, oldValue, newValue) { |
| + invocations.add('$name: $oldValue => $newValue'); |
| + } |
| +} |
| + |
| +main() { |
| + useHtmlIndividualConfiguration(); |
| + |
| + // Adapted from Blink's fast/dom/custom/attribute-changed-callback test. |
| + group('callback', () { |
| + test('transfer attribute changed callback', () { |
| + document.register(CustomA.tag, CustomA); |
| + var element = new CustomA(); |
| + |
| + element.attributes['a'] = 'b'; |
| + expect(CustomA.attributeChangedInvocations, 1); |
| + }); |
| + |
| + test('add, change and remove an attribute', () { |
| + document.register(CustomB.tag, CustomB); |
| + var b = new CustomB(); |
| + b.id = 'x'; |
| + expect(CustomB.invocations, ['created', 'id: null => x']); |
| + |
| + CustomB.invocations = []; |
| + b.attributes.remove('id'); |
| + expect(CustomB.invocations, ['id: x => null']); |
| + |
| + CustomB.invocations = []; |
| + b.attributes['data-s'] = 't'; |
| + expect(CustomB.invocations, ['data-s: null => t']); |
| + |
| + CustomB.invocations = []; |
| + b.classList.toggle('u'); |
| + expect(CustomB.invocations, ['class: null => u']); |
| + |
| + b.attributes['data-v'] = 'w'; |
| + CustomB.invocations = []; |
| + b.attributes['data-v'] = 'x'; |
| + expect(CustomB.invocations, ['data-v: w => x']); |
| + |
| + CustomB.invocations = []; |
| + b.attributes['data-v'] = 'x'; |
| + expect(CustomB.invocations, []); |
| + }); |
| + }); |
| +} |