summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/custom-elements/upgrading
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/custom-elements/upgrading')
-rw-r--r--testing/web-platform/tests/custom-elements/upgrading/Document-importNode-customized-builtins.html32
-rw-r--r--testing/web-platform/tests/custom-elements/upgrading/Document-importNode.html32
-rw-r--r--testing/web-platform/tests/custom-elements/upgrading/Node-cloneNode-customized-builtins.html48
-rw-r--r--testing/web-platform/tests/custom-elements/upgrading/Node-cloneNode.html206
-rw-r--r--testing/web-platform/tests/custom-elements/upgrading/upgrading-enqueue-reactions.html158
-rw-r--r--testing/web-platform/tests/custom-elements/upgrading/upgrading-parser-created-element.html125
6 files changed, 601 insertions, 0 deletions
diff --git a/testing/web-platform/tests/custom-elements/upgrading/Document-importNode-customized-builtins.html b/testing/web-platform/tests/custom-elements/upgrading/Document-importNode-customized-builtins.html
new file mode 100644
index 0000000000..91c9ea8aee
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/upgrading/Document-importNode-customized-builtins.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<link rel="help" href="https://dom.spec.whatwg.org/#dom-document-importnode">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/custom-elements-helpers.js"></script>
+<body>
+<script>
+test_with_window((w, doc) => {
+ class MyDiv extends HTMLDivElement {}
+ class MyDiv2 extends w.HTMLDivElement {}
+ customElements.define('my-div', MyDiv, { extends: 'div' });
+ w.customElements.define('my-div', MyDiv2, { extends: 'div' });
+
+ let original = document.createElement('div', { is: 'my-div' });
+ assert_true(original instanceof MyDiv);
+
+ let imported = doc.importNode(original);
+ assert_true(imported instanceof MyDiv2);
+}, 'built-in: document.importNode() should import custom elements successfully');
+
+test_with_window((w, doc) => {
+ class MyDiv2 extends w.HTMLDivElement {}
+ w.customElements.define('my-div2', MyDiv2, { extends: 'div' });
+
+ let original = document.createElement('div', { is: 'my-div2' });
+ assert_equals(original.constructor, HTMLDivElement);
+
+ let imported = doc.importNode(original);
+ assert_true(imported instanceof MyDiv2);
+}, 'built-in: document.importNode() should import "undefined" custom elements successfully');
+</script>
+</body>
diff --git a/testing/web-platform/tests/custom-elements/upgrading/Document-importNode.html b/testing/web-platform/tests/custom-elements/upgrading/Document-importNode.html
new file mode 100644
index 0000000000..3da4ccf46a
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/upgrading/Document-importNode.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<link rel="help" href="https://dom.spec.whatwg.org/#dom-document-importnode">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/custom-elements-helpers.js"></script>
+<body>
+<script>
+test_with_window((w, doc) => {
+ class MyElement extends HTMLElement {}
+ class MyElement2 extends w.HTMLElement {}
+ customElements.define('my-element', MyElement);
+ w.customElements.define('my-element', MyElement2);
+
+ let original = document.createElement('my-element');
+ assert_true(original instanceof MyElement);
+
+ let imported = doc.importNode(original);
+ assert_true(imported instanceof MyElement2);
+}, 'autonomous: document.importNode() should import custom elements successfully');
+
+test_with_window((w, doc) => {
+ class MyElement3 extends w.HTMLElement {}
+ w.customElements.define('my-element3', MyElement3);
+
+ let original = document.createElement('my-element3');
+ assert_equals(original.constructor, HTMLElement);
+
+ let imported = doc.importNode(original);
+ assert_true(imported instanceof MyElement3);
+}, 'autonomous: document.importNode() should import "undefined" custom elements successfully');
+</script>
+</body>
diff --git a/testing/web-platform/tests/custom-elements/upgrading/Node-cloneNode-customized-builtins.html b/testing/web-platform/tests/custom-elements/upgrading/Node-cloneNode-customized-builtins.html
new file mode 100644
index 0000000000..5e1122cc84
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/upgrading/Node-cloneNode-customized-builtins.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Custom Elements: Upgrading</title>
+<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
+<meta name="assert" content="Node.prototype.cloneNode should upgrade a custom element">
+<link rel="help" href="https://html.spec.whatwg.org/#upgrades">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/custom-elements-helpers.js"></script>
+</head>
+<body>
+<div id="log"></div>
+<script>
+setup({allow_uncaught_exception:true});
+
+test(function () {
+ class MyDiv1 extends HTMLDivElement {};
+ class MyDiv2 extends HTMLDivElement {};
+ class MyDiv3 extends HTMLDivElement {};
+ customElements.define('my-div1', MyDiv1, { extends: 'div' });
+ customElements.define('my-div2', MyDiv2, { extends: 'div' });
+
+ let instance = document.createElement('div', { is: 'my-div1'});
+ assert_true(instance instanceof MyDiv1);
+ instance.setAttribute('is', 'my-div2');
+ let clone = instance.cloneNode(false);
+ assert_not_equals(instance, clone);
+ assert_true(clone instanceof MyDiv1,
+ 'A cloned custom element must be an instance of the custom element even with an inconsistent "is" attribute');
+
+ let instance3 = document.createElement('div', { is: 'my-div3'});
+ assert_false(instance3 instanceof MyDiv3);
+ instance3.setAttribute('is', 'my-div2');
+ let clone3 = instance3.cloneNode(false);
+ assert_not_equals(instance3, clone);
+ customElements.define('my-div3', MyDiv3, { extends: 'div' });
+ document.body.appendChild(instance3);
+ document.body.appendChild(clone3);
+ assert_true(instance3 instanceof MyDiv3,
+ 'An undefined element must be upgraded even with an inconsistent "is" attribute');
+ assert_true(clone3 instanceof MyDiv3,
+ 'A cloned undefined element must be upgraded even with an inconsistent "is" attribute');
+}, 'Node.prototype.cloneNode(false) must be able to clone as a customized built-in element when it has an inconsistent "is" attribute');
+
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/custom-elements/upgrading/Node-cloneNode.html b/testing/web-platform/tests/custom-elements/upgrading/Node-cloneNode.html
new file mode 100644
index 0000000000..1a05e96964
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/upgrading/Node-cloneNode.html
@@ -0,0 +1,206 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Custom Elements: Upgrading</title>
+<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
+<meta name="assert" content="Node.prototype.cloneNode should upgrade a custom element">
+<link rel="help" href="https://html.spec.whatwg.org/#upgrades">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/custom-elements-helpers.js"></script>
+</head>
+<body>
+<div id="log"></div>
+<script>
+setup({allow_uncaught_exception:true});
+
+test(function () {
+ class MyCustomElement extends HTMLElement {}
+ customElements.define('my-custom-element', MyCustomElement);
+
+ var instance = document.createElement('my-custom-element');
+ assert_true(instance instanceof HTMLElement);
+ assert_true(instance instanceof MyCustomElement);
+
+ var clone = instance.cloneNode(false);
+ assert_not_equals(instance, clone);
+ assert_true(clone instanceof HTMLElement,
+ 'A cloned custom element must be an instance of HTMLElement');
+ assert_true(clone instanceof MyCustomElement,
+ 'A cloned custom element must be an instance of the custom element');
+}, 'Node.prototype.cloneNode(false) must be able to clone a custom element');
+
+test(function () {
+ class AutonomousCustomElement extends HTMLElement {};
+ class IsCustomElement extends HTMLElement {};
+
+ customElements.define('autonomous-custom-element', AutonomousCustomElement);
+ customElements.define('is-custom-element', IsCustomElement);
+
+ var instance = document.createElement('autonomous-custom-element', { is: "is-custom-element"});
+ assert_true(instance instanceof HTMLElement);
+ assert_true(instance instanceof AutonomousCustomElement);
+
+ var clone = instance.cloneNode(false);
+ assert_not_equals(instance, clone);
+ assert_true(clone instanceof HTMLElement,
+ 'A cloned custom element must be an instance of HTMLElement');
+ assert_true(clone instanceof AutonomousCustomElement,
+ 'A cloned custom element must be an instance of the custom element');
+}, 'Node.prototype.cloneNode(false) must be able to clone as a autonomous custom element when it contains is attribute');
+
+test_with_window(function (contentWindow) {
+ var contentDocument = contentWindow.document;
+ class MyCustomElement extends contentWindow.HTMLElement {}
+ contentWindow.customElements.define('my-custom-element', MyCustomElement);
+
+ var instance = contentDocument.createElement('my-custom-element');
+ assert_true(instance instanceof contentWindow.HTMLElement);
+ assert_true(instance instanceof MyCustomElement);
+
+ var clone = instance.cloneNode(false);
+ assert_not_equals(instance, clone);
+ assert_true(clone instanceof contentWindow.HTMLElement,
+ 'A cloned custom element must be an instance of HTMLElement');
+ assert_true(clone instanceof MyCustomElement,
+ 'A cloned custom element must be an instance of the custom element');
+}, 'Node.prototype.cloneNode(false) must be able to clone a custom element inside an iframe');
+
+test_with_window(function (contentWindow) {
+ var contentDocument = contentWindow.document;
+ class MyCustomElement extends contentWindow.HTMLElement { }
+ contentWindow.customElements.define('my-custom-element', MyCustomElement);
+
+ var instance = contentDocument.createElement('my-custom-element');
+ var container = contentDocument.createElement('div');
+ container.appendChild(instance);
+
+ var containerClone = container.cloneNode(true);
+ assert_true(containerClone instanceof contentWindow.HTMLDivElement);
+
+ var clone = containerClone.firstChild;
+ assert_not_equals(instance, clone);
+ assert_true(clone instanceof contentWindow.HTMLElement,
+ 'A cloned custom element must be an instance of HTMLElement');
+ assert_true(clone instanceof MyCustomElement,
+ 'A cloned custom element must be an instance of the custom element');
+}, 'Node.prototype.cloneNode(true) must be able to clone a descendent custom element');
+
+test_with_window(function (contentWindow) {
+ var parentNodeInConstructor;
+ var previousSiblingInConstructor;
+ var nextSiblingInConstructor;
+ class MyCustomElement extends contentWindow.HTMLElement {
+ constructor() {
+ super();
+ parentNodeInConstructor = this.parentNode;
+ previousSiblingInConstructor = this.previousSibling;
+ nextSiblingInConstructor = this.nextSibling;
+ }
+ }
+ contentWindow.customElements.define('my-custom-element', MyCustomElement);
+
+ var contentDocument = contentWindow.document;
+ var instance = contentDocument.createElement('my-custom-element');
+ var siblingBeforeInstance = contentDocument.createElement('b');
+ var siblingAfterInstance = contentDocument.createElement('a');
+ var container = contentDocument.createElement('div');
+ container.appendChild(siblingBeforeInstance);
+ container.appendChild(instance);
+ container.appendChild(siblingAfterInstance);
+
+ var containerClone = container.cloneNode(true);
+
+ assert_equals(parentNodeInConstructor, containerClone,
+ 'An upgraded element must have its parentNode set before the custom element constructor is called');
+ assert_equals(previousSiblingInConstructor, containerClone.firstChild,
+ 'An upgraded element must have its previousSibling set before the custom element constructor is called');
+ assert_equals(nextSiblingInConstructor, containerClone.lastChild,
+ 'An upgraded element must have its nextSibling set before the custom element constructor is called');
+}, 'Node.prototype.cloneNode(true) must set parentNode, previousSibling, and nextSibling before upgrading custom elements');
+
+// The error reporting isn't clear yet when multiple globals involved in custom
+// element, see w3c/webcomponents#635, so using test_with_window is not a good
+// idea here.
+test(function () {
+ class MyCustomElement extends HTMLElement {
+ constructor(doNotCreateItself) {
+ super();
+ if (!doNotCreateItself)
+ new MyCustomElement(true);
+ }
+ }
+ customElements.define('my-custom-element-constructed-after-super', MyCustomElement);
+
+ var instance = new MyCustomElement(false);
+ var uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ instance.cloneNode(false);
+ assert_equals(uncaughtError.name, 'TypeError');
+}, 'HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed'
+ + ' due to a custom element constructor constructing itself after super() call');
+
+test(function () {
+ class MyCustomElement extends HTMLElement {
+ constructor(doNotCreateItself) {
+ if (!doNotCreateItself)
+ new MyCustomElement(true);
+ super();
+ }
+ }
+ customElements.define('my-custom-element-constructed-before-super', MyCustomElement);
+
+ var instance = new MyCustomElement(false);
+ var uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ instance.cloneNode(false);
+ assert_equals(uncaughtError.name, 'TypeError');
+}, 'HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed'
+ + ' due to a custom element constructor constructing itself before super() call');
+
+test(function () {
+ var returnSpan = false;
+ class MyCustomElement extends HTMLElement {
+ constructor() {
+ super();
+ if (returnSpan)
+ return document.createElement('span');
+ }
+ }
+ customElements.define('my-custom-element-return-another', MyCustomElement);
+
+ var instance = new MyCustomElement(false);
+ returnSpan = true;
+ var uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ instance.cloneNode(false);
+ assert_equals(uncaughtError.name, 'TypeError');
+}, 'Upgrading a custom element must throw TypeError when the custom element\'s constructor returns another element');
+
+test(function () {
+ var instance = document.createElement('my-custom-element-throw-exception');
+ document.body.appendChild(instance);
+
+ var calls = [];
+ class MyCustomElement extends HTMLElement {
+ constructor() {
+ super();
+ calls.push(this);
+ throw 'bad';
+ }
+ }
+
+ var uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ customElements.define('my-custom-element-throw-exception', MyCustomElement);
+ assert_equals(uncaughtError, 'bad');
+
+ assert_array_equals(calls, [instance]);
+ document.body.removeChild(instance);
+ document.body.appendChild(instance);
+ assert_array_equals(calls, [instance]);
+}, 'Inserting an element must not try to upgrade a custom element when it had already failed to upgrade once');
+
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/custom-elements/upgrading/upgrading-enqueue-reactions.html b/testing/web-platform/tests/custom-elements/upgrading/upgrading-enqueue-reactions.html
new file mode 100644
index 0000000000..8238eee624
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/upgrading/upgrading-enqueue-reactions.html
@@ -0,0 +1,158 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Custom Elements: Upgrading custom elements should enqueue attributeChanged and connected callbacks</title>
+<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
+<meta name="assert" content="Upgrading custom elements should enqueue attributeChanged and connected callbacksml">
+<meta name="help" content="https://html.spec.whatwg.org/#upgrades">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../resources/custom-elements-helpers.js"></script>
+</head>
+<body>
+<div id="log"></div>
+<script>
+setup({allow_uncaught_exception:true});
+
+test_with_window(function (contentWindow) {
+ const contentDocument = contentWindow.document;
+ contentDocument.write('<test-element id="some" title="This is a test">');
+
+ const undefinedElement = contentDocument.querySelector('test-element');
+ assert_equals(Object.getPrototypeOf(undefinedElement), contentWindow.HTMLElement.prototype);
+
+ let log = [];
+ class TestElement extends contentWindow.HTMLElement {
+ constructor() {
+ super();
+ log.push(create_constructor_log(this));
+ }
+ attributeChangedCallback(...args) {
+ log.push(create_attribute_changed_callback_log(this, ...args));
+ }
+ static get observedAttributes() { return ['id', 'title']; }
+ }
+ contentWindow.customElements.define('test-element', TestElement);
+ assert_equals(Object.getPrototypeOf(undefinedElement), TestElement.prototype);
+
+ assert_equals(log.length, 3);
+ assert_constructor_log_entry(log[0], undefinedElement);
+ assert_attribute_log_entry(log[1], {name: 'id', oldValue: null, newValue: 'some', namespace: null});
+ assert_attribute_log_entry(log[2], {name: 'title', oldValue: null, newValue: 'This is a test', namespace: null});
+}, 'Upgrading a custom element must enqueue attributeChangedCallback on each attribute');
+
+test_with_window(function (contentWindow) {
+ const contentDocument = contentWindow.document;
+ contentDocument.write('<test-element id="some" title="This is a test" class="foo">');
+
+ const undefinedElement = contentDocument.querySelector('test-element');
+ assert_equals(Object.getPrototypeOf(undefinedElement), contentWindow.HTMLElement.prototype);
+
+ let log = [];
+ class TestElement extends contentWindow.HTMLElement {
+ constructor() {
+ super();
+ log.push(create_constructor_log(this));
+ }
+ attributeChangedCallback(...args) {
+ log.push(create_attribute_changed_callback_log(this, ...args));
+ }
+ static get observedAttributes() { return ['class', 'id']; }
+ }
+ contentWindow.customElements.define('test-element', TestElement);
+ assert_equals(Object.getPrototypeOf(undefinedElement), TestElement.prototype);
+
+ assert_equals(log.length, 3);
+ assert_constructor_log_entry(log[0], undefinedElement);
+ assert_attribute_log_entry(log[1], {name: 'id', oldValue: null, newValue: 'some', namespace: null});
+ assert_attribute_log_entry(log[2], {name: 'class', oldValue: null, newValue: 'foo', namespace: null});
+}, 'Upgrading a custom element not must enqueue attributeChangedCallback on unobserved attributes');
+
+test_with_window(function (contentWindow) {
+ const contentDocument = contentWindow.document;
+ contentDocument.write('<test-element id="some" title="This is a test" class="foo">');
+
+ const undefinedElement = contentDocument.querySelector('test-element');
+ assert_equals(Object.getPrototypeOf(undefinedElement), contentWindow.HTMLElement.prototype);
+
+ let log = [];
+ class TestElement extends contentWindow.HTMLElement {
+ constructor() {
+ super();
+ log.push(create_constructor_log(this));
+ }
+ connectedCallback(...args) {
+ log.push(create_connected_callback_log(this, ...args));
+ }
+ }
+ contentWindow.customElements.define('test-element', TestElement);
+ assert_equals(Object.getPrototypeOf(undefinedElement), TestElement.prototype);
+
+ assert_equals(log.length, 2);
+ assert_constructor_log_entry(log[0], undefinedElement);
+ assert_connected_log_entry(log[1], undefinedElement);
+}, 'Upgrading a custom element must enqueue connectedCallback if the element in the document');
+
+test_with_window(function (contentWindow) {
+ const contentDocument = contentWindow.document;
+ contentDocument.write('<test-element id="some" title="This is a test" class="foo">');
+
+ const undefinedElement = contentDocument.querySelector('test-element');
+ assert_equals(Object.getPrototypeOf(undefinedElement), contentWindow.HTMLElement.prototype);
+
+ let log = [];
+ class TestElement extends contentWindow.HTMLElement {
+ constructor() {
+ super();
+ log.push(create_constructor_log(this));
+ }
+ connectedCallback(...args) {
+ log.push(create_connected_callback_log(this, ...args));
+ }
+ attributeChangedCallback(...args) {
+ log.push(create_attribute_changed_callback_log(this, ...args));
+ }
+ static get observedAttributes() { return ['class', 'id']; }
+ }
+ contentWindow.customElements.define('test-element', TestElement);
+ assert_equals(Object.getPrototypeOf(undefinedElement), TestElement.prototype);
+
+ assert_equals(log.length, 4);
+ assert_constructor_log_entry(log[0], undefinedElement);
+ assert_attribute_log_entry(log[1], {name: 'id', oldValue: null, newValue: 'some', namespace: null});
+ assert_attribute_log_entry(log[2], {name: 'class', oldValue: null, newValue: 'foo', namespace: null});
+ assert_connected_log_entry(log[3], undefinedElement);
+}, 'Upgrading a custom element must enqueue attributeChangedCallback before connectedCallback');
+
+test_with_window(function (contentWindow) {
+ const contentDocument = contentWindow.document;
+ contentDocument.write('<test-element id="some" title="This is a test" class="foo">');
+
+ const undefinedElement = contentDocument.querySelector('test-element');
+ assert_equals(Object.getPrototypeOf(undefinedElement), contentWindow.HTMLElement.prototype);
+
+ let log = [];
+ class TestElement extends contentWindow.HTMLElement {
+ constructor() {
+ super();
+ log.push(create_constructor_log(this));
+ throw 'Exception thrown as a part of test';
+ }
+ connectedCallback(...args) {
+ log.push(create_connected_callback_log(this, ...args));
+ }
+ attributeChangedCallback(...args) {
+ log.push(create_attribute_changed_callback_log(this, ...args));
+ }
+ static get observedAttributes() { return ['class', 'id']; }
+ }
+ contentWindow.customElements.define('test-element', TestElement);
+ assert_equals(Object.getPrototypeOf(undefinedElement), TestElement.prototype);
+
+ assert_equals(log.length, 1);
+ assert_constructor_log_entry(log[0], undefinedElement);
+}, 'Upgrading a custom element must not invoke attributeChangedCallback and connectedCallback when the element failed to upgrade');
+
+</script>
+</body>
+</html>
diff --git a/testing/web-platform/tests/custom-elements/upgrading/upgrading-parser-created-element.html b/testing/web-platform/tests/custom-elements/upgrading/upgrading-parser-created-element.html
new file mode 100644
index 0000000000..0f7f95786d
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/upgrading/upgrading-parser-created-element.html
@@ -0,0 +1,125 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Custom Elements: Upgrading unresolved elements</title>
+<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
+<meta name="assert" content="HTML parser must add an unresolved custom element to the upgrade candidates map">
+<link rel="help" href="https://html.spec.whatwg.org/#upgrades">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+</head>
+<body>
+<div id="log"></div>
+<my-custom-element></my-custom-element>
+<instantiates-itself-after-super></instantiates-itself-after-super>
+<instantiates-itself-before-super></instantiates-itself-before-super>
+<my-other-element id="instance"></my-other-element>
+<my-other-element id="otherInstance"></my-other-element>
+<not-an-element></not-an-element>
+<not-an-html-element></not-an-html-element>
+<script>
+
+setup({allow_uncaught_exception:true});
+
+test(function () {
+ class MyCustomElement extends HTMLElement { }
+
+ var instance = document.querySelector('my-custom-element');
+ assert_true(instance instanceof HTMLElement);
+ assert_false(instance instanceof HTMLUnknownElement,
+ 'an unresolved custom element should not be an instance of HTMLUnknownElement');
+ assert_false(instance instanceof MyCustomElement);
+
+ customElements.define('my-custom-element', MyCustomElement);
+
+ assert_true(instance instanceof HTMLElement);
+ assert_true(instance instanceof MyCustomElement,
+ 'Calling customElements.define must upgrade existing custom elements');
+
+}, 'Element.prototype.createElement must add an unresolved custom element to the upgrade candidates map');
+
+test(function () {
+ class InstantiatesItselfAfterSuper extends HTMLElement {
+ constructor(doNotCreateItself) {
+ super();
+ if (!doNotCreateItself)
+ new InstantiatesItselfAfterSuper(true);
+ }
+ }
+
+ var uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ customElements.define('instantiates-itself-after-super', InstantiatesItselfAfterSuper);
+ assert_equals(uncaughtError.name, 'TypeError');
+}, 'HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed'
+ + ' due to a custom element constructor constructing itself after super() call');
+
+test(function () {
+ class InstantiatesItselfBeforeSuper extends HTMLElement {
+ constructor(doNotCreateItself) {
+ if (!doNotCreateItself)
+ new InstantiatesItselfBeforeSuper(true);
+ super();
+ }
+ }
+
+ var uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ customElements.define('instantiates-itself-before-super', InstantiatesItselfBeforeSuper);
+ assert_equals(uncaughtError.name, 'TypeError');
+}, 'HTMLElement constructor must throw an TypeError when the top of the construction stack is marked AlreadyConstructed'
+ + ' due to a custom element constructor constructing itself before super() call');
+
+test(function () {
+ class MyOtherElement extends HTMLElement {
+ constructor() {
+ super();
+ if (this == instance)
+ return otherInstance;
+ }
+ }
+ var instance = document.getElementById('instance');
+ var otherInstance = document.getElementById('otherInstance');
+
+ assert_false(instance instanceof MyOtherElement);
+ assert_false(otherInstance instanceof MyOtherElement);
+
+ var uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ customElements.define('my-other-element', MyOtherElement);
+ assert_equals(uncaughtError.name, 'TypeError');
+
+ assert_true(document.createElement('my-other-element') instanceof MyOtherElement,
+ 'Upgrading of custom elements must happen after the definition was added to the registry.');
+
+}, 'Upgrading a custom element must throw an TypeError when the returned element is not SameValue as the upgraded element');
+
+test(() => {
+ class NotAnElement extends HTMLElement {
+ constructor() {
+ return new Text();
+ }
+ }
+
+ let uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ customElements.define("not-an-element", NotAnElement);
+ assert_equals(uncaughtError.name, "TypeError");
+}, "Upgrading a custom element whose constructor returns a Text node must throw");
+
+test(() => {
+ class NotAnHTMLElement extends HTMLElement {
+ constructor() {
+ return document.createElementNS("", "test");
+ }
+ }
+
+ let uncaughtError;
+ window.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
+ customElements.define("not-an-html-element", NotAnHTMLElement);
+ assert_equals(uncaughtError.name, "TypeError");
+}, "Upgrading a custom element whose constructor returns an Element must throw");
+
+</script>
+</body>
+</html>