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 function assert_rethrown(func, description) { | |
11 assert_throws({ name: 'rethrown' }, () => { | |
12 const err = new Error('check this is rethrown'); | |
13 err.name = 'rethrown'; | |
14 func(err); | |
15 }, description); | |
16 } | |
17 | |
18 const expectTypeError = TypeError.prototype; | 10 const expectTypeError = TypeError.prototype; |
19 const expectNotSupportedError = 'NOT_SUPPORTED_ERR'; | 11 const expectNotSupportedError = 'NOT_SUPPORTED_ERR'; |
20 | 12 |
21 // https://dom.spec.whatwg.org/#concept-create-element | 13 // https://dom.spec.whatwg.org/#concept-create-element |
22 // 6. If definition is non-null, then: | 14 // 6. If definition is non-null, then: |
23 // 6.1. If the synchronous custom elements flag is set: | 15 // 6.1. If the synchronous custom elements flag is set: |
24 | 16 |
25 test_create_element_synchronous( | 17 test_create_element_synchronous( |
26 'createElement(): ', | 18 'createElement(): ', |
27 (w, constructor, options) => { | 19 (w, constructor, options) => { |
(...skipping 11 matching lines...) Expand all Loading... |
39 function test_create_element_synchronous(description, define_and_create_element)
{ | 31 function test_create_element_synchronous(description, define_and_create_element)
{ |
40 test_with_window((w) => { | 32 test_with_window((w) => { |
41 let is_constructed = false; | 33 let is_constructed = false; |
42 define_and_create_element(w, class extends w.HTMLElement { | 34 define_and_create_element(w, class extends w.HTMLElement { |
43 constructor() { super(); is_constructed = true; } | 35 constructor() { super(); is_constructed = true; } |
44 }); | 36 }); |
45 assert_true(is_constructed, 'custom constructor ran'); | 37 assert_true(is_constructed, 'custom constructor ran'); |
46 }, `${description}Pre-flight check should succeed`); | 38 }, `${description}Pre-flight check should succeed`); |
47 | 39 |
48 test_with_window((w) => { | 40 test_with_window((w) => { |
49 assert_rethrown(err => { | 41 const err = new Error('check this is reported'); |
| 42 err.name = 'reported'; |
| 43 assert_reports(w, err, () => { |
50 define_and_create_element(w, class extends w.HTMLElement { | 44 define_and_create_element(w, class extends w.HTMLElement { |
51 constructor() { super(); throw err; } | 45 constructor() { super(); throw err; } |
52 }); | 46 }); |
53 }); | 47 }); |
54 }, `${description}6.1.2. Errors in Construct(C) should be rethrown`); | 48 }, `${description}6.1.2. Errors in Construct(C) should be reported`); |
55 | 49 |
56 test_with_window((w) => { | 50 test_with_window((w) => { |
57 assert_throws(expectTypeError, () => { | 51 assert_reports(w, expectTypeError, () => { |
58 define_and_create_element(w, class { | 52 define_and_create_element(w, class { |
59 constructor() {} | 53 constructor() {} |
60 }); | 54 }); |
61 }); | 55 }); |
62 }, `${description}6.1.3. If result does not implement the HTMLElement interfac
e, throw a TypeError`); | 56 }, `${description}6.1.3. If result does not implement the HTMLElement interfac
e, throw a TypeError`); |
63 | 57 |
64 test_with_window((w) => { | 58 test_with_window((w) => { |
65 assert_throws(expectNotSupportedError, () => { | 59 assert_reports(w, expectNotSupportedError, () => { |
66 define_and_create_element(w, class extends w.HTMLElement { | 60 define_and_create_element(w, class extends w.HTMLElement { |
67 constructor() { super(); this.setAttribute('a', 'a'); } | 61 constructor() { super(); this.setAttribute('a', 'a'); } |
68 }); | 62 }); |
69 }); | 63 }); |
70 }, `${description}6.1.4. If result\'s attribute list is not empty, then throw
a NotSupportedError`); | 64 }, `${description}6.1.4. If result\'s attribute list is not empty, then throw
a NotSupportedError`); |
71 | 65 |
72 test_with_window((w) => { | 66 test_with_window((w) => { |
73 assert_throws(expectNotSupportedError, () => { | 67 assert_reports(w, expectNotSupportedError, () => { |
74 define_and_create_element(w, class extends w.HTMLElement { | 68 define_and_create_element(w, class extends w.HTMLElement { |
75 constructor() { super(); this.appendChild(w.document.createElement('a'))
; } | 69 constructor() { super(); this.appendChild(w.document.createElement('a'))
; } |
76 }); | 70 }); |
77 }, 'should throw if it has a child element'); | 71 }, 'should throw if it has a child element'); |
78 assert_throws(expectNotSupportedError, () => { | 72 }, `${description}6.1.5. If result has children, then throw a NotSupportedErro
r`); |
| 73 |
| 74 test_with_window((w) => { |
| 75 assert_reports(w, expectNotSupportedError, () => { |
79 define_and_create_element(w, class extends w.HTMLElement { | 76 define_and_create_element(w, class extends w.HTMLElement { |
80 constructor() { super(); this.appendChild(w.document.createTextNode('a')
); } | 77 constructor() { super(); this.append('a'); } |
81 }); | 78 }); |
82 }, 'should throw if it has a child text node'); | 79 }, 'should throw if it has a child text node'); |
83 }, `${description}6.1.5. If result has children, then throw a NotSupportedErro
r`); | 80 }, `${description}6.1.5. If result has children, then throw a NotSupportedErro
r`); |
84 | 81 |
85 test_with_window((w) => { | 82 test_with_window((w) => { |
86 assert_throws(expectNotSupportedError, () => { | 83 assert_reports(w, expectNotSupportedError, () => { |
87 define_and_create_element(w, class extends w.HTMLElement { | 84 define_and_create_element(w, class extends w.HTMLElement { |
88 constructor() { super(); w.document.createElement('div').appendChild(thi
s); } | 85 constructor() { super(); w.document.createElement('div').appendChild(thi
s); } |
89 }); | 86 }); |
90 }); | 87 }); |
91 }, `${description}6.1.6. If result\'s parent is not null, then throw a NotSupp
ortedError`); | 88 }, `${description}6.1.6. If result\'s parent is not null, then throw a NotSupp
ortedError`); |
92 | 89 |
93 test_with_window((w) => { | 90 test_with_window((w) => { |
94 assert_throws(expectNotSupportedError, () => { | 91 assert_reports(w, expectNotSupportedError, () => { |
95 define_and_create_element(w, class extends w.HTMLElement { | 92 define_and_create_element(w, class extends w.HTMLElement { |
96 constructor() { super(); return w.document.implementation.createHTMLDocu
ment().createElement('div'); } | 93 constructor() { super(); return w.document.implementation.createHTMLDocu
ment().createElement('div'); } |
97 }); | 94 }); |
98 }); | 95 }); |
99 }, `${description}6.1.7. If result\'s node document is not document, then thro
w a NotSupportedError`); | 96 }, `${description}6.1.7. If result\'s node document is not document, then thro
w a NotSupportedError`); |
100 | 97 |
101 /* This is not testsable today, see https://github.com/whatwg/html/issues/1402 | 98 // See the note in step 6.1.8. In future, it may be possible to throw |
| 99 // NotSupportedError for some elements. |
102 test_with_window((w) => { | 100 test_with_window((w) => { |
103 assert_throws(expectNotSupportedError, () => { | 101 assert_reports(w, expectTypeError, () => { |
104 define_and_create_element(w, class extends w.HTMLElement { | 102 define_and_create_element(w, class extends w.HTMLElement { |
105 constructor() { super(); return w.document.createElementNS('http://www.w
3.org/2000/svg', 'g'); } | 103 constructor() { super(); return w.document.createElementNS('http://www.w
3.org/2000/svg', 'g'); } |
106 }); | 104 }); |
107 }); | 105 }); |
108 }, `${description}6.1.8. If result\'s namespace is not the HTML namespace, the
n throw a NotSupportedError`); | 106 }, `${description}6.1.8. If result\'s namespace is not the HTML namespace, the
n throw (a NotSupportedError, currently TypeError)`); |
109 */ | |
110 | 107 |
111 test_with_window((w) => { | 108 test_with_window((w) => { |
112 assert_throws(expectNotSupportedError, () => { | 109 assert_reports(w, expectNotSupportedError, () => { |
113 define_and_create_element(w, class extends w.HTMLElement { | 110 define_and_create_element(w, class extends w.HTMLElement { |
114 constructor() { super(); return document.createElement('div'); } | 111 constructor() { super(); return document.createElement('div'); } |
115 }); | 112 }); |
116 }); | 113 }); |
117 }, `${description}6.1.9. If result\'s local name is not equal to localName, th
en throw a NotSupportedError`); | 114 }, `${description}6.1.9. If result\'s local name is not equal to localName, th
en throw a NotSupportedError`); |
118 } | 115 } |
119 </script> | 116 </script> |
120 </body> | 117 </body> |
OLD | NEW |