Index: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/upgrading-parser-created-element.html |
diff --git a/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/upgrading-parser-created-element.html b/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/upgrading-parser-created-element.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7cc3b18aeefb8db55bcac7ac1cf321c1b5fff28c |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/imported/wpt/custom-elements/upgrading/upgrading-parser-created-element.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> |