tor-browser

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

test_smilExtDoc.xhtml (2730B)


      1 <html xmlns="http://www.w3.org/1999/xhtml">
      2 <!--
      3 https://bugzilla.mozilla.org/show_bug.cgi?id=628888
      4 -->
      5 <head>
      6  <title>Test for Bug 628888 - Animations in external document sometimes don't run</title>
      7  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      8  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
      9 </head>
     10 <body style="margin:0px">
     11 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=628888">Mozilla Bug 628888</a>
     12 <p id="display"></p>
     13 <div id="content" style="background: red; width: 50px; height: 50px"/>
     14  
     15 <pre id="test">
     16 <script type="application/javascript">
     17 <![CDATA[
     18 
     19 /* Test for Bug 628888 - Animations in external document sometimes don't run
     20 *
     21 * This bug concerns a condition where an external document is loaded after the
     22 * page show event is dispatched, leaving the external document paused.
     23 *
     24 * To reproduce the bug we attach an external document with animation after the
     25 * page show event has fired.
     26 *
     27 * However, it is difficult to test if the animation is playing or not since we
     28 * don't receive events from animations running in an external document.
     29 *
     30 * Our approach is to simply render the result to a canvas (which requires
     31 * elevated privileges and that is why we are using a MochiTest rather
     32 * than a reftest) and poll one of the pixels to see if it changes colour.
     33 *
     34 * This should mean the test succeeds quickly but fails slowly.
     35 */
     36 
     37 const POLL_INTERVAL     = 100;   // ms
     38 const POLL_TIMEOUT      = 10000; // ms
     39 var accumulatedWaitTime = 0;
     40 
     41 function pageShow()
     42 {
     43  var content = document.getElementById("content");
     44  content.style.filter = "url(smilExtDoc_helper.svg#filter)";
     45  window.setTimeout(checkResult, 0);
     46 }
     47 
     48 function checkResult()
     49 {
     50  var content = document.getElementById("content");
     51  var bbox = content.getBoundingClientRect();
     52 
     53  var canvas = SpecialPowers.snapshotRect(window, bbox);
     54  var ctx = canvas.getContext("2d");
     55 
     56  var imgd = ctx.getImageData(bbox.width/2, bbox.height/2, 1, 1);
     57  var isGreen = (imgd.data[0] == 0) &&
     58                (imgd.data[1] == 255) &&
     59                (imgd.data[2] == 0);
     60  if (isGreen) {
     61    ok(true, "Filter is animated as expected");
     62  } else if (accumulatedWaitTime >= POLL_TIMEOUT) {
     63    ok(false, "No animation detected after waiting " + POLL_TIMEOUT + "ms");
     64  } else {
     65    accumulatedWaitTime += POLL_INTERVAL;
     66    window.setTimeout(checkResult, POLL_INTERVAL);
     67    return;
     68  }
     69  // Hide our content since mochitests normally try to be visually "quiet"
     70  content.style.display = 'none';
     71  SimpleTest.finish();
     72 }
     73 window.addEventListener('pageshow', pageShow);
     74 SimpleTest.waitForExplicitFinish();
     75 SimpleTest.requestFlakyTimeout("untriaged");
     76 ]]>
     77 </script>
     78 </pre>
     79 </body>
     80 </html>