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