Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / custom / attribute-changed-callback.html
blob195b1ae4e597a320827dba4864a67a48ddb4fd26
1 <!DOCTYPE html>
2 <script src="../../../resources/testharness.js"></script>
3 <script src="../../../resources/testharnessreport.js"></script>
4 <body>
5 <script>
6 test(function () {
7 var attributeChangedInvocations = 0;
8 function attributeChanged(_, _, _) {
9 attributeChangedInvocations++;
12 var getterInvocations = 0;
13 function getter() {
14 getterInvocations++;
15 return attributeChanged;
18 function failer() {
19 assert_unreached('the attribute changed callback must not be retrieved after registration');
22 var proto = Object.create(HTMLElement.prototype, {
23 attributeChangedCallback: {
24 get: getter
26 });
27 var ctor = document.registerElement('x-a', {prototype: proto});
28 assert_equals(getterInvocations, 1, 'the attribute changed callback must have been retrieved');
30 proto.attributeChangedCallback = failer;
31 var element = new ctor();
32 element.setAttribute('a', 'b');
33 assert_equals(attributeChangedInvocations, 1, 'the attribute changed callback retrieved at registration must be invoked');
34 }, 'transfer attribute changed callback');
36 test(function () {
37 var invocations = [];
38 function created() {
39 invocations.push('created');
41 function attributeChanged(name, oldValue, newValue) {
42 invocations.push(name + ': ' + oldValue + ' => ' + newValue);
45 var proto = Object.create(HTMLElement.prototype);
46 proto.createdCallback = created;
47 proto.attributeChangedCallback = attributeChanged;
48 var B = document.registerElement('x-b', {prototype: proto});
50 var b = new B();
51 b.id = 'x';
52 assert_array_equals(invocations, ['created', 'id: null => x'], 'setting a reflected attribute should invoke the attributeChanged callback');
54 invocations = [];
55 b.removeAttribute('id');
56 assert_array_equals(invocations, ['id: x => null'], 'removing an attribute should invoke the attributeChangedCallback');
58 invocations = [];
59 b.setAttribute('data-s', 't');
60 assert_array_equals(invocations, ['data-s: null => t'], 'adding an attribute with setAttribute should invoke the attributeChangedCallback');
62 invocations = [];
63 b.classList.toggle('u');
64 assert_array_equals(invocations, ['class: null => u'], 'adding a class attribute through classList should invoke the attributeChangedCallback');
66 b.setAttribute('data-v', 'w');
67 invocations = [];
68 b.setAttribute('data-v', 'x');
69 assert_array_equals(invocations, ['data-v: w => x'], 'changing an attribute with setAttribute should invoke the attributeChangedCallback');
71 invocations = [];
72 b.setAttribute('data-v', 'x');
73 assert_array_equals(invocations, [], 'setting an attribute to the existing value with setAttribute should not invoke the attributeChangedCallback');
74 }, 'add, change and remove an attribute');
75 </script>