dom/smil/test/test_smilSetCurrentTime.xhtml

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:1463913cb0c2
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 **/
17
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");
23
24 SimpleTest.waitForExplicitFinish();
25
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");
29
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 }
36
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 }
44
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 }
56
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 }
64
65 function assertFloatsEqual(aVal, aExpected) {
66 ok(Math.abs(aVal - aExpected) <= PRECISION_LEVEL,
67 "getCurrentTime returned " + aVal + " after seeking to " + aExpected)
68 }
69
70 window.addEventListener("load", main, false);
71 ]]>
72 </script>
73 </pre>
74 </body>
75 </html>

mercurial