|
1 <?xml version="1.0" encoding="UTF-8" ?> |
|
2 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
3 <head> |
|
4 <title>Test for syncbase targetting</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="svg" 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="circle"> |
|
14 <set attributeName="cx" to="0" begin="2s" dur="1s" id="a"/> |
|
15 <set attributeName="cx" to="0" begin="2s" dur="1s" xml:id="b"/> |
|
16 <set attributeName="cx" to="0" begin="2s" dur="1s" id="あ"/> |
|
17 <set attributeName="cx" to="0" begin="2s" dur="1s" id="a.b"/> |
|
18 <set attributeName="cx" to="0" begin="2s" dur="1s" id="a-b"/> |
|
19 <set attributeName="cx" to="0" begin="2s" dur="1s" id="a:b"/> |
|
20 <set attributeName="cx" to="0" begin="2s" dur="1s" id="-a"/> |
|
21 <set attributeName="cx" to="0" begin="2s" dur="1s" id="0"/> |
|
22 </circle> |
|
23 </svg> |
|
24 </div> |
|
25 <pre id="test"> |
|
26 <script class="testbody" type="text/javascript"> |
|
27 <![CDATA[ |
|
28 /** Test for syncbase targetting behavior **/ |
|
29 |
|
30 SimpleTest.waitForExplicitFinish(); |
|
31 |
|
32 function main() { |
|
33 var svg = getElement("svg"); |
|
34 ok(svg.animationsPaused(), "should be paused by <svg> load handler"); |
|
35 is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); |
|
36 |
|
37 testSpecs(); |
|
38 testChangeId(); |
|
39 testRemoveTimebase(); |
|
40 |
|
41 SimpleTest.finish(); |
|
42 } |
|
43 |
|
44 function testSpecs() { |
|
45 var anim = createAnim(); |
|
46 |
|
47 // Sanity check--initial state |
|
48 ok(noStart(anim), "Unexpected initial value for indefinite start time."); |
|
49 |
|
50 var specs = [ [ 'a.begin', 2 ], |
|
51 [ 'b.begin', 'todo' ], // xml:id support, bug 275196 |
|
52 [ 'あ.begin', 2 ], // unicode id |
|
53 [ ' a.begin ', 2 ], // whitespace |
|
54 [ 'a\\.b.begin', 2 ], // escaping |
|
55 [ 'a\\-b.begin', 2 ], // escaping |
|
56 [ 'a:b.begin', 2 ], |
|
57 // Invalid |
|
58 [ '-a.begin', 'notok' ], // invalid XML ID |
|
59 [ '\\-a.begin', 'notok' ], // invalid XML ID |
|
60 [ '0.begin', 'notok' ], // invalid XML ID |
|
61 [ '\xB7.begin', 'notok' ], // invalid XML ID |
|
62 [ '\x7B.begin', 'notok' ], // invalid XML ID |
|
63 [ '.begin', 'notok' ], |
|
64 [ ' .end ', 'notok' ], |
|
65 [ 'a.begin-5a', 'notok' ], |
|
66 // Offsets |
|
67 [ ' a.begin + 1min', 2 + 60 ], |
|
68 [ ' a.begin-0.5s', 1.5 ], |
|
69 ]; |
|
70 for (var i = 0; i < specs.length; i++) { |
|
71 var spec = specs[i][0]; |
|
72 var expected = specs[i][1]; |
|
73 anim.setAttribute('begin', spec); |
|
74 try { |
|
75 if (typeof(expected) == 'number') { |
|
76 is(anim.getStartTime(), expected, |
|
77 "Unexpected start time with spec: " + spec); |
|
78 } else if (expected == 'todo') { |
|
79 todo_is(anim.getStartTime(), 2,"Unexpected success with spec: " + spec); |
|
80 } else { |
|
81 anim.getStartTime(); |
|
82 ok(false, "Unexpected success with spec: " + spec); |
|
83 } |
|
84 } catch(e) { |
|
85 if (e.name == "InvalidStateError" && |
|
86 e.code == DOMException.INVALID_STATE_ERR) { |
|
87 if (typeof(expected) == 'number') |
|
88 ok(false, "Failed with spec: " + spec); |
|
89 else if (expected == 'todo') |
|
90 todo(false, "Yet to implement: " + spec); |
|
91 else |
|
92 ok(true); |
|
93 } else { |
|
94 ok(false, "Unexpected exception: " + e + "(with spec: " + spec + ")"); |
|
95 } |
|
96 } |
|
97 } |
|
98 |
|
99 anim.parentNode.removeChild(anim); |
|
100 } |
|
101 |
|
102 function testChangeId() { |
|
103 var anim = createAnim(); |
|
104 |
|
105 anim.setAttribute('begin', 'a.begin'); |
|
106 is(anim.getStartTime(), 2, "Unexpected start time."); |
|
107 |
|
108 var a = getElement('a'); |
|
109 a.setAttribute('id', 'a1'); |
|
110 ok(noStart(anim), "Unexpected return value after changing target ID."); |
|
111 |
|
112 a.setAttribute('id', 'a'); |
|
113 is(anim.getStartTime(), 2, |
|
114 "Unexpected start time after resetting target ID."); |
|
115 |
|
116 anim.parentNode.removeChild(anim); |
|
117 } |
|
118 |
|
119 function testRemoveTimebase() { |
|
120 var anim = createAnim(); |
|
121 anim.setAttribute('begin', 'a.begin'); |
|
122 ok(!noStart(anim), "Unexpected start time before removing timebase."); |
|
123 |
|
124 var circle = getElement('circle'); |
|
125 var a = getElement('a'); |
|
126 // Sanity check |
|
127 is(a, circle.firstElementChild, "Unexpected document structure"); |
|
128 |
|
129 // Remove timebase |
|
130 a.parentNode.removeChild(a); |
|
131 ok(noStart(anim), "Unexpected start time after removing timebase."); |
|
132 |
|
133 // Reinsert timebase |
|
134 circle.insertBefore(a, circle.firstElementChild); |
|
135 ok(!noStart(anim), "Unexpected start time after re-inserting timebase."); |
|
136 |
|
137 // Remove dependent element |
|
138 anim.parentNode.removeChild(anim); |
|
139 ok(noStart(anim), "Unexpected start time after removing dependent."); |
|
140 |
|
141 // Create a new dependent |
|
142 var anim2 = createAnim(); |
|
143 anim2.setAttribute('begin', 'a.begin'); |
|
144 is(anim2.getStartTime(), 2, |
|
145 "Unexpected start time after adding new dependent."); |
|
146 } |
|
147 |
|
148 function createAnim() { |
|
149 const svgns="http://www.w3.org/2000/svg"; |
|
150 var anim = document.createElementNS(svgns,'animate'); |
|
151 anim.setAttribute('attributeName','cx'); |
|
152 anim.setAttribute('from','0'); |
|
153 anim.setAttribute('to','100'); |
|
154 anim.setAttribute('begin','indefinite'); |
|
155 anim.setAttribute('dur','1s'); |
|
156 return getElement('circle').appendChild(anim); |
|
157 } |
|
158 |
|
159 function noStart(elem) { |
|
160 var exceptionCaught = false; |
|
161 |
|
162 try { |
|
163 elem.getStartTime(); |
|
164 } catch(e) { |
|
165 exceptionCaught = true; |
|
166 is (e.name, "InvalidStateError", |
|
167 "Unexpected exception from getStartTime."); |
|
168 is (e.code, DOMException.INVALID_STATE_ERR, |
|
169 "Unexpected exception code from getStartTime."); |
|
170 } |
|
171 |
|
172 return exceptionCaught; |
|
173 } |
|
174 |
|
175 window.addEventListener("load", main, false); |
|
176 ]]> |
|
177 </script> |
|
178 </pre> |
|
179 </body> |
|
180 </html> |