1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=610419
-->
<head>
<title>Test for Bug 610419</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/WindowSnapshot.js"></script>
<script type="application/javascript" src="imgutils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=610419">Mozilla Bug 610419</a>
<p id="display"></p>
<div id="content">
<div id="referenceDiv" style="height: 100px; width: 100px;
display: none; background: lime"></div>
<img>
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 610419*/
SimpleTest.requestFlakyTimeout("Pre-existing timeouts when converting from mochitest-chrome");
SimpleTest.requestCompleteLog();
SimpleTest.waitForExplicitFinish();
const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes)
var gListen = false;
const gImg = document.getElementsByTagName("img")[0];
gImg.onload = function() {
if (!gListen) {
return;
}
gListen = false;
setTimeout(myPoll, 20);
}
gImg.onerror = function() {
if (!gListen) {
return;
}
gListen = false;
setTimeout(myPoll, 20);
}
var gMyDecoderObserver; // value will be set in main()
var gReferenceSnapshot; // value will be set in takeReferenceSnapshot()
var gPollCounter = 0;
var gIsTestFinished = false;
var gSVGImages = [
"lime-anim-100x100.svg", // SMIL animation
"lime-css-anim-100x100.svg" // CSS animation
]
var gSVGCurrentImage = 0;
function takeReferenceSnapshot() {
// Take a snapshot of the initial (essentially blank) page
let blankSnapshot = snapshotWindow(window, false);
// Show reference div, & take a snapshot
let referenceDiv = document.getElementById("referenceDiv");
referenceDiv.style.display = "block";
gReferenceSnapshot = snapshotWindow(window, false);
ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0],
"reference snapshot shouldn't match blank page snapshot");
// Re-hide reference div, and take another snapshot to be sure it's gone
referenceDiv.style.display = "none";
let blankSnapshot2 = snapshotWindow(window, false);
ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0],
"reference div should disappear when it becomes display:none");
}
function loadNextImageAndPoll()
{
// kick off image-loading! onload/onerror handlers call myPoll to handles
// the rest.
gListen = true;
gImg.setAttribute("src", gSVGImages[gSVGCurrentImage]);
}
function myPoll() {
gPollCounter++;
ok(true, "myPoll called");
let currentSnapshot = snapshotWindow(window, false);
if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) {
// SUCCESS!
ok(true, "Animated image looks correct, " +
"at call #" + gPollCounter + " to myPoll");
if (++gSVGCurrentImage >= gSVGImages.length) {
cleanUpAndFinish();
} else {
loadNextImageAndPoll();
}
}
else {
setTimeout(myPoll, 20);
}
}
function failTest() {
ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " +
"Animated image still doesn't look correct, " +
"after call #" + gPollCounter + " to myPoll");
cleanUpAndFinish();
}
function cleanUpAndFinish() {
// On the off chance that failTest and myPoll are triggered
// back-to-back, use a flag to prevent multiple calls to SimpleTest.finish.
if (gIsTestFinished) {
return;
}
SimpleTest.finish();
gIsTestFinished = true;
}
function main() {
takeReferenceSnapshot();
// We want to test the cold loading behavior, so clear cache in case an
// earlier test got our image in there already.
clearAllImageCaches();
loadNextImageAndPoll();
// In case something goes wrong, fail earlier than mochitest timeout,
// and with more information.
setTimeout(failTest, FAILURE_TIMEOUT);
}
window.onload = main;
</script>
</pre>
</body>
</html>
|