|
1 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
2 <head> |
|
3 <title>Test for getSimpleDuration Behavior </title> |
|
4 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
|
6 </head> |
|
7 <body> |
|
8 <p id="display"></p> |
|
9 <div id="content" style="display: none"> |
|
10 <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"> |
|
11 <circle cx="20" cy="20" r="15" fill="blue"> |
|
12 <animate attributeName="cx" attributeType="XML" |
|
13 from="20" to="100" begin="1s" id="anim"/> |
|
14 </circle> |
|
15 </svg> |
|
16 </div> |
|
17 <pre id="test"> |
|
18 <script class="testbody" type="text/javascript"> |
|
19 <![CDATA[ |
|
20 /** Test for getSimpleDuration Behavior **/ |
|
21 |
|
22 /* Global Variables */ |
|
23 var svg = document.getElementById("svg"); |
|
24 |
|
25 SimpleTest.waitForExplicitFinish(); |
|
26 |
|
27 function main() { |
|
28 var anim = document.getElementById("anim"); |
|
29 |
|
30 /* Check initial state */ |
|
31 checkForException(anim, "dur not set"); |
|
32 |
|
33 /* Check basic operation */ |
|
34 anim.setAttribute("dur", "1s"); |
|
35 is(anim.getSimpleDuration(), 1); |
|
36 anim.setAttribute("dur", "1.5s"); |
|
37 is(anim.getSimpleDuration(), 1.5); |
|
38 |
|
39 /* Check exceptional states */ |
|
40 anim.setAttribute("dur", "0s"); |
|
41 checkForException(anim, "dur=0s"); |
|
42 anim.setAttribute("dur", "-1s"); |
|
43 checkForException(anim, "dur=-1s"); |
|
44 anim.setAttribute("dur", "indefinite"); |
|
45 checkForException(anim, "dur=indefinite"); |
|
46 anim.setAttribute("dur", "media"); |
|
47 checkForException(anim, "dur=media"); |
|
48 anim.setAttribute("dur", "abc"); |
|
49 checkForException(anim, "dur=abc"); |
|
50 anim.removeAttribute("dur"); |
|
51 checkForException(anim, "dur not set"); |
|
52 |
|
53 /* Check range/syntax */ |
|
54 anim.setAttribute("dur", "100ms"); |
|
55 millisecondCompare(anim.getSimpleDuration(), 0.1); |
|
56 anim.setAttribute("dur", "24h"); |
|
57 is(anim.getSimpleDuration(), 60 * 60 * 24); |
|
58 |
|
59 SimpleTest.finish(); |
|
60 } |
|
61 |
|
62 function millisecondCompare(a, b) { |
|
63 is(Math.round(a * 1000), Math.round(b * 1000)); |
|
64 } |
|
65 |
|
66 function checkForException(anim, descr) { |
|
67 var gotException = false; |
|
68 try { |
|
69 var dur = anim.getSimpleDuration(); |
|
70 } catch(e) { |
|
71 is (e.name, "NotSupportedError", |
|
72 "Wrong exception from getSimpleDuration"); |
|
73 is (e.code, DOMException.NOT_SUPPORTED_ERR, |
|
74 "Wrong exception from getSimpleDuration"); |
|
75 gotException = true; |
|
76 } |
|
77 ok(gotException, |
|
78 "Exception not thrown for indefinite simple duration when " + descr); |
|
79 } |
|
80 |
|
81 window.addEventListener("load", main, false); |
|
82 ]]> |
|
83 </script> |
|
84 </pre> |
|
85 </body> |
|
86 </html> |