dom/smil/test/test_smilGetStartTime.xhtml

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:0ffe5915b1cf
1 <html xmlns="http://www.w3.org/1999/xhtml">
2 <head>
3 <title>Test for getStartTime 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" width="120px" height="120px"
11 onload="this.pauseAnimations()">
12 <circle cx="20" cy="20" r="15" fill="blue">
13 <animate attributeName="cx" attributeType="XML"
14 from="20" to="100" begin="indefinite" dur="1s" id="anim"/>
15 </circle>
16 </svg>
17 </div>
18 <pre id="test">
19 <script class="testbody" type="text/javascript">
20 <![CDATA[
21 /** Test for getStartTime Behavior **/
22
23 SimpleTest.waitForExplicitFinish();
24
25 function main() {
26 var svg = document.getElementById("svg");
27 ok(svg.animationsPaused(), "should be paused by <svg> load handler");
28 is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
29
30 var anim = document.getElementById("anim");
31 // indefinite
32 var exceptionCaught = false;
33 try {
34 anim.getStartTime();
35 } catch(e) {
36 exceptionCaught = true;
37 is(e.name, "InvalidStateError",
38 "Unexpected exception from getStartTime.");
39 is(e.code, DOMException.INVALID_STATE_ERR,
40 "Unexpected exception code from getStartTime.");
41 }
42 ok(exceptionCaught, "No exception thrown for indefinite start time.");
43
44 // 1s
45 anim.setAttribute("begin", "1s");
46 is(anim.getStartTime(), 1, "Unexpected start time with begin=1s");
47
48 // We have to be careful here when choosing a negative time that we choose
49 // a time that will create an interval that reaches past t=0 as SMIL has
50 // special rules for throwing away intervals that end before t=0
51 anim.setAttribute("begin", "-0.5s");
52 is(anim.getStartTime(), -0.5, "Unexpected start time with begin=-0.5s");
53
54 // Once the animation has begun, the begin time is fixed so we need to end the
55 // element (or advance the timeline) to override the previous start time
56 anim.endElement();
57
58 // However, now we have an end instance, and the SMIL model dictates that if
59 // we have end instances and no end event conditions and all end instances are
60 // before our next begin, there's no valid interval. To overcome this we add
61 // an indefinite end.
62 anim.setAttribute("end", "indefinite");
63
64 // Now test over the lifetime of the animation when there are multiple
65 // intervals
66 anim.setAttribute("begin", "1s; 3s");
67 is(anim.getStartTime(), 1, "Unexpected start time before first interval");
68
69 svg.setCurrentTime(1);
70 is(anim.getStartTime(), 1,
71 "Unexpected start time at start of first interval");
72
73 svg.setCurrentTime(1.5);
74 is(anim.getStartTime(), 1, "Unexpected start time during first interval");
75
76 svg.setCurrentTime(2);
77 is(anim.getStartTime(), 3, "Unexpected start time after first interval");
78
79 svg.setCurrentTime(3);
80 is(anim.getStartTime(), 3, "Unexpected start time during second interval");
81
82 svg.setCurrentTime(4);
83 exceptionCaught = false;
84 try {
85 anim.getStartTime();
86 } catch(e) {
87 exceptionCaught = true;
88 is(e.name, "InvalidStateError",
89 "Unexpected exception from getStartTime.");
90 is(e.code, DOMException.INVALID_STATE_ERR,
91 "Unexpected exception code from getStartTime.");
92 }
93 ok(exceptionCaught, "No exception thrown for in postactive state.");
94
95 SimpleTest.finish();
96 }
97
98 window.addEventListener("load", main, false);
99 ]]>
100 </script>
101 </pre>
102 </body>
103 </html>

mercurial