OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <script src="../../../resources/testharness.js"></script> |
| 3 <script src="../../../resources/testharnessreport.js"></script> |
| 4 <body> |
| 5 <script> |
| 6 test(function() { |
| 7 var p = Object.create(HTMLDivElement.prototype); |
| 8 var C = document.register('x-div', {extends: 'div', prototype: p}); |
| 9 assert_equals(new C().outerHTML, '<div is="x-div"></div>', |
| 10 'type extensions should have an "is" attribute'); |
| 11 assert_equals(new C().tagName, 'DIV', |
| 12 'tag name should be that of the base element'); |
| 13 }, 'register a type extension'); |
| 14 |
| 15 test(function() { |
| 16 var p = Object.create(Window.prototype); |
| 17 var C = document.register('x-em', {extends: 'em', prototype: p}); |
| 18 var e = new C(); |
| 19 Node.prototype.appendChild.call(e, document.createTextNode('Hi!')); |
| 20 assert_equals(e.outerHTML, '<em is="x-em">Hi!</em>', |
| 21 'the type extension must not depend on the author-' + |
| 22 'specified prototype'); |
| 23 }, 'register a type extension with a non-element prototype'); |
| 24 |
| 25 test(function() { |
| 26 var p = Object.create(HTMLUnknownElement.prototype); |
| 27 var C = document.register('x-unknown', {extends: 'unknown', prototype: p}); |
| 28 assert_equals(new C().outerHTML, '<unknown is="x-unknown"></unknown>'); |
| 29 }, 'register a type extension of an unknown element'); |
| 30 |
| 31 test(function() { |
| 32 // registering an SVG element requires an SVGElement prototype |
| 33 var p = Object.create(SVGElement.prototype); |
| 34 var C = document.register('x-use', {extends: 'use', prototype: p}); |
| 35 assert_equals(new C().namespaceURI, 'http://www.w3.org/2000/svg', |
| 36 'SVG type extensions should have the SVG namespace'); |
| 37 }, 'register a type extension of an SVG element'); |
| 38 |
| 39 test(function() { |
| 40 var p = Object.create(HTMLElement.prototype); |
| 41 var C = document.register('x-sect', {extends: 'section', prototype: p}); |
| 42 assert_equals(new C().outerHTML, '<section is="x-sect"></section>'); |
| 43 }, 'register a type extension of an element whose interface is HTMLElement'); |
| 44 |
| 45 test(function() { |
| 46 var C = document.register('x-augment', {extends: 'ins', prototype: {}}); |
| 47 assert_equals(new C().outerHTML, '<ins is="x-augment"></ins>'); |
| 48 var D = document.register('x-elide', {extends: 'del', prototype: {}}); |
| 49 assert_equals(new D().outerHTML, '<del is="x-elide"></del>'); |
| 50 }, 'register a type extensions of an interface with multiple element names'); |
| 51 |
| 52 test(function() { |
| 53 var C = document.register('x-ins', {extends: 'InS', prototype: {}}); |
| 54 assert_equals(new C().tagName, 'INS', |
| 55 'tag name should be that of the base element'); |
| 56 }, 'register a type extension with unusual case'); |
| 57 |
| 58 test(function() { |
| 59 assert_throws( |
| 60 'INVALID_CHARACTER_ERR', |
| 61 function() { |
| 62 var p = Object.create(HTMLElement.prototype); |
| 63 document.register('x-bespoke', {extends: 'x-spoke', prototype: p}); |
| 64 }, |
| 65 'registering a type extension of a custom tag should fail'); |
| 66 }, 'registering a type extension of a custom tag should fail'); |
| 67 </script> |
OLD | NEW |