Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 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> | |
| 4 <script src="../../resources/testharness-helpers.js"></script> | |
| 5 <script src="../../resources/testharnessreport.js"></script> | |
| 6 <script src="resources/custom-elements-helpers.js"></script> | |
| 7 <body> | |
| 8 <script> | |
| 9 'use strict'; | |
| 10 | |
| 11 function assert_rethrown(func, description) { | |
| 12 assert_throws({ name: 'rethrown' }, () => { | |
| 13 const err = new Error('check this is rethrown'); | |
| 14 err.name = 'rethrown'; | |
| 15 func(err); | |
| 16 }, description); | |
| 17 } | |
| 18 | |
| 19 const expectTypeError = TypeError.prototype; | |
| 20 const expectNotSupportedError = 'NOT_SUPPORTED_ERR'; | |
| 21 | |
| 22 // https://dom.spec.whatwg.org/#concept-create-element | |
| 23 // 6. If definition is non-null, then: | |
| 24 // 6.1. If the synchronous custom elements flag is set: | |
| 25 | |
| 26 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
| |
| 27 w.customElements.define('a-a', constructor, options); | |
| 28 w.document.createElement('a-a'); | |
| 29 }); | |
| 30 | |
| 31 function test_create_element_synchronous(create_element) { | |
| 32 test_with_window((w) => { | |
| 33 let is_constructed = false; | |
| 34 create_element(w, class extends w.HTMLElement { | |
| 35 constructor() { super(); is_constructed = true; } | |
| 36 }); | |
| 37 assert_true(is_constructed, 'custom constructor ran'); | |
| 38 }, 'Pre-flight check should succeed'); | |
| 39 | |
| 40 test_with_window((w) => { | |
| 41 assert_rethrown(err => { | |
| 42 create_element(w, class extends w.HTMLElement { | |
| 43 constructor() { super(); throw err; } | |
| 44 }); | |
| 45 }); | |
| 46 }, '2. Errors in Construct(C) should be rethrown'); | |
| 47 | |
| 48 test_with_window((w) => { | |
| 49 assert_throws(expectTypeError, () => { | |
| 50 create_element(w, class { | |
| 51 constructor() {} | |
| 52 }); | |
| 53 }); | |
| 54 }, '3. If result does not implement the HTMLElement interface, throw a TypeErr or'); | |
|
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
| |
| 55 | |
| 56 test_with_window((w) => { | |
| 57 assert_throws(expectNotSupportedError, () => { | |
| 58 create_element(w, class extends w.HTMLElement { | |
| 59 constructor() { super(); this.setAttribute('a', 'a'); } | |
| 60 }); | |
| 61 }); | |
| 62 }, '4. If result\'s attribute list is not empty, then throw a NotSupportedErro r'); | |
| 63 | |
| 64 test_with_window((w) => { | |
| 65 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.
| |
| 66 create_element(w, class extends w.HTMLElement { | |
| 67 constructor() { super(); this.appendChild(w.document.createElement('a')) ; } | |
| 68 }); | |
| 69 }); | |
| 70 assert_throws(expectNotSupportedError, () => { | |
| 71 create_element(w, class extends w.HTMLElement { | |
| 72 constructor() { super(); this.appendChild(w.document.createTextNode('a') ); } | |
| 73 }); | |
| 74 }); | |
| 75 }, '5. If result has children, then throw a NotSupportedError'); | |
| 76 | |
| 77 test_with_window((w) => { | |
| 78 assert_throws(expectNotSupportedError, () => { | |
| 79 create_element(w, class extends w.HTMLElement { | |
| 80 constructor() { super(); w.document.createElement('div').appendChild(thi s); } | |
| 81 }); | |
| 82 }); | |
| 83 }, '6. If result\'s parent is not null, then throw a NotSupportedError'); | |
| 84 | |
| 85 test_with_window((w) => { | |
| 86 assert_throws(expectNotSupportedError, () => { | |
| 87 create_element(w, class extends w.HTMLElement { | |
| 88 constructor() { super(); return w.document.implementation.createHTMLDocu ment().createElement('div'); } | |
| 89 }); | |
| 90 }); | |
| 91 }, '7. If result\'s node document is not document, then throw a NotSupportedEr ror'); | |
| 92 | |
| 93 test_with_window((w) => { | |
| 94 assert_throws(expectNotSupportedError, () => { | |
| 95 create_element(w, class extends w.HTMLElement { | |
| 96 constructor() { super(); return w.document.createElementNS('http://www.w 3.org/2000/svg', 'g'); } | |
| 97 }); | |
| 98 }); | |
| 99 }, '8. If result\'s namespace is not the HTML namespace, then throw a NotSuppo rtedError'); | |
| 100 | |
| 101 test_with_window((w) => { | |
| 102 assert_throws(expectNotSupportedError, () => { | |
| 103 create_element(w, class extends w.HTMLElement { | |
| 104 constructor() { super(); return document.createElement('div'); } | |
| 105 }); | |
| 106 }); | |
| 107 }, '9. If result\'s local name is not equal to localName, then throw a NotSupp ortedError'); | |
| 108 } | |
| 109 </script> | |
| 110 </body> | |
| OLD | NEW |