Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <head> |
michael@0 | 3 | <title>Test for SMIL Restart Behavior </title> |
michael@0 | 4 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 5 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 6 | </head> |
michael@0 | 7 | <body> |
michael@0 | 8 | <p id="display"></p> |
michael@0 | 9 | <div id="content" style="display: none"> |
michael@0 | 10 | <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" |
michael@0 | 11 | onload="this.pauseAnimations()"> |
michael@0 | 12 | <!-- These 3 circles only differ in their animation's "restart" value --> |
michael@0 | 13 | <circle cx="20" cy="20" r="15" fill="blue"> |
michael@0 | 14 | <animate attributeName="cx" from="20" to="100" begin="1s" dur="4s" |
michael@0 | 15 | restart="always" id="always" attributeType="XML"/> |
michael@0 | 16 | </circle> |
michael@0 | 17 | <circle cx="20" cy="60" r="15" fill="blue"> |
michael@0 | 18 | <animate attributeName="cx" from="20" to="100" begin="1s" dur="4s" |
michael@0 | 19 | restart="whenNotActive" id="whenNotActive" attributeType="XML"/> |
michael@0 | 20 | </circle> |
michael@0 | 21 | <circle cx="20" cy="100" r="15" fill="blue"> |
michael@0 | 22 | <animate attributeName="cx" from="20" to="100" begin="1s" dur="4s" |
michael@0 | 23 | restart="never" id="never" attributeType="XML"/> |
michael@0 | 24 | </circle> |
michael@0 | 25 | </svg> |
michael@0 | 26 | </div> |
michael@0 | 27 | <pre id="test"> |
michael@0 | 28 | <script class="testbody" type="text/javascript"> |
michael@0 | 29 | <![CDATA[ |
michael@0 | 30 | /** Test for SMIL Restart Behavior **/ |
michael@0 | 31 | |
michael@0 | 32 | /* Global Variables */ |
michael@0 | 33 | var svg = document.getElementById("svg"); |
michael@0 | 34 | var always = document.getElementById("always"); |
michael@0 | 35 | var whenNotActive = document.getElementById("whenNotActive"); |
michael@0 | 36 | var never = document.getElementById("never"); |
michael@0 | 37 | |
michael@0 | 38 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 39 | |
michael@0 | 40 | function tryRestart(elem, state, expected) { |
michael@0 | 41 | var restartTime = svg.getCurrentTime(); |
michael@0 | 42 | elem.beginElement(); |
michael@0 | 43 | var restart = false; |
michael@0 | 44 | try { |
michael@0 | 45 | restart = (elem.getStartTime() === restartTime); |
michael@0 | 46 | } catch (e) { |
michael@0 | 47 | if (e.name != "InvalidStateError" || |
michael@0 | 48 | e.code != DOMException.INVALID_STATE_ERR) |
michael@0 | 49 | throw e; |
michael@0 | 50 | restart = false; |
michael@0 | 51 | } |
michael@0 | 52 | if (expected) { |
michael@0 | 53 | var msg = elem.id + " can't restart in " + state + " state"; |
michael@0 | 54 | ok(restart, msg); |
michael@0 | 55 | } else { |
michael@0 | 56 | var msg = elem.id + " can restart in " + state + " state"; |
michael@0 | 57 | ok(!restart, msg); |
michael@0 | 58 | } |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function main() { |
michael@0 | 62 | ok(svg.animationsPaused(), "should be paused by <svg> load handler"); |
michael@0 | 63 | is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); |
michael@0 | 64 | |
michael@0 | 65 | // At first everything should be starting at 1s |
michael@0 | 66 | is(always.getStartTime(), 1); |
michael@0 | 67 | is(whenNotActive.getStartTime(), 1); |
michael@0 | 68 | is(never.getStartTime(), 1); |
michael@0 | 69 | |
michael@0 | 70 | // Now try to restart everything early, should be allowed by all |
michael@0 | 71 | tryRestart(always, "waiting", true); |
michael@0 | 72 | tryRestart(whenNotActive, "waiting", true); |
michael@0 | 73 | tryRestart(never, "waiting", true); |
michael@0 | 74 | |
michael@0 | 75 | // Now skip to half-way |
michael@0 | 76 | var newTime = always.getStartTime() + 0.5 * always.getSimpleDuration(); |
michael@0 | 77 | svg.setCurrentTime(newTime); |
michael@0 | 78 | |
michael@0 | 79 | // Only 'always' should be able to be restarted |
michael@0 | 80 | tryRestart(always, "active", true); |
michael@0 | 81 | tryRestart(whenNotActive, "active", false); |
michael@0 | 82 | tryRestart(never, "active", false); |
michael@0 | 83 | |
michael@0 | 84 | // Now skip to the end |
michael@0 | 85 | newTime = always.getStartTime() + always.getSimpleDuration() + 1; |
michael@0 | 86 | svg.setCurrentTime(newTime); |
michael@0 | 87 | |
michael@0 | 88 | // All animations have finished, so 'always' and 'whenNotActive' should be |
michael@0 | 89 | // able to be restarted |
michael@0 | 90 | tryRestart(always, "postactive", true); |
michael@0 | 91 | tryRestart(whenNotActive, "postactive", true); |
michael@0 | 92 | tryRestart(never, "postactive", false); |
michael@0 | 93 | |
michael@0 | 94 | SimpleTest.finish(); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | window.addEventListener("load", main, false); |
michael@0 | 98 | ]]> |
michael@0 | 99 | </script> |
michael@0 | 100 | </pre> |
michael@0 | 101 | </body> |
michael@0 | 102 | </html> |