mirror of
https://github.com/servo/servo.git
synced 2025-08-24 14:48:21 +01:00
Update web-platform-tests to revision e8bfc205e36ad699601212cd50083870bad9a75d
This commit is contained in:
parent
65dd6d4340
commit
ccdb0a3458
1428 changed files with 118036 additions and 9786 deletions
|
@ -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>
|
|
@ -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>
|
|
@ -0,0 +1,97 @@
|
|||
<!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>
|
||||
<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, '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(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, '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(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, 'InvalidStateError');
|
||||
|
||||
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 InvalidStateError when the returned element is not SameValue as the upgraded element');
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue