Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <title>Test for moving animations between time containers</title>
5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
7 </head>
8 <body>
9 <p id="display"></p>
10 <div id="content" style="display: none">
11 <svg id="svga" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
12 onload="this.pauseAnimations()">
13 <circle cx="-20" cy="20" r="15" fill="blue" id="circlea"/>
14 </svg>
15 <svg id="svgb" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
16 onload="this.pauseAnimations()">
17 <circle cx="-20" cy="20" r="15" fill="blue" id="circleb">
18 <set attributeName="cy" to="120" begin="4s" dur="1s" id="syncb"/>
19 </circle>
20 </svg>
21 </div>
22 <pre id="test">
23 <script class="testbody" type="text/javascript">
24 <![CDATA[
25 /** Test for moving animations between time containers **/
27 SimpleTest.waitForExplicitFinish();
29 function main() {
30 var svga = getElement("svga");
31 ok(svga.animationsPaused(), "should be paused by <svg> load handler");
32 is(svga.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
33 svga.setCurrentTime(1);
35 var svgb = getElement("svgb");
36 ok(svgb.animationsPaused(), "should be paused by <svg> load handler");
37 is(svgb.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
38 svgb.setCurrentTime(1);
40 // Create animation and check initial state
41 var anim = createAnim();
42 ok(noStart(anim), "Animation has start time before attaching to document");
44 // Attach animation to first container
45 var circlea = getElement("circlea");
46 var circleb = getElement("circleb");
47 circlea.appendChild(anim);
49 // Check state after attaching
50 is(anim.getStartTime(), 2,
51 "Unexpected start time after attaching animation to target");
52 is(circlea.cx.animVal.value, -20,
53 "Unexpected animated value for yet-to-start animation");
54 is(circleb.cx.animVal.value, -20,
55 "Unexpected animated value for unanimated target");
57 // Move animation from first container to second
58 circleb.appendChild(anim);
60 // Advance first container and check animation has no effect
61 svga.setCurrentTime(2);
62 is(anim.getStartTime(), 2,
63 "Unexpected start time after moving animation");
64 is(circlea.cx.animVal.value, -20,
65 "Unexpected animated value for non-longer-animated target");
66 is(circleb.cx.animVal.value, -20,
67 "Unexpected animated value for now yet-to-start animation");
69 // Advance second container and check the animation only affects it
70 svgb.setCurrentTime(2);
71 is(anim.getStartTime(), 2, "Start time changed after time container seek");
72 is(circlea.cx.animVal.value, -20,
73 "Unanimated target changed after seek on other container");
74 is(circleb.cx.animVal.value, 100, "Animated target not animated after seek");
76 // Remove animation so that it belongs to no container and check that
77 // advancing the second container to the next milestone doesn't cause a crash
78 // (when the animation controller goes to run the next milestone sample).
79 anim.parentNode.removeChild(anim);
80 svgb.setCurrentTime(3);
82 // Do likewise with syncbase relationships
84 // Create the syncbase relationship
85 anim.setAttribute('begin', 'syncb.begin');
87 // Attach to second time container (where t=3s)
88 circleb.appendChild(anim);
89 is(anim.getStartTime(), 4,
90 "Unexpected start time for cross-time container syncbase dependency");
92 // Move to first time container (where t=1s).
93 // Because we're dealing with different time containers and both are paused,
94 // future times are effectively unresolved.
95 circlea.appendChild(anim);
96 ok(noStart(anim), "Unexpected start time for paused time container");
98 SimpleTest.finish();
99 }
101 function createAnim() {
102 const svgns="http://www.w3.org/2000/svg";
103 var anim = document.createElementNS(svgns,'set');
104 anim.setAttribute('attributeName','cx');
105 anim.setAttribute('to','100');
106 anim.setAttribute('begin','2s');
107 anim.setAttribute('dur','1s');
108 return anim;
109 }
111 function noStart(elem) {
112 var exceptionCaught = false;
114 try {
115 elem.getStartTime();
116 } catch(e) {
117 exceptionCaught = true;
118 is (e.name, "InvalidStateError",
119 "Unexpected exception from getStartTime.");
120 is (e.code, DOMException.INVALID_STATE_ERR,
121 "Unexpected exception code from getStartTime");
122 }
124 return exceptionCaught;
125 }
127 window.addEventListener("load", main, false);
128 ]]>
129 </script>
130 </pre>
131 </body>
132 </html>