dom/smil/test/test_smilSetCurrentTime.xhtml

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 <html xmlns="http://www.w3.org/1999/xhtml">
     2 <head>
     3   <title>Test for setCurrentTime Behavior </title>
     4   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     5   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     6 </head>
     7 <body>
     8 <p id="display"></p>
     9 <div id="content" style="display: none">
    10 <svg id="svg" xmlns="http://www.w3.org/2000/svg"
    11      onload="this.pauseAnimations()" />
    12 </div>
    13 <pre id="test">
    14 <script class="testbody" type="text/javascript">
    15 <![CDATA[
    16 /** Test for basic setCurrentTime / getCurrentTime Behavior  **/
    18 /* Global Variables & Constants */
    19 const PRECISION_LEVEL = 0.0000001; // Allow small level of floating-point error
    20 const gTimes = [0, 1.5, 0.2, 0.99, -400.5, 10000000, -1];
    21 const gWaitTime = 20;
    22 var gSvg = document.getElementById("svg");
    24 SimpleTest.waitForExplicitFinish();
    26 function main() {
    27   ok(gSvg.animationsPaused(), "should be paused by <svg> load handler");
    28   is(gSvg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
    30   // Test that seeking takes effect immediately
    31   for (var i = 0; i < gTimes.length; i++) {
    32     gSvg.setCurrentTime(gTimes[i]);
    33     // We adopt the SVGT1.2 behavior of clamping negative times to 0
    34     assertFloatsEqual(gSvg.getCurrentTime(), Math.max(gTimes[i], 0.0));
    35   }
    37   // Test that seeking isn't messed up by timeouts
    38   // (using tail recursion to set up the chain of timeout function calls)
    39   var func = function() {
    40     checkTimesAfterIndex(0);
    41   }
    42   setTimeout(func, gWaitTime);
    43 }
    45 /* This method seeks to the time at gTimes[index],
    46  * and then sets up a timeout to...
    47  *   - verify that the seek worked
    48  *   - make a recursive call for the next index.
    49  */
    50 function checkTimesAfterIndex(index) {
    51   if (index == gTimes.length) {
    52     // base case -- we're done!
    53     SimpleTest.finish();
    54     return;
    55   }
    57   gSvg.setCurrentTime(gTimes[index]);
    58   var func = function() {
    59     assertFloatsEqual(gSvg.getCurrentTime(), Math.max(gTimes[index], 0.0));
    60     checkTimesAfterIndex(index + 1);
    61   }
    62   setTimeout(func, gWaitTime);
    63 }
    65 function assertFloatsEqual(aVal, aExpected) {
    66   ok(Math.abs(aVal - aExpected) <= PRECISION_LEVEL,
    67      "getCurrentTime returned " + aVal + " after seeking to " + aExpected)
    68 }
    70 window.addEventListener("load", main, false);
    71 ]]>
    72 </script>
    73 </pre>
    74 </body>
    75 </html>

mercurial