Truly independent web browser
LibWeb: Import custom element adoption callback coverage
Andreas Klinga6de31e90a7e
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 67bf36164c2..e782b6d1df8 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -1,5 +1,8 @@[LoadFromHttpServer]Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/+; These custom-element fixtures fetch a detached document by XHR.+Text/input/wpt-import/custom-elements/adopted-callback.html+Text/input/wpt-import/custom-elements/connected-callbacks.htmlText/input/HTML/xml-document-encoding.htmlText/input/HTML/createImageBitmap-video.htmlText/input/HTML/HTMLVideoElement-capture-before-seek-keeps-frame.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/custom-elements/adopted-callback.txt b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/adopted-callback.txtnew file mode 100644index 00000000000..129e5b710f0--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/adopted-callback.txt@@ -0,0 +1,77 @@+Harness status: OK++Found 71 tests++17 Pass+54 Fail+Pass Inserting a custom element into the owner document must not enqueue and invoke adoptedCallback+Fail Inserting a custom element into the document of the template elements must enqueue and invoke adoptedCallback+Fail Moving a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback+Fail Inserting an ancestor of custom element into the document of the template elements must enqueue and invoke adoptedCallback+Fail Moving an ancestor of custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a shadow tree in the document of the template elements must enqueue and invoke adoptedCallback+Fail Inserting the shadow host of a custom element into the document of the template elements must enqueue and invoke adoptedCallback+Fail Moving the shadow host of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback+Fail Moving the shadow host's shadow of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback+Fail Moving the <template>'s content of a custom element from the owner document into the document of the template elements must enqueue and invoke adoptedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to the document of the template elements must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a new document must enqueue and invoke adoptedCallback+Fail Moving a custom element from the owner document into a new document must enqueue and invoke adoptedCallback+Fail Inserting an ancestor of custom element into a new document must enqueue and invoke adoptedCallback+Fail Moving an ancestor of custom element from the owner document into a new document must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a shadow tree in a new document must enqueue and invoke adoptedCallback+Fail Inserting the shadow host of a custom element into a new document must enqueue and invoke adoptedCallback+Fail Moving the shadow host of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback+Fail Moving the shadow host's shadow of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback+Fail Moving the <template>'s content of a custom element from the owner document into a new document must enqueue and invoke adoptedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to a new document must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a cloned document must enqueue and invoke adoptedCallback+Fail Moving a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback+Fail Inserting an ancestor of custom element into a cloned document must enqueue and invoke adoptedCallback+Fail Moving an ancestor of custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a shadow tree in a cloned document must enqueue and invoke adoptedCallback+Fail Inserting the shadow host of a custom element into a cloned document must enqueue and invoke adoptedCallback+Fail Moving the shadow host of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback+Fail Moving the shadow host's shadow of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback+Fail Moving the <template>'s content of a custom element from the owner document into a cloned document must enqueue and invoke adoptedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to a cloned document must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Moving a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Inserting an ancestor of custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Moving an ancestor of custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a shadow tree in a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Inserting the shadow host of a custom element into a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Moving the shadow host of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Moving the shadow host's shadow of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Moving the <template>'s content of a custom element from the owner document into a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to a document created by createHTMLDocument must enqueue and invoke adoptedCallback+Fail Inserting a custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback+Fail Moving a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback+Fail Inserting an ancestor of custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback+Fail Moving an ancestor of custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a shadow tree in an HTML document created by createDocument must enqueue and invoke adoptedCallback+Fail Inserting the shadow host of a custom element into an HTML document created by createDocument must enqueue and invoke adoptedCallback+Fail Moving the shadow host of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback+Fail Moving the shadow host's shadow of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback+Fail Moving the <template>'s content of a custom element from the owner document into an HTML document created by createDocument must enqueue and invoke adoptedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to an HTML document created by createDocument must enqueue and invoke adoptedCallback+Pass Inserting a custom element into the document of an iframe must enqueue and invoke adoptedCallback+Pass Moving a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback+Pass Inserting an ancestor of custom element into the document of an iframe must enqueue and invoke adoptedCallback+Pass Moving an ancestor of custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback+Pass Inserting a custom element into a shadow tree in the document of an iframe must enqueue and invoke adoptedCallback+Pass Inserting the shadow host of a custom element into the document of an iframe must enqueue and invoke adoptedCallback+Pass Moving the shadow host of a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback+Pass Moving the shadow host's shadow of a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback+Pass Moving the <template>'s content of a custom element from the owner document into the document of an iframe must enqueue and invoke adoptedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to the document of an iframe must enqueue and invoke adoptedCallback+Fail Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Fail Moving a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Fail Inserting an ancestor of custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Fail Moving an ancestor of custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Fail Inserting a custom element into a shadow tree in an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Fail Inserting the shadow host of a custom element into an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Fail Moving the shadow host of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Fail Moving the shadow host's shadow of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Fail Moving the <template>'s content of a custom element from the owner document into an HTML document fetched by XHR must enqueue and invoke adoptedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to an HTML document fetched by XHR must enqueue and invoke adoptedCallback\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/custom-elements/connected-callbacks.txt b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/connected-callbacks.txtnew file mode 100644index 00000000000..bcf79822fcc--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/custom-elements/connected-callbacks.txt@@ -0,0 +1,46 @@+Harness status: OK++Found 40 tests++16 Pass+24 Fail+Pass Inserting a custom element into the document must enqueue and invoke connectedCallback+Pass Inserting an ancestor of custom element into the document must enqueue and invoke connectedCallback+Pass Inserting a custom element into a shadow tree in the document must enqueue and invoke connectedCallback+Pass Inserting the shadow host of a custom element into the document must enqueue and invoke connectedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to the document must not enqueue and invoke connectedCallback+Fail Inserting a custom element into the document of the template elements must enqueue and invoke connectedCallback+Fail Inserting an ancestor of custom element into the document of the template elements must enqueue and invoke connectedCallback+Fail Inserting a custom element into a shadow tree in the document of the template elements must enqueue and invoke connectedCallback+Fail Inserting the shadow host of a custom element into the document of the template elements must enqueue and invoke connectedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to the document of the template elements must not enqueue and invoke connectedCallback+Fail Inserting a custom element into a new document must enqueue and invoke connectedCallback+Fail Inserting an ancestor of custom element into a new document must enqueue and invoke connectedCallback+Fail Inserting a custom element into a shadow tree in a new document must enqueue and invoke connectedCallback+Fail Inserting the shadow host of a custom element into a new document must enqueue and invoke connectedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to a new document must not enqueue and invoke connectedCallback+Fail Inserting a custom element into a cloned document must enqueue and invoke connectedCallback+Fail Inserting an ancestor of custom element into a cloned document must enqueue and invoke connectedCallback+Fail Inserting a custom element into a shadow tree in a cloned document must enqueue and invoke connectedCallback+Fail Inserting the shadow host of a custom element into a cloned document must enqueue and invoke connectedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to a cloned document must not enqueue and invoke connectedCallback+Fail Inserting a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback+Fail Inserting an ancestor of custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback+Fail Inserting a custom element into a shadow tree in a document created by createHTMLDocument must enqueue and invoke connectedCallback+Fail Inserting the shadow host of a custom element into a document created by createHTMLDocument must enqueue and invoke connectedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to a document created by createHTMLDocument must not enqueue and invoke connectedCallback+Fail Inserting a custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback+Fail Inserting an ancestor of custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback+Fail Inserting a custom element into a shadow tree in an HTML document created by createDocument must enqueue and invoke connectedCallback+Fail Inserting the shadow host of a custom element into an HTML document created by createDocument must enqueue and invoke connectedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to an HTML document created by createDocument must not enqueue and invoke connectedCallback+Pass Inserting a custom element into the document of an iframe must enqueue and invoke connectedCallback+Pass Inserting an ancestor of custom element into the document of an iframe must enqueue and invoke connectedCallback+Pass Inserting a custom element into a shadow tree in the document of an iframe must enqueue and invoke connectedCallback+Pass Inserting the shadow host of a custom element into the document of an iframe must enqueue and invoke connectedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to the document of an iframe must not enqueue and invoke connectedCallback+Fail Inserting a custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback+Fail Inserting an ancestor of custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback+Fail Inserting a custom element into a shadow tree in an HTML document fetched by XHR must enqueue and invoke connectedCallback+Fail Inserting the shadow host of a custom element into an HTML document fetched by XHR must enqueue and invoke connectedCallback+Pass Inserting a custom element into a detached shadow tree that belongs to an HTML document fetched by XHR must not enqueue and invoke connectedCallback\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/custom-elements/adopted-callback.html b/Tests/LibWeb/Text/input/wpt-import/custom-elements/adopted-callback.htmlnew file mode 100644index 00000000000..a87d6b04ca6--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/custom-elements/adopted-callback.html@@ -0,0 +1,167 @@+<!DOCTYPE html>+<html>+<head>+<title>Custom Elements: adoptedCallback</title>+<meta name="author" title="Ryosuke Niwa" href="mailto:[email protected]">+<meta name="assert" content="adoptedCallback must be enqueued whenever custom element is adopted into a new document">+<link rel="help" href="https://w3c.github.io/webcomponents/spec/custom/#dfn-connected-callback">+<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>++var calls = [];+class MyCustomElement extends HTMLElement {+ connectedCallback() { calls.push('connected'); }+ adoptedCallback(oldDocument, newDocument) { calls.push('adopted'); calls.push(oldDocument); calls.push(newDocument); }+ disconnectedCallback() { calls.push('disconnected'); }+}+customElements.define('my-custom-element', MyCustomElement);++test(function () {+ var instance = document.createElement('my-custom-element');+ calls = [];+ document.body.appendChild(instance);+ assert_array_equals(calls, ['connected']);+}, 'Inserting a custom element into the owner document must not enqueue and invoke adoptedCallback');++document_types().forEach(function (entry) {+ if (entry.isOwner)+ return;++ var documentName = entry.name;+ var getDocument = entry.create;++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ calls = [];+ doc.documentElement.appendChild(instance);+ assert_array_equals(calls, ['adopted', document, doc, 'connected']);+ });+ }, 'Inserting a custom element into ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ document.body.appendChild(instance);+ calls = [];+ doc.documentElement.appendChild(instance);+ assert_array_equals(calls, ['disconnected', 'adopted', document, doc, 'connected']);+ });+ }, 'Moving a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var parent = document.createElement('div');+ parent.appendChild(instance);+ calls = [];+ doc.documentElement.appendChild(parent);+ assert_array_equals(calls, ['adopted', document, doc, 'connected']);+ });+ }, 'Inserting an ancestor of custom element into ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var parent = document.createElement('div');+ parent.appendChild(instance);+ document.body.appendChild(parent);+ calls = [];+ doc.documentElement.appendChild(parent);+ assert_array_equals(calls, ['disconnected', 'adopted', document, doc, 'connected']);+ });+ }, 'Moving an ancestor of custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div');+ var shadowRoot = host.attachShadow({mode: 'closed'});+ doc.documentElement.appendChild(host);++ calls = [];+ shadowRoot.appendChild(instance);+ assert_array_equals(calls, ['adopted', document, doc, 'connected']);+ });+ }, 'Inserting a custom element into a shadow tree in ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var host = document.createElement('div');+ var shadowRoot = host.attachShadow({mode: 'closed'});+ shadowRoot.appendChild(instance);++ calls = [];+ doc.documentElement.appendChild(host);+ assert_array_equals(calls, ['adopted', document, doc, 'connected']);+ });+ }, 'Inserting the shadow host of a custom element into ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var host = document.createElement('div');+ var shadowRoot = host.attachShadow({mode: 'closed'});+ shadowRoot.appendChild(instance);+ document.body.appendChild(host);++ calls = [];+ doc.documentElement.appendChild(host);+ assert_array_equals(calls, ['disconnected', 'adopted', document, doc, 'connected']);+ });+ }, 'Moving the shadow host of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ const instance = document.createElement('my-custom-element');+ const host = document.createElement('div');+ const shadowRoot = host.attachShadow({mode: 'closed'});+ shadowRoot.appendChild(instance);+ document.body.appendChild(host);++ calls = [];+ doc.documentElement.appendChild(shadowRoot);+ assert_array_equals(calls, ['disconnected', 'adopted', document, doc, 'connected']);+ });+ }, 'Moving the shadow host\'s shadow of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ const instance = document.createElement('my-custom-element');+ const template = document.createElement('template');+ const templateContent = template.content;+ templateContent.appendChild(instance);+ document.body.appendChild(template);++ calls = [];+ doc.documentElement.appendChild(templateContent);+ if (doc === templateContent.ownerDocument) {+ assert_array_equals(calls, ['connected']);+ } else {+ assert_array_equals(calls, ['adopted', templateContent.ownerDocument, doc, 'connected']);+ }+ });+ }, 'Moving the <template>\'s content of a custom element from the owner document into ' + documentName + ' must enqueue and invoke adoptedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div');+ var shadowRoot = host.attachShadow({mode: 'closed'});++ calls = [];+ shadowRoot.appendChild(instance);+ assert_array_equals(calls, ['adopted', document, doc]);+ });+ }, 'Inserting a custom element into a detached shadow tree that belongs to ' + documentName + ' must enqueue and invoke adoptedCallback');+});++</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/custom-elements/connected-callbacks.html b/Tests/LibWeb/Text/input/wpt-import/custom-elements/connected-callbacks.htmlnew file mode 100644index 00000000000..e08f2b0a911--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/custom-elements/connected-callbacks.html@@ -0,0 +1,88 @@+<!DOCTYPE html>+<html>+<head>+<title>Custom Elements: connectedCallback</title>+<meta name="author" title="Ryosuke Niwa" href="mailto:[email protected]">+<meta name="assert" content="connectedCallback must be enqueued whenever custom element is inserted into a document">+<link rel="help" href="https://w3c.github.io/webcomponents/spec/custom/#dfn-connected-callback">+<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>++var calls = [];+class MyCustomElement extends HTMLElement {+ connectedCallback() { calls.push('connected', this); }+ disconnectedCallback() { calls.push('disconnected', this); }+}+customElements.define('my-custom-element', MyCustomElement);++document_types().forEach(function (entry) {+ var documentName = entry.name;+ var getDocument = entry.create;++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ calls = [];+ doc.documentElement.appendChild(instance);+ assert_array_equals(calls, ['connected', instance]);+ });+ }, 'Inserting a custom element into ' + documentName + ' must enqueue and invoke connectedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var parent = document.createElement('div');+ parent.appendChild(instance);+ calls = [];+ doc.documentElement.appendChild(parent);+ assert_array_equals(calls, ['connected', instance]);+ });+ }, 'Inserting an ancestor of custom element into ' + documentName + ' must enqueue and invoke connectedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div');+ var shadowRoot = host.attachShadow({mode: 'closed'});+ doc.documentElement.appendChild(host);++ calls = [];+ shadowRoot.appendChild(instance);+ assert_array_equals(calls, ['connected', instance]);+ });+ }, 'Inserting a custom element into a shadow tree in ' + documentName + ' must enqueue and invoke connectedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div');+ var shadowRoot = host.attachShadow({mode: 'closed'});+ shadowRoot.appendChild(instance);++ calls = [];+ doc.documentElement.appendChild(host);+ assert_array_equals(calls, ['connected', instance]);+ });+ }, 'Inserting the shadow host of a custom element into ' + documentName + ' must enqueue and invoke connectedCallback');++ promise_test(function () {+ return getDocument().then(function (doc) {+ var instance = document.createElement('my-custom-element');+ var host = doc.createElementNS('http://www.w3.org/1999/xhtml', 'div');+ var shadowRoot = host.attachShadow({mode: 'closed'});++ calls = [];+ shadowRoot.appendChild(instance);+ assert_array_equals(calls, []);+ });+ }, 'Inserting a custom element into a detached shadow tree that belongs to ' + documentName + ' must not enqueue and invoke connectedCallback');+});++</script>+</body>+</html>