Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=867758 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 867758</title> |
michael@0 | 8 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/WindowSnapshot.js"></script> |
michael@0 | 10 | <script type="application/javascript" src="imgutils.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> |
michael@0 | 12 | </head> |
michael@0 | 13 | <body> |
michael@0 | 14 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=867758">Mozilla Bug 867758</a> |
michael@0 | 15 | <p id="display"></p> |
michael@0 | 16 | <div id="content"> |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script type="application/javascript;version=1.8"> |
michael@0 | 20 | /** Test for Bug 867758**/ |
michael@0 | 21 | |
michael@0 | 22 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 23 | |
michael@0 | 24 | const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes) |
michael@0 | 25 | |
michael@0 | 26 | const Cc = Components.classes; |
michael@0 | 27 | const Ci = Components.interfaces; |
michael@0 | 28 | const Cu = Components.utils; |
michael@0 | 29 | const gContent = document.getElementById("content"); |
michael@0 | 30 | |
michael@0 | 31 | var gDispatched = false; |
michael@0 | 32 | var gRanEvent = false; |
michael@0 | 33 | var gObserver; |
michael@0 | 34 | var gImg1; |
michael@0 | 35 | var gImg2; |
michael@0 | 36 | var gOuter; |
michael@0 | 37 | var gFinished = false; |
michael@0 | 38 | var gFirstRequest = null; |
michael@0 | 39 | |
michael@0 | 40 | function cleanUpAndFinish() { |
michael@0 | 41 | if (gFinished) { |
michael@0 | 42 | return; |
michael@0 | 43 | } |
michael@0 | 44 | var imgLoadingContent = gImg1.QueryInterface(Ci.nsIImageLoadingContent); |
michael@0 | 45 | imgLoadingContent.removeObserver(gOuter); |
michael@0 | 46 | |
michael@0 | 47 | imgLoadingContent = gImg2.QueryInterface(Ci.nsIImageLoadingContent); |
michael@0 | 48 | imgLoadingContent.removeObserver(gOuter); |
michael@0 | 49 | |
michael@0 | 50 | SimpleTest.finish(); |
michael@0 | 51 | |
michael@0 | 52 | gFinished = true; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function frameUpdate(aRequest) { |
michael@0 | 56 | if (!gDispatched) { |
michael@0 | 57 | var util = window.getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 58 | util.runBeforeNextEvent(function() { |
michael@0 | 59 | gRanEvent = true; |
michael@0 | 60 | }); |
michael@0 | 61 | gDispatched = true; |
michael@0 | 62 | gFirstRequest = aRequest; |
michael@0 | 63 | } else if (aRequest != gFirstRequest) { |
michael@0 | 64 | ok(!gRanEvent, "Should not have run event before all frame update events occurred!"); |
michael@0 | 65 | cleanUpAndFinish(); |
michael@0 | 66 | } |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function failTest() { |
michael@0 | 70 | ok(false, "timing out after " + FAILURE_TIMEOUT + "ms. "); |
michael@0 | 71 | cleanUpAndFinish(); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function main() { |
michael@0 | 75 | gImg1 = new Image(); |
michael@0 | 76 | gImg2 = new Image(); |
michael@0 | 77 | |
michael@0 | 78 | // Create, customize & attach decoder observer |
michael@0 | 79 | var obs = new ImageDecoderObserverStub(); |
michael@0 | 80 | obs.frameUpdate = frameUpdate; |
michael@0 | 81 | |
michael@0 | 82 | gOuter = Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools).createScriptedObserver(obs); |
michael@0 | 83 | var imgLoadingContent = gImg1.QueryInterface(Ci.nsIImageLoadingContent); |
michael@0 | 84 | imgLoadingContent.addObserver(gOuter); |
michael@0 | 85 | |
michael@0 | 86 | imgLoadingContent = gImg2.QueryInterface(Ci.nsIImageLoadingContent); |
michael@0 | 87 | imgLoadingContent.addObserver(gOuter); |
michael@0 | 88 | |
michael@0 | 89 | // We want to test the cold loading behavior, so clear cache in case an |
michael@0 | 90 | // earlier test got our image in there already. |
michael@0 | 91 | clearImageCache(); |
michael@0 | 92 | |
michael@0 | 93 | // These are two copies of the same image; hence, they have the same frame rate. |
michael@0 | 94 | gImg1.src = "animated1.gif"; |
michael@0 | 95 | gImg2.src = "animated2.gif"; |
michael@0 | 96 | |
michael@0 | 97 | gContent.appendChild(gImg1); |
michael@0 | 98 | gContent.appendChild(gImg2); |
michael@0 | 99 | |
michael@0 | 100 | // In case something goes wrong, fail earlier than mochitest timeout, |
michael@0 | 101 | // and with more information. |
michael@0 | 102 | setTimeout(failTest, FAILURE_TIMEOUT); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | window.onload = main; |
michael@0 | 106 | |
michael@0 | 107 | </script> |
michael@0 | 108 | </pre> |
michael@0 | 109 | </body> |
michael@0 | 110 | </html> |