OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
5 </head> | 5 </head> |
6 <body> | 6 <body> |
7 <script> | 7 <script> |
8 description('Using document.register() for extending HTML and non-HTML elements.
'); | 8 description('Using document.registerElement() for extending HTML and non-HTML el
ements.'); |
9 | 9 |
10 function createElementFromHTML(html) | 10 function createElementFromHTML(html) |
11 { | 11 { |
12 var container = document.createElement('div'); | 12 var container = document.createElement('div'); |
13 container.innerHTML = html; | 13 container.innerHTML = html; |
14 return container.firstChild; | 14 return container.firstChild; |
15 } | 15 } |
16 | 16 |
17 function createElementFromSVG(svg) | 17 function createElementFromSVG(svg) |
18 { | 18 { |
19 var container = document.createElement('div'); | 19 var container = document.createElement('div'); |
20 container.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg">' + svg + '</
svg>'; | 20 container.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg">' + svg + '</
svg>'; |
21 return container.firstChild.firstChild; | 21 return container.firstChild.firstChild; |
22 } | 22 } |
23 | 23 |
24 CustomHTMLElement = document.register('html-foo', { prototype: Object.create(HTM
LElement.prototype) }); | 24 CustomHTMLElement = document.registerElement('html-foo', { prototype: Object.cre
ate(HTMLElement.prototype) }); |
25 CustomSVGElement = document.register('svg-foo', { prototype: Object.create(SVGGE
lement.prototype), extends: 'g' }); | 25 CustomSVGElement = document.registerElement('svg-foo', { prototype: Object.creat
e(SVGGElement.prototype), extends: 'g' }); |
26 | 26 |
27 var html1 = new CustomHTMLElement(); | 27 var html1 = new CustomHTMLElement(); |
28 shouldBe('html1.namespaceURI', '"http://www.w3.org/1999/xhtml"'); | 28 shouldBe('html1.namespaceURI', '"http://www.w3.org/1999/xhtml"'); |
29 var html2 = document.createElement('html-foo'); | 29 var html2 = document.createElement('html-foo'); |
30 shouldBe('html2.namespaceURI', '"http://www.w3.org/1999/xhtml"'); | 30 shouldBe('html2.namespaceURI', '"http://www.w3.org/1999/xhtml"'); |
31 var html3 = document.createElementNS('http://www.w3.org/1999/xhtml', 'html-foo')
; | 31 var html3 = document.createElementNS('http://www.w3.org/1999/xhtml', 'html-foo')
; |
32 shouldBe('html3.namespaceURI', '"http://www.w3.org/1999/xhtml"'); | 32 shouldBe('html3.namespaceURI', '"http://www.w3.org/1999/xhtml"'); |
33 var html4 = createElementFromHTML('<html-foo></html-foo>'); | 33 var html4 = createElementFromHTML('<html-foo></html-foo>'); |
34 shouldBe('html4.namespaceURI', '"http://www.w3.org/1999/xhtml"'); | 34 shouldBe('html4.namespaceURI', '"http://www.w3.org/1999/xhtml"'); |
35 | 35 |
(...skipping 22 matching lines...) Expand all Loading... |
58 shouldBe('Object.getPrototypeOf(notSVG1)', 'HTMLElement.prototype'); | 58 shouldBe('Object.getPrototypeOf(notSVG1)', 'HTMLElement.prototype'); |
59 var notSVG2 = createElementFromHTML('<svg-foo></svg-foo>'); | 59 var notSVG2 = createElementFromHTML('<svg-foo></svg-foo>'); |
60 shouldBe('notSVG2.namespaceURI', '"http://www.w3.org/1999/xhtml"'); | 60 shouldBe('notSVG2.namespaceURI', '"http://www.w3.org/1999/xhtml"'); |
61 shouldBeFalse('notSVG2 instanceof CustomSVGElement'); | 61 shouldBeFalse('notSVG2 instanceof CustomSVGElement'); |
62 shouldBeFalse('notSVG2 instanceof HTMLUnknownElement'); | 62 shouldBeFalse('notSVG2 instanceof HTMLUnknownElement'); |
63 shouldBeTrue('notSVG2 instanceof HTMLElement'); | 63 shouldBeTrue('notSVG2 instanceof HTMLElement'); |
64 shouldBe('Object.getPrototypeOf(notSVG2)', 'HTMLElement.prototype'); | 64 shouldBe('Object.getPrototypeOf(notSVG2)', 'HTMLElement.prototype'); |
65 </script> | 65 </script> |
66 </body> | 66 </body> |
67 </html> | 67 </html> |
OLD | NEW |