summaryrefslogtreecommitdiffstats
path: root/dom/smil/test/test_smilGetSimpleDuration.xhtml
blob: e36922c34a1f6c1cc15a502ee38c429162d4f6f9 (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
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test for getSimpleDuration Behavior </title>
  <script 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">
  <circle cx="20" cy="20" r="15" fill="blue">
    <animate attributeName="cx" attributeType="XML" 
      from="20" to="100" begin="1s" id="anim"/>
  </circle>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for getSimpleDuration Behavior  **/

/* Global Variables */
var svg = document.getElementById("svg");

SimpleTest.waitForExplicitFinish();

function main() {
  var anim = document.getElementById("anim");

  /* Check initial state */
  checkForException(anim, "dur not set");

  /* Check basic operation */
  anim.setAttribute("dur", "1s");
  is(anim.getSimpleDuration(), 1);
  anim.setAttribute("dur", ".15s");
  isfuzzy(anim.getSimpleDuration(), 0.15, 0.001);
  anim.setAttribute("dur", "1.5s");
  is(anim.getSimpleDuration(), 1.5);

  /* Check exceptional states */
  anim.setAttribute("dur", "0s");
  checkForException(anim, "dur=0s");
  anim.setAttribute("dur", "-1s");
  checkForException(anim, "dur=-1s");
  anim.setAttribute("dur", "indefinite");
  checkForException(anim, "dur=indefinite");
  anim.setAttribute("dur", "media");
  checkForException(anim, "dur=media");
  anim.setAttribute("dur", "abc");
  checkForException(anim, "dur=abc");
  anim.removeAttribute("dur");
  checkForException(anim, "dur not set");

  /* Check range/syntax */
  anim.setAttribute("dur", "100ms");
  isfuzzy(anim.getSimpleDuration(), 0.1, 0.001);
  anim.setAttribute("dur", "24h");
  is(anim.getSimpleDuration(), 60 * 60 * 24);

  SimpleTest.finish();
}

function checkForException(anim, descr) {
  var gotException = false;
  try {
    var dur = anim.getSimpleDuration();
  } catch(e) {
    is (e.name, "NotSupportedError",
        "Wrong exception from getSimpleDuration");
    is (e.code, DOMException.NOT_SUPPORTED_ERR,
        "Wrong exception from getSimpleDuration");
    gotException = true;
  }
  ok(gotException,
     "Exception not thrown for indefinite simple duration when " + descr);
}

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