tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_animation_operators.html (5179B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=936720
      5 -->
      6 <head>
      7  <title>Test for Bug 936720</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
     10  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     11 </head>
     12 <body>
     13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=936720">Mozilla Bug 936720</a>
     14 <pre id="test">
     15 <script type="application/javascript">
     16 
     17 /** Test for Bug 936720 */
     18 
     19 // Because there is no event telling us when an animated image finishes
     20 // animating, tests for the operators used by animated GIFs and PNGs
     21 // require that we poll until we get the correct result. A fixed timeout
     22 // can easily result in intermittent failures on tests running in VMs.
     23 
     24 // (Note that we do _not_ poll the reference, so it must not be animated.)
     25 
     26 var gTests = [
     27  // IMPORTANT NOTE: For these tests, the test and reference are not
     28  // snapshotted in the same way.  The REFERENCE (second file) is
     29  // assumed to be complete when loaded, but we poll the TEST
     30  // (first file) until the test passes.
     31 
     32  // Tests of the allowed disposal operators for GIF, APNG and WebP: keep, clear,
     33  // and restore previous.
     34  "== green-background.html?clear.gif green.png",
     35  "== green-background.html?clear.png green.png",
     36  "== green-background.html?clear.webp green.png",
     37  "== green-background.html?clear.avif green.png",
     38  "== keep.gif green.png",
     39  "== keep.png green.png",
     40  "== keep.webp green.png",
     41  "== restore-previous.gif green.png",
     42  "== restore-previous.png green.png",
     43 
     44  // Tests of the blending/compositing operators that only APNG supports.
     45  "== over.png grey.png",
     46  "!= source.png grey.png",
     47  "== bug900200.png bug900200-ref.png",
     48  "== bug1319025.png bug1319025-ref.png",
     49 
     50  // Test of subframe updates.
     51  "== clear2.gif clear2-results.gif",
     52  "== clear2.webp clear2-results.gif",
     53 ];
     54 
     55 // Maintain a reference count of how many things we're waiting for until
     56 // we can say the tests are done.
     57 var gDelayCount = 0;
     58 function AddFinishDependency()
     59  { ++gDelayCount; }
     60 function RemoveFinishDependency()
     61  { if (--gDelayCount == 0) SimpleTest.finish(); }
     62 
     63 // We record the maximum number of times we had to look at a test before
     64 // it switched to the passing state (though we assume it's 10 to start
     65 // rather than 0 so that we have a reasonable default).  Then we make a
     66 // test "time out" if it takes more than gTimeoutFactor times that
     67 // amount of time.  This allows us to report a test failure rather than
     68 // making a test failure just show up as a timeout.
     69 var gMaxPassingTries = 10;
     70 var gTimeoutFactor = 10;
     71 
     72 function takeSnapshot(iframe_element)
     73 {
     74  return snapshotWindow(iframe_element.contentWindow, false);
     75 }
     76 
     77 function passes(op, shot1, shot2)
     78 {
     79  var values = compareSnapshots(shot1, shot2, op == "==");
     80  return values[0];
     81 }
     82 
     83 function startTest(i)
     84 {
     85  var testLine = gTests[i];
     86  var splitData = testLine.split(" ");
     87  var testData =
     88    { op: splitData[0], test: splitData[1], reference: splitData[2] };
     89  var tries = 0;
     90 
     91  // Maintain state specific to this test in the closure exposed to all
     92  // the functions nested inside this one.
     93 
     94  function startIframe(url)
     95  {
     96    var element = document.createElement("iframe");
     97    element.addEventListener("load", handleLoad);
     98    // Smaller than normal reftests, but enough for these.
     99    element.setAttribute("style", "width: 100px; height: 100px");
    100    element.setAttribute("frameborder", "0");
    101    element.setAttribute("scrolling", "no");
    102    element.src = url;
    103    document.body.appendChild(element);
    104    function handleLoad()
    105    {
    106      iframe.loaded = true;
    107      if (iframe == reference) {
    108        reference.snapshot = takeSnapshot(element);
    109      }
    110      var other = (iframe == test) ? reference : test;
    111      if (other.loaded) {
    112        setTimeout(checkTest, 100);
    113      }
    114    }
    115    function checkTest()
    116    {
    117      var test_snapshot = takeSnapshot(test.element);
    118      if (passes(testData.op, test_snapshot, reference.snapshot)) {
    119        if (tries > gMaxPassingTries) {
    120          gMaxPassingTries = tries;
    121        }
    122        report(true);
    123      } else {
    124        ++tries;
    125        if (tries > gMaxPassingTries * gTimeoutFactor) {
    126          info("Giving up after " + tries + " tries, " +
    127               "maxp=" + gMaxPassingTries +
    128               "fact=" + gTimeoutFactor);
    129          report(false);
    130        } else {
    131          // The animation might not have finished.  Try again in 100ms.
    132          setTimeout(checkTest, 100);
    133        }
    134      }
    135    }
    136    function report(result)
    137    {
    138      ok(result, "(" + i + ") " +
    139                 testData.op + " " + testData.test + " " + testData.reference);
    140      RemoveFinishDependency();
    141    }
    142    var iframe = { element, loaded: false };
    143 
    144    return iframe;
    145  }
    146 
    147  AddFinishDependency();
    148  var test = startIframe(testData.test);
    149  var reference = startIframe(testData.reference);
    150 }
    151 
    152 function runTests()
    153 {
    154  // Run the tests.
    155  for (var i = 0; i < gTests.length; ++i) {
    156    startTest(i);
    157  }
    158 }
    159 
    160 SimpleTest.waitForExplicitFinish();
    161 SimpleTest.requestFlakyTimeout("untriaged");
    162 runTests();
    163 
    164 </script>
    165 </pre>
    166 </body>
    167 </html>