1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/test/mochitest/test_animSVGImage.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=610419 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 610419</title> 1.11 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script> 1.13 + <script type="application/javascript" src="imgutils.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.15 +</head> 1.16 +<body> 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=610419">Mozilla Bug 610419</a> 1.18 +<p id="display"></p> 1.19 +<div id="content"> 1.20 + <div id="referenceDiv" style="height: 100px; width: 100px; 1.21 + display: none; background: lime"></div> 1.22 + <img> 1.23 +</div> 1.24 +<pre id="test"> 1.25 +<script type="application/javascript;version=1.8"> 1.26 +/** Test for Bug 610419**/ 1.27 + 1.28 +SimpleTest.waitForExplicitFinish(); 1.29 + 1.30 +const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes) 1.31 + 1.32 +const Cc = Components.classes; 1.33 +const Ci = Components.interfaces; 1.34 +const gImg = document.getElementsByTagName("img")[0]; 1.35 + 1.36 +var gMyDecoderObserver; // value will be set in main() 1.37 +var gReferenceSnapshot; // value will be set in takeReferenceSnapshot() 1.38 +var gOnStopFrameCounter = 0; 1.39 +var gIsTestFinished = false; 1.40 + 1.41 + 1.42 +function takeReferenceSnapshot() { 1.43 + // Take a snapshot of the initial (essentially blank) page 1.44 + let blankSnapshot = snapshotWindow(window, false); 1.45 + 1.46 + // Show reference div, & take a snapshot 1.47 + let referenceDiv = document.getElementById("referenceDiv"); 1.48 + referenceDiv.style.display = "block"; 1.49 + gReferenceSnapshot = snapshotWindow(window, false); 1.50 + ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0], 1.51 + "reference snapshot shouldn't match blank page snapshot"); 1.52 + 1.53 + // Re-hide reference div, and take another snapshot to be sure it's gone 1.54 + referenceDiv.style.display = "none"; 1.55 + let blankSnapshot2 = snapshotWindow(window, false); 1.56 + ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0], 1.57 + "reference div should disappear when it becomes display:none"); 1.58 +} 1.59 + 1.60 +function myOnStopFrame() { 1.61 + gOnStopFrameCounter++; 1.62 + ok(true, "myOnStopFrame called"); 1.63 + let currentSnapshot = snapshotWindow(window, false); 1.64 + if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) { 1.65 + // SUCCESS! 1.66 + ok(true, "Animated image looks correct, " + 1.67 + "at call #" + gOnStopFrameCounter + " to onStopFrame"); 1.68 + cleanUpAndFinish(); 1.69 + } 1.70 + else 1.71 + setTimeout(myOnStopFrame, 1); 1.72 +} 1.73 + 1.74 +function failTest() { 1.75 + ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " + 1.76 + "Animated image still doesn't look correct, " + 1.77 + "after call #" + gOnStopFrameCounter + " to onStopFrame"); 1.78 + cleanUpAndFinish(); 1.79 +} 1.80 + 1.81 +function cleanUpAndFinish() { 1.82 + // On the off chance that failTest and myOnStopFrame are triggered 1.83 + // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish. 1.84 + if (gIsTestFinished) { 1.85 + return; 1.86 + } 1.87 + SimpleTest.finish(); 1.88 + gIsTestFinished = true; 1.89 +} 1.90 + 1.91 +function main() { 1.92 + takeReferenceSnapshot(); 1.93 + 1.94 + // We want to test the cold loading behavior, so clear cache in case an 1.95 + // earlier test got our image in there already. 1.96 + clearImageCache(); 1.97 + 1.98 + setTimeout(myOnStopFrame, 1); 1.99 + 1.100 + // kick off image-loading! myOnStopFrame handles the rest. 1.101 + gImg.setAttribute("src", "lime-anim-100x100.svg"); 1.102 + 1.103 + // In case something goes wrong, fail earlier than mochitest timeout, 1.104 + // and with more information. 1.105 + setTimeout(failTest, FAILURE_TIMEOUT); 1.106 +} 1.107 + 1.108 +window.onload = main; 1.109 + 1.110 +</script> 1.111 +</pre> 1.112 +</body> 1.113 +</html>