1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/smil/test/test_smilDynamicDelayedBeginElement.xhtml Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +<html xmlns="http://www.w3.org/1999/xhtml"> 1.5 +<!-- 1.6 +https://bugzilla.mozilla.org/show_bug.cgi?id=699143 1.7 +--> 1.8 +<head> 1.9 + <title>Test for Bug 699143</title> 1.10 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <script type="text/javascript" src="smilTestUtils.js"></script> 1.12 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.13 +</head> 1.14 +<body> 1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=699143">Mozilla Bug 699143</a> 1.16 +<p id="display"></p> 1.17 +<div id="content" style="display: none"> 1.18 + <svg xmlns="http://www.w3.org/2000/svg"> 1.19 + <rect id="r" height="500px" width="500px" fill="blue"/> 1.20 + </svg> 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script type="text/javascript"> 1.24 +<![CDATA[ 1.25 + 1.26 +/** Test for Bug 699143 **/ 1.27 +SimpleTest.waitForExplicitFinish(); 1.28 + 1.29 +// Values for 'width' attr on the <rect> above 1.30 +const INITIAL_VAL = "500px" 1.31 +const FROM_VAL = "20px"; 1.32 +const TO_VAL = "80px"; 1.33 + 1.34 +// Helper functions 1.35 + 1.36 +// This function allows 10ms to pass 1.37 +function allowTimeToPass() { 1.38 + var initialDate = new Date(); 1.39 + while (new Date() - initialDate < 10) {} 1.40 +} 1.41 + 1.42 +// This function returns a newly created <animate> element for use in this test 1.43 +function createAnim() { 1.44 + var a = document.createElementNS('http://www.w3.org/2000/svg', 'animate'); 1.45 + a.setAttribute('attributeName', 'width'); 1.46 + a.setAttribute('from', FROM_VAL); 1.47 + a.setAttribute('to', TO_VAL); 1.48 + a.setAttribute('begin', 'indefinite'); 1.49 + a.setAttribute('dur', '3s'); 1.50 + a.setAttribute('fill', 'freeze'); 1.51 + return a; 1.52 +} 1.53 + 1.54 +// Main Functions 1.55 +function main() { 1.56 + // In unpatched Firefox builds, we'll only trigger Bug 699143 if we insert 1.57 + // an animation and call beginElement() **after** the document start-time. 1.58 + // Hence, we use executeSoon here to allow some time to pass. (And then 1.59 + // we'll use a short busy-loop, for good measure.) 1.60 + SimpleTest.executeSoon(runTest); 1.61 +} 1.62 + 1.63 +function runTest() { 1.64 + var svg = SMILUtil.getSVGRoot(); 1.65 + 1.66 + // In case our executeSoon fired immediately, we force a very small amount 1.67 + // of time to pass here, using a 10ms busy-loop. 1.68 + allowTimeToPass(); 1.69 + 1.70 + is(svg.getCurrentTime(), 0, 1.71 + "even though we've allowed time to pass, we shouldn't have bothered " + 1.72 + "updating the current time, since there aren't any animation elements"); 1.73 + 1.74 + // Insert an animation elem (should affect currentTime but not targeted attr) 1.75 + var r = document.getElementById("r"); 1.76 + var a = createAnim(); 1.77 + r.appendChild(a); 1.78 + isnot(svg.getCurrentTime(), 0, 1.79 + "insertion of first animation element should have triggered a " + 1.80 + "synchronous sample and updated our current time"); 1.81 + is(r.width.animVal.valueAsString, INITIAL_VAL, 1.82 + "inserted animation shouldn't have affected its targeted attribute, " + 1.83 + "since it doesn't have any intervals yet"); 1.84 + 1.85 + // Trigger the animation & be sure it takes effect 1.86 + a.beginElement(); 1.87 + is(r.width.animVal.valueAsString, FROM_VAL, 1.88 + "beginElement() should activate our animation & set its 'from' val"); 1.89 + 1.90 + // Rewind to time=0 & check target attr, to be sure beginElement()-generated 1.91 + // interval starts later than that. 1.92 + svg.setCurrentTime(0); 1.93 + is(r.width.animVal.valueAsString, INITIAL_VAL, 1.94 + "after rewinding to 0, our beginElement()-generated interval " + 1.95 + "shouldn't be active yet"); 1.96 + 1.97 + SimpleTest.finish(); 1.98 +} 1.99 + 1.100 +window.addEventListener("load", main, false); 1.101 + 1.102 +]]> 1.103 +</script> 1.104 +</pre> 1.105 +</body> 1.106 +</html>