Skip to content

Commit 1f33822

Browse files
EdgarChenTakayoshi Kochi
authored and
Takayoshi Kochi
committed
Fix data document tests in custom-elements/parser/parser-uses-registry-of-owner-document.html (web-platform-tests#8537)
* Change to use DOMParser to test data document * Add test for a custom element appearing in an XMLHttpRequest response body
1 parent 6df9808 commit 1f33822

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

custom-elements/parser/parser-uses-registry-of-owner-document.html

+9-8
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,14 @@
7171
document.body.removeChild(iframe);
7272

7373
test(function () {
74-
var windowlessDocument = document.implementation.createHTMLDocument();
75-
windowlessDocument.open();
76-
windowlessDocument.write('<my-custom-element></my-custom-element>');
77-
windowlessDocument.close();
74+
var windowlessDocument = (new DOMParser()).parseFromString('<my-custom-element></my-custom-element>', "text/html");
7875

7976
var instance = windowlessDocument.querySelector('my-custom-element');
8077

8178
assert_true(instance instanceof HTMLElement);
8279
assert_false(instance instanceof MyCustomElement);
8380

84-
}, 'HTML parser must use the registry of window.document in a document created by document.implementation.createHTMLDocument()');
81+
}, 'HTML parser must use the registry of window.document in a document created by DOMParser');
8582

8683
test(function () {
8784
var windowlessDocument = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
@@ -108,16 +105,20 @@
108105
promise_test(function () {
109106
return new Promise(function (resolve, reject) {
110107
var xhr = new XMLHttpRequest();
111-
xhr.open('GET', '../resources/empty-html-document.html');
108+
xhr.open('GET', '../resources/my-custom-element-html-document.html');
112109
xhr.overrideMimeType('text/xml');
113110
xhr.onload = function () { resolve(xhr.responseXML); }
114111
xhr.onerror = function () { reject('Failed to fetch the document'); }
115112
xhr.send();
116113
}).then(function (doc) {
117-
doc.documentElement.innerHTML = '<my-custom-element></my-custom-element>';
118114
var instance = doc.querySelector('my-custom-element');
119115
assert_true(instance instanceof Element);
120-
assert_false(instance instanceof MyCustomElement);
116+
assert_false(instance instanceof MyCustomElement);
117+
118+
doc.documentElement.innerHTML = '<my-custom-element></my-custom-element>';
119+
var instance2 = doc.querySelector('my-custom-element');
120+
assert_true(instance2 instanceof Element);
121+
assert_false(instance2 instanceof MyCustomElement);
121122
});
122123
}, 'HTML parser must use the registry of window.document in a document created by XMLHttpRequest');
123124

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<my-custom-element></my-custom-element>
5+
</body>
6+
</html>

0 commit comments

Comments
 (0)