1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/image/test/mochitest/test_synchronized_animation.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=867758 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 867758</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=867758">Mozilla Bug 867758</a> 1.18 +<p id="display"></p> 1.19 +<div id="content"> 1.20 +</div> 1.21 +<pre id="test"> 1.22 +<script type="application/javascript;version=1.8"> 1.23 +/** Test for Bug 867758**/ 1.24 + 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 + 1.27 +const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes) 1.28 + 1.29 +const Cc = Components.classes; 1.30 +const Ci = Components.interfaces; 1.31 +const Cu = Components.utils; 1.32 +const gContent = document.getElementById("content"); 1.33 + 1.34 +var gDispatched = false; 1.35 +var gRanEvent = false; 1.36 +var gObserver; 1.37 +var gImg1; 1.38 +var gImg2; 1.39 +var gOuter; 1.40 +var gFinished = false; 1.41 +var gFirstRequest = null; 1.42 + 1.43 +function cleanUpAndFinish() { 1.44 + if (gFinished) { 1.45 + return; 1.46 + } 1.47 + var imgLoadingContent = gImg1.QueryInterface(Ci.nsIImageLoadingContent); 1.48 + imgLoadingContent.removeObserver(gOuter); 1.49 + 1.50 + imgLoadingContent = gImg2.QueryInterface(Ci.nsIImageLoadingContent); 1.51 + imgLoadingContent.removeObserver(gOuter); 1.52 + 1.53 + SimpleTest.finish(); 1.54 + 1.55 + gFinished = true; 1.56 +} 1.57 + 1.58 +function frameUpdate(aRequest) { 1.59 + if (!gDispatched) { 1.60 + var util = window.getInterface(Ci.nsIDOMWindowUtils); 1.61 + util.runBeforeNextEvent(function() { 1.62 + gRanEvent = true; 1.63 + }); 1.64 + gDispatched = true; 1.65 + gFirstRequest = aRequest; 1.66 + } else if (aRequest != gFirstRequest) { 1.67 + ok(!gRanEvent, "Should not have run event before all frame update events occurred!"); 1.68 + cleanUpAndFinish(); 1.69 + } 1.70 +} 1.71 + 1.72 +function failTest() { 1.73 + ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. "); 1.74 + cleanUpAndFinish(); 1.75 +} 1.76 + 1.77 +function main() { 1.78 + gImg1 = new Image(); 1.79 + gImg2 = new Image(); 1.80 + 1.81 + // Create, customize & attach decoder observer 1.82 + var obs = new ImageDecoderObserverStub(); 1.83 + obs.frameUpdate = frameUpdate; 1.84 + 1.85 + gOuter = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools).createScriptedObserver(obs); 1.86 + var imgLoadingContent = gImg1.QueryInterface(Ci.nsIImageLoadingContent); 1.87 + imgLoadingContent.addObserver(gOuter); 1.88 + 1.89 + imgLoadingContent = gImg2.QueryInterface(Ci.nsIImageLoadingContent); 1.90 + imgLoadingContent.addObserver(gOuter); 1.91 + 1.92 + // We want to test the cold loading behavior, so clear cache in case an 1.93 + // earlier test got our image in there already. 1.94 + clearImageCache(); 1.95 + 1.96 + // These are two copies of the same image; hence, they have the same frame rate. 1.97 + gImg1.src = "animated1.gif"; 1.98 + gImg2.src = "animated2.gif"; 1.99 + 1.100 + gContent.appendChild(gImg1); 1.101 + gContent.appendChild(gImg2); 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>