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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/HTMLElement-constructor.html

Issue 2360123002: Import wpt@3801ab5834101113e5f53bfb57e3c76b2b87ecbb (Closed)
Patch Set: Mark the failing test to Win only 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 unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>Custom Elements: HTMLElement must allow subclassing</title>
5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
6 <meta name="assert" content="HTMLElement must allow subclassing">
7 <link rel="help" href="https://html.spec.whatwg.org/#html-element-constructors">
8 <script src="/resources/testharness.js"></script>
9 <script src="/resources/testharnessreport.js"></script>
10 </head>
11 <body>
12 <div id="log"></div>
13 <script>
14
15 test(function () {
16 customElements.define('html-custom-element', HTMLElement);
17 assert_throws({'name': 'TypeError'}, function () { new HTMLElement(); });
18 }, 'HTMLElement constructor must throw a TypeError when NewTarget is equal to it self');
19
20 test(function () {
21 customElements.define('html-proxy-custom-element', new Proxy(HTMLElement, {} ));
22 assert_throws({'name': 'TypeError'}, function () { new HTMLElement(); });
23 }, 'HTMLElement constructor must throw a TypeError when NewTarget is equal to it self via a Proxy object');
24
25 test(function () {
26 class SomeCustomElement extends HTMLElement {};
27 assert_throws({'name': 'TypeError'}, function () { new SomeCustomElement; }) ;
28 }, 'HTMLElement constructor must throw TypeError when it has not been defined by customElements.define');
29
30 test(function () {
31 class CustomElementWithInferredTagName extends HTMLElement {};
32 customElements.define('inferred-name', CustomElementWithInferredTagName);
33
34 var instance = new CustomElementWithInferredTagName;
35 assert_true(instance instanceof Element, 'A custom element must inherit from Element');
36 assert_true(instance instanceof Node, 'A custom element must inherit from No de');
37 assert_equals(instance.localName, 'inferred-name');
38 assert_equals(instance.nodeName, 'INFERRED-NAME');
39 assert_equals(instance.namespaceURI, 'http://www.w3.org/1999/xhtml', 'A cust om HTML element must use HTML namespace');
40
41 document.body.appendChild(instance);
42 assert_equals(document.body.lastChild, instance,
43 'document.body.appendChild must be able to insert a custom element');
44 assert_equals(document.querySelector('inferred-name'), instance,
45 'document.querySelector must be able to find a custom element by its tag name');
46
47 }, 'HTMLElement constructor must infer the tag name from the element interface') ;
48
49 test(function () {
50 class ConcreteCustomElement extends HTMLElement { };
51 class SubCustomElement extends ConcreteCustomElement { };
52 customElements.define('concrete-custom-element', ConcreteCustomElement);
53 customElements.define('sub-custom-element', SubCustomElement);
54
55 var instance = new ConcreteCustomElement();
56 assert_true(instance instanceof ConcreteCustomElement);
57 assert_false(instance instanceof SubCustomElement);
58 assert_equals(instance.localName, 'concrete-custom-element');
59 assert_equals(instance.nodeName, 'CONCRETE-CUSTOM-ELEMENT');
60
61 var instance = new SubCustomElement();
62 assert_true(instance instanceof ConcreteCustomElement);
63 assert_true(instance instanceof SubCustomElement);
64 assert_equals(instance.localName, 'sub-custom-element');
65 assert_equals(instance.nodeName, 'SUB-CUSTOM-ELEMENT');
66
67 }, 'HTMLElement constructor must allow subclassing a custom element');
68
69 test(function () {
70 class AbstractCustomElement extends HTMLElement { };
71 class ConcreteSubCustomElement extends AbstractCustomElement { };
72 customElements.define('concrete-sub-custom-element', ConcreteSubCustomElemen t);
73
74 var instance = new ConcreteSubCustomElement();
75 assert_true(instance instanceof AbstractCustomElement);
76 assert_true(instance instanceof ConcreteSubCustomElement);
77 assert_equals(instance.localName, 'concrete-sub-custom-element');
78 assert_equals(instance.nodeName, 'CONCRETE-SUB-CUSTOM-ELEMENT');
79
80 }, 'HTMLElement constructor must allow subclassing an user-defined subclass of H TMLElement');
81
82 </script>
83 </body>
84 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698