Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Unified Diff: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/parser/parser-uses-constructed-element.html

Issue 2446483002: Import wpt@c5a14f553cba5f197743b9af605a84eddd8692a2 (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/parser/parser-uses-constructed-element.html
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/parser/parser-uses-constructed-element.html b/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/parser/parser-uses-constructed-element.html
new file mode 100644
index 0000000000000000000000000000000000000000..393bbec698b6021c78064cf30a712ea6994d0141
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/parser/parser-uses-constructed-element.html
@@ -0,0 +1,75 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Custom Elements: HTML parser must construct a custom element instead of upgrading</title>
+<meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
+<meta name="assert" content="HTML parser must construct a custom element instead of upgrading">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<link rel="help" href="https://html.spec.whatwg.org/#create-an-element-for-the-token">
+<link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element">
+</head>
+<body>
+<div id="log"></div>
+<script>
+
+let anotherElementCreatedBeforeSuperCall = undefined;
+let elementCreatedBySuperCall = undefined;
+let shouldCreateElementBeforeSuperCall = true;
+class InstantiatesItselfBeforeSuper extends HTMLElement {
+ constructor() {
+ if (shouldCreateElementBeforeSuperCall) {
+ shouldCreateElementBeforeSuperCall = false;
+ anotherElementCreatedBeforeSuperCall = new InstantiatesItselfBeforeSuper();
+ }
+ super();
+ elementCreatedBySuperCall = this;
+ }
+};
+customElements.define('instantiates-itself-before-super', InstantiatesItselfBeforeSuper);
+
+let shouldCreateAnotherInstance = true;
+let anotherInstance = undefined;
+let firstInstance = undefined;
+class ReturnsAnotherInstance extends HTMLElement {
+ constructor() {
+ super();
+ if (shouldCreateAnotherInstance) {
+ shouldCreateAnotherInstance = false;
+ firstInstance = this;
+ anotherInstance = new ReturnsAnotherInstance;
+ return anotherInstance;
+ } else
+ return this;
+ }
+};
+customElements.define('returns-another-instance', ReturnsAnotherInstance);
+
+</script>
+<instantiates-itself-before-super></instantiates-itself-before-super>
+<returns-another-instance></returns-another-instance>
+<script>
+
+test(function () {
+ var instance = document.querySelector('instantiates-itself-before-super');
+
+ assert_equals(instance instanceof InstantiatesItselfBeforeSuper, 'HTML parser must insert the synchronously constructed custom element');
+ assert_equals(instance, elementCreatedBySuperCall, 'HTML parser must insert the element returned by the custom element constructor');
+ assert_not_equals(instance, anotherElementCreatedBeforeSuperCall, 'HTML parser must not insert another instance of the custom element created before super() call');
+ assert_equals(anotherElementCreatedBeforeSuperCall.parentNode, null, 'HTML parser must not insert another instance of the custom element created before super() call');
+
+}, 'HTML parser must use the returned value of the custom element constructor instead of the one created before super() call');
+
+test(function () {
+ var instance = document.querySelector('returns-another-instance');
+
+ assert_equals(instance instanceof ReturnsAnotherInstance, 'HTML parser must insert the synchronously constructed custom element');
+ assert_equals(instance, anotherInstance, 'HTML parser must insert the element returned by the custom element constructor');
+ assert_not_equals(instance, firstInstance, 'HTML parser must not insert the element created by super() call if the constructor returned another element');
+ assert_equals(firstInstance.parentNode, null, 'HTML parser must not insert the element created by super() call if the constructor returned another element');
+
+}, 'HTML parser must use the returned value of the custom element constructor instead using the one created in super() call');
+
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698