Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/custom-elements/spec/create-element-defined-synchronous.html |
| diff --git a/third_party/WebKit/LayoutTests/custom-elements/spec/create-element-defined-synchronous.html b/third_party/WebKit/LayoutTests/custom-elements/spec/create-element-defined-synchronous.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f08fe4fa0dc20bd3470d5733c187a47a7807125f |
| --- /dev/null |
| +++ b/third_party/WebKit/LayoutTests/custom-elements/spec/create-element-defined-synchronous.html |
| @@ -0,0 +1,110 @@ |
| +<!DOCTYPE html> |
| +<title>Custom Elements: Create an element when definition is non-null and synchronous flag set</title> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharness-helpers.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script src="resources/custom-elements-helpers.js"></script> |
| +<body> |
| +<script> |
| +'use strict'; |
| + |
| +function assert_rethrown(func, description) { |
| + assert_throws({ name: 'rethrown' }, () => { |
| + const err = new Error('check this is rethrown'); |
| + err.name = 'rethrown'; |
| + func(err); |
| + }, description); |
| +} |
| + |
| +const expectTypeError = TypeError.prototype; |
| +const expectNotSupportedError = 'NOT_SUPPORTED_ERR'; |
| + |
| +// https://dom.spec.whatwg.org/#concept-create-element |
| +// 6. If definition is non-null, then: |
| +// 6.1. If the synchronous custom elements flag is set: |
| + |
| +test_create_element_synchronous((w, constructor, options) => { |
|
dominicc (has gone to gerrit)
2016/06/09 06:39:22
Why do it this way, where you're passing in this h
|
| + w.customElements.define('a-a', constructor, options); |
| + w.document.createElement('a-a'); |
| +}); |
| + |
| +function test_create_element_synchronous(create_element) { |
| + test_with_window((w) => { |
| + let is_constructed = false; |
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); is_constructed = true; } |
| + }); |
| + assert_true(is_constructed, 'custom constructor ran'); |
| + }, 'Pre-flight check should succeed'); |
| + |
| + test_with_window((w) => { |
| + assert_rethrown(err => { |
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); throw err; } |
| + }); |
| + }); |
| + }, '2. Errors in Construct(C) should be rethrown'); |
| + |
| + test_with_window((w) => { |
| + assert_throws(expectTypeError, () => { |
| + create_element(w, class { |
| + constructor() {} |
| + }); |
| + }); |
| + }, '3. If result does not implement the HTMLElement interface, throw a TypeError'); |
|
dominicc (has gone to gerrit)
2016/06/09 06:39:22
Might be useful to include tests with HTMLImageEle
kojii
2016/06/09 16:54:21
Let me try this in following patch. Extending HTML
|
| + |
| + test_with_window((w) => { |
| + assert_throws(expectNotSupportedError, () => { |
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); this.setAttribute('a', 'a'); } |
| + }); |
| + }); |
| + }, '4. If result\'s attribute list is not empty, then throw a NotSupportedError'); |
| + |
| + test_with_window((w) => { |
| + assert_throws(expectNotSupportedError, () => { |
|
dominicc (has gone to gerrit)
2016/06/09 06:39:22
These should have messages so we get descriptive f
kojii
2016/06/09 16:54:21
Done.
|
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); this.appendChild(w.document.createElement('a')); } |
| + }); |
| + }); |
| + assert_throws(expectNotSupportedError, () => { |
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); this.appendChild(w.document.createTextNode('a')); } |
| + }); |
| + }); |
| + }, '5. If result has children, then throw a NotSupportedError'); |
| + |
| + test_with_window((w) => { |
| + assert_throws(expectNotSupportedError, () => { |
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); w.document.createElement('div').appendChild(this); } |
| + }); |
| + }); |
| + }, '6. If result\'s parent is not null, then throw a NotSupportedError'); |
| + |
| + test_with_window((w) => { |
| + assert_throws(expectNotSupportedError, () => { |
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); return w.document.implementation.createHTMLDocument().createElement('div'); } |
| + }); |
| + }); |
| + }, '7. If result\'s node document is not document, then throw a NotSupportedError'); |
| + |
| + test_with_window((w) => { |
| + assert_throws(expectNotSupportedError, () => { |
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); return w.document.createElementNS('http://www.w3.org/2000/svg', 'g'); } |
| + }); |
| + }); |
| + }, '8. If result\'s namespace is not the HTML namespace, then throw a NotSupportedError'); |
| + |
| + test_with_window((w) => { |
| + assert_throws(expectNotSupportedError, () => { |
| + create_element(w, class extends w.HTMLElement { |
| + constructor() { super(); return document.createElement('div'); } |
| + }); |
| + }); |
| + }, '9. If result\'s local name is not equal to localName, then throw a NotSupportedError'); |
| +} |
| +</script> |
| +</body> |