Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: LayoutTests/fast/dom/custom/attribute-changed-callback.html

Issue 18789002: Implement Custom Elements' attributeChangedCallback. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | LayoutTests/fast/dom/custom/attribute-changed-callback-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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(_, _, _) {
dglazkov 2013/07/06 01:57:45 cute!
9 attributeChangedInvocations++;
10 }
11
12 var getterInvocations = 0;
13 function getter() {
14 getterInvocations++;
15 return attributeChanged;
16 }
17
18 function failer() {
19 assert_unreached('the attribute changed callback must not be retrieved a fter registration');
20 }
21
22 var proto = Object.create(HTMLElement.prototype, {
23 attributeChangedCallback: {
24 get: getter
25 }
26 });
27 var ctor = document.register('x-a', {prototype: proto});
28 assert_equals(getterInvocations, 1, 'the attribute changed callback must hav e been retrieved');
29
30 proto.attributeChangedCallback = failer;
31 var element = new ctor();
32 element.setAttribute('a', 'b');
33 assert_equals(attributeChangedInvocations, 1, 'the attribute changed callbac k retrieved at registration must be invoked');
34 }, 'transfer attribute changed callback');
35
36 test(function () {
37 var invocations = [];
38 function created() {
39 invocations.push('created');
40 }
41 function attributeChanged(name, oldValue, newValue) {
42 invocations.push(name + ': ' + oldValue + ' => ' + newValue);
43 }
44
45 var proto = Object.create(HTMLElement.prototype);
46 proto.createdCallback = created;
47 proto.attributeChangedCallback = attributeChanged;
48 var B = document.register('x-b', {prototype: proto});
49
50 var b = new B();
51 b.id = 'x';
52 assert_array_equals(invocations, ['created', 'id: null => x'], 'setting a re flected attribute should invoke the attributeChanged callback');
53
54 invocations = [];
55 b.removeAttribute('id');
56 assert_array_equals(invocations, ['id: x => null'], 'removing an attribute s hould invoke the attributeChangedCallback');
57
58 invocations = [];
59 b.setAttribute('data-x', 'y');
60 assert_array_equals(invocations, ['data-x: null => y'], 'setAttribute should invoke the attributeChangedCallback');
61
62 invocations = [];
63 b.classList.toggle('z');
64 assert_array_equals(invocations, ['class: null => z'], 'changing the class a ttribute through classList should invoke the attributeChangedCallback');
65 }, 'add, change and remove an attribute');
66 </script>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/fast/dom/custom/attribute-changed-callback-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698