mirror of
https://github.com/classilla/tenfourfox.git
synced 2025-01-06 09:29:35 +00:00
109 lines
4.1 KiB
HTML
109 lines
4.1 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=870022
|
|
-->
|
|
<head>
|
|
<title>Test for dom.image.picture.enabled (Bug 870022)</title>
|
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body onload="setupTest()">
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=870022">Mozilla Bug 870022</a>
|
|
|
|
<!-- Tests that the picture pref can still be disabled, accounting
|
|
for dom.images.srcset.enabled being flipped on in the mean time. -->
|
|
|
|
<!-- these should all load red.png (naturalWidth 1) not big.png (natural
|
|
width 3000) regardless of dom.images.srcset.enabled being on or off -->
|
|
|
|
<div id="testContainer">
|
|
<picture>
|
|
<source srcset="http://example.com/tests/image/test/mochitest/big.png">
|
|
<img id="img1" src="http://example.com/tests/image/test/mochitest/red.png">
|
|
</picture>
|
|
|
|
<picture>
|
|
<source srcset="http://example.com/tests/image/test/mochitest/big.png 500w"
|
|
sizes="500w">
|
|
<img id="img2"
|
|
src="http://example.com/tests/image/test/mochitest/red.png"
|
|
srcset="http://example.com/tests/image/test/mochitest/big.png 500w"
|
|
sizes="50px">
|
|
</picture>
|
|
|
|
<!-- Should load red.png with srcset on, otherwise nothing -->
|
|
<img id="img-srcset-only"
|
|
srcset="http://example.com/tests/image/test/mochitest/big.png 500w, http://example.com/tests/image/test/mochitest/red.png 1x"
|
|
sizes="50px">
|
|
|
|
<!-- Should not load regardless of srcset pref -->
|
|
<img id="img-never"
|
|
srcset="http://example.com/tests/image/test/mochitest/big.png 500w"
|
|
sizes="50px">
|
|
</div>
|
|
|
|
<script type="application/javascript">
|
|
|
|
const srcsetPref = 'dom.image.srcset.enabled';
|
|
const picturePref = 'dom.image.picture.enabled';
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
var srcsetEnabled = SpecialPowers.getBoolPref(srcsetPref);
|
|
var pictureEnabled = SpecialPowers.getBoolPref(picturePref);
|
|
|
|
is(pictureEnabled, true, "picture expected to be enabled by default");
|
|
|
|
function setupTest() {
|
|
SpecialPowers.pushPrefEnv({'set': [[ "dom.image.picture.enabled", false ]] }, function() {
|
|
var container = document.querySelector("#testContainer");
|
|
// We want to re-create the elements with the pref disabled to ensure
|
|
// webIDL attributes are not attached
|
|
var iframe = document.createElement("iframe");
|
|
iframe.addEventListener("load", function() {
|
|
runTest(iframe);
|
|
});
|
|
document.body.appendChild(iframe);
|
|
iframe.src = "data:text/html;base64," + btoa(container.innerHTML);
|
|
});
|
|
}
|
|
|
|
function runTest(iframe) {
|
|
var doc = iframe.contentDocument;
|
|
var win = iframe.contentWindow;
|
|
var img = doc.querySelector("img");
|
|
var source = doc.querySelector("source");
|
|
|
|
is(img.sizes, undefined, "sizes should not be visible on <img>");
|
|
is(source.sizes, undefined, "sizes should not be visible on <source>");
|
|
is(source.srcset, undefined, "srcset should not be visible on <source>");
|
|
|
|
var imgSizesDesc = Object.getOwnPropertyDescriptor(win.HTMLImageElement.prototype, "sizes");
|
|
var sourceSizesDesc = Object.getOwnPropertyDescriptor(win.HTMLSourceElement.prototype, "sizes");
|
|
var sourceSrcsetDesc = Object.getOwnPropertyDescriptor(win.HTMLSourceElement.prototype, "srcset");
|
|
is(imgSizesDesc, undefined, "HTMLImageElement should know nothing of sizes");
|
|
is(sourceSizesDesc, undefined, "HTMLSourceElement should know nothing of sizes");
|
|
is(sourceSrcsetDesc, undefined, "HTMLSourceElement should know nothing of srcset");
|
|
|
|
// Make sure the test images loaded red.png, which is 1x1, not big.png
|
|
for (var id of [ 'img1', 'img2' ]) {
|
|
var testImg = doc.getElementById(id);
|
|
is(testImg.naturalWidth, 1, "Image should have loaded small source");
|
|
}
|
|
|
|
var srcsetOnlyImg = doc.getElementById("img-srcset-only");
|
|
is(srcsetOnlyImg.naturalWidth, srcsetEnabled ? 1 : 0,
|
|
"srcset image should only load if srcset is enabled, and never the computed width candidate");
|
|
|
|
var neverImg = doc.getElementById("img-never");
|
|
is(neverImg.naturalWidth, 0, "Image should not have loaded");
|
|
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|