image/test/mochitest/test_synchronized_animation.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial