|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <!-- |
|
3 https://bugzilla.mozilla.org/show_bug.cgi?id=436418 |
|
4 --> |
|
5 <head> |
|
6 <title>Test for overriding of path-defining attributes for animateMotion</title> |
|
7 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
8 <script type="text/javascript" src="smilTestUtils.js" /> |
|
9 <script type="text/javascript" src="smilAnimateMotionValueLists.js" /> |
|
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
11 </head> |
|
12 <body> |
|
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=436418">Mozilla Bug 436418</a> |
|
14 <p id="display"></p> |
|
15 <div id="content" style="visibility: hidden"> |
|
16 <svg xmlns="http://www.w3.org/2000/svg" id="svg" |
|
17 width="200px" height="200px" |
|
18 onload="this.pauseAnimations()"> |
|
19 <!-- Paths for mpath to refer to --> |
|
20 <path id="validPathElem" d="M10 10 h-10"/> |
|
21 <path id="invalidPathElem" d="abc"/> |
|
22 |
|
23 <!-- The rect whose motion is animated --> |
|
24 <rect id="rect" x="20" y="20" width="200" height="200"/> |
|
25 </svg> |
|
26 </div> |
|
27 <pre id="test"> |
|
28 <script class="testbody" type="text/javascript"> |
|
29 <![CDATA[ |
|
30 |
|
31 // Constant strings (& string-arrays) |
|
32 const SVGNS = "http://www.w3.org/2000/svg"; |
|
33 const XLINKNS = "http://www.w3.org/1999/xlink"; |
|
34 |
|
35 // Constant objects |
|
36 const gSvg = document.getElementById("svg"); |
|
37 const gRect = document.getElementById("rect"); |
|
38 const gUnAnimatedCTM = gRect.getCTM(); |
|
39 |
|
40 // Values for path-defining attributes, and their expected |
|
41 // CTMs halfway through the animation |
|
42 var gMpathValidTarget = "#validPathElem"; |
|
43 var gMpathCTM = CTMUtil.generateCTM([ 5, 10, 0 ]); |
|
44 |
|
45 var gMpathInvalidTargetA = "#invalidPathElem"; |
|
46 var gMpathInvalidTargetB = "#nonExistentElem"; |
|
47 |
|
48 var gInvalidAttrValue = "i-am-invalid"; // Invalid for all tested attributes |
|
49 |
|
50 var gPathValidValue = "M20 20 h10"; |
|
51 var gPathCTM = CTMUtil.generateCTM([ 25, 20, 0 ]); |
|
52 |
|
53 var gValuesValidValue = "30 30; 40 30" |
|
54 var gValuesCTM = CTMUtil.generateCTM([ 35, 30, 0 ]); |
|
55 |
|
56 var gFromValidValue = "50 50"; |
|
57 |
|
58 var gByValidValue = "10 2"; |
|
59 var gPureByCTM = CTMUtil.generateCTM([ 5, 1, 0 ]); |
|
60 var gFromByCTM = CTMUtil.generateCTM([ 55, 51, 0 ]); |
|
61 |
|
62 var gToValidValue = "80 60"; |
|
63 var gPureToCTM = CTMUtil.generateCTM([ 40, 30, 0 ]); |
|
64 var gFromToCTM = CTMUtil.generateCTM([ 65, 55, 0 ]); |
|
65 |
|
66 |
|
67 SimpleTest.waitForExplicitFinish(); |
|
68 |
|
69 function createAnim() |
|
70 { |
|
71 var anim = document.createElementNS(SVGNS, "animateMotion"); |
|
72 return gRect.appendChild(anim); |
|
73 } |
|
74 |
|
75 function removeElem(aElem) |
|
76 { |
|
77 aElem.parentNode.removeChild(aElem); |
|
78 } |
|
79 |
|
80 function createMpath(aAnimElement, aHrefVal) |
|
81 { |
|
82 var mpath = document.createElementNS(SVGNS, "mpath"); |
|
83 mpath.setAttributeNS(XLINKNS, "href", aHrefVal); |
|
84 return aAnimElement.appendChild(mpath); |
|
85 } |
|
86 |
|
87 function runTest() { |
|
88 // Start out with valid values for all path-defining attributes |
|
89 var attrSettings = { |
|
90 "mpath" : gMpathValidTarget, |
|
91 "path" : gPathValidValue, |
|
92 "values" : gValuesValidValue, |
|
93 "from" : gFromValidValue, |
|
94 "to" : gToValidValue, |
|
95 "by" : gByValidValue, |
|
96 }; |
|
97 |
|
98 // Test that <mpath> overrides everything below it |
|
99 testAttrSettings(attrSettings, gMpathCTM, |
|
100 "<mpath> should win"); |
|
101 var mpathInvalidTargets = [gMpathInvalidTargetA, gMpathInvalidTargetB]; |
|
102 for (var i in mpathInvalidTargets) { |
|
103 var curInvalidValue = mpathInvalidTargets[i]; |
|
104 attrSettings["mpath"] = curInvalidValue; |
|
105 testAttrSettings(attrSettings, gUnAnimatedCTM, |
|
106 "invalid <mpath> should block animation"); |
|
107 } |
|
108 delete attrSettings["mpath"]; |
|
109 |
|
110 // Test that 'path' overrides everything below it |
|
111 testAttrSettings(attrSettings, gPathCTM, |
|
112 "'path' should win vs all but mpath"); |
|
113 attrSettings["path"] = gInvalidAttrValue; |
|
114 testAttrSettings(attrSettings, gUnAnimatedCTM, |
|
115 "invalid 'path' should block animation vs all but mpath"); |
|
116 delete attrSettings["path"]; |
|
117 |
|
118 // Test that 'values' overrides everything below it |
|
119 testAttrSettings(attrSettings, gValuesCTM, |
|
120 "'values' should win vs from/by/to"); |
|
121 attrSettings["values"] = gInvalidAttrValue; |
|
122 testAttrSettings(attrSettings, gUnAnimatedCTM, |
|
123 "invalid 'values' should block animation vs from/by/to"); |
|
124 delete attrSettings["values"]; |
|
125 |
|
126 // Test that 'from' & 'to' overrides 'by' |
|
127 testAttrSettings(attrSettings, gFromToCTM, |
|
128 "'from/to' should win vs 'by'"); |
|
129 attrSettings["to"] = gInvalidAttrValue; |
|
130 testAttrSettings(attrSettings, gUnAnimatedCTM, |
|
131 "invalid 'to' should block animation vs 'by'"); |
|
132 delete attrSettings["to"]; |
|
133 |
|
134 // Test that 'from' & 'by' are effective |
|
135 testAttrSettings(attrSettings, gFromByCTM, |
|
136 "'from/by' should be visible"); |
|
137 attrSettings["by"] = gInvalidAttrValue; |
|
138 testAttrSettings(attrSettings, gUnAnimatedCTM, |
|
139 "invalid 'by' should block animation"); |
|
140 delete attrSettings["from"]; |
|
141 |
|
142 // REINSERT "to" & fix up "by" so we can test pure-"to" vs pure-"by" |
|
143 attrSettings["to"] = gToValidValue; |
|
144 attrSettings["by"] = gByValidValue; |
|
145 testAttrSettings(attrSettings, gPureToCTM, |
|
146 "pure-'to' should be effective & beat pure-'by'"); |
|
147 attrSettings["to"] = gInvalidAttrValue; |
|
148 testAttrSettings(attrSettings, gUnAnimatedCTM, |
|
149 "invalid pure-'to' should block animation vs pure-'by'"); |
|
150 delete attrSettings["to"]; |
|
151 |
|
152 // Test that pure-"by" is effective |
|
153 testAttrSettings(attrSettings, gPureByCTM, |
|
154 "pure-by should be visible"); |
|
155 attrSettings["by"] = gInvalidAttrValue; |
|
156 testAttrSettings(attrSettings, gUnAnimatedCTM, |
|
157 "invalid 'by' should block animation"); |
|
158 delete attrSettings["by"]; |
|
159 |
|
160 // Make sure that our hash is empty now. |
|
161 for (var unexpectedKey in attrSettings) { |
|
162 ok(false, "Unexpected mapping remains in attrSettings: " + |
|
163 unexpectedKey + "-->" + unexpectedValue); |
|
164 } |
|
165 } |
|
166 |
|
167 function testAttrSettings(aAttrValueHash, aExpectedCTM, aErrMsg) |
|
168 { |
|
169 var isDebug = false; // XXdholbert |
|
170 !isDebug || todo(false, "ENTERING testAttrSettings"); |
|
171 // Set up animateMotion element |
|
172 var animElement = document.createElementNS(SVGNS, "animateMotion"); |
|
173 animElement.setAttribute("dur", "2s"); |
|
174 for (var attrName in aAttrValueHash) { |
|
175 !isDebug || todo(false, "setting '" + attrName +"' to '" + |
|
176 aAttrValueHash[attrName] +"'"); |
|
177 if (attrName == "mpath") { |
|
178 createMpath(animElement, aAttrValueHash[attrName]); |
|
179 } else { |
|
180 animElement.setAttribute(attrName, aAttrValueHash[attrName]); |
|
181 } |
|
182 } |
|
183 |
|
184 gRect.appendChild(animElement); |
|
185 |
|
186 // Seek to halfway through animation |
|
187 SMILUtil.getSVGRoot().setCurrentTime(1); // Seek halfway through animation |
|
188 |
|
189 // Check CTM against expected value |
|
190 CTMUtil.assertCTMEqual(gRect.getCTM(), aExpectedCTM, |
|
191 CTMUtil.CTM_COMPONENTS_ALL, aErrMsg, false); |
|
192 |
|
193 // CLEAN UP |
|
194 SMILUtil.getSVGRoot().setCurrentTime(0); |
|
195 removeElem(animElement); |
|
196 } |
|
197 |
|
198 // Main Function |
|
199 function main() |
|
200 { |
|
201 // Start out with document paused |
|
202 var svg = SMILUtil.getSVGRoot(); |
|
203 ok(svg.animationsPaused(), "should be paused by <svg> load handler"); |
|
204 is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); |
|
205 |
|
206 runTest(); |
|
207 SimpleTest.finish(); |
|
208 } |
|
209 |
|
210 window.addEventListener("load", main, false); |
|
211 ]]> |
|
212 </script> |
|
213 </pre> |
|
214 </body> |
|
215 </html> |