OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Custom Elements: Create an element when definition is non-null and synchr onous flag set</title> | 2 <title>Custom Elements: Create an element when definition is non-null and synchr onous flag set</title> |
3 <script src="../../resources/testharness.js"></script> | 3 <script src="../../resources/testharness.js"></script> |
4 <script src="../../resources/testharnessreport.js"></script> | 4 <script src="../../resources/testharnessreport.js"></script> |
5 <script src="resources/custom-elements-helpers.js"></script> | 5 <script src="resources/custom-elements-helpers.js"></script> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 'use strict'; | 8 'use strict'; |
9 | 9 |
10 const expectTypeError = TypeError.prototype; | 10 const expectTypeError = TypeError.prototype; |
11 const expectNotSupportedError = 'NOT_SUPPORTED_ERR'; | 11 const expectNotSupportedError = 'NOT_SUPPORTED_ERR'; |
12 | 12 |
13 // https://dom.spec.whatwg.org/#concept-create-element | 13 // https://dom.spec.whatwg.org/#concept-create-element |
14 // 5. If definition is non-null and the definition represents a customized built -in element: | |
15 // 5.3. If the synchronous custom elements flag is set: | |
14 // 6. If definition is non-null, then: | 16 // 6. If definition is non-null, then: |
15 // 6.1. If the synchronous custom elements flag is set: | 17 // 6.1. If the synchronous custom elements flag is set: |
16 | 18 |
17 test_create_element_synchronous( | 19 test_create_element_synchronous( |
18 'createElement(): ', | 20 'createElement(): ', |
19 (w, constructor, options) => { | 21 (w, constructor, type) => { |
dominicc (has gone to gerrit)
2016/11/10 03:43:09
Maybe name this opt_type indicating it is optional
| |
20 w.customElements.define('a-a', constructor, options); | 22 if (!type) { |
21 return w.document.createElement('a-a'); | 23 w.customElements.define('a-a', constructor); |
dominicc (has gone to gerrit)
2016/11/10 03:43:09
a-a appears four times here now; might be time to
| |
24 return w.document.createElement('a-a'); | |
25 } else { | |
26 let extend_options = { extends: type }; | |
27 w.customElements.define('a-a', constructor, extend_options); | |
28 return w.document.createElement(type, { is: 'a-a' }); | |
29 } | |
22 }); | 30 }); |
23 | 31 |
24 test_create_element_synchronous( | 32 test_create_element_synchronous( |
25 'createElementNS(): ', | 33 'createElementNS(): ', |
26 (w, constructor, options) => { | 34 (w, constructor, type) => { |
27 w.customElements.define('a-a', constructor, options); | 35 if (!type) { |
28 return w.document.createElementNS('http://www.w3.org/1999/xhtml', 'a-a'); | 36 w.customElements.define('a-a', constructor); |
37 return w.document.createElementNS('http://www.w3.org/1999/xhtml', 'a-a'); | |
38 } else { | |
39 let extend_options = { extends: type }; | |
40 w.customElements.define('a-a', constructor, extend_options); | |
41 return w.document.createElementNS('http://www.w3.org/1999/xhtml', type, { is: 'a-a' }); | |
42 } | |
29 }); | 43 }); |
30 | 44 |
31 function test_create_element_synchronous(description, define_and_create_element) { | 45 function test_create_element_synchronous(description, define_and_create_element) { |
32 test_with_window((w) => { | 46 test_with_window((w) => { |
33 let is_constructed = false; | 47 let is_constructed = false; |
34 define_and_create_element(w, class extends w.HTMLElement { | 48 class A extends w.HTMLElement { |
35 constructor() { super(); is_constructed = true; } | 49 constructor() { super(); is_constructed = true; } |
36 }); | 50 } |
51 let o = define_and_create_element(w, A); | |
37 assert_true(is_constructed, 'custom constructor ran'); | 52 assert_true(is_constructed, 'custom constructor ran'); |
53 assert_equals(o.constructor, A); | |
38 }, `${description}Pre-flight check should succeed`); | 54 }, `${description}Pre-flight check should succeed`); |
39 | 55 |
40 test_with_window((w) => { | 56 test_with_window((w) => { |
57 let is_constructed = false; | |
58 class A extends w.HTMLDivElement { | |
59 constructor() { super(); is_constructed = true; } | |
60 } | |
61 let o = define_and_create_element(w, A, 'div'); | |
62 assert_true(is_constructed, 'custom constructor ran'); | |
63 assert_equals(o.constructor, A); | |
64 }, `${description}5. Create a customized built-in element`); | |
65 | |
66 test_with_window((w) => { | |
67 let is_constructed = false; | |
68 class A extends w.HTMLElement { | |
69 constructor() { super(); is_constructed = true; } | |
70 } | |
71 define_and_create_element(w, A); | |
72 assert_true(is_constructed, 'custom constructor ran'); | |
73 }, `${description}6. Create an autonomous custom element`); | |
74 | |
75 test_with_window((w) => { | |
41 const err = new Error('check this is reported'); | 76 const err = new Error('check this is reported'); |
42 err.name = 'reported'; | 77 err.name = 'reported'; |
43 assert_reports(w, err, () => { | 78 assert_reports(w, err, () => { |
44 define_and_create_element(w, class extends w.HTMLElement { | 79 define_and_create_element(w, class extends w.HTMLElement { |
45 constructor() { super(); throw err; } | 80 constructor() { super(); throw err; } |
46 }); | 81 }); |
47 }); | 82 }); |
48 }, `${description}6.1.2. Errors in Construct(C) should be reported`); | 83 }, `${description}6.1.2. Errors in Construct(C) should be reported`); |
49 | 84 |
50 test_with_window((w) => { | 85 test_with_window((w) => { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 test_with_window((w) => { | 143 test_with_window((w) => { |
109 assert_reports(w, expectNotSupportedError, () => { | 144 assert_reports(w, expectNotSupportedError, () => { |
110 define_and_create_element(w, class extends w.HTMLElement { | 145 define_and_create_element(w, class extends w.HTMLElement { |
111 constructor() { super(); return document.createElement('div'); } | 146 constructor() { super(); return document.createElement('div'); } |
112 }); | 147 }); |
113 }); | 148 }); |
114 }, `${description}6.1.9. If result\'s local name is not equal to localName, th en throw a NotSupportedError`); | 149 }, `${description}6.1.9. If result\'s local name is not equal to localName, th en throw a NotSupportedError`); |
115 } | 150 } |
116 </script> | 151 </script> |
117 </body> | 152 </body> |
OLD | NEW |