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 | <?xml version="1.0" encoding="UTF-8" ?> |
michael@0 | 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>Test for adding and removing animations from a time container</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 7 | </head> |
michael@0 | 8 | <body> |
michael@0 | 9 | <p id="display"></p> |
michael@0 | 10 | <div id="content" style="display: none"> |
michael@0 | 11 | <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" |
michael@0 | 12 | onload="this.pauseAnimations()"> |
michael@0 | 13 | <circle cx="-20" cy="20" r="15" fill="blue" id="circle"> |
michael@0 | 14 | <set attributeName="cy" to="120" begin="0s; 2s" dur="1s" id="b"/> |
michael@0 | 15 | </circle> |
michael@0 | 16 | </svg> |
michael@0 | 17 | </div> |
michael@0 | 18 | <pre id="test"> |
michael@0 | 19 | <script class="testbody" type="text/javascript"> |
michael@0 | 20 | <![CDATA[ |
michael@0 | 21 | /** Test for adding and removing animations from a time container **/ |
michael@0 | 22 | |
michael@0 | 23 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 24 | |
michael@0 | 25 | function main() { |
michael@0 | 26 | var svg = getElement("svg"); |
michael@0 | 27 | ok(svg.animationsPaused(), "should be paused by <svg> load handler"); |
michael@0 | 28 | is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); |
michael@0 | 29 | |
michael@0 | 30 | // Create animation and check initial state |
michael@0 | 31 | var anim = createAnim(); |
michael@0 | 32 | anim.setAttribute('begin','b.begin+2s; 6s'); |
michael@0 | 33 | ok(noStart(anim), "Animation has start time before attaching to document."); |
michael@0 | 34 | |
michael@0 | 35 | // Attach animation to container |
michael@0 | 36 | var circle = getElement("circle"); |
michael@0 | 37 | circle.appendChild(anim); |
michael@0 | 38 | |
michael@0 | 39 | // Check state after attaching |
michael@0 | 40 | is(anim.getStartTime(), 2); |
michael@0 | 41 | |
michael@0 | 42 | // Unbind from tree -- the syncbase instance time(s) should become unresolved |
michael@0 | 43 | // but the offset time should remain |
michael@0 | 44 | anim.parentNode.removeChild(anim); |
michael@0 | 45 | is(anim.getStartTime(), 6); |
michael@0 | 46 | |
michael@0 | 47 | // Rebind and check everything is re-resolved |
michael@0 | 48 | circle.appendChild(anim); |
michael@0 | 49 | is(anim.getStartTime(), 2); |
michael@0 | 50 | |
michael@0 | 51 | // Advance document time to t=1s |
michael@0 | 52 | // Now the current interval for b is 2s-3s but the current interval for anim |
michael@0 | 53 | // is still 2s-2.5s based on b's previous interval |
michael@0 | 54 | svg.setCurrentTime(1); |
michael@0 | 55 | is(anim.getStartTime(), 2); |
michael@0 | 56 | |
michael@0 | 57 | // Unbind |
michael@0 | 58 | anim.parentNode.removeChild(anim); |
michael@0 | 59 | is(anim.getStartTime(), 6); |
michael@0 | 60 | |
michael@0 | 61 | // Rebind |
michael@0 | 62 | // At this point only the current interval will be re-added to anim (this is |
michael@0 | 63 | // for consistency since old intervals may or may not have been filtered). |
michael@0 | 64 | // Therefore the start time should be 4s instead of 2s. |
michael@0 | 65 | circle.appendChild(anim); |
michael@0 | 66 | is(anim.getStartTime(), 4); |
michael@0 | 67 | |
michael@0 | 68 | SimpleTest.finish(); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function createAnim() { |
michael@0 | 72 | const svgns="http://www.w3.org/2000/svg"; |
michael@0 | 73 | var anim = document.createElementNS(svgns,'set'); |
michael@0 | 74 | anim.setAttribute('attributeName','cx'); |
michael@0 | 75 | anim.setAttribute('to','100'); |
michael@0 | 76 | anim.setAttribute('dur','0.5s'); |
michael@0 | 77 | return anim; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | function noStart(elem) { |
michael@0 | 81 | var exceptionCaught = false; |
michael@0 | 82 | |
michael@0 | 83 | try { |
michael@0 | 84 | elem.getStartTime(); |
michael@0 | 85 | } catch(e) { |
michael@0 | 86 | exceptionCaught = true; |
michael@0 | 87 | is (e.name, "InvalidStateError", |
michael@0 | 88 | "Unexpected exception from getStartTime."); |
michael@0 | 89 | is (e.code, DOMException.INVALID_STATE_ERR, |
michael@0 | 90 | "Unexpected exception code from getStartTime."); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | return exceptionCaught; |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | window.addEventListener("load", main, false); |
michael@0 | 97 | ]]> |
michael@0 | 98 | </script> |
michael@0 | 99 | </pre> |
michael@0 | 100 | </body> |
michael@0 | 101 | </html> |