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