Commit 1252ba16 authored by Dominic Farolino's avatar Dominic Farolino Committed by Commit Bot

Add initial resource load priority layout tests

R=kinuko@chromium.org, kouhei@chromium.org, yhirano@chromium.org, yoav@yoav.ws

Bug: 882344
Change-Id: I42e264f9fc1591129091aa9f18b258a4e2313181
Reviewed-on: https://chromium-review.googlesource.com/c/1249400
Commit-Queue: Dominic Farolino <domfarolino@gmail.com>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604181}
parent 9e93f760
<title>ResourceLoadPriority tests</title>
<script src="resources/common.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
function openWindow(url) {
const win = window.open(url, '_blank');
add_result_callback(() => win.close());
return win;
}
function resource_load_priority_test(windowURL, expected_priority, description) {
promise_test(async () => {
openWindow('resources/' + windowURL);
const priority_event =
await new Promise(resolve => window.onmessage = resolve);
assert_not_equals(priority_event.data,
'FAILED',
'The resource failed to load for some reason.');
assert_equals(priority_event.data, expected_priority);
}, description);
}
resource_load_priority_test(
'off-screen-image.html', kLow,
'Off-screen images should be loaded with kLow priority');
resource_load_priority_test(
'render-blocking-stylesheet.html', kVeryHigh,
'Render-blocking style sheets should be loaded with kVeryHigh priority');
resource_load_priority_test(
'parser-blocking-script.html', kHigh,
'Parser-blocking scripts should be loaded with kHigh priority');
resource_load_priority_test(
'async-script.html', kHigh,
'Async scripts should be loaded with kLow priority');
resource_load_priority_test(
'defer-script.html', kHigh,
'Deferred scripts should be loaded with kLow priority');
resource_load_priority_test(
'module-script.html', kHigh,
'Module scripts should be loaded with kHigh priority');
resource_load_priority_test(
'iframe.html', kVeryHigh, 'Iframes should be loaded with kVeryHigh priority');
resource_load_priority_test(
'fetch.html', kHigh,
'Requests from the Fetch API should be loaded with kHigh priority');
resource_load_priority_test(
'xhr.html', kHigh, 'XHRs should be loaded with kHigh priority');
resource_load_priority_test(
'sync-xhr.html', kVeryHigh,
'Synchronous XHRs should be loaded with kVeryHigh priority');
// Preload tests.
resource_load_priority_test(
'preload/as-style.html', kVeryHigh,
'Preloaded style sheets should be loaded with kVeryHigh priority');
resource_load_priority_test(
'preload/as-script.html', kHigh,
'Preloaded scripts should be loaded with kHigh priority');
resource_load_priority_test(
'preload/as-font.html', kHigh,
'Preloaded fonts should be loaded with kHigh priority');
resource_load_priority_test(
'preload/as-audio.html', kLow,
'Preloaded audio files should be loaded with kLow priority');
resource_load_priority_test(
'preload/as-video.html', kLow,
'Preloaded videos should be loaded with kLow priority');
resource_load_priority_test(
'preload/as-fetch.html', kHigh,
'Preloaded fetches should be loaded with kHigh priority');
resource_load_priority_test(
'preload/as-image.html', kLow,
'Preloaded images should be loaded with kLow priority');
</script>
<script src="common.js"></script>
<script src="../../resources/dummy.js" async onload="reportPriority(this.src)" onerror="reportFailure()"></script>
/**
* These values map to some of the the current
* priority enum members in blink::ResourceLoadPriority.
* The values are exposed through window.internals
* and in these tests, we use the below variables to represent
* the exposed values in a readable way.
*/
const kLow = 1,
kMedium = 2,
kHigh = 3,
kVeryHigh = 4;
function reportPriority(url, optionalDoc) {
const documentToUse = optionalDoc ? optionalDoc : document;
const loadPriority = internals.getResourcePriority(url, documentToUse);
window.opener.postMessage(loadPriority, '*');
}
function reportFailure() {
window.opener.postMessage('FAILED', '*');
}
<script src="common.js"></script>
<script src="../../resources/dummy.js" defer onload="reportPriority(this.src)" onerror="reportFailure()"></script>
<script src="common.js"></script>
<script>
fetch('../../resources/dummy.html')
.then(response => {
reportPriority(response.url);
})
.catch(() => {
reportFailure();
});
</script>
<script src="common.js"></script>
<iframe src="../../resources/dummy.html" onload="reportPriority(this.src, this.contentDocument)" onerror="reportFailure()"></iframe>
<script src="common.js"></script>
<script src="../../resources/dummy.js" type=module onload="reportPriority(this.src)" onerror="reportFailure()"></script>
<script src="common.js"></script>
<script>
const image = new Image();
image.src = '../../resources/square.png';
image.onload = e => {
reportPriority(image.src);
};
image.onerror = e => reportFailure;
</script>
<script src="common.js"></script>
<script src="../../resources/dummy.js" onload="reportPriority(this.src)" onerror="reportFailure()"></script>
<script src="../common.js"></script>
<link rel="preload" as="audio" href="../../../resources/test.wav" type="audio/wav" onload="reportPriority(this.href)" onerror="reportFailure()"></script>
<script src="../common.js"></script>
<link rel="preload" as="fetch" href=../../../resources/dummy.html onload="reportPriority(this.href)" onerror="reportFailure()"></script>
<script src="../common.js"></script>
<link rel="preload" as="font" href=../../../resources/Ahem.ttf type="font/ttf" onload="reportPriority(this.href)" onerror="reportFailure()">
<script src="../common.js"></script>
<link rel="preload" as="image" href="../../../resources/square.png" onload="reportPriority(this.href)" onerror="reportFailure()"></script>
<script src="../common.js"></script>
<link rel="preload" as="script" href="../../../resources/dummy.js" onload="reportPriority(this.href)" onerror="reportFailure()"></script>
<script src="../common.js"></script>
<!-- Media-matching style sheets block rendering, and are critical -->
<link rel="preload" as="style" href="../../../resources/dummy.css" onload="reportPriority(this.href)" onerror="reportFailure()">
<script src="../common.js"></script>
<link rel="preload" as="video" href=../../../resources/test.mp4 type="video/mp4" onload="reportPriority(this.href)" onerror="reportFailure()"></script>
<script src="common.js"></script>
<!-- Media-matching style sheets block rendering, and are critical -->
<link rel="stylesheet" href="../../resources/dummy.css" onload="reportPriority(this.href)" onerror="reportFailure()">
<script src="common.js"></script>
<script>
const xhr = new XMLHttpRequest();
xhr.open('GET', '../../resources/dummy.html', false);
xhr.send();
if (xhr.status === 200)
reportPriority(xhr.responseURL);
else
reportFailure();
</script>
<script src="common.js"></script>
<script>
const xhr = new XMLHttpRequest();
xhr.open('GET', '../../resources/dummy.html');
xhr.send();
xhr.onload = e => {
reportPriority(xhr.responseURL);
}
xhr.onerror = reportFailure;
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment