dom/smil/test/test_smilCrossContainer.xhtml

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

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 moving animations between time containers</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="svga" 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="circlea"/>
michael@0 14 </svg>
michael@0 15 <svg id="svgb" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
michael@0 16 onload="this.pauseAnimations()">
michael@0 17 <circle cx="-20" cy="20" r="15" fill="blue" id="circleb">
michael@0 18 <set attributeName="cy" to="120" begin="4s" dur="1s" id="syncb"/>
michael@0 19 </circle>
michael@0 20 </svg>
michael@0 21 </div>
michael@0 22 <pre id="test">
michael@0 23 <script class="testbody" type="text/javascript">
michael@0 24 <![CDATA[
michael@0 25 /** Test for moving animations between time containers **/
michael@0 26
michael@0 27 SimpleTest.waitForExplicitFinish();
michael@0 28
michael@0 29 function main() {
michael@0 30 var svga = getElement("svga");
michael@0 31 ok(svga.animationsPaused(), "should be paused by <svg> load handler");
michael@0 32 is(svga.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
michael@0 33 svga.setCurrentTime(1);
michael@0 34
michael@0 35 var svgb = getElement("svgb");
michael@0 36 ok(svgb.animationsPaused(), "should be paused by <svg> load handler");
michael@0 37 is(svgb.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
michael@0 38 svgb.setCurrentTime(1);
michael@0 39
michael@0 40 // Create animation and check initial state
michael@0 41 var anim = createAnim();
michael@0 42 ok(noStart(anim), "Animation has start time before attaching to document");
michael@0 43
michael@0 44 // Attach animation to first container
michael@0 45 var circlea = getElement("circlea");
michael@0 46 var circleb = getElement("circleb");
michael@0 47 circlea.appendChild(anim);
michael@0 48
michael@0 49 // Check state after attaching
michael@0 50 is(anim.getStartTime(), 2,
michael@0 51 "Unexpected start time after attaching animation to target");
michael@0 52 is(circlea.cx.animVal.value, -20,
michael@0 53 "Unexpected animated value for yet-to-start animation");
michael@0 54 is(circleb.cx.animVal.value, -20,
michael@0 55 "Unexpected animated value for unanimated target");
michael@0 56
michael@0 57 // Move animation from first container to second
michael@0 58 circleb.appendChild(anim);
michael@0 59
michael@0 60 // Advance first container and check animation has no effect
michael@0 61 svga.setCurrentTime(2);
michael@0 62 is(anim.getStartTime(), 2,
michael@0 63 "Unexpected start time after moving animation");
michael@0 64 is(circlea.cx.animVal.value, -20,
michael@0 65 "Unexpected animated value for non-longer-animated target");
michael@0 66 is(circleb.cx.animVal.value, -20,
michael@0 67 "Unexpected animated value for now yet-to-start animation");
michael@0 68
michael@0 69 // Advance second container and check the animation only affects it
michael@0 70 svgb.setCurrentTime(2);
michael@0 71 is(anim.getStartTime(), 2, "Start time changed after time container seek");
michael@0 72 is(circlea.cx.animVal.value, -20,
michael@0 73 "Unanimated target changed after seek on other container");
michael@0 74 is(circleb.cx.animVal.value, 100, "Animated target not animated after seek");
michael@0 75
michael@0 76 // Remove animation so that it belongs to no container and check that
michael@0 77 // advancing the second container to the next milestone doesn't cause a crash
michael@0 78 // (when the animation controller goes to run the next milestone sample).
michael@0 79 anim.parentNode.removeChild(anim);
michael@0 80 svgb.setCurrentTime(3);
michael@0 81
michael@0 82 // Do likewise with syncbase relationships
michael@0 83
michael@0 84 // Create the syncbase relationship
michael@0 85 anim.setAttribute('begin', 'syncb.begin');
michael@0 86
michael@0 87 // Attach to second time container (where t=3s)
michael@0 88 circleb.appendChild(anim);
michael@0 89 is(anim.getStartTime(), 4,
michael@0 90 "Unexpected start time for cross-time container syncbase dependency");
michael@0 91
michael@0 92 // Move to first time container (where t=1s).
michael@0 93 // Because we're dealing with different time containers and both are paused,
michael@0 94 // future times are effectively unresolved.
michael@0 95 circlea.appendChild(anim);
michael@0 96 ok(noStart(anim), "Unexpected start time for paused time container");
michael@0 97
michael@0 98 SimpleTest.finish();
michael@0 99 }
michael@0 100
michael@0 101 function createAnim() {
michael@0 102 const svgns="http://www.w3.org/2000/svg";
michael@0 103 var anim = document.createElementNS(svgns,'set');
michael@0 104 anim.setAttribute('attributeName','cx');
michael@0 105 anim.setAttribute('to','100');
michael@0 106 anim.setAttribute('begin','2s');
michael@0 107 anim.setAttribute('dur','1s');
michael@0 108 return anim;
michael@0 109 }
michael@0 110
michael@0 111 function noStart(elem) {
michael@0 112 var exceptionCaught = false;
michael@0 113
michael@0 114 try {
michael@0 115 elem.getStartTime();
michael@0 116 } catch(e) {
michael@0 117 exceptionCaught = true;
michael@0 118 is (e.name, "InvalidStateError",
michael@0 119 "Unexpected exception from getStartTime.");
michael@0 120 is (e.code, DOMException.INVALID_STATE_ERR,
michael@0 121 "Unexpected exception code from getStartTime");
michael@0 122 }
michael@0 123
michael@0 124 return exceptionCaught;
michael@0 125 }
michael@0 126
michael@0 127 window.addEventListener("load", main, false);
michael@0 128 ]]>
michael@0 129 </script>
michael@0 130 </pre>
michael@0 131 </body>
michael@0 132 </html>

mercurial