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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/parser/parser-sets-attributes-and-children.html

Issue 2434563008: Import wpt@26c8d4e87448d1c4e5ebf2ddb4917c0633c201db (Closed)
Patch Set: Mark one more test as potentially timing out Created 4 years, 1 month 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: Changes to the HTML parser</title>
5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
6 <meta name="assert" content="HTML parser must set the attributes and append the children on a custom element">
7 <link rel="help" href="https://html.spec.whatwg.org/#create-an-element-for-the-t oken">
8 <link rel="help" href="https://dom.spec.whatwg.org/#concept-create-element">
9 <script src="/resources/testharness.js"></script>
10 <script src="/resources/testharnessreport.js"></script>
11 </head>
12 <body>
13 <div id="log"></div>
14 <script>
15
16 var numberOfAttributesInConstructor;
17 var numberOfChildNodesInConstructor;
18
19 class MyCustomElement extends HTMLElement {
20 constructor(...args) {
21 super(...args);
22 numberOfAttributesInConstructor = this.attributes.length;
23 numberOfChildNodesInConstructor = this.childNodes.length;
24 }
25 };
26 customElements.define('my-custom-element', MyCustomElement);
27
28 </script>
29 <my-custom-element id="custom-element-id" class="class1 class2">hello <b>world</ b></my-custom-element>
30 <script>
31
32 var customElement = document.querySelector('my-custom-element');
33
34 test(function () {
35 assert_equals(customElement.getAttribute('id'), 'custom-element-id', 'HTML p arser must preserve the id attribute');
36 assert_equals(customElement.id, 'custom-element-id', 'HTML parser must prese rve the semantics of reflect for the id attribute');
37 assert_equals(customElement.getAttribute('class'), 'class1 class2', 'HTML pa rser must preserve the class attribute');
38 assert_equals(customElement.classList.length, 2, 'HTML parser must initializ e classList on custom elements');
39 assert_equals(customElement.classList[0], 'class1', 'HTML parser must initia lize classList on custom elements');
40 assert_equals(customElement.classList[1], 'class2', 'HTML parser must initia lize classList on custom elements');
41 }, 'HTML parser must set the attributes');
42
43 test(function () {
44 assert_equals(customElement.childNodes.length, 2, 'HTML parser must append c hild nodes');
45 assert_true(customElement.firstChild instanceof Text, 'HTML parser must appe nd Text node child to a custom element');
46 assert_equals(customElement.firstChild.data, 'hello ', 'HTML parser must app end Text node child to a custom element');
47 assert_true(customElement.lastChild instanceof HTMLElement, 'HTML parser mus t append a builtin element child to a custom element');
48 assert_true(customElement.lastChild.firstChild instanceof Text, 'HTML parser must preserve grandchild nodes of a custom element');
49 assert_equals(customElement.lastChild.firstChild.data, 'world', 'HTML parser must preserve grandchild nodes of a custom element');
50 }, 'HTML parser must append child nodes');
51
52 test(function () {
53 assert_equals(numberOfAttributesInConstructor, 0, 'HTML parser must not set attributes on a custom element before invoking the constructor');
54 assert_equals(numberOfChildNodesInConstructor, 0, 'HTML parser must not appe nd child nodes to a custom element before invoking the constructor');
55 }, 'HTML parser must set the attributes or append children before calling constr uctor');
56
57 </script>
58 </body>
59 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698