dom/smil/test/test_smilAnimateMotionInvalidValues.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/test/test_smilAnimateMotionInvalidValues.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,176 @@
     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 animateMotion acceptance of invalid values</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 +  <rect id="rect" x="20" y="20" width="200" height="200"/>
    1.23 +</svg>
    1.24 +</div>
    1.25 +<pre id="test">
    1.26 +<script class="testbody" type="text/javascript">
    1.27 +<![CDATA[
    1.28 +
    1.29 +// Constant strings (& string-arrays)
    1.30 +const SVGNS = "http://www.w3.org/2000/svg";
    1.31 +const XLINKNS = "http://www.w3.org/1999/xlink";
    1.32 +
    1.33 +// Constant objects
    1.34 +const gSvg = document.getElementById("svg");
    1.35 +const gRect = document.getElementById("rect");
    1.36 +const gUnAnimatedCTM = gRect.getCTM();
    1.37 +
    1.38 +SimpleTest.waitForExplicitFinish();
    1.39 +
    1.40 +function createAnim()
    1.41 +{
    1.42 +  var anim = document.createElementNS(SVGNS, "animateMotion");
    1.43 +  anim.setAttribute("dur", "2s");
    1.44 +  return gRect.appendChild(anim);
    1.45 +}
    1.46 +
    1.47 +function removeElem(aElem)
    1.48 +{
    1.49 +  aElem.parentNode.removeChild(aElem);
    1.50 +}
    1.51 +
    1.52 +function testAttr(aAttrName, aAttrValueArray, aIsValid)
    1.53 +{
    1.54 +  var componentsToCheck;
    1.55 +
    1.56 +  for (var i in aAttrValueArray) {
    1.57 +    var curVal = aAttrValueArray[i];
    1.58 +    var anim = createAnim();
    1.59 +    anim.setAttribute(aAttrName, curVal);
    1.60 +    if (aAttrName == "rotate") {
    1.61 +      // Apply a diagonal translation (so rotate='auto' will have an effect)
    1.62 +      // and just test the rotation matrix components
    1.63 +      anim.setAttribute("values", "0 0; 50 50");
    1.64 +      componentsToCheck = CTMUtil.CTM_COMPONENTS_ROTATE;
    1.65 +    } else {
    1.66 +      // Apply a supplementary rotation to make sure that we don't apply it if
    1.67 +      // our value is rejected.
    1.68 +      anim.setAttribute("rotate", Math.PI/4);
    1.69 +      componentsToCheck = CTMUtil.CTM_COMPONENTS_ALL;
    1.70 +      if (aAttrName == "keyPoints") {
    1.71 +        // Add three times so we can test a greater range of values for
    1.72 +        // keyPoints
    1.73 +        anim.setAttribute("values", "0 0; 25 25; 50 50");
    1.74 +        anim.setAttribute("keyTimes", "0; 0.5; 1");
    1.75 +        anim.setAttribute("calcMode", "discrete");
    1.76 +      }
    1.77 +    }
    1.78 +
    1.79 +    var curCTM = gRect.getCTM();
    1.80 +    if (aIsValid) {
    1.81 +      var errMsg = "CTM should have changed when applying animateMotion " +
    1.82 +        "with '" + aAttrName + "' set to valid value '" + curVal + "'";
    1.83 +      CTMUtil.assertCTMNotEqual(curCTM, gUnAnimatedCTM, componentsToCheck,
    1.84 +                                errMsg, false);
    1.85 +    } else {
    1.86 +      var errMsg = "CTM should not have changed when applying animateMotion " +
    1.87 +        "with '" + aAttrName + "' set to invalid value '" + curVal + "'";
    1.88 +      CTMUtil.assertCTMEqual(curCTM, gUnAnimatedCTM, componentsToCheck,
    1.89 +                             errMsg, false);
    1.90 +    }
    1.91 +    removeElem(anim);
    1.92 +  }
    1.93 +}
    1.94 +
    1.95 +function createPath(aPathDescription)
    1.96 +{
    1.97 +  var path = document.createElementNS(SVGNS, "path");
    1.98 +  path.setAttribute("d", aPathDescription);
    1.99 +  path.setAttribute("id", "thePath");
   1.100 +  return gSvg.appendChild(path);
   1.101 +}
   1.102 +
   1.103 +function createMpath(aAnimElement)
   1.104 +{
   1.105 +  var mpath = document.createElementNS(SVGNS, "mpath");
   1.106 +  mpath.setAttributeNS(XLINKNS, "href", "#thePath");
   1.107 +  return aAnimElement.appendChild(mpath);
   1.108 +}
   1.109 +
   1.110 +function testMpathElem(aPathValueArray, aIsValid)
   1.111 +{
   1.112 +  for (var i in aPathValueArray) {
   1.113 +    var curVal = aPathValueArray[i];
   1.114 +    var anim = createAnim();
   1.115 +    var mpath = createMpath(anim);
   1.116 +    var path = createPath(curVal);
   1.117 +
   1.118 +    // Apply a supplementary rotation to make sure that we don't apply it if
   1.119 +    // our value is rejected.
   1.120 +    anim.setAttribute("rotate", Math.PI/4);
   1.121 +    componentsToCheck = CTMUtil.CTM_COMPONENTS_ALL;
   1.122 +
   1.123 +    if (aIsValid) {
   1.124 +      var errMsg = "CTM should have changed when applying animateMotion " +
   1.125 +        "with mpath linking to a path with valid value '" + curVal + "'";
   1.126 +
   1.127 +      CTMUtil.assertCTMNotEqual(gRect.getCTM(), gUnAnimatedCTM,
   1.128 +                                componentsToCheck, errMsg, false);
   1.129 +    } else {
   1.130 +      var errMsg = "CTM should not have changed when applying animateMotion " +
   1.131 +        "with mpath linking to a path with invalid value '" + curVal + "'";
   1.132 +      CTMUtil.assertCTMEqual(gRect.getCTM(), gUnAnimatedCTM,
   1.133 +                             componentsToCheck, errMsg, false);
   1.134 +    }
   1.135 +    removeElem(anim);
   1.136 +    removeElem(path);
   1.137 +    removeElem(mpath);
   1.138 + } 
   1.139 +}
   1.140 +
   1.141 +// Main Function
   1.142 +function main()
   1.143 +{
   1.144 +  // Start out with document paused
   1.145 +  var svg = SMILUtil.getSVGRoot();
   1.146 +  ok(svg.animationsPaused(), "should be paused by <svg> load handler");
   1.147 +  is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
   1.148 +
   1.149 +  testAttr("values", gValidValues, true);
   1.150 +  testAttr("values", gInvalidValues, false);
   1.151 +
   1.152 +  testAttr("rotate", gValidRotate, true);
   1.153 +  testAttr("rotate", gInvalidRotate, false);
   1.154 +
   1.155 +  testAttr("to", gValidToBy, true);
   1.156 +  testAttr("to", gInvalidToBy, false);
   1.157 +
   1.158 +  testAttr("by", gValidToBy, true);
   1.159 +  testAttr("by", gInvalidToBy, false);
   1.160 +
   1.161 +  testAttr("path", gValidPath, true);
   1.162 +  testAttr("path", gInvalidPath, false);
   1.163 +  testAttr("path", gValidPathWithErrors, true);
   1.164 +
   1.165 +  testAttr("keyPoints", gValidKeyPoints, true);
   1.166 +  testAttr("keyPoints", gInvalidKeyPoints, false);
   1.167 +
   1.168 +  testMpathElem(gValidPath, true);
   1.169 +  testMpathElem(gInvalidPath, false);
   1.170 +
   1.171 +  SimpleTest.finish();
   1.172 +}
   1.173 +
   1.174 +window.addEventListener("load", main, false);
   1.175 +]]>
   1.176 +</script>
   1.177 +</pre>
   1.178 +</body>
   1.179 +</html>

mercurial