Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!DOCTYPE html>
<meta charset=utf-8>
<title>Makes sure that Link headers preload resources in non-HTML documents</title>
<meta name="timeout" content="long">
<script src="resources/dummy.js?link-header-preload2"></script>
<script src="/common/utils.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/preload/resources/preload_helper.js"></script>
function test_document_type(options, desc) {
promise_test(async t => {
const id = token();
const preloadLink = `/html/semantics/document-metadata/the-link-element/${id}`;
const params = new URLSearchParams();
for (const opt in options)
params.set(opt, options[opt]);
params.set('link', `<${preloadLink}>;rel=preload;as=style`);
const docURL = getAbsoluteURL(`./resources/${params.toString()}`);
const iframe = document.createElement('iframe');
t.add_cleanup(() => iframe.remove());
iframe.src = docURL;
await new Promise(resolve => iframe.addEventListener('load', resolve));
const timeout = 5000;
const interval = 25;
let count = 0;
const before =;
while ( < before + timeout) {
// count=true returns the number of times the resource was accessed
const res = await fetch(preloadLink + '&count=true');
// If count is positive, the resource was accessed.
count = Number(await res.text());
if (count > 0)
await new Promise(resolve => t.step_timeout(resolve, interval));
assert_equals(count, 1, "verify that request was issued exactly once");
}, `${desc} documents should respect preload Link headers`);
type: 'application/xml',
content: `<?xml version="1.0" encoding="utf-8"?>
</html>`}, "XHTML");
test_document_type({content: 'Hello', type: 'text/plain'}, 'plain text');
test_document_type({file: 'square.png', type: 'image/png'}, 'image');
test_document_type({file: 'white.mp4', type: 'video/mp4'}, 'media');
test_document_type({content: 'dummy', type: 'image/png'}, 'invalid image');