test_smilBackwardsSeeking.xhtml (5602B)
1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <title>Test for backwards seeking behavior </title> 4 <script src="/tests/SimpleTest/SimpleTest.js"></script> 5 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 6 </head> 7 <body> 8 <p id="display"></p> 9 <div id="content" style="display: none"> 10 <svg id="svg" xmlns="http://www.w3.org/2000/svg" /> 11 </div> 12 <pre id="test"> 13 <script class="testbody" type="text/javascript"> 14 <![CDATA[ 15 /** Test for backwards seeking behavior */ 16 17 var gSvg = document.getElementById("svg"); 18 19 SimpleTest.waitForExplicitFinish(); 20 21 function main() 22 { 23 // Pause our document, so that the setCurrentTime calls are the only 24 // thing affecting document time 25 gSvg.pauseAnimations(); 26 27 // We define a series of scenarios, sample times, and expected return values 28 // from getStartTime. 29 // 30 // Each scenario is basically a variation on the following arrangement: 31 // 32 // <svg> 33 // <set ... dur="1s" begin="<A-BEGIN>"/> 34 // <set ... dur="1s" begin="<B-BEGIN>"/> 35 // </svg> 36 // 37 // Each test then consists of the following: 38 // animA: attributes to be applied to a 39 // animB: attributes to be applied to b 40 // times: a series of triples which consist of: 41 // <sample time, a's expected start time, b's expected start time> 42 // * The sample time is the time passed to setCurrentTime and so is 43 // in seconds. 44 // * The expected start times are compared with the return value of 45 // getStartTime. To check for an unresolved start time where 46 // getStartTime would normally throw an exception use 47 // 'unresolved'. 48 // * We also allow the special notation to indicate a call to 49 // beginElement 50 // <'beginElementAt', id of animation element, offset> 51 // 52 // In the diagrams below '^' means the time before the seek and '*' is the 53 // seek time. 54 var testCases = Array(); 55 56 // 0: Simple case 57 // 58 // A: +------- 59 // B: +------- begin: a.begin 60 // * ^ 61 testCases[0] = { 62 'animA': {'begin':'1s', 'id':'a'}, 63 'animB': {'begin':'a.begin'}, 64 'times': [ [0, 1, 1], 65 [1, 1, 1], 66 [2, 'unresolved', 'unresolved'], 67 [0, 1, 1], 68 [1.5, 1, 1], 69 [1, 1, 1], 70 [2, 'unresolved', 'unresolved'] ] 71 }; 72 73 // 1: Restored times should be live 74 // 75 // When we restore times they should be live. So we have the following 76 // scenario. 77 // 78 // A: +------- 79 // B: +------- begin: a.begin 80 // * ^ 81 // 82 // Then we call beginElement at an earlier time which should give us the 83 // following. 84 // 85 // A: +------- 86 // B: +------- 87 // * ^ 88 // 89 // If the times are not live however we'll end up with this 90 // 91 // A: +------- 92 // B: +-+------- 93 // * ^ 94 testCases[1] = { 95 'animA': {'begin':'1s', 'id':'a', 'restart':'whenNotActive'}, 96 'animB': {'begin':'a.begin', 'restart':'always'}, 97 'times': [ [0, 1, 1], 98 [2, 'unresolved', 'unresolved'], 99 [0.25, 1, 1], 100 ['beginElementAt', 'a', 0.25], // = start time of 0.5 101 [0.25, 0.5, 0.5], 102 [1, 0.5, 0.5], 103 [1.5, 'unresolved', 'unresolved'] ] 104 }; 105 106 // 2: Multiple intervals A 107 // 108 // A: +- +- 109 // B: +- +- begin: a.begin+4s 110 // * ^ 111 testCases[2] = { 112 'animA': {'begin':'1s; 3s', 'id':'a'}, 113 'animB': {'begin':'a.begin+4s'}, 114 'times': [ [0, 1, 5], 115 [3, 3, 5], 116 [6.5, 'unresolved', 7], 117 [4, 'unresolved', 5], 118 [6, 'unresolved', 7], 119 [2, 3, 5], 120 ['beginElementAt', 'a', 0], 121 [2, 2, 5], 122 [5, 'unresolved', 5], 123 [6, 'unresolved', 6], 124 [7, 'unresolved', 7], 125 [8, 'unresolved', 'unresolved'] ] 126 }; 127 128 for (var i = 0; i < testCases.length; i++) { 129 gSvg.setCurrentTime(0); 130 var test = testCases[i]; 131 132 // Create animation elements 133 var animA = createAnim(test.animA); 134 var animB = createAnim(test.animB); 135 136 // Run samples 137 for (var j = 0; j < test.times.length; j++) { 138 var times = test.times[j]; 139 if (times[0] == 'beginElementAt') { 140 var anim = getElement(times[1]); 141 anim.beginElementAt(times[2]); 142 } else { 143 gSvg.setCurrentTime(times[0]); 144 checkStartTime(animA, times[1], times[0], i, 'a'); 145 checkStartTime(animB, times[2], times[0], i, 'b'); 146 } 147 } 148 149 // Tidy up 150 animA.remove(); 151 animB.remove(); 152 } 153 154 SimpleTest.finish(); 155 } 156 157 function createAnim(attr) 158 { 159 const svgns = "http://www.w3.org/2000/svg"; 160 var anim = document.createElementNS(svgns, 'set'); 161 anim.setAttribute('attributeName','x'); 162 anim.setAttribute('to','10'); 163 anim.setAttribute('dur','1s'); 164 for (name in attr) { 165 anim.setAttribute(name, attr[name]); 166 } 167 return gSvg.appendChild(anim); 168 } 169 170 function checkStartTime(anim, expectedStartTime, sampleTime, caseNum, id) 171 { 172 var startTime = 'unresolved'; 173 try { 174 startTime = anim.getStartTime(); 175 } catch (e) { 176 if (e.name != "InvalidStateError" || 177 e.code != DOMException.INVALID_STATE_ERR) 178 throw e; 179 } 180 181 var msg = "Test case " + caseNum + ", t=" + sampleTime + " animation '" + 182 id + "': Unexpected getStartTime:"; 183 is(startTime, expectedStartTime, msg); 184 } 185 186 window.addEventListener("load", main); 187 ]]> 188 </script> 189 </pre> 190 </body> 191 </html>