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: third_party/WebKit/LayoutTests/custom-elements/spec/upgrade-element.html

Issue 2303663004: Pass null to attributeChangedCallback when there's no namespace URI (Closed)
Patch Set: Update test. Created 4 years, 3 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
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Custom Elements: upgrade element</title> 2 <title>Custom Elements: upgrade element</title>
3 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#con cept-upgrade-an-element"> 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/scripting.html#con cept-upgrade-an-element">
4 <script src="../../resources/testharness.js"></script> 4 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script> 5 <script src="../../resources/testharnessreport.js"></script>
6 <script src="resources/custom-elements-helpers.js"></script> 6 <script src="resources/custom-elements-helpers.js"></script>
7 <body> 7 <body>
8 <script> 8 <script>
9 9
10 'use strict' 10 'use strict'
11 11
12 // 6. If C non-conformantly uses an API decorated with the [CEReactions] extende d attribute, 12 // 6. If C non-conformantly uses an API decorated with the [CEReactions] extende d attribute,
13 // then the reactions enqueued at the beginning of upgrade will execute during t his step, 13 // then the reactions enqueued at the beginning of upgrade will execute during t his step,
14 // before C finishes and control returns to this algorithm. 14 // before C finishes and control returns to this algorithm.
15 test_with_window((w) => { 15 test_with_window((w) => {
16 let invocations = []; 16 let invocations = [];
17 let changedCallbackArgs = []; 17 let changedCallbackArgs = [];
18 let a = w.document.createElement('a-a'); 18 let a = w.document.createElement('a-a');
19 w.document.body.appendChild(a); 19 w.document.body.appendChild(a);
20 a.setAttribute('x', '1'); 20 a.setAttribute('x', '1');
21 class X extends w.HTMLElement { 21 class X extends w.HTMLElement {
22 constructor() { 22 constructor() {
23 super(); 23 super();
24 this.setAttribute('y', '2'); 24 this.setAttribute('y', '2');
25 invocations.push(['constructor', this]); 25 invocations.push(['constructor', this]);
26 } 26 }
27 connectedCallback() { invocations.push(['connected', this]); } 27 connectedCallback() { invocations.push(['connected', this]); }
28 static get observedAttributes() { return ['x', 'y']; } 28 static get observedAttributes() { return ['x', 'y']; }
29 attributeChangedCallback() { 29 attributeChangedCallback() {
30 invocations.push(['attributeChanged', this]); 30 invocations.push(['attributeChanged', this]);
31 changedCallbackArgs.push(arguments); 31 changedCallbackArgs.push(arguments);
32 } 32 }
33 } 33 }
34 w.customElements.define('a-a', X); 34 w.customElements.define('a-a', X);
35 // Unlike calling new, upgrading element with createElement does not set eleme nt's state 35 // Unlike calling new, upgrading element with createElement does not set eleme nt's state
36 // to "custom" during HTMLConstructor. Thus, appending attribute after super() 36 // to "custom" during HTMLConstructor. Thus, appending attribute after super()
37 // does not enqueue a callback reaction. 37 // does not enqueue a callback reaction.
38 assert_equals(invocations.length, 3); 38 assert_equals(invocations.length, 3);
39 assert_equals(changedCallbackArgs.length, 1, 'attributeChangedCallback should only be invoked once'); 39 assert_equals(changedCallbackArgs.length, 1, 'attributeChangedCallback should only be invoked once');
40 assert_array_equals(invocations[0], ['constructor', a], 'constructor should ex ecute first'); 40 assert_array_equals(invocations[0], ['constructor', a], 'constructor should ex ecute first');
41 assert_array_equals(invocations[1], ['attributeChanged', a], 'attributeChanged Callback should execute after constructor'); 41 assert_array_equals(invocations[1], ['attributeChanged', a], 'attributeChanged Callback should execute after constructor');
42 assert_array_equals(changedCallbackArgs[0], ['x', null, '1', ''], 'attributeCh angedCallback should execute for setAttribute outside of the constructor'); 42 assert_array_equals(changedCallbackArgs[0], ['x', null, '1', null], 'attribute ChangedCallback should execute for setAttribute outside of the constructor');
43 assert_array_equals(invocations[2], ['connected', a], 'connectedCallback shoul d execute after the constrcutor'); 43 assert_array_equals(invocations[2], ['connected', a], 'connectedCallback shoul d execute after the constrcutor');
44 }, 'The constructor non-conformatly uses API decorated with the [CEReactions] wh en constuctor is invoked during upgrade'); 44 }, 'The constructor non-conformatly uses API decorated with the [CEReactions] wh en constuctor is invoked during upgrade');
45 45
46 // Step 6 case when constructor is invoked with new 46 // Step 6 case when constructor is invoked with new
47 test_with_window((w) => { 47 test_with_window((w) => {
48 let invocations = []; 48 let invocations = [];
49 let changedCallbackArgs = []; 49 let changedCallbackArgs = [];
50 class X extends w.HTMLElement { 50 class X extends w.HTMLElement {
51 constructor() { 51 constructor() {
52 super(); 52 super();
53 this.setAttribute('y', '2'); 53 this.setAttribute('y', '2');
54 invocations.push(['constructor', this]); 54 invocations.push(['constructor', this]);
55 } 55 }
56 connectedCallback() { invocations.push(['connected', this]); } 56 connectedCallback() { invocations.push(['connected', this]); }
57 static get observedAttributes() { return ['x', 'y']; } 57 static get observedAttributes() { return ['x', 'y']; }
58 attributeChangedCallback() { 58 attributeChangedCallback() {
59 invocations.push(['attributeChanged', this]); 59 invocations.push(['attributeChanged', this]);
60 changedCallbackArgs.push(arguments); 60 changedCallbackArgs.push(arguments);
61 } 61 }
62 } 62 }
63 w.customElements.define('a-a', X); 63 w.customElements.define('a-a', X);
64 let a = new X(); 64 let a = new X();
65 a.setAttribute('x','1'); 65 a.setAttribute('x','1');
66 assert_equals(invocations.length, 3); 66 assert_equals(invocations.length, 3);
67 assert_equals(changedCallbackArgs.length, 2, 'attributeChangedCallback should be invoked twice'); 67 assert_equals(changedCallbackArgs.length, 2, 'attributeChangedCallback should be invoked twice');
68 assert_array_equals(invocations[0], ['attributeChanged', a], 'attributeChanged Callback for "a" should execute before the constructor is finished'); 68 assert_array_equals(invocations[0], ['attributeChanged', a], 'attributeChanged Callback for "a" should execute before the constructor is finished');
69 assert_array_equals(invocations[1], ['constructor', a], 'constructor executes second'); 69 assert_array_equals(invocations[1], ['constructor', a], 'constructor executes second');
70 assert_array_equals(invocations[2], ['attributeChanged', a], 'setAttribute out side of the constructorshould be invoked'); 70 assert_array_equals(invocations[2], ['attributeChanged', a], 'setAttribute out side of the constructorshould be invoked');
71 assert_array_equals(changedCallbackArgs[0], ['y', null, '2', '']); 71 assert_array_equals(changedCallbackArgs[0], ['y', null, '2', null]);
72 assert_array_equals(changedCallbackArgs[1], ['x', null, '1', '']); 72 assert_array_equals(changedCallbackArgs[1], ['x', null, '1', null]);
73 }, 'The constructor non-conformatly uses API decorated with the [CEReactions] wh en consturctor is invoked with new'); 73 }, 'The constructor non-conformatly uses API decorated with the [CEReactions] wh en constructor is invoked with new');
74 74
75 75
76 // 8. If constructResult is an abrupt completion, then return constructResult 76 // 8. If constructResult is an abrupt completion, then return constructResult
77 // (i.e., rethrow the exception). 77 // (i.e., rethrow the exception).
78 test_with_window((w) => { 78 test_with_window((w) => {
79 let error_log = []; 79 let error_log = [];
80 let doc = w.document; 80 let doc = w.document;
81 doc.body.appendChild(doc.createElement('a-a')); 81 doc.body.appendChild(doc.createElement('a-a'));
82 w.onerror = function (msg, url, lineNo, columnNo, error) { 82 w.onerror = function (msg, url, lineNo, columnNo, error) {
83 error_log.push(error.name); 83 error_log.push(error.name);
84 return true; 84 return true;
85 }; 85 };
86 class X extends w.HTMLElement { 86 class X extends w.HTMLElement {
87 constructor() { 87 constructor() {
88 super(); 88 super();
89 assert_false(this.matches(':defined'), 'calling super() with non-empty con struction stack should not define the element'); 89 assert_false(this.matches(':defined'), 'calling super() with non-empty con struction stack should not define the element');
90 throw { name: 'constructor throws' }; 90 throw { name: 'constructor throws' };
91 } 91 }
92 } 92 }
93 w.customElements.define('a-a', X); 93 w.customElements.define('a-a', X);
94 assert_array_equals(error_log, ['constructor throws'], 'rethrow any exception thrown from constructor'); 94 assert_array_equals(error_log, ['constructor throws'], 'rethrow any exception thrown from constructor');
95 }, 'Upgrading an element with a throwing constructor should rethrow that excepti on'); 95 }, 'Upgrading an element with a throwing constructor should rethrow that excepti on');
96 96
97 // 9. If SameValue(constructResult.[[value]], element) is false, then throw an 97 // 9. If SameValue(constructResult.[[value]], element) is false, then throw an
98 // "InvalidStateError" DOMException and terminate these steps. 98 // "InvalidStateError" DOMException and terminate these steps.
99 test_with_window((w) => { 99 test_with_window((w) => {
100 let error_log = []; 100 let error_log = [];
101 w.onerror = function (msg, url, lineNo, columnNo, error) { 101 w.onerror = function (msg, url, lineNo, columnNo, error) {
102 error_log.push(error.name); 102 error_log.push(error.name);
103 return true; 103 return true;
104 }; 104 };
105 let a = w.document.createElement('a-a'); 105 let a = w.document.createElement('a-a');
106 w.document.body.appendChild(a); 106 w.document.body.appendChild(a);
107 class X extends w.HTMLElement { 107 class X extends w.HTMLElement {
108 constructor() { 108 constructor() {
109 super(); 109 super();
110 return ['aaaa']; 110 return ['aaaa'];
111 } 111 }
112 } 112 }
113 w.customElements.define('a-a', X); 113 w.customElements.define('a-a', X);
114 assert_array_equals(error_log, ['InvalidStateError'], 'returning object that i s different from element should throw "InvalidStateError"'); 114 assert_array_equals(error_log, ['InvalidStateError'], 'returning object that i s different from element should throw "InvalidStateError"');
115 }, 'Upgrading an element with constructor that returns different object'); 115 }, 'Upgrading an element with constructor that returns different object');
116 </script> 116 </script>
117 </body> 117 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698