| Index: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/Node-cloneNode.html
|
| diff --git a/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/Node-cloneNode.html b/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/Node-cloneNode.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..61580f4184b62e87bb231641317d9eb6ef1dea50
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/Node-cloneNode.html
|
| @@ -0,0 +1,185 @@
|
| +<!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>
|
| +
|
| +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_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');
|
| +
|
| +test_with_window(function (contentWindow) {
|
| + class MyCustomElement extends contentWindow.HTMLElement {
|
| + constructor(doNotCreateItself) {
|
| + super();
|
| + if (!doNotCreateItself)
|
| + new MyCustomElement(true);
|
| + }
|
| + }
|
| + contentWindow.customElements.define('my-custom-element', MyCustomElement);
|
| +
|
| + var instance = new MyCustomElement(false);
|
| + var uncaughtError;
|
| + contentWindow.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
|
| + instance.cloneNode(false);
|
| + assert_equals(uncaughtError.name, 'InvalidStateError');
|
| +}, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
|
| + + ' due to a custom element constructor constructing itself after super() call');
|
| +
|
| +test_with_window(function (contentWindow) {
|
| + class MyCustomElement extends contentWindow.HTMLElement {
|
| + constructor(doNotCreateItself) {
|
| + if (!doNotCreateItself)
|
| + new MyCustomElement(true);
|
| + super();
|
| + }
|
| + }
|
| + contentWindow.customElements.define('my-custom-element', MyCustomElement);
|
| +
|
| + var instance = new MyCustomElement(false);
|
| + var uncaughtError;
|
| + contentWindow.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
|
| + instance.cloneNode(false);
|
| + assert_equals(uncaughtError.name, 'InvalidStateError');
|
| +}, 'HTMLElement constructor must throw an InvalidStateError when the top of the construction stack is marked AlreadyConstructed'
|
| + + ' due to a custom element constructor constructing itself before super() call');
|
| +
|
| +test_with_window(function (contentWindow) {
|
| + var contentDocument = contentWindow.document;
|
| + var returnSpan = false;
|
| + class MyCustomElement extends contentWindow.HTMLElement {
|
| + constructor() {
|
| + super();
|
| + if (returnSpan)
|
| + return contentDocument.createElement('span');
|
| + }
|
| + }
|
| + contentWindow.customElements.define('my-custom-element', MyCustomElement);
|
| +
|
| + var instance = new MyCustomElement(false);
|
| + returnSpan = true;
|
| + var uncaughtError;
|
| + contentWindow.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
|
| + instance.cloneNode(false);
|
| + assert_equals(uncaughtError.name, 'InvalidStateError');
|
| +}, 'Upgrading a custom element must throw InvalidStateError when the custom element\'s constructor returns another element');
|
| +
|
| +test_with_window(function (contentWindow) {
|
| + var contentDocument = contentWindow.document;
|
| + var instance = contentDocument.createElement('my-custom-element');
|
| + contentDocument.body.appendChild(instance);
|
| +
|
| + var calls = [];
|
| + class MyCustomElement extends contentWindow.HTMLElement {
|
| + constructor() {
|
| + super();
|
| + calls.push(this);
|
| + throw 'bad';
|
| + }
|
| + }
|
| +
|
| + var uncaughtError;
|
| + contentWindow.onerror = function (message, url, lineNumber, columnNumber, error) { uncaughtError = error; return true; }
|
| + contentWindow.customElements.define('my-custom-element', MyCustomElement);
|
| + assert_equals(uncaughtError, 'bad');
|
| +
|
| + assert_array_equals(calls, [instance]);
|
| + contentDocument.body.removeChild(instance);
|
| + contentDocument.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>
|
|
|