2 <script src=
"../../../resources/testharness.js"></script>
3 <script src=
"../../../resources/testharnessreport.js"></script>
7 var attributeChangedInvocations
= 0;
8 function attributeChanged(_
, _
, _
) {
9 attributeChangedInvocations
++;
12 var getterInvocations
= 0;
15 return attributeChanged
;
19 assert_unreached('the attribute changed callback must not be retrieved after registration');
22 var proto
= Object
.create(HTMLElement
.prototype, {
23 attributeChangedCallback
: {
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');
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
});
52 assert_array_equals(invocations
, ['created', 'id: null => x'], 'setting a reflected attribute should invoke the attributeChanged callback');
55 b
.removeAttribute('id');
56 assert_array_equals(invocations
, ['id: x => null'], 'removing an attribute should invoke the attributeChangedCallback');
59 b
.setAttribute('data-s', 't');
60 assert_array_equals(invocations
, ['data-s: null => t'], 'adding an attribute with setAttribute should invoke the attributeChangedCallback');
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');
68 b
.setAttribute('data-v', 'x');
69 assert_array_equals(invocations
, ['data-v: w => x'], 'changing an attribute with setAttribute should invoke the attributeChangedCallback');
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');