dom/smil/test/test_smilBackwardsSeeking.xhtml

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/smil/test/test_smilBackwardsSeeking.xhtml	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,191 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<head>
     1.6 +  <title>Test for backwards seeking 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" />
    1.14 +</div>
    1.15 +<pre id="test">
    1.16 +<script class="testbody" type="text/javascript">
    1.17 +<![CDATA[
    1.18 +/** Test for backwards seeking behavior  **/
    1.19 +
    1.20 +var gSvg = document.getElementById("svg");
    1.21 +
    1.22 +SimpleTest.waitForExplicitFinish();
    1.23 +
    1.24 +function main()
    1.25 +{
    1.26 +  // Pause our document, so that the setCurrentTime calls are the only
    1.27 +  // thing affecting document time
    1.28 +  gSvg.pauseAnimations();
    1.29 +
    1.30 +  // We define a series of scenarios, sample times, and expected return values
    1.31 +  // from getStartTime.
    1.32 +  //
    1.33 +  // Each scenario is basically a variation on the following arrangement:
    1.34 +  //
    1.35 +  // <svg>
    1.36 +  //   <set ... dur="1s" begin="<A-BEGIN>"/>
    1.37 +  //   <set ... dur="1s" begin="<B-BEGIN>"/>
    1.38 +  // </svg>
    1.39 +  //
    1.40 +  // Each test then consists of the following:
    1.41 +  //    animA: attributes to be applied to a
    1.42 +  //    animB: attributes to be applied to b
    1.43 +  //    times: a series of triples which consist of:
    1.44 +  //             <sample time, a's expected start time, b's expected start time>
    1.45 +  //           * The sample time is the time passed to setCurrentTime and so is
    1.46 +  //             in seconds.
    1.47 +  //           * The expected start times are compared with the return value of
    1.48 +  //             getStartTime. To check for an unresolved start time where
    1.49 +  //             getStartTime would normally throw an exception use
    1.50 +  //             'unresolved'.
    1.51 +  //           * We also allow the special notation to indicate a call to
    1.52 +  //             beginElement
    1.53 +  //             <'beginElementAt', id of animation element, offset>
    1.54 +  //
    1.55 +  // In the diagrams below '^' means the time before the seek and '*' is the
    1.56 +  // seek time.
    1.57 +  var testCases = Array();
    1.58 +
    1.59 +  // 0: Simple case
    1.60 +  //
    1.61 +  //   A:     +-------
    1.62 +  //   B:     +-------       begin: a.begin
    1.63 +  //        *            ^
    1.64 +  testCases[0] = {
    1.65 +    'animA': {'begin':'1s', 'id':'a'},
    1.66 +    'animB': {'begin':'a.begin'},
    1.67 +    'times': [ [0, 1, 1],
    1.68 +               [1, 1, 1],
    1.69 +               [2, 'unresolved', 'unresolved'],
    1.70 +               [0, 1, 1],
    1.71 +               [1.5, 1, 1],
    1.72 +               [1, 1, 1],
    1.73 +               [2, 'unresolved', 'unresolved'] ]
    1.74 +  };
    1.75 +
    1.76 +  // 1: Restored times should be live
    1.77 +  //
    1.78 +  // When we restore times they should be live. So we have the following
    1.79 +  // scenario.
    1.80 +  //
    1.81 +  //   A:     +-------
    1.82 +  //   B:     +-------       begin: a.begin
    1.83 +  //       *            ^
    1.84 +  //
    1.85 +  // Then we call beginElement at an earlier time which should give us the
    1.86 +  // following.
    1.87 +  //
    1.88 +  //   A:   +-------
    1.89 +  //   B:   +-------
    1.90 +  //       *            ^
    1.91 +  //
    1.92 +  //  If the times are not live however we'll end up with this
    1.93 +  //
    1.94 +  //   A:   +-------
    1.95 +  //   B:   +-+-------
    1.96 +  //       *            ^
    1.97 +  testCases[1] = {
    1.98 +    'animA': {'begin':'1s', 'id':'a', 'restart':'whenNotActive'},
    1.99 +    'animB': {'begin':'a.begin', 'restart':'always'},
   1.100 +    'times': [ [0, 1, 1],
   1.101 +               [2, 'unresolved', 'unresolved'],
   1.102 +               [0.25, 1, 1],
   1.103 +               ['beginElementAt', 'a', 0.25], // = start time of 0.5
   1.104 +               [0.25, 0.5, 0.5],
   1.105 +               [1, 0.5, 0.5],
   1.106 +               [1.5, 'unresolved', 'unresolved'] ]
   1.107 +  };
   1.108 +
   1.109 +  // 2: Multiple intervals A
   1.110 +  //
   1.111 +  //   A:  +-  +-
   1.112 +  //   B:          +-  +-   begin: a.begin+4s
   1.113 +  //             *    ^
   1.114 +  testCases[2] = {
   1.115 +    'animA': {'begin':'1s; 3s', 'id':'a'},
   1.116 +    'animB': {'begin':'a.begin+4s'},
   1.117 +    'times': [ [0, 1, 5],
   1.118 +               [3, 3, 5],
   1.119 +               [6.5, 'unresolved', 7],
   1.120 +               [4, 'unresolved', 5],
   1.121 +               [6, 'unresolved', 7],
   1.122 +               [2, 3, 5],
   1.123 +               ['beginElementAt', 'a', 0],
   1.124 +               [2, 2, 5],
   1.125 +               [5, 'unresolved', 5],
   1.126 +               [6, 'unresolved', 6],
   1.127 +               [7, 'unresolved', 7],
   1.128 +               [8, 'unresolved', 'unresolved'] ]
   1.129 +  };
   1.130 +
   1.131 +  for (var i = 0; i < testCases.length; i++) {
   1.132 +    gSvg.setCurrentTime(0);
   1.133 +    var test = testCases[i];
   1.134 +
   1.135 +    // Create animation elements
   1.136 +    var animA = createAnim(test.animA);
   1.137 +    var animB = createAnim(test.animB);
   1.138 +
   1.139 +    // Run samples
   1.140 +    for (var j = 0; j < test.times.length; j++) {
   1.141 +      var times = test.times[j];
   1.142 +      if (times[0] == 'beginElementAt') {
   1.143 +        var anim = getElement(times[1]);
   1.144 +        anim.beginElementAt(times[2]);
   1.145 +      } else {
   1.146 +        gSvg.setCurrentTime(times[0]);
   1.147 +        checkStartTime(animA, times[1], times[0], i, 'a');
   1.148 +        checkStartTime(animB, times[2], times[0], i, 'b');
   1.149 +      }
   1.150 +    }
   1.151 +
   1.152 +    // Tidy up
   1.153 +    animA.parentNode.removeChild(animA);
   1.154 +    animB.parentNode.removeChild(animB);
   1.155 +  }
   1.156 +
   1.157 +  SimpleTest.finish();
   1.158 +}
   1.159 +
   1.160 +function createAnim(attr)
   1.161 +{
   1.162 +  const svgns = "http://www.w3.org/2000/svg";
   1.163 +  var anim = document.createElementNS(svgns, 'set');
   1.164 +  anim.setAttribute('attributeName','x');
   1.165 +  anim.setAttribute('to','10');
   1.166 +  anim.setAttribute('dur','1s');
   1.167 +  for (name in attr) {
   1.168 +    anim.setAttribute(name, attr[name]);
   1.169 +  }
   1.170 +  return gSvg.appendChild(anim);
   1.171 +}
   1.172 +
   1.173 +function checkStartTime(anim, expectedStartTime, sampleTime, caseNum, id)
   1.174 +{
   1.175 +  var startTime = 'unresolved';
   1.176 +  try {
   1.177 +    startTime = anim.getStartTime();
   1.178 +  } catch (e) {
   1.179 +    if (e.name != "InvalidStateError" ||
   1.180 +        e.code != DOMException.INVALID_STATE_ERR)
   1.181 +      throw e;
   1.182 +  }
   1.183 +
   1.184 +  var msg = "Test case " + caseNum + ", t=" + sampleTime + " animation '" +
   1.185 +    id + "': Unexpected getStartTime:";
   1.186 +  is(startTime, expectedStartTime, msg);
   1.187 +}
   1.188 +
   1.189 +window.addEventListener("load", main, false);
   1.190 +]]>
   1.191 +</script>
   1.192 +</pre>
   1.193 +</body>
   1.194 +</html>

mercurial