1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/test/mochitest/test_animSVGImage2.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=907503 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 907503</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=907503">Mozilla Bug 907503</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 907503**/ 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 +var gTimer = null; 1.41 + 1.42 + 1.43 +function takeReferenceSnapshot() { 1.44 + // Take a snapshot of the initial (essentially blank) page 1.45 + let blankSnapshot = snapshotWindow(window, false); 1.46 + 1.47 + // Show reference div, & take a snapshot 1.48 + let referenceDiv = document.getElementById("referenceDiv"); 1.49 + referenceDiv.style.display = "block"; 1.50 + gReferenceSnapshot = snapshotWindow(window, false); 1.51 + ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0], 1.52 + "reference snapshot shouldn't match blank page snapshot"); 1.53 + 1.54 + // Re-hide reference div, and take another snapshot to be sure it's gone 1.55 + referenceDiv.style.display = "none"; 1.56 + let blankSnapshot2 = snapshotWindow(window, false); 1.57 + ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0], 1.58 + "reference div should disappear when it becomes display:none"); 1.59 +} 1.60 + 1.61 +function myOnStopFrame(aRequest) { 1.62 + gOnStopFrameCounter++; 1.63 + ok(true, "myOnStopFrame called"); 1.64 + let currentSnapshot = snapshotWindow(window, false); 1.65 + if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) { 1.66 + // SUCCESS! 1.67 + ok(true, "Animated image looks correct, " + 1.68 + "at call #" + gOnStopFrameCounter + " to onStopFrame"); 1.69 + cleanUpAndFinish(); 1.70 + } 1.71 + if (!gTimer) 1.72 + gTimer = setTimeout(function() { gTimer = null; myOnStopFrame(0, 0); }, 1000); 1.73 +} 1.74 + 1.75 +function failTest() { 1.76 + ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. " + 1.77 + "Animated image still doesn't look correct, " + 1.78 + "after call #" + gOnStopFrameCounter + " to onStopFrame"); 1.79 + cleanUpAndFinish(); 1.80 +} 1.81 + 1.82 +function cleanUpAndFinish() { 1.83 + clearTimeout(gTimer); 1.84 + // On the off chance that failTest and myOnStopFrame are triggered 1.85 + // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish. 1.86 + if (gIsTestFinished) { 1.87 + return; 1.88 + } 1.89 + let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); 1.90 + imgLoadingContent.removeObserver(gMyDecoderObserver); 1.91 + SimpleTest.finish(); 1.92 + gIsTestFinished = true; 1.93 +} 1.94 + 1.95 +function main() { 1.96 + takeReferenceSnapshot(); 1.97 + 1.98 + // Create, customize & attach decoder observer 1.99 + observer = new ImageDecoderObserverStub(); 1.100 + observer.frameComplete = myOnStopFrame; 1.101 + gMyDecoderObserver = 1.102 + Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools) 1.103 + .createScriptedObserver(observer); 1.104 + let imgLoadingContent = gImg.QueryInterface(Ci.nsIImageLoadingContent); 1.105 + imgLoadingContent.addObserver(gMyDecoderObserver); 1.106 + 1.107 + // We want to test the cold loading behavior, so clear cache in case an 1.108 + // earlier test got our image in there already. 1.109 + clearImageCache(); 1.110 + 1.111 + // kick off image-loading! myOnStopFrame handles the rest. 1.112 + gImg.setAttribute("src", "lime-anim-100x100-2.svg"); 1.113 + 1.114 + // In case something goes wrong, fail earlier than mochitest timeout, 1.115 + // and with more information. 1.116 + setTimeout(failTest, FAILURE_TIMEOUT); 1.117 +} 1.118 + 1.119 +window.onload = main; 1.120 + 1.121 +</script> 1.122 +</pre> 1.123 +</body> 1.124 +</html>