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/testharnessreport.js"></script> |
| 5 <script src="resources/custom-elements-helpers.js"></script> |
| 6 <body> |
| 7 <script> |
| 8 'use strict'; |
| 9 |
| 10 // https://dom.spec.whatwg.org/#dom-document-createelement |
| 11 // 1. If localName does not match the Name production, then throw an InvalidChar
acterError |
| 12 // 2. If context object is an HTML document, let localName be converted to ASCII
lowercase |
| 13 // 5. If 'is' is non-null and definition is null, then throw a NotFoundError |
| 14 // 6. If 'is' is non-null, then set is attribute to 'is' |
| 15 |
| 16 // https://dom.spec.whatwg.org/#internal-createelementns-steps |
| 17 // 4. If 'is' is non-null and definition is null, then throw a NotFoundError |
| 18 // Different from createElement: localName is not converted to ASCII lowercas
e |
| 19 |
| 20 function setup(w) { |
| 21 class A extends w.HTMLElement { |
| 22 constructor() { |
| 23 super(); |
| 24 } |
| 25 } |
| 26 w.customElements.define('a-a', A); |
| 27 |
| 28 class B extends w.HTMLDivElement { |
| 29 constructor() { |
| 30 super(); |
| 31 } |
| 32 } |
| 33 w.customElements.define('b-b', B, {extends: 'div'}); |
| 34 } |
| 35 |
| 36 test_with_window((w) => { |
| 37 assert_throws_dom_exception(w, 'InvalidCharacterError', () => { |
| 38 w.document.createElement('.invalid.name.'); |
| 39 }); |
| 40 }, 'createElement 1. If localName does not match the Name production, then thr
ow an InvalidCharacterError'); |
| 41 |
| 42 test_with_window((w) => { |
| 43 setup(w); |
| 44 |
| 45 assert_not_equals(w.document.createElement('A-a').constructor, w.HTMLElement); |
| 46 assert_throws_dom_exception(w, 'NotFoundError', () => { |
| 47 w.document.createElement('div', {is: 'b-B'}); |
| 48 }, 'The \'is\' option should not be converted to ASCII lowercase'); |
| 49 }, 'createElement 2. If context object is an HTML document, let localName be c
onverted to ASCII lowercase'); |
| 50 |
| 51 test_with_window((w) => { |
| 52 setup(w); |
| 53 assert_throws_dom_exception(w, 'NotFoundError', () => { |
| 54 w.document.createElement('div', {is: 'a-a'}); |
| 55 }, 'Custom element definition named \'a-a\' is not a customized built-in eleme
nt'); |
| 56 assert_throws_dom_exception(w, 'NotFoundError', () => { |
| 57 w.document.createElement('button', {is: 'b-b'}); |
| 58 }, 'Custom element definition named \'b-b\' is not an HTMLButtonElement'); |
| 59 assert_throws_dom_exception(w, 'NotFoundError', () => { |
| 60 w.document.createElement('button', {id: 'b-b'}); |
| 61 }, 'An \'is\' attribute is needed to create a customized built-in element'); |
| 62 assert_throws_dom_exception(w, 'NotFoundError', () => { |
| 63 w.document.createElement('div', {is: ''}); |
| 64 }, 'There is no custom element definition named with an empty string'); |
| 65 assert_throws_dom_exception(w, 'NotFoundError', () => { |
| 66 w.document.createElement('div', {}); |
| 67 }, 'There is no custom element definition named with null'); |
| 68 }, 'createElement 5. If \'is\' is non-null and definition is null, then throw
a NotFoundError'); |
| 69 |
| 70 test_with_window((w) => { |
| 71 setup(w); |
| 72 let a = w.document.createElement('a-a'); |
| 73 let b = w.document.createElement('div', {is : 'b-b'}); |
| 74 assert_equals(a.getAttribute('is'), null); |
| 75 assert_equals(b.getAttribute('is'), 'b-b'); |
| 76 }, 'createElement 6. If \'is\' is non-null, then set is-attribute to \'is\''); |
| 77 |
| 78 test_with_window((w) => { |
| 79 setup(w); |
| 80 assert_equals(w.document.createElementNS('http://www.w3.org/1999/xhtml', 'a-A'
).constructor, w.HTMLElement); |
| 81 assert_throws_dom_exception(w, 'NotFoundError', () => { |
| 82 w.document.createElementNS('http://www.w3.org/1999/xhtml', 'dIv', {is: 'b-b'
}); |
| 83 }); |
| 84 }, 'createElementNS 4. If \'is\' is non-null and definition is null, then throw
a NotFoundError'); |
| 85 |
| 86 </script> |
| 87 </body> |
OLD | NEW |