dom/smil/test/test_smilKeyTimesPacedMode.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/test/test_smilKeyTimesPacedMode.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,123 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<head>
     1.6 +  <title>Tests updated intervals</title>
     1.7 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.8 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     1.9 +</head>
    1.10 +<body>
    1.11 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=555026">Mozilla Bug 555026</a>
    1.12 +<p id="display"></p>
    1.13 +<div id="content" style="display: none">
    1.14 +<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
    1.15 +     onload="this.pauseAnimations()">
    1.16 +  <circle r="10" id="circle"/>
    1.17 +</svg>
    1.18 +</div>
    1.19 +<pre id="test">
    1.20 +<script class="testbody" type="text/javascript">
    1.21 +<![CDATA[
    1.22 +/** Test that we ignore keyTimes attr when calcMode="paced" **/
    1.23 +
    1.24 +/* Global Variables */
    1.25 +const SVGNS = "http://www.w3.org/2000/svg";
    1.26 +const ANIM_DUR = "2s";
    1.27 +const HALF_TIME = "1";
    1.28 +const ATTR_NAME = "cx"
    1.29 +const KEYTIMES_TO_TEST = [
    1.30 +  // potentially-valid values (depending on number of values in animation)
    1.31 +  "0; 0.2; 1",
    1.32 +  "0; 0.5",
    1.33 +  "0; 1",
    1.34 +  // invalid values:
    1.35 +  "", "abc", "-0.5", "0; 0.5; 1.01", "5"
    1.36 +];
    1.37 +const gSvg = document.getElementById("svg");
    1.38 +const gCircle = document.getElementById("circle");
    1.39 +
    1.40 +SimpleTest.waitForExplicitFinish();
    1.41 +
    1.42 +
    1.43 +// MAIN FUNCTIONS
    1.44 +function main() {
    1.45 +  ok(gSvg.animationsPaused(), "should be paused by <svg> load handler");
    1.46 +  is(gSvg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
    1.47 +
    1.48 +  testByAnimation();
    1.49 +  testToAnimation();
    1.50 +  testValuesAnimation();
    1.51 +  SimpleTest.finish();
    1.52 +}
    1.53 +
    1.54 +function testByAnimation() {
    1.55 +  for (var i = 0; i < KEYTIMES_TO_TEST.length; i++) {
    1.56 +    setupTest();
    1.57 +    var anim = createAnim();
    1.58 +    anim.setAttribute("by", "200");
    1.59 +    var curKeyTimes = KEYTIMES_TO_TEST[i];
    1.60 +    anim.setAttribute("keyTimes", curKeyTimes);
    1.61 +
    1.62 +    gSvg.setCurrentTime(HALF_TIME);
    1.63 +    is(gCircle.cx.animVal.value, 100,
    1.64 +       "Checking animVal with 'by' and keyTimes='" + curKeyTimes + "'");
    1.65 +
    1.66 +    anim.parentNode.removeChild(anim); // clean up
    1.67 +  }
    1.68 +}
    1.69 +
    1.70 +function testToAnimation() {
    1.71 +  for (var i = 0; i < KEYTIMES_TO_TEST.length; i++) {
    1.72 +    setupTest();
    1.73 +    var anim = createAnim();
    1.74 +    anim.setAttribute("to", "200");
    1.75 +    var curKeyTimes = KEYTIMES_TO_TEST[i];
    1.76 +    anim.setAttribute("keyTimes", curKeyTimes);
    1.77 +
    1.78 +    gSvg.setCurrentTime(HALF_TIME);
    1.79 +    is(gCircle.cx.animVal.value, 100,
    1.80 +       "Checking animVal with 'to' and keyTimes='" + curKeyTimes + "'");
    1.81 +
    1.82 +    anim.parentNode.removeChild(anim); // clean up
    1.83 +  }
    1.84 +}
    1.85 +
    1.86 +function testValuesAnimation() {
    1.87 +  for (var i = 0; i < KEYTIMES_TO_TEST.length; i++) {
    1.88 +    setupTest();
    1.89 +    var anim = createAnim();
    1.90 +    anim.setAttribute("values", "100; 110; 200");
    1.91 +    var curKeyTimes = KEYTIMES_TO_TEST[i];
    1.92 +    anim.setAttribute("keyTimes", curKeyTimes);
    1.93 +
    1.94 +    gSvg.setCurrentTime(HALF_TIME);
    1.95 +    is(gCircle.cx.animVal.value, 150,
    1.96 +       "Checking animVal with 'values' and keyTimes='" + curKeyTimes + "'");
    1.97 +
    1.98 +    anim.parentNode.removeChild(anim); // clean up
    1.99 +  }
   1.100 +}
   1.101 +
   1.102 +// HELPER FUNCTIONS
   1.103 +// Common setup code for each test function: seek to 0, and make sure
   1.104 +// the previous test cleaned up its animations.
   1.105 +function setupTest() {
   1.106 +  gSvg.setCurrentTime(0);
   1.107 +  if (gCircle.firstChild) {
   1.108 +    ok(false, "Previous test didn't clean up after itself.");
   1.109 +  }
   1.110 +}
   1.111 +
   1.112 +function createAnim() {
   1.113 +  var anim = document.createElementNS(SVGNS,"animate");
   1.114 +  anim.setAttribute("attributeName", ATTR_NAME);
   1.115 +  anim.setAttribute("dur", ANIM_DUR);
   1.116 +  anim.setAttribute("begin", "0s");
   1.117 +  anim.setAttribute("calcMode", "paced");
   1.118 +  return gCircle.appendChild(anim);
   1.119 +}
   1.120 +
   1.121 +window.addEventListener("load", main, false);
   1.122 +]]>
   1.123 +</script>
   1.124 +</pre>
   1.125 +</body>
   1.126 +</html>

mercurial