promise_test(() => {
return fetch("resources/content-types.json").then(res => res.json()).then(runTests);
}, "Loading JSONā¦");
function runTests(tests) {
tests.forEach(testUnit => {
runFrameTest(testUnit, false);
runFrameTest(testUnit, true);
runFetchTest(testUnit, false);
runFetchTest(testUnit, true);
runRequestResponseTest(testUnit, "Request");
runRequestResponseTest(testUnit, "Response");
});
}
function runFrameTest(testUnit, singleHeader) {
// Note: window.js is always UTF-8
const encoding = testUnit.encoding !== null ? testUnit.encoding : "UTF-8";
async_test(t => {
const frame = document.body.appendChild(document.createElement("iframe"));
t.add_cleanup(() => frame.remove());
frame.src = getURL(testUnit.contentType, singleHeader);
frame.onload = t.step_func_done(() => {
// Edge requires toUpperCase()
const doc = frame.contentDocument;
assert_equals(doc.characterSet.toUpperCase(), encoding.toUpperCase());
if (testUnit.documentContentType === "text/plain") {
assert_equals(doc.body.textContent, "hi\n");
} else if (testUnit.documentContentType === "text/html") {
assert_equals(doc.body.firstChild.localName, "b");
assert_equals(doc.body.firstChild.textContent, "hi");
}
assert_equals(doc.contentType, testUnit.documentContentType);
});
}, getDesc("