<!DOCTYPE HTML><html><!--https://bugzilla.mozilla.org/show_bug.cgi?id=867758--><head><title>Test for Bug 867758</title><scriptsrc="/tests/SimpleTest/SimpleTest.js"></script><scriptsrc="/tests/SimpleTest/WindowSnapshot.js"></script><scripttype="application/javascript"src="imgutils.js"></script><linkrel="stylesheet"type="text/css"href="/tests/SimpleTest/test.css"/></head><body><atarget="_blank"href="https://bugzilla.mozilla.org/show_bug.cgi?id=867758">Mozilla Bug 867758</a><pid="display"></p><divid="content"></div><preid="test"><scripttype="application/javascript">/** Test for Bug 867758**/SimpleTest.requestFlakyTimeout("Early failure timeout");SimpleTest.waitForExplicitFinish();constFAILURE_TIMEOUT=120000;// Fail early after 120 seconds (2 minutes)constCc=SpecialPowers.Cc;constCi=SpecialPowers.Ci;constgContent=document.getElementById("content");vargDispatched=false;vargRanEvent=false;vargObserver;vargImg1;vargImg2;vargFirstImageLoaded=false;vargOuter;vargFinished=false;vargFirstRequest=null;functioncleanUpAndFinish(){if(gFinished){return;}varimgLoadingContent=SpecialPowers.wrap(gImg1);imgLoadingContent.removeObserver(gOuter);imgLoadingContent=SpecialPowers.wrap(gImg2);imgLoadingContent.removeObserver(gOuter);SimpleTest.finish();gFinished=true;}functionframeUpdate(aRequest){if(!gDispatched){Promise.resolve().then(function(){gRanEvent=true;});gDispatched=true;gFirstRequest=aRequest;}elseif(aRequest!=gFirstRequest){ok(!gRanEvent,"Should not have run event before all frame update events occurred!");cleanUpAndFinish();}}functionfailTest(){ok(false,"timing out after "+FAILURE_TIMEOUT+"ms. ");cleanUpAndFinish();}functionwaitForLoadAndTest(image){return()=>{// Draw the image into a canvas to ensure it's decoded.varcanvas=document.createElement('canvas');varcontext=canvas.getContext('2d');context.drawImage(image,0,0);// Attach the observer.varimgLoadingContent=SpecialPowers.wrap(image);imgLoadingContent.addObserver(gOuter);// If the other image already loaded, add both images to the document, which// begins the real test.if(gFirstImageLoaded){gContent.appendChild(gImg1);gContent.appendChild(gImg2);}else{gFirstImageLoaded=true;}};}functionmain(){gImg1=newImage();gImg2=newImage();// Create and customize decoder observervarobs=newImageDecoderObserverStub();obs.frameUpdate=frameUpdate;gOuter=Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools).createScriptedObserver(SpecialPowers.wrapCallbackObject(obs));// We want to test the cold loading behavior, so clear cache in case an// earlier test got our image in there already.clearAllImageCaches();// These are two copies of the same image; hence, they have the same frame rate.gImg1.src="animated1.gif";gImg2.src="animated2.gif";// Wait for each image to load.gImg1.addEventListener('load',waitForLoadAndTest(gImg1));gImg2.addEventListener('load',waitForLoadAndTest(gImg2));// 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>