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

Side by Side Diff: third_party/WebKit/LayoutTests/imported/wpt/custom-elements/parser/parser-uses-registry-of-owner-document.html

Issue 2446483002: Import wpt@c5a14f553cba5f197743b9af605a84eddd8692a2 (Closed)
Patch Set: 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: HTML parser must use the owner document's custom element registry</title>
5 <meta name="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
6 <meta name="assert" content="HTML parser must use the owner document's custom el ement registry">
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 class MyCustomElement extends HTMLElement { };
17 customElements.define('my-custom-element', MyCustomElement);
18
19 document.write('<template><my-custom-element></my-custom-element></template>');
20
21 test(function () {
22 var template = document.querySelector('template');
23 var instance = template.content.firstChild;
24
25 assert_true(instance instanceof HTMLElement,
26 'A custom element inside a template element must be an instance of HTMLE lement');
27 assert_false(instance instanceof MyCustomElement,
28 'A custom element must not be instantiated inside a template element usi ng the registry of the template element\'s owner document');
29 assert_equals(instance.ownerDocument, template.content.ownerDocument,
30 'Custom elements inside a template must use the appropriate template con tents owner document as the owner document');
31
32 }, 'HTML parser must not instantiate custom elements inside template elements');
33
34 var iframe = document.createElement('iframe');
35 document.body.appendChild(iframe);
36 iframe.contentDocument.body.innerHTML = '<my-custom-element></my-custom-element> ';
37
38 test(function () {
39 var instance = iframe.contentDocument.querySelector('my-custom-element');
40
41 assert_true(instance instanceof iframe.contentWindow.HTMLElement);
42 assert_false(instance instanceof MyCustomElement);
43
44 }, 'HTML parser must not use the registry of the owner element\'s document insid e an iframe');
45
46 class ElementInIFrame extends iframe.contentWindow.HTMLElement { };
47 iframe.contentWindow.customElements.define('element-in-iframe', ElementInIFrame) ;
48 iframe.contentDocument.body.innerHTML = '<element-in-iframe></element-in-iframe> ';
49
50 test(function () {
51 var instance = iframe.contentDocument.querySelector('element-in-iframe');
52
53 assert_true(instance instanceof iframe.contentWindow.HTMLElement, 'A custom element inside an iframe must be an instance of HTMLElement');
54 assert_true(instance instanceof ElementInIFrame,
55 'A custom element must be instantiated inside an iframe using the regist ry of the content document');
56 assert_equals(instance.ownerDocument, iframe.contentDocument,
57 'The owner document of custom elements inside an iframe must be the cont ent document of the iframe');
58
59 }, 'HTML parser must use the registry of the content document inside an iframe') ;
60
61 document.write('<element-in-iframe></element-in-iframe>');
62
63 test(function () {
64 var instance = document.querySelector('element-in-iframe');
65
66 assert_true(instance instanceof HTMLElement);
67 assert_false(instance instanceof ElementInIFrame);
68
69 }, 'HTML parser must not instantiate a custom element defined inside an frame in frame element\'s owner document');
70
71 document.body.removeChild(iframe);
72
73 test(function () {
74 var windowlessDocument = document.implementation.createHTMLDocument();
75 windowlessDocument.open();
76 windowlessDocument.write('<my-custom-element></my-custom-element>');
77 windowlessDocument.close();
78
79 var instance = windowlessDocument.querySelector('my-custom-element');
80
81 assert_true(instance instanceof HTMLElement);
82 assert_false(instance instanceof MyCustomElement);
83
84 }, 'HTML parser must use the registry of window.document in a document created b y document.implementation.createHTMLDocument()');
85
86 test(function () {
87 var windowlessDocument = document.implementation.createDocument ('http://www .w3.org/1999/xhtml', 'html', null);
88 windowlessDocument.documentElement.innerHTML = '<my-custom-element></my-cust om-element>';
89
90 var instance = windowlessDocument.querySelector('my-custom-element');
91 assert_true(instance instanceof HTMLElement);
92 assert_false(instance instanceof MyCustomElement);
93
94 }, 'HTML parser must use the registry of window.document in a document created b y document.implementation.createXHTMLDocument()');
95
96 test(function () {
97 var windowlessDocument = new Document;
98 windowlessDocument.appendChild(windowlessDocument.createElement('html'));
99 windowlessDocument.documentElement.innerHTML = '<my-custom-element></my-cust om-element>';
100
101 var instance = windowlessDocument.querySelector('my-custom-element');
102
103 assert_true(instance instanceof Element);
104 assert_false(instance instanceof MyCustomElement);
105
106 }, 'HTML parser must use the registry of window.document in a document created b y new Document');
107
108 promise_test(function () {
109 return new Promise(function (resolve, reject) {
110 var xhr = new XMLHttpRequest();
111 xhr.open('GET', '../resources/empty-html-document.html');
112 xhr.overrideMimeType('text/xml');
113 xhr.onload = function () { resolve(xhr.responseXML); }
114 xhr.onerror = function () { reject('Failed to fetch the document'); }
115 xhr.send();
116 }).then(function (doc) {
117 doc.documentElement.innerHTML = '<my-custom-element></my-custom-element> ';
118 var instance = doc.querySelector('my-custom-element');
119 assert_true(instance instanceof Element);
120 assert_false(instance instanceof MyCustomElement);
121 });
122 }, 'HTML parser must use the registry of window.document in a document created b y XMLHttpRequest');
123
124 </script>
125 </body>
126 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698