test_smilDynamicDelayedBeginElement.xhtml (3326B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <!-- 3 https://bugzilla.mozilla.org/show_bug.cgi?id=699143 4 --> 5 <head> 6 <title>Test for Bug 699143</title> 7 <script src="/tests/SimpleTest/SimpleTest.js"></script> 8 <script type="text/javascript" src="smilTestUtils.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=699143">Mozilla Bug 699143</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 <svg xmlns="http://www.w3.org/2000/svg"> 16 <rect id="r" height="500px" width="500px" fill="blue"/> 17 </svg> 18 </div> 19 <pre id="test"> 20 <script type="text/javascript"> 21 <![CDATA[ 22 23 /** Test for Bug 699143 */ 24 SimpleTest.waitForExplicitFinish(); 25 26 // Values for 'width' attr on the <rect> above 27 const INITIAL_VAL = "500px" 28 const FROM_VAL = "20px"; 29 const TO_VAL = "80px"; 30 31 // Helper functions 32 33 // This function allows 10ms to pass 34 function allowTimeToPass() { 35 var initialDate = new Date(); 36 while (new Date() - initialDate < 10) {} 37 } 38 39 // This function returns a newly created <animate> element for use in this test 40 function createAnim() { 41 var a = document.createElementNS('http://www.w3.org/2000/svg', 'animate'); 42 a.setAttribute('attributeName', 'width'); 43 a.setAttribute('from', FROM_VAL); 44 a.setAttribute('to', TO_VAL); 45 a.setAttribute('begin', 'indefinite'); 46 a.setAttribute('dur', '3s'); 47 a.setAttribute('fill', 'freeze'); 48 return a; 49 } 50 51 // Main Functions 52 function main() { 53 // In unpatched Firefox builds, we'll only trigger Bug 699143 if we insert 54 // an animation and call beginElement() **after** the document start-time. 55 // Hence, we use executeSoon here to allow some time to pass. (And then 56 // we'll use a short busy-loop, for good measure.) 57 SimpleTest.executeSoon(runTest); 58 } 59 60 function runTest() { 61 var svg = SMILUtil.getSVGRoot(); 62 63 // In case our executeSoon fired immediately, we force a very small amount 64 // of time to pass here, using a 10ms busy-loop. 65 allowTimeToPass(); 66 67 is(svg.getCurrentTime(), 0, 68 "even though we've allowed time to pass, we shouldn't have bothered " + 69 "updating the current time, since there aren't any animation elements"); 70 71 // Insert an animation elem (should affect currentTime but not targeted attr) 72 var r = document.getElementById("r"); 73 var a = createAnim(); 74 r.appendChild(a); 75 isnot(svg.getCurrentTime(), 0, 76 "insertion of first animation element should have triggered a " + 77 "synchronous sample and updated our current time"); 78 is(r.width.animVal.valueAsString, INITIAL_VAL, 79 "inserted animation shouldn't have affected its targeted attribute, " + 80 "since it doesn't have any intervals yet"); 81 82 // Trigger the animation & be sure it takes effect 83 a.beginElement(); 84 is(r.width.animVal.valueAsString, FROM_VAL, 85 "beginElement() should activate our animation & set its 'from' val"); 86 87 // Rewind to time=0 & check target attr, to be sure beginElement()-generated 88 // interval starts later than that. 89 svg.setCurrentTime(0); 90 is(r.width.animVal.valueAsString, INITIAL_VAL, 91 "after rewinding to 0, our beginElement()-generated interval " + 92 "shouldn't be active yet"); 93 94 SimpleTest.finish(); 95 } 96 97 window.addEventListener("load", main); 98 99 ]]> 100 </script> 101 </pre> 102 </body> 103 </html>