Bug 1517860 [wpt PR 14721] - WebKit export of https://bugs.webkit.org/show_bug.cgi?id=183586, a=testonly
authorDarshan Kadu <darsh7807@gmail.com>
Thu, 31 Jan 2019 15:44:36 +0000
changeset 457874 86527c29d084e195d6bbfaddc4530d1692cc8e98
parent 457873 3a93031da62a897935aca1fa041cff3bf141e95e
child 457875 fb93cb2bfc57617c7ab26218f5d152e3178c0637
push id35518
push useropoprus@mozilla.com
push dateFri, 08 Feb 2019 09:55:14 +0000
treeherdermozilla-central@3a3e393396f4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1517860, 14721, 183586
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1517860 [wpt PR 14721] - WebKit export of https://bugs.webkit.org/show_bug.cgi?id=183586, a=testonly Automatic update from web-platform-tests WebKit export of https://bugs.webkit.org/show_bug.cgi?id=183586 (#14721) -- wpt-commits: 1d3a454b4af3f3d70206b53a6dce49ae0ddcc7a9 wpt-pr: 14721
testing/web-platform/tests/custom-elements/enqueue-custom-element-callback-reactions-inside-another-callback.html
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/custom-elements/enqueue-custom-element-callback-reactions-inside-another-callback.html
@@ -0,0 +1,223 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Custom Elements: must enqueue an element on the appropriate element queue after checking callback is null and the attribute name</title>
+<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
+<meta name="assert" content="To enqueue a custom element callback reaction, the callback must be checked of being null and whether the attribute name is observed or not">
+<link rel="help" content="https://html.spec.whatwg.org/multipage/custom-elements.html#enqueue-a-custom-element-callback-reaction">
+<link rel="help" content="https://github.com/w3c/webcomponents/issues/760">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/custom-elements-helpers.js"></script>
+</head>
+<body>
+<script>
+
+test_with_window((contentWindow, contentDocument) => {
+    class ParentElement extends contentWindow.HTMLElement {
+        connectedCallback()
+        {
+            logs.push('begin');
+            const child = this.firstChild;
+            child.remove();
+            logs.push('end');
+        }
+    }
+    contentWindow.customElements.define('parent-element', ParentElement);
+
+    const logs = [];
+    class ChildElement extends contentWindow.HTMLElement {
+        connectedCallback() { logs.push('connected'); }
+        disconnectedCallback() { logs.push('disconnected'); }
+    }
+    contentWindow.customElements.define('child-element', ChildElement);
+
+    const parent = new ParentElement;
+    const child = new ChildElement;
+    parent.appendChild(child);
+
+    contentDocument.body.appendChild(parent);
+    assert_array_equals(logs, ['begin', 'connected', 'disconnected', 'end']);
+}, 'Disconnecting an element with disconnectedCallback while it has a connectedCallback in its custom element reaction queue must result in connectedCallback getting invoked before the removal completes');
+
+test_with_window((contentWindow, contentDocument) => {
+    class ParentElement extends contentWindow.HTMLElement {
+        connectedCallback()
+        {
+            logs.push('begin');
+            const child = this.firstChild;
+            child.remove();
+            logs.push('end');
+        }
+    }
+    contentWindow.customElements.define('parent-element', ParentElement);
+
+    const logs = [];
+    class ChildElement extends contentWindow.HTMLElement {
+        connectedCallback() { logs.push('connected'); }
+    }
+    contentWindow.customElements.define('child-element', ChildElement);
+
+    const parent = new ParentElement;
+    const child = new ChildElement;
+    parent.appendChild(child);
+
+    contentDocument.body.appendChild(parent);
+    assert_array_equals(logs, ['begin', 'end', 'connected']);
+}, 'Disconnecting an element without disconnectedCallback while it has a connectedCallback in its custom element reaction queue must not result in connectedCallback getting invoked before the removal completes');
+
+test_with_window((contentWindow, contentDocument) => {
+    class ParentElement extends contentWindow.HTMLElement {
+        disconnectedCallback()
+        {
+            logs.push('begin');
+            contentDocument.body.appendChild(this.firstChild);
+            logs.push('end');
+        }
+    }
+    contentWindow.customElements.define('parent-element', ParentElement);
+
+    const logs = [];
+    class ChildElement extends contentWindow.HTMLElement {
+        connectedCallback() { logs.push('connected'); }
+        disconnectedCallback() { logs.push('disconnected'); }
+    }
+    contentWindow.customElements.define('child-element', ChildElement);
+
+    const parent = new ParentElement;
+    const child = new ChildElement;
+    parent.appendChild(child);
+    contentDocument.body.appendChild(parent);
+    parent.remove();
+    assert_array_equals(logs, ['connected', 'begin', 'disconnected', 'connected', 'end']);
+}, 'Connecting a element with connectedCallback while it has a disconnectedCallback in its custom element reaction queue must result in disconnectedCallback getting invoked before the insertion completes');
+
+test_with_window((contentWindow, contentDocument) => {
+    class ParentElement extends contentWindow.HTMLElement {
+        disconnectedCallback()
+        {
+            logs.push('begin');
+            contentDocument.body.appendChild(this.firstChild);
+            logs.push('end');
+        }
+    }
+    contentWindow.customElements.define('parent-element', ParentElement);
+
+    const logs = [];
+    class ChildElement extends contentWindow.HTMLElement {
+        disconnectedCallback() { logs.push('disconnected'); }
+    }
+    contentWindow.customElements.define('child-element', ChildElement);
+
+    const parent = new ParentElement;
+    const child = new ChildElement;
+    parent.appendChild(child);
+    contentDocument.body.appendChild(parent);
+    parent.remove();
+    assert_array_equals(logs, ['begin', 'end', 'disconnected']);
+}, 'Connecting an element without connectedCallback while it has a disconnectedCallback in its custom element reaction queue must not result in disconnectedCallback getting invoked before the insertion completes');
+
+test_with_window((contentWindow, contentDocument) => {
+    class ParentElement extends contentWindow.HTMLElement {
+        connectedCallback()
+        {
+            logs.push('begin');
+            document.adoptNode(this.firstChild);
+            logs.push('end');
+        }
+    }
+    contentWindow.customElements.define('parent-element', ParentElement);
+
+    const logs = [];
+    class ChildElement extends contentWindow.HTMLElement {
+        adoptedCallback() { logs.push('adopted'); }
+        connectedCallback() { logs.push('connected'); }
+    }
+    contentWindow.customElements.define('child-element', ChildElement);
+
+    const parent = new ParentElement;
+    const child = new ChildElement;
+    parent.appendChild(child);
+    contentDocument.body.appendChild(parent);
+    assert_array_equals(logs, ['begin', 'connected', 'adopted', 'end']);
+}, 'Adopting an element with adoptingCallback while it has a connectedCallback in its custom element reaction queue must result in connectedCallback getting invoked before the adoption completes');
+
+test_with_window((contentWindow, contentDocument) => {
+    class ParentElement extends contentWindow.HTMLElement {
+        connectedCallback()
+        {
+            logs.push('begin');
+            document.adoptNode(this.firstChild);
+            logs.push('end');
+        }
+    }
+    contentWindow.customElements.define('parent-element', ParentElement);
+
+    const logs = [];
+    class ChildElement extends contentWindow.HTMLElement {
+        connectedCallback() { logs.push('connected'); }
+    }
+    contentWindow.customElements.define('child-element', ChildElement);
+
+    const parent = new ParentElement;
+    const child = new ChildElement;
+    parent.appendChild(child);
+    contentDocument.body.appendChild(parent);
+    assert_array_equals(logs, ['begin', 'end', 'connected']);
+}, 'Adopting an element without adoptingCallback while it has a connectedCallback in its custom element reaction queue must not result in connectedCallback getting invoked before the adoption completes');
+
+test_with_window((contentWindow, contentDocument) => {
+    class ParentElement extends contentWindow.HTMLElement {
+        connectedCallback()
+        {
+            logs.push('begin');
+            this.firstChild.setAttribute('title', 'foo');
+            logs.push('end');
+        }
+    }
+    contentWindow.customElements.define('parent-element', ParentElement);
+
+    const logs = [];
+    class ChildElement extends contentWindow.HTMLElement {
+        attributeChangedCallback() { logs.push('attributeChanged'); }
+        connectedCallback() { logs.push('connected'); }
+        static get observedAttributes() { return ['title']; }
+    }
+    contentWindow.customElements.define('child-element', ChildElement);
+
+    const parent = new ParentElement;
+    const child = new ChildElement;
+    parent.appendChild(child);
+    contentDocument.body.appendChild(parent);
+    assert_array_equals(logs, ['begin', 'connected', 'attributeChanged', 'end']);
+}, 'Setting an observed attribute on an element with attributeChangedCallback while it has a connectedCallback in its custom element reaction queue must result in connectedCallback getting invoked before the attribute change completes');
+
+test_with_window((contentWindow, contentDocument) => {
+    class ParentElement extends contentWindow.HTMLElement {
+        connectedCallback()
+        {
+            logs.push('begin');
+            this.firstChild.setAttribute('lang', 'en');
+            logs.push('end');
+        }
+    }
+    contentWindow.customElements.define('parent-element', ParentElement);
+
+    const logs = [];
+    class ChildElement extends contentWindow.HTMLElement {
+        attributeChangedCallback() { logs.push('attributeChanged'); }
+        connectedCallback() { logs.push('connected'); }
+        static get observedAttributes() { return ['title']; }
+    }
+    contentWindow.customElements.define('child-element', ChildElement);
+
+    const parent = new ParentElement;
+    const child = new ChildElement;
+    parent.appendChild(child);
+    contentDocument.body.appendChild(parent);
+    assert_array_equals(logs, ['begin', 'end', 'connected']);
+}, 'Setting an observed attribute on an element with attributeChangedCallback while it has a connectedCallback in its custom element reaction queue must not result in connectedCallback getting invoked before the attribute change completes');
+
+</script>
+</body>
+</html>