dom/smil/test/test_smilCrossContainer.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/test/test_smilCrossContainer.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,132 @@
     1.4 +<?xml version="1.0" encoding="UTF-8" ?>
     1.5 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.6 +<head>
     1.7 +  <title>Test for moving animations between time containers</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +</head>
    1.11 +<body>
    1.12 +<p id="display"></p>
    1.13 +<div id="content" style="display: none">
    1.14 +<svg id="svga" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
    1.15 +     onload="this.pauseAnimations()">
    1.16 +  <circle cx="-20" cy="20" r="15" fill="blue" id="circlea"/>
    1.17 +</svg>
    1.18 +<svg id="svgb" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
    1.19 +     onload="this.pauseAnimations()">
    1.20 +  <circle cx="-20" cy="20" r="15" fill="blue" id="circleb">
    1.21 +    <set attributeName="cy" to="120" begin="4s" dur="1s" id="syncb"/>
    1.22 +  </circle>
    1.23 +</svg>
    1.24 +</div>
    1.25 +<pre id="test">
    1.26 +<script class="testbody" type="text/javascript">
    1.27 +<![CDATA[
    1.28 +/** Test for moving animations between time containers **/
    1.29 +
    1.30 +SimpleTest.waitForExplicitFinish();
    1.31 +
    1.32 +function main() {
    1.33 +  var svga = getElement("svga");
    1.34 +  ok(svga.animationsPaused(), "should be paused by <svg> load handler");
    1.35 +  is(svga.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
    1.36 +  svga.setCurrentTime(1);
    1.37 +
    1.38 +  var svgb = getElement("svgb");
    1.39 +  ok(svgb.animationsPaused(), "should be paused by <svg> load handler");
    1.40 +  is(svgb.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
    1.41 +  svgb.setCurrentTime(1);
    1.42 +
    1.43 +  // Create animation and check initial state
    1.44 +  var anim = createAnim();
    1.45 +  ok(noStart(anim), "Animation has start time before attaching to document");
    1.46 +
    1.47 +  // Attach animation to first container
    1.48 +  var circlea = getElement("circlea");
    1.49 +  var circleb = getElement("circleb");
    1.50 +  circlea.appendChild(anim);
    1.51 +
    1.52 +  // Check state after attaching
    1.53 +  is(anim.getStartTime(), 2,
    1.54 +    "Unexpected start time after attaching animation to target");
    1.55 +  is(circlea.cx.animVal.value, -20,
    1.56 +    "Unexpected animated value for yet-to-start animation");
    1.57 +  is(circleb.cx.animVal.value, -20,
    1.58 +    "Unexpected animated value for unanimated target");
    1.59 +
    1.60 +  // Move animation from first container to second
    1.61 +  circleb.appendChild(anim);
    1.62 +
    1.63 +  // Advance first container and check animation has no effect
    1.64 +  svga.setCurrentTime(2);
    1.65 +  is(anim.getStartTime(), 2,
    1.66 +    "Unexpected start time after moving animation");
    1.67 +  is(circlea.cx.animVal.value, -20,
    1.68 +    "Unexpected animated value for non-longer-animated target");
    1.69 +  is(circleb.cx.animVal.value, -20,
    1.70 +    "Unexpected animated value for now yet-to-start animation");
    1.71 +
    1.72 +  // Advance second container and check the animation only affects it
    1.73 +  svgb.setCurrentTime(2);
    1.74 +  is(anim.getStartTime(), 2, "Start time changed after time container seek");
    1.75 +  is(circlea.cx.animVal.value, -20,
    1.76 +    "Unanimated target changed after seek on other container");
    1.77 +  is(circleb.cx.animVal.value, 100, "Animated target not animated after seek");
    1.78 +
    1.79 +  // Remove animation so that it belongs to no container and check that
    1.80 +  // advancing the second container to the next milestone doesn't cause a crash
    1.81 +  // (when the animation controller goes to run the next milestone sample).
    1.82 +  anim.parentNode.removeChild(anim);
    1.83 +  svgb.setCurrentTime(3);
    1.84 +
    1.85 +  // Do likewise with syncbase relationships
    1.86 +
    1.87 +  // Create the syncbase relationship
    1.88 +  anim.setAttribute('begin', 'syncb.begin');
    1.89 +
    1.90 +  // Attach to second time container (where t=3s)
    1.91 +  circleb.appendChild(anim);
    1.92 +  is(anim.getStartTime(), 4,
    1.93 +    "Unexpected start time for cross-time container syncbase dependency");
    1.94 +
    1.95 +  // Move to first time container (where t=1s).
    1.96 +  // Because we're dealing with different time containers and both are paused,
    1.97 +  // future times are effectively unresolved.
    1.98 +  circlea.appendChild(anim);
    1.99 +  ok(noStart(anim), "Unexpected start time for paused time container");
   1.100 +
   1.101 +  SimpleTest.finish();
   1.102 +}
   1.103 +
   1.104 +function createAnim() {
   1.105 +  const svgns="http://www.w3.org/2000/svg";
   1.106 +  var anim = document.createElementNS(svgns,'set');
   1.107 +  anim.setAttribute('attributeName','cx');
   1.108 +  anim.setAttribute('to','100');
   1.109 +  anim.setAttribute('begin','2s');
   1.110 +  anim.setAttribute('dur','1s');
   1.111 +  return anim;
   1.112 +}
   1.113 +
   1.114 +function noStart(elem) {
   1.115 +  var exceptionCaught = false;
   1.116 +
   1.117 +  try {
   1.118 +    elem.getStartTime();
   1.119 +  } catch(e) {
   1.120 +    exceptionCaught = true;
   1.121 +    is (e.name, "InvalidStateError",
   1.122 +        "Unexpected exception from getStartTime.");
   1.123 +    is (e.code, DOMException.INVALID_STATE_ERR,
   1.124 +        "Unexpected exception code from getStartTime");
   1.125 +  }
   1.126 +
   1.127 +  return exceptionCaught;
   1.128 +}
   1.129 +
   1.130 +window.addEventListener("load", main, false);
   1.131 +]]>
   1.132 +</script>
   1.133 +</pre>
   1.134 +</body>
   1.135 +</html>

mercurial