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

Side by Side Diff: third_party/WebKit/LayoutTests/custom-elements/spec/upgrade-element.html

Issue 2129843002: CustomElements: upgrade an element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | 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 <title>Custom Elements: upgrade element</title>
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>
5 <script src="../../resources/testharnessreport.js"></script>
6 <script src="resources/custom-elements-helpers.js"></script>
7 <body>
8 <script>
9
10 'use strict'
11 // 6. "attributeChangedCallback" and "connectedCallback" should execute after C and
12 // the rest of the upgrade process finishes.
13 test_with_window((w) => {
14 let invocations = [];
15 let changedCallbackArgs;
16 let a = w.document.createElement('a-a');
17 w.document.body.appendChild(a);
18 a.setAttribute('x', '1');
19 class X extends w.HTMLElement {
20 constructor() {
21 super();
22 invocations.push(['constructor', this]);
23 }
24 connectedCallback() { invocations.push(['connected', this]); }
25 static get observedAttributes() { return ['x']; }
26 attributeChangedCallback() {
27 invocations.push(['attributeChanged', this]);
28 changedCallbackArgs = arguments;
29 }
30 }
31 w.customElements.define('a-a', X);
32 assert_array_equals(invocations[0], ['constructor', a], 'constructor should ex ecute first');
33 assert_array_equals(invocations[1], ['attributeChanged', a], 'attributeChanged Callback should execute after the constructor');
34 assert_array_equals(changedCallbackArgs, ['x', null, '1', '']);
35 assert_array_equals(invocations[2], ['connected', a], 'connectedCallback shoul d execute after the constructor');
dominicc (has gone to gerrit) 2016/07/13 07:06:17 This is great. Maybe add something that checks the
36 }, '"connectedCallback", "attributeChangedCallback" reactions should execute aft er the constructor');
37
38 // 6. If C non-conformantly uses an API decorated with the [CEReactions] extende d attribute,
39 // then the reactions enqueued at the beginning of upgrade will execute during t his step,
40 // before C finishes and control returns to this algorithm.
41 test_with_window((w) => {
42 let invocations = [];
43 let changedCallbackArgs;
44 let a = w.document.createElement('a-a');
45 w.document.body.appendChild(a);
46 class X extends w.HTMLElement {
47 constructor() {
48 super();
49 this.setAttribute('x', '1');
50 invocations.push(['constructor', this]);
51 }
52 connectedCallback() { invocations.push(['connected', this]); }
53 static get observedAttributes() { return ['x']; }
54 attributeChangedCallback() {
55 invocations.push(['attributeChanged', this]);
56 changedCallbackArgs = arguments;
57 }
58 }
59 w.customElements.define('a-a', X);
60 assert_array_equals(invocations[0], ['connected', a], 'connectedCallback execu tes before the constructor');
61 assert_array_equals(invocations[1], ['attributeChanged', a], 'attributeChanged Callback executes before the constructor');
62 assert_array_equals(changedCallbackArgs, ['x', null, '1', '']);
63 assert_array_equals(invocations[2], ['constructor', a], 'constructor executes last');
64 }, 'The constructor non-conformatly uses API decorated with the [CEReactions]');
65
66 // 8. If constructResult is an abrupt completion, then return constructResult
67 // (i.e., rethrow the exception).
68 test_with_window((w) => {
69 let error_log = [];
70 let a = w.document.createElement('a-a');
dominicc (has gone to gerrit) 2016/07/13 07:06:17 If you don't need a, maybe simplify this and the a
71 w.document.body.appendChild(a);
72 w.onerror = function (msg, url, lineNo, columnNo, error) {
73 error_log.push(error);
74 return true;
75 };
76 class X extends w.HTMLElement {
77 constructor() { throw 'constructor throws'; }
78 }
79 w.customElements.define('a-a', X);
80 assert_array_equals(error_log, ['constructor throws'], 'rethrow any exception thrown from constructor');
81 }, 'Upgrading an element with a throwing constructor should rethrow that excepti on');
82
83 // TODO(davaajav): add a failure expectation to this file
84 // 9. If SameValue(constructResult.[[value]], element) is false, then throw an
85 // "InvalidStateError" DOMException and terminate these steps.
86 test_with_window((w) => {
87 let a = w.document.createElement('a-a');
88 w.document.body.appendChild(a);
89 class X extends w.HTMLElement {
90 constructor() {
91 super();
92 return ['aaaa'];
93 }
94 }
95 assert_throws('InvalidStateError', () => {
96 w.customElements.define('a-a', X);
97 }, 'Using JavaScript return-override should throw "InvalidStateError"DOMExcept ion');
dominicc (has gone to gerrit) 2016/07/13 07:06:17 space after "
98 }, 'Upgrading an element with invalid constructor');
99
100 // 10. Set element's custom element state to "custom".
dominicc (has gone to gerrit) 2016/07/13 07:06:17 Could you file that bug and delete this FIXME? Sen
101 // TODO(davaajav): file spec bug. Step 10 is redundant.
102 </script>
103 </body>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698