<!DOCTYPE html>
<title>document.contentType</title>
<link rel="help" href="https://dom.spec.whatwg.org/#dom-document-contenttype">
<script src="../../resources/js-test.js"></script>
<body>
<p>
<iframe data-mt="text/html"></iframe>
<iframe data-mt="text/xml"></iframe>
<iframe data-mt="application/xml"></iframe>
<iframe data-mt="image/svg+xml"></iframe>
</p>
<script>
window.jsTestIsAsync = true;
var events = [];
window.onmessage = function(e) {
// For consistent ordering, we capture the events, sort them and then test them.
if (e.data)
events.push(e);
else
testFailed("Null message payload");
if (--expectedMessagesCount == 0) {
events.sort((e1, e2) => {
if (e1.data.obtained < e2.data.obtained) {
return -1;
} if (e1.data.obtained > e2.data.obtained) {
return 1;
} else {
return 0;
}
});
for (var i in events) {
var e = events[i];
shouldBe('"' + e.data.obtained + '"', '"' + e.data.expected + '"');
}
finishJSTest();
}
};
var documentContents = '<script xmlns="http://www.w3.org/1999/xhtml">' +
'parent.postMessage(' +
'{obtained: document.contentType, expected: "{0}"}, "*");' +
'<' + '/script>';
var iframes = document.getElementsByTagName('iframe');
for (var k = 0, f; f = iframes[k]; k++) {
f.src = 'data:' + f.dataset.mt + ',' +
encodeURIComponent(documentContents.replace('{0}', f.dataset.mt));
}
var expectedMessagesCount = iframes.length;
</script>