OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <script src="../resources/testharness.js"></script> | 2 <script src="../resources/testharness.js"></script> |
3 <script src="../resources/testharnessreport.js"></script> | 3 <script src="../resources/testharnessreport.js"></script> |
4 <script src="spec/resources/custom-elements-helpers.js"></script> | 4 <script src="spec/resources/custom-elements-helpers.js"></script> |
5 <body> | 5 <body> |
6 <script> | 6 <script> |
7 'use strict'; | 7 'use strict'; |
8 | 8 |
9 test_with_window((w) => { | 9 test_with_window((w) => { |
10 class X extends w.HTMLElement {} | 10 class X extends w.HTMLElement {} |
11 | 11 |
12 w.customElements.define('new-old', X); | 12 w.customElements.define('new-old', X); |
13 assert_throws(null, () => { | 13 assert_throws(null, () => { |
14 w.document.registerElement('new-old', {prototype: X.prototype}); | 14 w.document.registerElement('new-old', {prototype: X.prototype}); |
15 }, '"registering" (v0) a name already "defined" should throw'); | 15 }, '"registering" (v0) a name already "defined" should throw'); |
16 | 16 |
17 w.document.registerElement('old-new', { | 17 w.document.registerElement('old-new', { |
18 prototype: Object.create(w.HTMLElement.prototype) | 18 prototype: Object.create(w.HTMLElement.prototype) |
19 }); | 19 }); |
20 class Y extends w.HTMLElement {} | 20 class Y extends w.HTMLElement {} |
21 assert_throws(null, () => { | 21 assert_throws(null, () => { |
22 w.customElements.define('old-new', Y); | 22 w.customElements.define('old-new', Y); |
23 }, '"defining" (v1) a name already "registered" (v0) should throw'); | 23 }, '"defining" (v1) a name already "registered" (v0) should throw'); |
24 }, 'Overlapping old and new-style custom elements are not allowed'); | 24 }, 'Overlapping old and new-style custom elements are not allowed'); |
| 25 |
| 26 test_with_window((w) => { |
| 27 var A = w.document.registerElement('a-a', { |
| 28 prototype: Object.create(w.HTMLDivElement.prototype), |
| 29 extends: 'div' |
| 30 }); |
| 31 var a = w.document.createElement('div', 'a-a'); |
| 32 |
| 33 assert_true(a instanceof A, |
| 34 'V0 createElement syntax works with V0 registerElement'); |
| 35 assert_throws_dom_exception(w, 'NotFoundError', () => { |
| 36 w.document.createElement('div', {is: 'a-a'}); |
| 37 }, 'V1 createElement syntax does not work with V0 registerElement'); |
| 38 |
| 39 class B extends w.HTMLDivElement { |
| 40 constructor() { |
| 41 super(); |
| 42 this.addEventListener("click", () => { |
| 43 console.log("CLICKED B!"); |
| 44 }); |
| 45 } |
| 46 } |
| 47 w.customElements.define('b-b', B, {extends: 'div' }); |
| 48 |
| 49 assert_true(w.document.createElement('div', {is: 'b-b'}) instanceof B, |
| 50 'V1 createElement syntax works with V1 defined element'); |
| 51 assert_true(w.document.createElement('div', 'b-b') instanceof w.HTMLDivElement
, |
| 52 'V0 createElement syntax does not work with V1 defined element'); |
| 53 }, 'V0 and V1 definition and createElement cannot be used together'); |
25 </script> | 54 </script> |
OLD | NEW |