tor-browser

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

test_animSVGImage2.html (4062B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=907503
      5 -->
      6 <head>
      7  <title>Test for Bug 907503</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=907503">Mozilla Bug 907503</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 907503*/
     24 
     25 SimpleTest.requestFlakyTimeout("Early failure timeout");
     26 SimpleTest.waitForExplicitFinish();
     27 
     28 const FAILURE_TIMEOUT = 120000; // Fail early after 120 seconds (2 minutes)
     29 
     30 const Cc = SpecialPowers.Cc;
     31 const Ci = SpecialPowers.Ci;
     32 const gImg = document.getElementsByTagName("img")[0];
     33 
     34 var gMyDecoderObserver; // value will be set in main()
     35 var gReferenceSnapshot; // value will be set in takeReferenceSnapshot()
     36 var gOnFrameUpdateCounter = 0;
     37 var gIsTestFinished = false;
     38 
     39 
     40 function takeReferenceSnapshot() {
     41  // Take a snapshot of the initial (essentially blank) page
     42  let blankSnapshot = snapshotWindow(window, false);
     43 
     44  // Show reference div, & take a snapshot
     45  let referenceDiv = document.getElementById("referenceDiv");
     46  referenceDiv.style.display = "block";
     47  gReferenceSnapshot = snapshotWindow(window, false);
     48  ok(compareSnapshots(blankSnapshot, gReferenceSnapshot, false)[0],
     49     "reference snapshot shouldn't match blank page snapshot");
     50 
     51  // Re-hide reference div, and take another snapshot to be sure it's gone
     52  referenceDiv.style.display = "none";
     53  let blankSnapshot2 = snapshotWindow(window, false);
     54  ok(compareSnapshots(blankSnapshot, blankSnapshot2, true)[0],
     55     "reference div should disappear when it becomes display:none");
     56 }
     57 
     58 function myOnFrameUpdate() {
     59  if (gIsTestFinished) {
     60    return;
     61  }
     62  gOnFrameUpdateCounter++;
     63  ok(true, "myOnFrameUpdate called");
     64  let currentSnapshot = snapshotWindow(window, false);
     65  if (compareSnapshots(currentSnapshot, gReferenceSnapshot, true)[0]) {
     66    // SUCCESS!
     67    ok(true, "Animated image looks correct, " +
     68             "at call #" + gOnFrameUpdateCounter + " to myOnFrameUpdate");
     69    cleanUpAndFinish();
     70  }
     71 }
     72 
     73 function failTest() {
     74  if (gIsTestFinished) {
     75    return;
     76  }
     77  ok(false, "timing out after " + FAILURE_TIMEOUT + "ms.  " +
     78            "Animated image still doesn't look correct, " +
     79            "after call #" + gOnFrameUpdateCounter + " to myOnFrameUpdate");
     80  cleanUpAndFinish();
     81 }
     82 
     83 function cleanUpAndFinish() {
     84  // On the off chance that failTest and myOnFrameUpdate are triggered
     85  // back-to-back, use a flag to prevent multiple calls to SimpleTest.finish.
     86  if (gIsTestFinished) {
     87    return;
     88  }
     89  let imgLoadingContent = SpecialPowers.wrap(gImg);
     90  imgLoadingContent.removeObserver(gMyDecoderObserver);
     91  SimpleTest.finish();
     92  gIsTestFinished = true;
     93 }
     94 
     95 function main() {
     96  takeReferenceSnapshot();
     97 
     98  // Create, customize & attach decoder observer
     99  var observer = new ImageDecoderObserverStub();
    100  observer.frameUpdate = myOnFrameUpdate;
    101  gMyDecoderObserver =
    102    Cc["@mozilla.org/image/tools;1"].getService(Ci.imgITools)
    103      .createScriptedObserver(SpecialPowers.wrapCallbackObject(observer));
    104  let imgLoadingContent = SpecialPowers.wrap(gImg);
    105  imgLoadingContent.addObserver(gMyDecoderObserver);
    106 
    107  // We want to test the cold loading behavior, so clear cache in case an
    108  // earlier test got our image in there already.
    109  clearAllImageCaches();
    110 
    111  // kick off image-loading! myOnFrameUpdate handles the rest.
    112  gImg.setAttribute("src", "lime-anim-100x100-2.svg");
    113 
    114  // In case something goes wrong, fail earlier than mochitest timeout,
    115  // and with more information.
    116  setTimeout(failTest, FAILURE_TIMEOUT);
    117 }
    118 
    119 window.onload = main;
    120 
    121 </script>
    122 </pre>
    123 </body>
    124 </html>