Skip to content

Commit

Permalink
Fix data document tests in custom-elements/parser/parser-uses-registr…
Browse files Browse the repository at this point in the history
…y-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
  • Loading branch information
EdgarChen authored and Takayoshi Kochi committed Dec 4, 2017
1 parent 6df9808 commit 1f33822
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@
document.body.removeChild(iframe);

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

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

assert_true(instance instanceof HTMLElement);
assert_false(instance instanceof MyCustomElement);

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

test(function () {
var windowlessDocument = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null);
Expand All @@ -108,16 +105,20 @@
promise_test(function () {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('GET', '../resources/empty-html-document.html');
xhr.open('GET', '../resources/my-custom-element-html-document.html');
xhr.overrideMimeType('text/xml');
xhr.onload = function () { resolve(xhr.responseXML); }
xhr.onerror = function () { reject('Failed to fetch the document'); }
xhr.send();
}).then(function (doc) {
doc.documentElement.innerHTML = '<my-custom-element></my-custom-element>';
var instance = doc.querySelector('my-custom-element');
assert_true(instance instanceof Element);
assert_false(instance instanceof MyCustomElement);
assert_false(instance instanceof MyCustomElement);

doc.documentElement.innerHTML = '<my-custom-element></my-custom-element>';
var instance2 = doc.querySelector('my-custom-element');
assert_true(instance2 instanceof Element);
assert_false(instance2 instanceof MyCustomElement);
});
}, 'HTML parser must use the registry of window.document in a document created by XMLHttpRequest');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html>
<body>
<my-custom-element></my-custom-element>
</body>
</html>

0 comments on commit 1f33822

Please sign in to comment.