summaryrefslogtreecommitdiffstats
path: root/dom/smil/test/test_smilContainerBinding.xhtml
blob: 1a47703bffbaaf9ba44d639844b910beaac0c8cc (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
<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test for adding and removing animations from a time container</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" width="120px" height="120px"
     onload="this.pauseAnimations()">
  <circle cx="-20" cy="20" r="15" fill="blue" id="circle">
    <set attributeName="cy" to="120" begin="0s; 2s" dur="1s" id="b"/>
  </circle>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for adding and removing animations from a time container **/

SimpleTest.waitForExplicitFinish();

function main() {
  var svg = getElement("svg");
  ok(svg.animationsPaused(), "should be paused by <svg> load handler");
  is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");

  // Create animation and check initial state
  var anim = createAnim();
  anim.setAttribute('begin','b.begin+2s; 6s');
  ok(noStart(anim), "Animation has start time before attaching to document.");

  // Attach animation to container
  var circle = getElement("circle");
  circle.appendChild(anim);

  // Check state after attaching
  is(anim.getStartTime(), 2);

  // Unbind from tree -- the syncbase instance time(s) should become unresolved
  // but the offset time should remain
  anim.parentNode.removeChild(anim);
  is(anim.getStartTime(), 6);

  // Rebind and check everything is re-resolved
  circle.appendChild(anim);
  is(anim.getStartTime(), 2);

  // Advance document time to t=1s
  // Now the current interval for b is 2s-3s but the current interval for anim
  // is still 2s-2.5s based on b's previous interval
  svg.setCurrentTime(1);
  is(anim.getStartTime(), 2);

  // Unbind
  anim.parentNode.removeChild(anim);
  is(anim.getStartTime(), 6);

  // Rebind
  // At this point only the current interval will be re-added to anim (this is
  // for consistency since old intervals may or may not have been filtered).
  // Therefore the start time should be 4s instead of 2s.
  circle.appendChild(anim);
  is(anim.getStartTime(), 4);

  SimpleTest.finish();
}

function createAnim() {
  const svgns="http://www.w3.org/2000/svg";
  var anim = document.createElementNS(svgns,'set');
  anim.setAttribute('attributeName','cx');
  anim.setAttribute('to','100');
  anim.setAttribute('dur','0.5s');
  return anim;
}

function noStart(elem) {
  var exceptionCaught = false;

  try {
    elem.getStartTime();
  } catch(e) {
    exceptionCaught = true;
    is (e.name, "InvalidStateError",
        "Unexpected exception from getStartTime.");
    is (e.code, DOMException.INVALID_STATE_ERR,
        "Unexpected exception code from getStartTime.");
  }

  return exceptionCaught;
}

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