| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../../resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <div id="container"></div> |
| <form id="testForm"></form> |
| <script> |
| description("Testing document.register() type extension behaviours through createElement()."); |
| |
| function isFormControl(element) |
| { |
| testForm.appendChild(element); |
| return element.form == testForm; |
| } |
| |
| if (window.testRunner) |
| testRunner.dumpAsText(); |
| document.register = document.register || document.webkitRegister; |
| |
| // |
| // Inheritance here is shaped like this: |
| // |
| // HTMLElement <- input <- x-bar <- x-qux |
| // <- x-foo <- x-baz |
| // |
| |
| fooConstructor = document.register('x-foo', { prototype: Object.create(HTMLElement.prototype) }); |
| barConstructor = document.register('x-bar', { prototype: Object.create(HTMLInputElement.prototype) }); |
| bazConstructor = document.register('x-baz', { prototype: Object.create(fooConstructor.prototype) }); |
| quxConstructor = document.register('x-qux', { prototype: Object.create(barConstructor.prototype) }); |
| |
| // Same name, different local name |
| shouldThrow("document.register('x-foo', { prototype: Object.create(HTMLDivElement.prototype) })", "'Error: InvalidStateError: DOM Exception 11'"); |
| |
| // |
| // Generated constructors |
| // |
| |
| fooNewed = new fooConstructor(); |
| fooOuterHTML = "'<x-foo></x-foo>'"; |
| shouldBe("fooNewed.outerHTML", fooOuterHTML); |
| shouldBeTrue("fooNewed instanceof fooConstructor && fooNewed instanceof HTMLElement"); |
| shouldBeFalse("fooNewed instanceof HTMLUnknownElement"); |
| |
| barNewed = new barConstructor(); |
| barOuterHTML = "'<input is=\"x-bar\">'"; |
| shouldBe("barNewed.outerHTML", barOuterHTML); |
| shouldBeTrue("barNewed instanceof barConstructor && barNewed instanceof HTMLInputElement"); |
| shouldBeTrue("isFormControl(barNewed)"); |
| |
| bazNewed = new bazConstructor(); |
| bazOuterHTML = "'<x-baz></x-baz>'"; |
| shouldBe("bazNewed.outerHTML", bazOuterHTML); |
| shouldBeTrue("bazNewed instanceof bazConstructor && bazNewed instanceof HTMLElement"); |
| shouldBeFalse("bazNewed instanceof HTMLUnknownElement"); |
| |
| quxNewed = new quxConstructor(); |
| quxOuterHTML = "'<input is=\"x-qux\">'"; |
| shouldBeTrue("quxNewed instanceof quxConstructor && quxNewed instanceof barConstructor && quxNewed instanceof HTMLInputElement"); |
| shouldBe("quxNewed.outerHTML", quxOuterHTML); |
| shouldBeTrue("isFormControl(quxNewed)"); |
| |
| // |
| // Single parameter createElement() |
| // |
| |
| fooCreated = document.createElement("x-foo"); |
| shouldBe("fooCreated.outerHTML", fooOuterHTML); |
| shouldBeTrue("fooCreated instanceof fooConstructor"); |
| |
| barCreated = document.createElement("x-bar"); |
| shouldBe("barCreated.outerHTML", "'<x-bar></x-bar>'"); |
| shouldBeFalse("barCreated instanceof barConstructor"); |
| shouldBeTrue("barCreated instanceof HTMLUnknownElement"); |
| |
| bazCreated = document.createElement("x-baz"); |
| shouldBe("bazCreated.outerHTML", "'<x-baz></x-baz>'"); |
| shouldBeTrue("bazCreated instanceof bazConstructor"); |
| shouldBeFalse("bazCreated instanceof HTMLUnknownElement"); |
| |
| quxCreated = document.createElement("x-qux"); |
| shouldBe("quxCreated.outerHTML", "'<x-qux></x-qux>'"); |
| shouldBeFalse("quxCreated instanceof quxConstructor"); |
| shouldBeTrue("quxCreated instanceof HTMLUnknownElement"); |
| |
| // |
| // createElement() with type extensions |
| // |
| |
| divFooCreated = document.createElement("div", "x-foo"); |
| shouldBe("divFooCreated.outerHTML", "'<div is=\"x-foo\"></div>'"); |
| shouldBeFalse("divFooCreated instanceof fooConstructor"); |
| shouldBeTrue("divFooCreated instanceof HTMLDivElement"); |
| |
| inputBarCreated = document.createElement("input", "x-bar"); |
| shouldBe("inputBarCreated.outerHTML", barOuterHTML); |
| shouldBeTrue("inputBarCreated instanceof barConstructor"); |
| shouldBeFalse("inputBarCreated instanceof HTMLUnknownElement"); |
| shouldBeTrue("isFormControl(inputBarCreated)"); |
| |
| divBarCreated = document.createElement("div", "x-bar"); |
| shouldBe("divBarCreated.outerHTML", "'<div is=\"x-bar\"></div>'"); |
| shouldBeFalse("divBarCreated instanceof barConstructor"); |
| shouldBeTrue("divBarCreated instanceof HTMLDivElement"); |
| |
| fooBarCreated = document.createElement("x-foo", "x-bar"); |
| shouldBe("fooBarCreated.outerHTML", "'<x-foo is=\"x-bar\"></x-foo>'"); |
| shouldBeTrue("fooBarCreated instanceof fooConstructor"); |
| |
| barFooCreated = document.createElement("x-bar", "x-foo"); |
| shouldBe("barFooCreated.outerHTML", "'<x-bar is=\"x-foo\"></x-bar>'"); |
| shouldBeTrue("barFooCreated instanceof HTMLUnknownElement"); |
| |
| fooCreatedNull = document.createElement("x-foo", null); |
| shouldBe("fooCreatedNull.outerHTML", fooOuterHTML); |
| shouldBeTrue("fooCreatedNull instanceof fooConstructor"); |
| |
| fooCreatedEmpty = document.createElement("x-foo", ""); |
| shouldBe("fooCreatedEmpty.outerHTML", fooOuterHTML); |
| shouldBeTrue("fooCreatedEmpty instanceof fooConstructor"); |
| |
| shouldThrow("document.createElement('@invalid', 'x-bar')", "'Error: InvalidCharacterError: DOM Exception 5'"); |
| |
| // |
| // createElementNS() with type extensions |
| // |
| |
| fooCreatedNS = document.createElementNS("http://www.w3.org/1999/xhtml", "x-foo", null); |
| shouldBe("fooCreatedNS.outerHTML", fooOuterHTML); |
| shouldBeTrue("fooCreatedNS instanceof fooConstructor"); |
| |
| barCreatedNS = document.createElementNS("http://www.w3.org/1999/xhtml", "input", "x-bar"); |
| shouldBe("barCreatedNS.outerHTML", barOuterHTML); |
| shouldBeTrue("barCreatedNS instanceof barConstructor"); |
| shouldBeTrue("isFormControl(barCreatedNS)"); |
| |
| shouldThrow("document.createElementNS('http://example.com/2013/no-such-namespace', 'xml:lang', 'x-bar')", "'Error: NamespaceError: DOM Exception 14'"); |
| |
| // parser |
| function createElementFromHTML(html) { |
| var container = document.createElement("div"); |
| container.innerHTML = html; |
| return container.firstChild; |
| } |
| |
| fooParsed = createElementFromHTML('<x-foo>'); |
| shouldBeTrue("fooParsed instanceof fooConstructor"); |
| |
| barParsed = createElementFromHTML('<input is=x-bar>') |
| shouldBeTrue("barParsed instanceof barConstructor"); |
| shouldBeTrue("isFormControl(barParsed)"); |
| |
| divFooParsed = createElementFromHTML('<div is=x-foo>') |
| shouldBeFalse("divFooParsed instanceof fooConstructor"); |
| shouldBeTrue("divFooParsed instanceof HTMLDivElement"); |
| |
| namedBarParsed = createElementFromHTML('<x-bar>') |
| shouldBeFalse("namedBarParsed instanceof barConstructor"); |
| shouldBeTrue("namedBarParsed instanceof HTMLUnknownElement"); |
| |
| divBarParsed = createElementFromHTML('<div is=x-bar>') |
| shouldBeFalse("divBarParsed instanceof barConstructor"); |
| shouldBeTrue("divBarParsed instanceof HTMLDivElement"); |
| |
| </script> |
| <script src="../../../resources/js-test-post.js"></script> |
| </body> |
| </html> |