Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/custom-elements/spec/construct.html |
| diff --git a/third_party/WebKit/LayoutTests/custom-elements/spec/construct.html b/third_party/WebKit/LayoutTests/custom-elements/spec/construct.html |
| index 18a7f79884e7d286444dc8fade2b131305fc5363..509018c2ce04d1e5159a2819b844e17227012487 100644 |
| --- a/third_party/WebKit/LayoutTests/custom-elements/spec/construct.html |
| +++ b/third_party/WebKit/LayoutTests/custom-elements/spec/construct.html |
| @@ -58,6 +58,7 @@ test_with_window((w) => { |
| assert_equals(num_constructor_invocations, |
| 1, |
| 'the constructor should have been invoked once'); |
| + assert_true(e.matches(':defined'), 'custom element constructed with new should be "custom"'); |
| }, 'Custom element constructor, construct'); |
| test_with_window((w) => { |
| @@ -74,4 +75,75 @@ test_with_window((w) => { |
| }, 'constructing a custom element with a non-object new.target should ' + |
| 'throw a TypeError'); |
| }, 'Custom element constructor, construct invalid new.target'); |
| + |
| +test_with_window((w) => { |
|
dominicc (has gone to gerrit)
2016/09/13 08:27:31
This is a good test. We pass this "by accident" no
|
| + w.customElements.define('a-a', w.HTMLButtonElement); |
| + assert_throws(TypeError.prototype, () => { |
| + w.document.createElement('a-a'); |
| + }, 'If NewTarget is equal to active function object, TypeError should be thrown'); |
| +}, 'Custom element constructor, NewTarget is equal to active function object'); |
| + |
| +test_with_window((w) => { |
| + w.customElements.define('a-a', class extends w.HTMLButtonElement {} ); |
| + assert_throws(TypeError.prototype, () => { |
| + w.document.createElement('a-a'); |
| + }, 'If NewTarget is equal to active function object, TypeError should be thrown'); |
| +}, 'Custom element constructor, active function object is not equal to HTMLElement'); |
| + |
| +test_with_window((w) => { |
| + let flag = true; |
| + class A extends w.HTMLElement { |
| + constructor() { |
| + if (flag) { |
| + flag = false; |
| + new A(); |
| + } |
| + super(); |
| + } |
| + } |
| + w.customElements.define('a-a', A); |
| + let e = new A(); |
| + assert_true(e.matches(':defined'), |
| + 'constructing a custom element with new should not throw InvalidStateError ' + |
| + 'and should return a "custom" element'); |
| +}, 'Already constructed marker, construct with new'); |
| + |
| +test_with_window((w) => { |
| + let flag = true; |
| + class A extends w.HTMLElement { |
| + constructor() { |
| + if (flag) { |
| + flag = false; |
| + new A(); |
| + } |
| + super(); |
| + } |
| + } |
| + w.customElements.define('a-a', A); |
| + assert_throws_dom_exception(w, 'INVALID_STATE_ERR', () => { |
| + w.document.createElement('a-a'); |
| + }, 'Creating an element that is already constructed marker should throw InvalidStateError'); |
| +}, 'Already constructed marker, create element'); |
| + |
| +test_with_window((w) => { |
| + let errors = []; |
| + w.onerror = function (event, source, lineno, colno, error) { |
| + errors.push(error.name); |
| + return true; |
| + }; |
| + let flag = true; |
| + let e = w.document.createElement('a-a'); |
| + class A extends w.HTMLElement { |
| + constructor() { |
| + if (flag) { |
| + flag = false; |
| + new A(); |
| + } |
| + super(); |
| + } |
| + } |
| + w.customElements.define('a-a', A); |
| + w.document.body.appendChild(e); |
| + assert_array_equals(errors, ['InvalidStateError'], 'Upgrading an element that is already constructed marker should throw InvalidStateError'); |
|
dominicc (has gone to gerrit)
2016/09/13 08:27:31
Try to stick to lines less than 80 cols; maybe use
|
| +}, 'Already constructed marker, upgrade element'); |
| </script> |