dom/smil/test/test_smilRestart.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/test/test_smilRestart.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<head>
     1.6 +  <title>Test for SMIL Restart Behavior </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 +<p id="display"></p>
    1.12 +<div id="content" style="display: none">
    1.13 +<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
    1.14 +     onload="this.pauseAnimations()">
    1.15 +  <!-- These 3 circles only differ in their animation's "restart" value -->
    1.16 +  <circle cx="20" cy="20" r="15" fill="blue">
    1.17 +    <animate attributeName="cx" from="20" to="100" begin="1s" dur="4s"
    1.18 +             restart="always" id="always" attributeType="XML"/>
    1.19 +  </circle>
    1.20 +  <circle cx="20" cy="60" r="15" fill="blue">
    1.21 +    <animate attributeName="cx" from="20" to="100" begin="1s" dur="4s"
    1.22 +             restart="whenNotActive" id="whenNotActive" attributeType="XML"/>
    1.23 +  </circle>
    1.24 +  <circle cx="20" cy="100" r="15" fill="blue">
    1.25 +    <animate attributeName="cx" from="20" to="100" begin="1s" dur="4s"
    1.26 +             restart="never" id="never" attributeType="XML"/>
    1.27 +  </circle>
    1.28 +</svg>
    1.29 +</div>
    1.30 +<pre id="test">
    1.31 +<script class="testbody" type="text/javascript">
    1.32 +<![CDATA[
    1.33 +/** Test for SMIL Restart Behavior  **/
    1.34 +
    1.35 +/* Global Variables */
    1.36 +var svg = document.getElementById("svg");
    1.37 +var always = document.getElementById("always");
    1.38 +var whenNotActive = document.getElementById("whenNotActive");
    1.39 +var never = document.getElementById("never");
    1.40 +
    1.41 +SimpleTest.waitForExplicitFinish();
    1.42 +
    1.43 +function tryRestart(elem, state, expected) {
    1.44 +  var restartTime = svg.getCurrentTime();
    1.45 +  elem.beginElement();
    1.46 +  var restart = false;
    1.47 +  try {
    1.48 +    restart = (elem.getStartTime() === restartTime);
    1.49 +  } catch (e) {
    1.50 +    if (e.name != "InvalidStateError" ||
    1.51 +        e.code != DOMException.INVALID_STATE_ERR)
    1.52 +      throw e;
    1.53 +    restart = false;
    1.54 +  }
    1.55 +  if (expected) {
    1.56 +    var msg = elem.id + " can't restart in " + state + " state";
    1.57 +    ok(restart, msg);
    1.58 +  } else {
    1.59 +    var msg = elem.id + " can restart in " + state + " state";
    1.60 +    ok(!restart, msg);
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +function main() {
    1.65 +  ok(svg.animationsPaused(), "should be paused by <svg> load handler");
    1.66 +  is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
    1.67 +
    1.68 +  // At first everything should be starting at 1s
    1.69 +  is(always.getStartTime(), 1);
    1.70 +  is(whenNotActive.getStartTime(), 1);
    1.71 +  is(never.getStartTime(), 1);
    1.72 +
    1.73 +  // Now try to restart everything early, should be allowed by all
    1.74 +  tryRestart(always, "waiting", true);
    1.75 +  tryRestart(whenNotActive, "waiting", true);
    1.76 +  tryRestart(never, "waiting", true);
    1.77 +
    1.78 +  // Now skip to half-way
    1.79 +  var newTime = always.getStartTime() + 0.5 * always.getSimpleDuration();
    1.80 +  svg.setCurrentTime(newTime);
    1.81 +
    1.82 +  // Only 'always' should be able to be restarted
    1.83 +  tryRestart(always, "active", true);
    1.84 +  tryRestart(whenNotActive, "active", false);
    1.85 +  tryRestart(never, "active", false);
    1.86 +
    1.87 +  // Now skip to the end 
    1.88 +  newTime = always.getStartTime() + always.getSimpleDuration() + 1;
    1.89 +  svg.setCurrentTime(newTime);
    1.90 +
    1.91 +  // All animations have finished, so 'always' and 'whenNotActive' should be
    1.92 +  // able to be restarted
    1.93 +  tryRestart(always, "postactive", true);
    1.94 +  tryRestart(whenNotActive, "postactive", true);
    1.95 +  tryRestart(never, "postactive", false);
    1.96 +
    1.97 +  SimpleTest.finish();
    1.98 +}
    1.99 +
   1.100 +window.addEventListener("load", main, false);
   1.101 +]]>
   1.102 +</script>
   1.103 +</pre>
   1.104 +</body>
   1.105 +</html>

mercurial