tor-browser

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

test_animSVGImage.html (4033B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=610419
      5 -->
      6 <head>
      7  <title>Test for Bug 610419</title>
      8  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      9  <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
     10  <script type="application/javascript" src="imgutils.js"></script>
     11  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     12 </head>
     13 <body>
     14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=610419">Mozilla Bug 610419</a>
     15 <p id="display"></p>
     16 <div id="content">
     17  <div id="referenceDiv" style="height: 100px; width: 100px;
     18                                display: none; background: lime"></div>
     19  <img>
     20 </div>
     21 <pre id="test">
     22 <script type="application/javascript">
     23 /** Test for Bug 610419*/
     24 
     25 SimpleTest.requestFlakyTimeout("Pre-existing timeouts when converting from mochitest-chrome");
     26 SimpleTest.requestCompleteLog();
     27 SimpleTest.waitForExplicitFinish();
     28 
     29 const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes)
     30 
     31 var gListen = false;
     32 const gImg = document.getElementsByTagName("img")[0];
     33 gImg.onload = function() {
     34  if (!gListen) {
     35    return;
     36  }
     37  gListen = false;
     38  setTimeout(myPoll, 20);
     39 }
     40 gImg.onerror = function() {
     41  if (!gListen) {
     42    return;
     43  }
     44  gListen = false;
     45  setTimeout(myPoll, 20);
     46 }
     47 
     48 var gMyDecoderObserver; // value will be set in main()
     49 var gReferenceSnapshot; // value will be set in takeReferenceSnapshot()
     50 var gPollCounter = 0;
     51 var gIsTestFinished = false;
     52 var gSVGImages = [
     53  "lime-anim-100x100.svg",    // SMIL animation
     54  "lime-css-anim-100x100.svg" // CSS animation
     55 ]
     56 var gSVGCurrentImage = 0;
     57 
     58 function takeReferenceSnapshot() {
     59  // Take a snapshot of the initial (essentially blank) page
     60  let blankSnapshot = snapshotWindow(window, false);
     61 
     62  // Show reference div, & take a snapshot
     63  let referenceDiv = document.getElementById("referenceDiv");
     64  referenceDiv.style.display = "block";
     65  gReferenceSnapshot = snapshotWindow(window, false);
     66  ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0],
     67     "reference snapshot shouldn't match blank page snapshot");
     68 
     69  // Re-hide reference div, and take another snapshot to be sure it's gone
     70  referenceDiv.style.display = "none";
     71  let blankSnapshot2 = snapshotWindow(window, false);
     72  ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0],
     73     "reference div should disappear when it becomes display:none");
     74 }
     75 
     76 function loadNextImageAndPoll()
     77 {
     78  // kick off image-loading! onload/onerror handlers call myPoll to handles
     79  // the rest.
     80  gListen = true;
     81  gImg.setAttribute("src", gSVGImages[gSVGCurrentImage]);
     82 }
     83 
     84 function myPoll() {
     85  gPollCounter++;
     86  ok(true, "myPoll called");
     87  let currentSnapshot = snapshotWindow(window, false);
     88  if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) {
     89    // SUCCESS!
     90    ok(true, "Animated image looks correct, " +
     91             "at call #" + gPollCounter + " to myPoll");
     92 
     93    if (++gSVGCurrentImage >= gSVGImages.length) {
     94      cleanUpAndFinish();
     95    } else {
     96      loadNextImageAndPoll();
     97    }
     98  }
     99  else {
    100    setTimeout(myPoll, 20);
    101  }
    102 }
    103 
    104 function failTest() {
    105  ok(false, "timing out after " + FAILURE_TIMEOUT + "ms.  " +
    106            "Animated image still doesn't look correct, " +
    107            "after call #" + gPollCounter + " to myPoll");
    108  cleanUpAndFinish();
    109 }
    110 
    111 function cleanUpAndFinish() {
    112  // On the off chance that failTest and myPoll are triggered
    113  // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish.
    114  if (gIsTestFinished) {
    115    return;
    116  }
    117  SimpleTest.finish();
    118  gIsTestFinished = true;
    119 }
    120 
    121 function main() {
    122  takeReferenceSnapshot();
    123 
    124  // We want to test the cold loading behavior, so clear cache in case an
    125  // earlier test got our image in there already.
    126  clearAllImageCaches();
    127 
    128  loadNextImageAndPoll();
    129 
    130  // In case something goes wrong, fail earlier than mochitest timeout,
    131  // and with more information.
    132  setTimeout(failTest, FAILURE_TIMEOUT);
    133 }
    134 
    135 window.onload = main;
    136 
    137 </script>
    138 </pre>
    139 </body>
    140 </html>