summaryrefslogtreecommitdiffstats
path: root/dom/smil/test/test_smilBackwardsSeeking.xhtml
blob: 7a40bf718d6df99ad21b6f2c681d223cafd393bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test for backwards seeking behavior </title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
<svg id="svg" xmlns="http://www.w3.org/2000/svg" />
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for backwards seeking behavior  **/

var gSvg = document.getElementById("svg");

SimpleTest.waitForExplicitFinish();

function main()
{
  // Pause our document, so that the setCurrentTime calls are the only
  // thing affecting document time
  gSvg.pauseAnimations();

  // We define a series of scenarios, sample times, and expected return values
  // from getStartTime.
  //
  // Each scenario is basically a variation on the following arrangement:
  //
  // <svg>
  //   <set ... dur="1s" begin="<A-BEGIN>"/>
  //   <set ... dur="1s" begin="<B-BEGIN>"/>
  // </svg>
  //
  // Each test then consists of the following:
  //    animA: attributes to be applied to a
  //    animB: attributes to be applied to b
  //    times: a series of triples which consist of:
  //             <sample time, a's expected start time, b's expected start time>
  //           * The sample time is the time passed to setCurrentTime and so is
  //             in seconds.
  //           * The expected start times are compared with the return value of
  //             getStartTime. To check for an unresolved start time where
  //             getStartTime would normally throw an exception use
  //             'unresolved'.
  //           * We also allow the special notation to indicate a call to
  //             beginElement
  //             <'beginElementAt', id of animation element, offset>
  //
  // In the diagrams below '^' means the time before the seek and '*' is the
  // seek time.
  var testCases = Array();

  // 0: Simple case
  //
  //   A:     +-------
  //   B:     +-------       begin: a.begin
  //        *            ^
  testCases[0] = {
    'animA': {'begin':'1s', 'id':'a'},
    'animB': {'begin':'a.begin'},
    'times': [ [0, 1, 1],
               [1, 1, 1],
               [2, 'unresolved', 'unresolved'],
               [0, 1, 1],
               [1.5, 1, 1],
               [1, 1, 1],
               [2, 'unresolved', 'unresolved'] ]
  };

  // 1: Restored times should be live
  //
  // When we restore times they should be live. So we have the following
  // scenario.
  //
  //   A:     +-------
  //   B:     +-------       begin: a.begin
  //       *            ^
  //
  // Then we call beginElement at an earlier time which should give us the
  // following.
  //
  //   A:   +-------
  //   B:   +-------
  //       *            ^
  //
  //  If the times are not live however we'll end up with this
  //
  //   A:   +-------
  //   B:   +-+-------
  //       *            ^
  testCases[1] = {
    'animA': {'begin':'1s', 'id':'a', 'restart':'whenNotActive'},
    'animB': {'begin':'a.begin', 'restart':'always'},
    'times': [ [0, 1, 1],
               [2, 'unresolved', 'unresolved'],
               [0.25, 1, 1],
               ['beginElementAt', 'a', 0.25], // = start time of 0.5
               [0.25, 0.5, 0.5],
               [1, 0.5, 0.5],
               [1.5, 'unresolved', 'unresolved'] ]
  };

  // 2: Multiple intervals A
  //
  //   A:  +-  +-
  //   B:          +-  +-   begin: a.begin+4s
  //             *    ^
  testCases[2] = {
    'animA': {'begin':'1s; 3s', 'id':'a'},
    'animB': {'begin':'a.begin+4s'},
    'times': [ [0, 1, 5],
               [3, 3, 5],
               [6.5, 'unresolved', 7],
               [4, 'unresolved', 5],
               [6, 'unresolved', 7],
               [2, 3, 5],
               ['beginElementAt', 'a', 0],
               [2, 2, 5],
               [5, 'unresolved', 5],
               [6, 'unresolved', 6],
               [7, 'unresolved', 7],
               [8, 'unresolved', 'unresolved'] ]
  };

  for (var i = 0; i < testCases.length; i++) {
    gSvg.setCurrentTime(0);
    var test = testCases[i];

    // Create animation elements
    var animA = createAnim(test.animA);
    var animB = createAnim(test.animB);

    // Run samples
    for (var j = 0; j < test.times.length; j++) {
      var times = test.times[j];
      if (times[0] == 'beginElementAt') {
        var anim = getElement(times[1]);
        anim.beginElementAt(times[2]);
      } else {
        gSvg.setCurrentTime(times[0]);
        checkStartTime(animA, times[1], times[0], i, 'a');
        checkStartTime(animB, times[2], times[0], i, 'b');
      }
    }

    // Tidy up
    animA.parentNode.removeChild(animA);
    animB.parentNode.removeChild(animB);
  }

  SimpleTest.finish();
}

function createAnim(attr)
{
  const svgns = "http://www.w3.org/2000/svg";
  var anim = document.createElementNS(svgns, 'set');
  anim.setAttribute('attributeName','x');
  anim.setAttribute('to','10');
  anim.setAttribute('dur','1s');
  for (name in attr) {
    anim.setAttribute(name, attr[name]);
  }
  return gSvg.appendChild(anim);
}

function checkStartTime(anim, expectedStartTime, sampleTime, caseNum, id)
{
  var startTime = 'unresolved';
  try {
    startTime = anim.getStartTime();
  } catch (e) {
    if (e.name != "InvalidStateError" ||
        e.code != DOMException.INVALID_STATE_ERR)
      throw e;
  }

  var msg = "Test case " + caseNum + ", t=" + sampleTime + " animation '" +
    id + "': Unexpected getStartTime:";
  is(startTime, expectedStartTime, msg);
}

window.addEventListener("load", main, false);
]]>
</script>
</pre>
</body>
</html>