summaryrefslogtreecommitdiffstats
path: root/parser/htmlparser/tests/mochitest/test_img_picture_preload.html
diff options
context:
space:
mode:
Diffstat (limited to 'parser/htmlparser/tests/mochitest/test_img_picture_preload.html')
-rw-r--r--parser/htmlparser/tests/mochitest/test_img_picture_preload.html88
1 files changed, 88 insertions, 0 deletions
diff --git a/parser/htmlparser/tests/mochitest/test_img_picture_preload.html b/parser/htmlparser/tests/mochitest/test_img_picture_preload.html
new file mode 100644
index 0000000000..295993060b
--- /dev/null
+++ b/parser/htmlparser/tests/mochitest/test_img_picture_preload.html
@@ -0,0 +1,88 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1067345
+-->
+<head>
+ <title>Test for Bug 1067345</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" 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);
+
+ SpecialPowers.pushPrefEnv({"set": [ [ "dom.image.srcset.enabled", true ],
+ [ "dom.image.picture.enabled", true ]] },
+ function() {
+ // 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) {
+ 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", function() {
+ SpecialPowers.pushPrefEnv({"set": [ [ "layout.css.devPixelsPerPx", currentDPI ]] },
+ function() {
+ // 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});
+ } else {
+ SimpleTest.finish();
+ }
+ }
+ </script>
+
+</body>
+</html>