dom/smil/test/test_smilContainerBinding.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/test/test_smilContainerBinding.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     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 adding and removing animations from a time container</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="svg" 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="circle">
    1.17 +    <set attributeName="cy" to="120" begin="0s; 2s" dur="1s" id="b"/>
    1.18 +  </circle>
    1.19 +</svg>
    1.20 +</div>
    1.21 +<pre id="test">
    1.22 +<script class="testbody" type="text/javascript">
    1.23 +<![CDATA[
    1.24 +/** Test for adding and removing animations from a time container **/
    1.25 +
    1.26 +SimpleTest.waitForExplicitFinish();
    1.27 +
    1.28 +function main() {
    1.29 +  var svg = getElement("svg");
    1.30 +  ok(svg.animationsPaused(), "should be paused by <svg> load handler");
    1.31 +  is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
    1.32 +
    1.33 +  // Create animation and check initial state
    1.34 +  var anim = createAnim();
    1.35 +  anim.setAttribute('begin','b.begin+2s; 6s');
    1.36 +  ok(noStart(anim), "Animation has start time before attaching to document.");
    1.37 +
    1.38 +  // Attach animation to container
    1.39 +  var circle = getElement("circle");
    1.40 +  circle.appendChild(anim);
    1.41 +
    1.42 +  // Check state after attaching
    1.43 +  is(anim.getStartTime(), 2);
    1.44 +
    1.45 +  // Unbind from tree -- the syncbase instance time(s) should become unresolved
    1.46 +  // but the offset time should remain
    1.47 +  anim.parentNode.removeChild(anim);
    1.48 +  is(anim.getStartTime(), 6);
    1.49 +
    1.50 +  // Rebind and check everything is re-resolved
    1.51 +  circle.appendChild(anim);
    1.52 +  is(anim.getStartTime(), 2);
    1.53 +
    1.54 +  // Advance document time to t=1s
    1.55 +  // Now the current interval for b is 2s-3s but the current interval for anim
    1.56 +  // is still 2s-2.5s based on b's previous interval
    1.57 +  svg.setCurrentTime(1);
    1.58 +  is(anim.getStartTime(), 2);
    1.59 +
    1.60 +  // Unbind
    1.61 +  anim.parentNode.removeChild(anim);
    1.62 +  is(anim.getStartTime(), 6);
    1.63 +
    1.64 +  // Rebind
    1.65 +  // At this point only the current interval will be re-added to anim (this is
    1.66 +  // for consistency since old intervals may or may not have been filtered).
    1.67 +  // Therefore the start time should be 4s instead of 2s.
    1.68 +  circle.appendChild(anim);
    1.69 +  is(anim.getStartTime(), 4);
    1.70 +
    1.71 +  SimpleTest.finish();
    1.72 +}
    1.73 +
    1.74 +function createAnim() {
    1.75 +  const svgns="http://www.w3.org/2000/svg";
    1.76 +  var anim = document.createElementNS(svgns,'set');
    1.77 +  anim.setAttribute('attributeName','cx');
    1.78 +  anim.setAttribute('to','100');
    1.79 +  anim.setAttribute('dur','0.5s');
    1.80 +  return anim;
    1.81 +}
    1.82 +
    1.83 +function noStart(elem) {
    1.84 +  var exceptionCaught = false;
    1.85 +
    1.86 +  try {
    1.87 +    elem.getStartTime();
    1.88 +  } catch(e) {
    1.89 +    exceptionCaught = true;
    1.90 +    is (e.name, "InvalidStateError",
    1.91 +        "Unexpected exception from getStartTime.");
    1.92 +    is (e.code, DOMException.INVALID_STATE_ERR,
    1.93 +        "Unexpected exception code from getStartTime.");
    1.94 +  }
    1.95 +
    1.96 +  return exceptionCaught;
    1.97 +}
    1.98 +
    1.99 +window.addEventListener("load", main, false);
   1.100 +]]>
   1.101 +</script>
   1.102 +</pre>
   1.103 +</body>
   1.104 +</html>

mercurial