| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Custom Elements: Constructor Tests</title> | 2 <title>Custom Elements: Constructor Tests</title> |
| 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/dom.html#elements-
in-the-dom"> | 3 <link rel="help" href="https://html.spec.whatwg.org/multipage/dom.html#elements-
in-the-dom"> |
| 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org"> | 4 <meta name="author" title="Dominic Cooney" href="mailto:dominicc@chromium.org"> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="resources/custom-elements-helpers.js"></script> | 7 <script src="resources/custom-elements-helpers.js"></script> |
| 8 <body> | 8 <body> |
| 9 <script> | 9 <script> |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 class A extends w.HTMLElement { | 115 class A extends w.HTMLElement { |
| 116 constructor() { | 116 constructor() { |
| 117 if (flag) { | 117 if (flag) { |
| 118 flag = false; | 118 flag = false; |
| 119 new A(); | 119 new A(); |
| 120 } | 120 } |
| 121 super(); | 121 super(); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 w.customElements.define('a-a', A); | 124 w.customElements.define('a-a', A); |
| 125 assert_reports(w, 'INVALID_STATE_ERR', () => { | 125 let e = w.document.createElement('a-a'); |
| 126 w.document.createElement('a-a'); | 126 assert_true(e.matches(':defined'), |
| 127 }, 'Creating an element that is already constructed marker should report ' + | 127 'constructing an autonomous custom element with create element should ' + |
| 128 'InvalidStateError'); | 128 'not throw InvalidStateError ' + |
| 129 'and should return a "custom" element'); |
| 129 }, 'Already constructed marker, create element'); | 130 }, 'Already constructed marker, create element'); |
| 130 | 131 |
| 131 test_with_window((w) => { | 132 test_with_window((w) => { |
| 133 let flag = true; |
| 134 class A extends w.HTMLElement { |
| 135 constructor() { |
| 136 if (flag) { |
| 137 flag = false; |
| 138 new A(); |
| 139 } |
| 140 super(); |
| 141 } |
| 142 } |
| 143 w.customElements.define('a-a', A); |
| 144 let d = w.document.createElement('div'); |
| 145 assert_reports(w, 'INVALID_STATE_ERR', () => { |
| 146 d.innerHTML = '<a-a>'; |
| 147 }, 'Creating an element that is already constructed marker should report ' + |
| 148 'InvalidStateError'); |
| 149 }, 'Already constructed marker, fragment parsing should set marker'); |
| 150 |
| 151 test_with_window((w) => { |
| 132 let errors = []; | 152 let errors = []; |
| 133 w.onerror = function (event, source, lineno, colno, error) { | 153 w.onerror = function (event, source, lineno, colno, error) { |
| 134 errors.push(error.name); | 154 errors.push(error.name); |
| 135 return true; | 155 return true; |
| 136 }; | 156 }; |
| 137 let flag = true; | 157 let flag = true; |
| 138 let e = w.document.createElement('a-a'); | 158 let e = w.document.createElement('a-a'); |
| 139 class A extends w.HTMLElement { | 159 class A extends w.HTMLElement { |
| 140 constructor() { | 160 constructor() { |
| 141 if (flag) { | 161 if (flag) { |
| 142 flag = false; | 162 flag = false; |
| 143 new A(); | 163 new A(); |
| 144 } | 164 } |
| 145 super(); | 165 super(); |
| 146 } | 166 } |
| 147 } | 167 } |
| 148 w.customElements.define('a-a', A); | 168 w.customElements.define('a-a', A); |
| 149 w.document.body.appendChild(e); | 169 w.document.body.appendChild(e); |
| 150 assert_array_equals(errors, ['InvalidStateError'], 'Upgrading an element ' + | 170 assert_array_equals(errors, ['InvalidStateError'], 'Upgrading an element ' + |
| 151 'that is already constructed marker should throw InvalidStateError'); | 171 'that is already constructed marker should throw InvalidStateError'); |
| 152 }, 'Already constructed marker, upgrade element'); | 172 }, 'Already constructed marker, upgrade element'); |
| 153 </script> | 173 </script> |
| OLD | NEW |