test_smilGetSimpleDuration.xhtml (2419B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>Test for getSimpleDuration Behavior </title> 4 <script 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", ".15s"); 37 isfuzzy(anim.getSimpleDuration(), 0.15, 0.001); 38 anim.setAttribute("dur", "1.5s"); 39 is(anim.getSimpleDuration(), 1.5); 40 41 /* Check exceptional states */ 42 anim.setAttribute("dur", "0s"); 43 checkForException(anim, "dur=0s"); 44 anim.setAttribute("dur", "-1s"); 45 checkForException(anim, "dur=-1s"); 46 anim.setAttribute("dur", "indefinite"); 47 checkForException(anim, "dur=indefinite"); 48 anim.setAttribute("dur", "media"); 49 checkForException(anim, "dur=media"); 50 anim.setAttribute("dur", "abc"); 51 checkForException(anim, "dur=abc"); 52 anim.removeAttribute("dur"); 53 checkForException(anim, "dur not set"); 54 55 /* Check range/syntax */ 56 anim.setAttribute("dur", "100ms"); 57 isfuzzy(anim.getSimpleDuration(), 0.1, 0.001); 58 anim.setAttribute("dur", "24h"); 59 is(anim.getSimpleDuration(), 60 * 60 * 24); 60 61 SimpleTest.finish(); 62 } 63 64 function checkForException(anim, descr) { 65 var gotException = false; 66 try { 67 var dur = anim.getSimpleDuration(); 68 } catch(e) { 69 is (e.name, "NotSupportedError", 70 "Wrong exception from getSimpleDuration"); 71 is (e.code, DOMException.NOT_SUPPORTED_ERR, 72 "Wrong exception from getSimpleDuration"); 73 gotException = true; 74 } 75 ok(gotException, 76 "Exception not thrown for indefinite simple duration when " + descr); 77 } 78 79 window.addEventListener("load", main); 80 ]]> 81 </script> 82 </pre> 83 </body> 84 </html>