1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/test/test_smilAnimateMotionOverrideRules.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,215 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<!-- 1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=436418 1.7 +--> 1.8 +<head> 1.9 + <title>Test for overriding of path-defining attributes for animateMotion</title> 1.10 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <script type="text/javascript" src="smilTestUtils.js" /> 1.12 + <script type="text/javascript" src="smilAnimateMotionValueLists.js" /> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=436418">Mozilla Bug 436418</a> 1.17 +<p id="display"></p> 1.18 +<div id="content" style="visibility: hidden"> 1.19 +<svg xmlns="http://www.w3.org/2000/svg" id="svg" 1.20 + width="200px" height="200px" 1.21 + onload="this.pauseAnimations()"> 1.22 + <!-- Paths for mpath to refer to --> 1.23 + <path id="validPathElem" d="M10 10 h-10"/> 1.24 + <path id="invalidPathElem" d="abc"/> 1.25 + 1.26 + <!-- The rect whose motion is animated --> 1.27 + <rect id="rect" x="20" y="20" width="200" height="200"/> 1.28 +</svg> 1.29 +</div> 1.30 +<pre id="test"> 1.31 +<script class="testbody" type="text/javascript"> 1.32 +<![CDATA[ 1.33 + 1.34 +// Constant strings (& string-arrays) 1.35 +const SVGNS = "http://www.w3.org/2000/svg"; 1.36 +const XLINKNS = "http://www.w3.org/1999/xlink"; 1.37 + 1.38 +// Constant objects 1.39 +const gSvg = document.getElementById("svg"); 1.40 +const gRect = document.getElementById("rect"); 1.41 +const gUnAnimatedCTM = gRect.getCTM(); 1.42 + 1.43 +// Values for path-defining attributes, and their expected 1.44 +// CTMs halfway through the animation 1.45 +var gMpathValidTarget = "#validPathElem"; 1.46 +var gMpathCTM = CTMUtil.generateCTM([ 5, 10, 0 ]); 1.47 + 1.48 +var gMpathInvalidTargetA = "#invalidPathElem"; 1.49 +var gMpathInvalidTargetB = "#nonExistentElem"; 1.50 + 1.51 +var gInvalidAttrValue = "i-am-invalid"; // Invalid for all tested attributes 1.52 + 1.53 +var gPathValidValue = "M20 20 h10"; 1.54 +var gPathCTM = CTMUtil.generateCTM([ 25, 20, 0 ]); 1.55 + 1.56 +var gValuesValidValue = "30 30; 40 30" 1.57 +var gValuesCTM = CTMUtil.generateCTM([ 35, 30, 0 ]); 1.58 + 1.59 +var gFromValidValue = "50 50"; 1.60 + 1.61 +var gByValidValue = "10 2"; 1.62 +var gPureByCTM = CTMUtil.generateCTM([ 5, 1, 0 ]); 1.63 +var gFromByCTM = CTMUtil.generateCTM([ 55, 51, 0 ]); 1.64 + 1.65 +var gToValidValue = "80 60"; 1.66 +var gPureToCTM = CTMUtil.generateCTM([ 40, 30, 0 ]); 1.67 +var gFromToCTM = CTMUtil.generateCTM([ 65, 55, 0 ]); 1.68 + 1.69 + 1.70 +SimpleTest.waitForExplicitFinish(); 1.71 + 1.72 +function createAnim() 1.73 +{ 1.74 + var anim = document.createElementNS(SVGNS, "animateMotion"); 1.75 + return gRect.appendChild(anim); 1.76 +} 1.77 + 1.78 +function removeElem(aElem) 1.79 +{ 1.80 + aElem.parentNode.removeChild(aElem); 1.81 +} 1.82 + 1.83 +function createMpath(aAnimElement, aHrefVal) 1.84 +{ 1.85 + var mpath = document.createElementNS(SVGNS, "mpath"); 1.86 + mpath.setAttributeNS(XLINKNS, "href", aHrefVal); 1.87 + return aAnimElement.appendChild(mpath); 1.88 +} 1.89 + 1.90 +function runTest() { 1.91 + // Start out with valid values for all path-defining attributes 1.92 + var attrSettings = { 1.93 + "mpath" : gMpathValidTarget, 1.94 + "path" : gPathValidValue, 1.95 + "values" : gValuesValidValue, 1.96 + "from" : gFromValidValue, 1.97 + "to" : gToValidValue, 1.98 + "by" : gByValidValue, 1.99 + }; 1.100 + 1.101 + // Test that <mpath> overrides everything below it 1.102 + testAttrSettings(attrSettings, gMpathCTM, 1.103 + "<mpath> should win"); 1.104 + var mpathInvalidTargets = [gMpathInvalidTargetA, gMpathInvalidTargetB]; 1.105 + for (var i in mpathInvalidTargets) { 1.106 + var curInvalidValue = mpathInvalidTargets[i]; 1.107 + attrSettings["mpath"] = curInvalidValue; 1.108 + testAttrSettings(attrSettings, gUnAnimatedCTM, 1.109 + "invalid <mpath> should block animation"); 1.110 + } 1.111 + delete attrSettings["mpath"]; 1.112 + 1.113 + // Test that 'path' overrides everything below it 1.114 + testAttrSettings(attrSettings, gPathCTM, 1.115 + "'path' should win vs all but mpath"); 1.116 + attrSettings["path"] = gInvalidAttrValue; 1.117 + testAttrSettings(attrSettings, gUnAnimatedCTM, 1.118 + "invalid 'path' should block animation vs all but mpath"); 1.119 + delete attrSettings["path"]; 1.120 + 1.121 + // Test that 'values' overrides everything below it 1.122 + testAttrSettings(attrSettings, gValuesCTM, 1.123 + "'values' should win vs from/by/to"); 1.124 + attrSettings["values"] = gInvalidAttrValue; 1.125 + testAttrSettings(attrSettings, gUnAnimatedCTM, 1.126 + "invalid 'values' should block animation vs from/by/to"); 1.127 + delete attrSettings["values"]; 1.128 + 1.129 + // Test that 'from' & 'to' overrides 'by' 1.130 + testAttrSettings(attrSettings, gFromToCTM, 1.131 + "'from/to' should win vs 'by'"); 1.132 + attrSettings["to"] = gInvalidAttrValue; 1.133 + testAttrSettings(attrSettings, gUnAnimatedCTM, 1.134 + "invalid 'to' should block animation vs 'by'"); 1.135 + delete attrSettings["to"]; 1.136 + 1.137 + // Test that 'from' & 'by' are effective 1.138 + testAttrSettings(attrSettings, gFromByCTM, 1.139 + "'from/by' should be visible"); 1.140 + attrSettings["by"] = gInvalidAttrValue; 1.141 + testAttrSettings(attrSettings, gUnAnimatedCTM, 1.142 + "invalid 'by' should block animation"); 1.143 + delete attrSettings["from"]; 1.144 + 1.145 + // REINSERT "to" & fix up "by" so we can test pure-"to" vs pure-"by" 1.146 + attrSettings["to"] = gToValidValue; 1.147 + attrSettings["by"] = gByValidValue; 1.148 + testAttrSettings(attrSettings, gPureToCTM, 1.149 + "pure-'to' should be effective & beat pure-'by'"); 1.150 + attrSettings["to"] = gInvalidAttrValue; 1.151 + testAttrSettings(attrSettings, gUnAnimatedCTM, 1.152 + "invalid pure-'to' should block animation vs pure-'by'"); 1.153 + delete attrSettings["to"]; 1.154 + 1.155 + // Test that pure-"by" is effective 1.156 + testAttrSettings(attrSettings, gPureByCTM, 1.157 + "pure-by should be visible"); 1.158 + attrSettings["by"] = gInvalidAttrValue; 1.159 + testAttrSettings(attrSettings, gUnAnimatedCTM, 1.160 + "invalid 'by' should block animation"); 1.161 + delete attrSettings["by"]; 1.162 + 1.163 + // Make sure that our hash is empty now. 1.164 + for (var unexpectedKey in attrSettings) { 1.165 + ok(false, "Unexpected mapping remains in attrSettings: " + 1.166 + unexpectedKey + "-->" + unexpectedValue); 1.167 + } 1.168 +} 1.169 + 1.170 +function testAttrSettings(aAttrValueHash, aExpectedCTM, aErrMsg) 1.171 +{ 1.172 + var isDebug = false; // XXdholbert 1.173 + !isDebug || todo(false, "ENTERING testAttrSettings"); 1.174 + // Set up animateMotion element 1.175 + var animElement = document.createElementNS(SVGNS, "animateMotion"); 1.176 + animElement.setAttribute("dur", "2s"); 1.177 + for (var attrName in aAttrValueHash) { 1.178 + !isDebug || todo(false, "setting '" + attrName +"' to '" + 1.179 + aAttrValueHash[attrName] +"'"); 1.180 + if (attrName == "mpath") { 1.181 + createMpath(animElement, aAttrValueHash[attrName]); 1.182 + } else { 1.183 + animElement.setAttribute(attrName, aAttrValueHash[attrName]); 1.184 + } 1.185 + } 1.186 + 1.187 + gRect.appendChild(animElement); 1.188 + 1.189 + // Seek to halfway through animation 1.190 + SMILUtil.getSVGRoot().setCurrentTime(1); // Seek halfway through animation 1.191 + 1.192 + // Check CTM against expected value 1.193 + CTMUtil.assertCTMEqual(gRect.getCTM(), aExpectedCTM, 1.194 + CTMUtil.CTM_COMPONENTS_ALL, aErrMsg, false); 1.195 + 1.196 + // CLEAN UP 1.197 + SMILUtil.getSVGRoot().setCurrentTime(0); 1.198 + removeElem(animElement); 1.199 +} 1.200 + 1.201 +// Main Function 1.202 +function main() 1.203 +{ 1.204 + // Start out with document paused 1.205 + var svg = SMILUtil.getSVGRoot(); 1.206 + ok(svg.animationsPaused(), "should be paused by <svg> load handler"); 1.207 + is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); 1.208 + 1.209 + runTest(); 1.210 + SimpleTest.finish(); 1.211 +} 1.212 + 1.213 +window.addEventListener("load", main, false); 1.214 +]]> 1.215 +</script> 1.216 +</pre> 1.217 +</body> 1.218 +</html>