| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="../../resources/testharness.js"></script> | 2 <script src="../../resources/testharness.js"></script> |
| 3 <script src="../../resources/testharnessreport.js"></script> | 3 <script src="../../resources/testharnessreport.js"></script> |
| 4 <script src="resources/custom-elements-helpers.js"></script> | 4 <script src="resources/custom-elements-helpers.js"></script> |
| 5 <body> | 5 <body> |
| 6 <script> | 6 <script> |
| 7 'use strict'; | 7 'use strict'; |
| 8 | 8 |
| 9 // Looks up the preceeding element (which should be a template | 9 // Looks up the preceeding element (which should be a template |
| 10 // element) and creates a Promise test. The test name is taken from | 10 // element) and creates a Promise test. The test name is taken from |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 test_with_content((w) => { | 118 test_with_content((w) => { |
| 119 assert_equals(w.document.querySelectorAll('b').length, 0); | 119 assert_equals(w.document.querySelectorAll('b').length, 0); |
| 120 }); | 120 }); |
| 121 </script> | 121 </script> |
| 122 | 122 |
| 123 <template data-test="destructive writes are blocked during construction"> | 123 <template data-test="destructive writes are blocked during construction"> |
| 124 <script> | 124 <script> |
| 125 // Custom element constructors do not set the insertion point, which | 125 // Custom element constructors do not set the insertion point, which |
| 126 // makes document.write() "destructive." However they increment the | 126 // makes document.write() "destructive." However they increment the |
| 127 // ignore-destructive-writes counter, which blocks document.write. | 127 // throw-on-dynamic-insertion counter, which blocks document.write and |
| 128 // throws "InvalidStateError" DOMException. |
| 128 // https://html.spec.whatwg.org/#create-an-element-for-the-token | 129 // https://html.spec.whatwg.org/#create-an-element-for-the-token |
| 129 // https://github.com/whatwg/html/issues/1630 | |
| 130 // https://html.spec.whatwg.org/#document.write() | 130 // https://html.spec.whatwg.org/#document.write() |
| 131 'use strict'; | 131 'use strict'; |
| 132 | 132 |
| 133 window.errors = []; |
| 134 window.onerror = function (event, source, lineno, colno, error) { |
| 135 errors.push(error.name); |
| 136 return true; // Cancel the error event. |
| 137 }; |
| 138 |
| 133 window.invocations = []; | 139 window.invocations = []; |
| 134 customElements.define('a-a', class extends HTMLElement { | 140 customElements.define('a-a', class extends HTMLElement { |
| 135 constructor() { | 141 constructor() { |
| 136 super(); | 142 super(); |
| 137 invocations.push('constructor'); | 143 invocations.push('constructor'); |
| 138 document.write( | 144 document.write( |
| 139 `<script>'use strict'; invocations.push('written');</scr${'i'}pt>`); | 145 `<script>'use strict'; invocations.push('written');</scr${'i'}pt>`); |
| 140 } | 146 } |
| 141 connectedCallback() { | 147 connectedCallback() { |
| 142 invocations.push('connected'); | 148 invocations.push('connected'); |
| 143 } | 149 } |
| 144 }); | 150 }); |
| 145 </script> | 151 </script> |
| 146 <a-a> | 152 <a-a> |
| 147 <script> | 153 <script> |
| 148 'use strict'; | 154 'use strict'; |
| 149 invocations.push('parsed'); | 155 invocations.push('parsed'); |
| 150 </script> | 156 </script> |
| 151 </template> | 157 </template> |
| 152 <script> | 158 <script> |
| 153 'use strict'; | 159 'use strict'; |
| 154 | 160 |
| 155 test_with_content((w) => { | 161 test_with_content((w) => { |
| 156 assert_array_equals( | 162 assert_array_equals( |
| 157 w.invocations, | 163 w.invocations, |
| 158 ['constructor', 'connected', 'parsed'], | 164 ['constructor', 'parsed'], |
| 159 'the destructive document.write content should have been ignored'); | 165 'the destructive document.write content should have been ignored; ' + |
| 166 'connectedCallback should not be executed, since the constructor threw'); |
| 167 assert_array_equals( |
| 168 w.errors, |
| 169 ['InvalidStateError'], |
| 170 'create an element for the token should report the exception'); |
| 160 }); | 171 }); |
| 161 </script> | 172 </script> |
| 162 | 173 |
| 163 <template data-test="non-destructive writes are not blocked"> | 174 <template data-test="non-destructive writes are not blocked"> |
| 164 <script> | 175 <script> |
| 165 // Script running sets the insertion point, which makes makes | 176 // Script running sets the insertion point, which makes makes |
| 166 // document.write() "non-destructive." Custom elements do not block | 177 // document.write() "non-destructive." Custom elements should block |
| 167 // non-destructive writes. | 178 // non-destructive writes. |
| 168 // https://html.spec.whatwg.org/#create-an-element-for-the-token | 179 // https://html.spec.whatwg.org/#create-an-element-for-the-token |
| 169 // https://html.spec.whatwg.org/#document.write() | 180 // https://html.spec.whatwg.org/#document.write() |
| 170 'use strict'; | 181 'use strict'; |
| 171 | 182 |
| 183 window.errors = []; |
| 184 window.onerror = function (event, source, lineno, colno, error) { |
| 185 errors.push(error.name); |
| 186 return true; // Cancel the error event. |
| 187 }; |
| 188 |
| 172 window.invocations = []; | 189 window.invocations = []; |
| 173 customElements.define('a-a', class extends HTMLElement { | 190 customElements.define('a-a', class extends HTMLElement { |
| 174 constructor() { | 191 constructor() { |
| 175 super(); | 192 super(); |
| 176 invocations.push('constructor'); | 193 invocations.push('constructor'); |
| 177 document.write( | 194 document.write( |
| 178 `<script>'use strict'; invocations.push('written');</scr${'i'}pt>`); | 195 `<script>'use strict'; invocations.push('written');</scr${'i'}pt>`); |
| 179 } | 196 } |
| 180 connectedCallback() { | 197 connectedCallback() { |
| 181 invocations.push('connected'); | 198 invocations.push('connected'); |
| 182 } | 199 } |
| 183 }); | 200 }); |
| 184 document.write('<a-a>'); | 201 document.write('<a-a>'); |
| 185 invocations.push('post write'); | 202 invocations.push('post write'); |
| 186 </script> | 203 </script> |
| 187 <script> | 204 <script> |
| 188 'use strict'; | 205 'use strict'; |
| 189 invocations.push('parsed'); | 206 invocations.push('parsed'); |
| 190 </script> | 207 </script> |
| 191 </template> | 208 </template> |
| 192 <script> | 209 <script> |
| 193 'use strict'; | 210 'use strict'; |
| 194 | 211 |
| 195 test_with_content((w) => { | 212 test_with_content((w) => { |
| 196 assert_array_equals( | 213 assert_array_equals( |
| 197 w.invocations, | 214 w.invocations, |
| 198 ['constructor', 'connected', 'post write', 'written', 'parsed'], | 215 ['constructor', 'post write', 'parsed'], |
| 199 'the non-destructive document.write content should have been inserted'); | 216 'the non-destructive document.write content should have been ignored' + |
| 217 'connectedCallback should not be executed, since the constructor threw'); |
| 218 assert_array_equals( |
| 219 w.errors, |
| 220 ['InvalidStateError'], |
| 221 'create an element for the token should report the exception'); |
| 200 }); | 222 }); |
| 201 </script> | 223 </script> |
| 202 | 224 |
| 203 <template data-test="innerHTML is not blocked by custom element constructors"> | 225 <template data-test="innerHTML is not blocked by custom element constructors"> |
| 204 <script> | 226 <script> |
| 205 'use strict'; | 227 'use strict'; |
| 206 | 228 |
| 207 window.invocations = []; | 229 window.invocations = []; |
| 208 customElements.define('a-a', class extends HTMLElement { | 230 customElements.define('a-a', class extends HTMLElement { |
| 209 constructor() { | 231 constructor() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 'the element should have been created successfully'); | 298 'the element should have been created successfully'); |
| 277 | 299 |
| 278 let elements = f.detached.querySelectorAll('a-a'); | 300 let elements = f.detached.querySelectorAll('a-a'); |
| 279 console.log(f.invocations[0].parentNode); | 301 console.log(f.invocations[0].parentNode); |
| 280 assert_equals(elements.length, 2, | 302 assert_equals(elements.length, 2, |
| 281 'two elements should have been created'); | 303 'two elements should have been created'); |
| 282 assert_equals(Object.getPrototypeOf(elements[1]), w.HTMLElement.prototype, | 304 assert_equals(Object.getPrototypeOf(elements[1]), w.HTMLElement.prototype, |
| 283 'the second element should be un-upgraded, not failed'); | 305 'the second element should be un-upgraded, not failed'); |
| 284 }); | 306 }); |
| 285 </script> | 307 </script> |
| OLD | NEW |