Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Errors

<!DOCTYPE HTML>
<html>
<!--
-->
<head>
<title>Test for Bug 1067345</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
</head>
<body>
<script>
// Ensure srcset/picture are enabled, re-run the test at different DPI
// levels to ensure preload step does the right responsive image selection
SimpleTest.waitForExplicitFinish();
var testDPIs = ["1.0", "0.5", "2.0", "1.5"];
var iframe = document.createElement("iframe");
// These accessed by child frame
var currentDPI;
document.body.appendChild(iframe);
// Reset the sjs helper so repeat runs work
resetRequests();
setTimeout(nextTest, 0);
function resetRequests() {
// Ask the SJS to reset requests
var request = new XMLHttpRequest();
request.open("GET", "./file_img_picture_preload.sjs?reset", false);
request.send(null);
is(request.status, 200, "Sending reset to helper should succeed");
// Script responds with pre-reset request count
var previousRequests = +request.responseText;
return previousRequests;
}
// Called when iframe is finished
function childTestFinished(requestsMade) {
setTimeout(function() {
// Reset sjs, ensure no new requests appeared after test finished
var requestsCleared = resetRequests();
is(requestsCleared, requestsMade,
"Should not have recorded new requests after test iteration completed");
setTimeout(nextTest, 0);
}, 0);
}
function nextTest() {
// Re-run test for each DPI level
if (!testDPIs.length) {
SimpleTest.finish();
return;
}
currentDPI = testDPIs.pop();
info("Starting test for DPI: " + currentDPI);
// To avoid spurious image loads being reported when the resolution changes,
// load an intermediate iframe.
iframe.src = "about:blank";
iframe.addEventListener("load", async function() {
await SpecialPowers.pushPrefEnv({"set": [ [ "layout.css.devPixelsPerPx", currentDPI ]] });
// Make sure we trigger a layout flush so that the frame is sized
// appropriately after the DPI changes.
iframe.getBoundingClientRect();
// Clear image cache for next run (we don't try to validate cached items
// in preload).
SpecialPowers.Cc["@mozilla.org/image/tools;1"]
.getService(SpecialPowers.Ci.imgITools)
.getImgCacheForDocument(iframe.contentDocument)
.clearCache(false);
iframe.src = "./file_img_picture_preload.html?" + currentDPI;
}, {once: true});
}
</script>
</body>
</html>