Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

  • This test has a WPT meta file that expects 1 subtest issues.
  • This WPT test may be referenced by the following Test IDs:
<!DOCTYPE html>
<meta charset="utf-8">
<title>PageHideEvent speculations - used preloads are included</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Test that used preloads are reported in the pagehide event.
function isPageHideSpeculationsEnabled() {
return 'PageHideEvent' in window;
}
promise_test(async t => {
assert_true(isPageHideSpeculationsEnabled(),
"PageHideSpeculations feature must be enabled for these tests");
}, "PageHideSpeculations feature check");
promise_test(async t => {
if (!isPageHideSpeculationsEnabled()) {
return;
}
// This page has a preload that IS used
const iframe = document.createElement('iframe');
iframe.src = "support/page-with-used-preload-and-reporter.html";
document.body.appendChild(iframe);
t.add_cleanup(() => iframe.remove());
await new Promise(resolve => {
iframe.onload = resolve;
});
const result = await new Promise((resolve, reject) => {
const timeoutId = setTimeout(() => {
reject(new Error("pagehide event did not fire within timeout"));
}, 5000);
window.pagehideCallback = function(data) {
clearTimeout(timeoutId);
window.pagehideCallback = null;
resolve(data);
};
iframe.src = "support/blank.html";
});
assert_not_equals(result.speculations, null,
"speculations should not be null");
assert_not_equals(result.speculations, undefined,
"speculations should not be undefined");
const preloads = result.speculations.preloads;
assert_equals(preloads.length, 1,
"should have exactly one preload entry");
const preload = preloads[0];
assert_true(preload.url.includes("preloaded-script.js"),
"preload url should reference preloaded-script.js");
assert_equals(preload.as, "script",
"preload as should be 'script'");
assert_equals(preload.used, true,
"preload that was used should have used=true");
}, "Used preload should be included in pagehide event with used=true");
</script>
</body>