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 | <html xmlns="http://www.w3.org/1999/xhtml"> |
michael@0 | 2 | <head> |
michael@0 | 3 | <title>Test for SMIL timing</title> |
michael@0 | 4 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 5 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 6 | </head> |
michael@0 | 7 | <body> |
michael@0 | 8 | <p id="display"></p> |
michael@0 | 9 | <div id="content" style="display: none"> |
michael@0 | 10 | <svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px" |
michael@0 | 11 | onload="this.pauseAnimations()"> |
michael@0 | 12 | <circle cx="-100" cy="20" r="15" fill="blue" id="circle"/> |
michael@0 | 13 | </svg> |
michael@0 | 14 | </div> |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | <script class="testbody" type="text/javascript"> |
michael@0 | 17 | <![CDATA[ |
michael@0 | 18 | /** Test for SMIL timing **/ |
michael@0 | 19 | |
michael@0 | 20 | /* Global Variables */ |
michael@0 | 21 | const svgns = "http://www.w3.org/2000/svg"; |
michael@0 | 22 | var gSvg = document.getElementById("svg"); |
michael@0 | 23 | var gCircle = document.getElementById('circle'); |
michael@0 | 24 | |
michael@0 | 25 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 26 | |
michael@0 | 27 | function main() { |
michael@0 | 28 | ok(gSvg.animationsPaused(), "should be paused by <svg> load handler"); |
michael@0 | 29 | is(gSvg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler"); |
michael@0 | 30 | |
michael@0 | 31 | var testCases = Array(); |
michael@0 | 32 | |
michael@0 | 33 | const secPerMin = 60; |
michael@0 | 34 | const secPerHour = secPerMin * 60; |
michael@0 | 35 | |
michael@0 | 36 | // In the following tests that compare start times, getStartTime will round |
michael@0 | 37 | // the start time to three decimal places since we expect our implementation |
michael@0 | 38 | // to be millisecond accurate. |
michael@0 | 39 | |
michael@0 | 40 | // Offset syntax |
michael@0 | 41 | // -- Basic tests, sign and whitespace |
michael@0 | 42 | testCases.push(StartTimeTest('3s', 3)); |
michael@0 | 43 | testCases.push(StartTimeTest('0s', 0)); |
michael@0 | 44 | testCases.push(StartTimeTest('+2s', 2)); |
michael@0 | 45 | testCases.push(StartTimeTest('-1s\t\r', -1)); |
michael@0 | 46 | testCases.push(StartTimeTest('- 1s', -1)); |
michael@0 | 47 | testCases.push(StartTimeTest(' -1s', -1)); |
michael@0 | 48 | testCases.push(StartTimeTest(' - 1s', -1)); |
michael@0 | 49 | testCases.push(StartTimeTest(' \t\n\r-1s', -1)); |
michael@0 | 50 | testCases.push(StartTimeTest('+\n5s', 5)); |
michael@0 | 51 | testCases.push(StartTimeTest('-\n5s', -5)); |
michael@0 | 52 | testCases.push(StartTimeTest('\t 5s', 5)); |
michael@0 | 53 | // -- These tests are from SMILANIM 3.6.7 |
michael@0 | 54 | testCases.push(StartTimeTest('02:30:03', 2*secPerHour + 30*secPerMin + 3)); |
michael@0 | 55 | testCases.push(StartTimeTest('50:00:10.25', 50*secPerHour + 10.25)); |
michael@0 | 56 | testCases.push(StartTimeTest('02:33', 2*secPerMin + 33)); |
michael@0 | 57 | testCases.push(StartTimeTest('00:10.5', 10.5)); |
michael@0 | 58 | testCases.push(StartTimeTest('3.2h', 3.2*secPerHour)); |
michael@0 | 59 | testCases.push(StartTimeTest('45min', 45*secPerMin)); |
michael@0 | 60 | testCases.push(StartTimeTest('30s', 30)); |
michael@0 | 61 | testCases.push(StartTimeTest('5ms', 0.005)); |
michael@0 | 62 | testCases.push(StartTimeTest('12.467', 12.467)); |
michael@0 | 63 | testCases.push(StartTimeTest('00.5s', 0.5)); |
michael@0 | 64 | testCases.push(StartTimeTest('00:00.005', 0.005)); |
michael@0 | 65 | // -- Additional tests |
michael@0 | 66 | testCases.push(StartTimeTest('61:59:59', 61*secPerHour + 59*secPerMin + 59)); |
michael@0 | 67 | testCases.push(StartTimeTest('02:59.999999999999999999999', 3*secPerMin)); |
michael@0 | 68 | testCases.push(StartTimeTest('1234:23:45', |
michael@0 | 69 | 1234*secPerHour + 23*secPerMin + 45)); |
michael@0 | 70 | testCases.push(StartTimeTest('61min', 61*secPerMin)); |
michael@0 | 71 | testCases.push(StartTimeTest('0:30:03', 30*secPerMin + 3)); |
michael@0 | 72 | // -- Fractional precision |
michael@0 | 73 | testCases.push(StartTimeTest('25.4567', 25.457)); |
michael@0 | 74 | testCases.push(StartTimeTest('0.123456789', 0.123)); |
michael@0 | 75 | testCases.push(StartTimeTest('0.00000000000000000000001', 0)); |
michael@0 | 76 | testCases.push(StartTimeTest('-0.00000000000000000000001', 0)); |
michael@0 | 77 | testCases.push(StartTimeTest('0.0009', 0.001)); |
michael@0 | 78 | testCases.push(StartTimeTest('0.99999999999999999999999999999999999999', 1)); |
michael@0 | 79 | testCases.push(StartTimeTest('23.4567ms', 0.023)); |
michael@0 | 80 | testCases.push(StartTimeTest('23.7ms', 0.024)); |
michael@0 | 81 | // -- Test errors |
michael@0 | 82 | testCases.push(StartTimeTest(' + +3s', 'none')); |
michael@0 | 83 | testCases.push(StartTimeTest(' +-3s', 'none')); |
michael@0 | 84 | testCases.push(StartTimeTest('1:12:12:12', 'none')); |
michael@0 | 85 | testCases.push(StartTimeTest('4:50:60', 'none')); |
michael@0 | 86 | testCases.push(StartTimeTest('4:60:0', 'none')); |
michael@0 | 87 | testCases.push(StartTimeTest('4:60', 'none')); |
michael@0 | 88 | testCases.push(StartTimeTest('4:-1:00', 'none')); |
michael@0 | 89 | testCases.push(StartTimeTest('4 5m', 'none')); |
michael@0 | 90 | testCases.push(StartTimeTest('4 5ms', 'none')); |
michael@0 | 91 | testCases.push(StartTimeTest('02:3:03', 'none')); |
michael@0 | 92 | testCases.push(StartTimeTest('45.7 s', 'none')); |
michael@0 | 93 | testCases.push(StartTimeTest(' 3 h ', 'none')); |
michael@0 | 94 | testCases.push(StartTimeTest('2:33 ', 'none')); |
michael@0 | 95 | testCases.push(StartTimeTest('02:33 2', 'none')); |
michael@0 | 96 | testCases.push(StartTimeTest('\u000B 02:33', 'none')); |
michael@0 | 97 | testCases.push(StartTimeTest('h', 'none')); |
michael@0 | 98 | testCases.push(StartTimeTest('23.s', 'none')); |
michael@0 | 99 | testCases.push(StartTimeTest('23.', 'none')); |
michael@0 | 100 | testCases.push(StartTimeTest('23.54.2s', 'none')); |
michael@0 | 101 | testCases.push(StartTimeTest('23sec', 'none')); |
michael@0 | 102 | testCases.push(StartTimeTest('five', 'none')); |
michael@0 | 103 | testCases.push(StartTimeTest('', 'none')); |
michael@0 | 104 | testCases.push(StartTimeTest('02:33s', 'none')); |
michael@0 | 105 | testCases.push(StartTimeTest('02:33 s', 'none')); |
michael@0 | 106 | testCases.push(StartTimeTest('2.54e6', 'none')); |
michael@0 | 107 | testCases.push(StartTimeTest('02.5:33', 'none')); |
michael@0 | 108 | testCases.push(StartTimeTest('2:-45:33', 'none')); |
michael@0 | 109 | testCases.push(StartTimeTest('2:4.5:33', 'none')); |
michael@0 | 110 | testCases.push(StartTimeTest('45m', 'none')); |
michael@0 | 111 | testCases.push(StartTimeTest(':20:30', 'none')); |
michael@0 | 112 | testCases.push(StartTimeTest('1.5:30', 'none')); |
michael@0 | 113 | testCases.push(StartTimeTest('15:-30', 'none')); |
michael@0 | 114 | testCases.push(StartTimeTest('::30', 'none')); |
michael@0 | 115 | testCases.push(StartTimeTest('15:30s', 'none')); |
michael@0 | 116 | testCases.push(StartTimeTest('2:1.:30', 'none')); |
michael@0 | 117 | testCases.push(StartTimeTest('2:.1:30', 'none')); |
michael@0 | 118 | testCases.push(StartTimeTest('2.0:15:30', 'none')); |
michael@0 | 119 | testCases.push(StartTimeTest('2.:15:30', 'none')); |
michael@0 | 120 | testCases.push(StartTimeTest('.2:15:30', 'none')); |
michael@0 | 121 | testCases.push(StartTimeTest('70:15', 'none')); |
michael@0 | 122 | testCases.push(StartTimeTest('media', 'none')); |
michael@0 | 123 | testCases.push(StartTimeTest('5mi', 'none')); |
michael@0 | 124 | testCases.push(StartTimeTest('5hours', 'none')); |
michael@0 | 125 | testCases.push(StartTimeTest('h05:30', 'none')); |
michael@0 | 126 | testCases.push(StartTimeTest('05:40\x9A', 'none')); |
michael@0 | 127 | testCases.push(StartTimeTest('05:40\u30D5', 'none')); |
michael@0 | 128 | testCases.push(StartTimeTest('05:40β', 'none')); |
michael@0 | 129 | |
michael@0 | 130 | // List syntax |
michael@0 | 131 | testCases.push(StartTimeTest('3', 3)); |
michael@0 | 132 | testCases.push(StartTimeTest('3;', 3)); |
michael@0 | 133 | testCases.push(StartTimeTest('3; ', 3)); |
michael@0 | 134 | testCases.push(StartTimeTest('3 ; ', 3)); |
michael@0 | 135 | testCases.push(StartTimeTest('3;;', 'none')); |
michael@0 | 136 | testCases.push(StartTimeTest('3;; ', 'none')); |
michael@0 | 137 | testCases.push(StartTimeTest(';3', 'none')); |
michael@0 | 138 | testCases.push(StartTimeTest(' ;3', 'none')); |
michael@0 | 139 | testCases.push(StartTimeTest('3;4', 3)); |
michael@0 | 140 | testCases.push(StartTimeTest(' 3 ; 4 ', 3)); |
michael@0 | 141 | |
michael@0 | 142 | // List syntax on end times |
michael@0 | 143 | testCases.push({ |
michael@0 | 144 | 'attr' : { 'begin': '0s', |
michael@0 | 145 | 'end': '1s; 2s' }, |
michael@0 | 146 | 'times': [ [ 0, 0 ], |
michael@0 | 147 | [ 1, -100 ] ] |
michael@0 | 148 | }); |
michael@0 | 149 | testCases.push({ |
michael@0 | 150 | 'attr' : { 'begin': '0s', |
michael@0 | 151 | 'end': '1s; 2s; ' }, |
michael@0 | 152 | 'times': [ [ 0, 0 ], |
michael@0 | 153 | [ 1, -100 ] ] |
michael@0 | 154 | }); |
michael@0 | 155 | testCases.push({ |
michael@0 | 156 | 'attr' : { 'begin': '0s', |
michael@0 | 157 | 'end': '3s; 2s' }, |
michael@0 | 158 | 'times': [ [ 0, 0 ], |
michael@0 | 159 | [ 1, 10 ], |
michael@0 | 160 | [ 2, -100 ] ] |
michael@0 | 161 | }); |
michael@0 | 162 | |
michael@0 | 163 | // Simple case |
michael@0 | 164 | testCases.push({ |
michael@0 | 165 | 'attr' : { 'begin': '3s' }, |
michael@0 | 166 | 'times': [ [ 0, -100 ], |
michael@0 | 167 | [ 4, 10 ] ] |
michael@0 | 168 | }); |
michael@0 | 169 | |
michael@0 | 170 | // Multiple begins |
michael@0 | 171 | testCases.push({ |
michael@0 | 172 | 'attr' : { 'begin': '2s; 6s', |
michael@0 | 173 | 'dur': '2s' }, |
michael@0 | 174 | 'times': [ [ 0, -100 ], |
michael@0 | 175 | [ 3, 50 ], |
michael@0 | 176 | [ 4, -100 ], |
michael@0 | 177 | [ 7, 50 ], |
michael@0 | 178 | [ 8, -100 ] ] |
michael@0 | 179 | }); |
michael@0 | 180 | |
michael@0 | 181 | // Negative begins |
michael@0 | 182 | testCases.push({ |
michael@0 | 183 | 'attr' : { 'begin': '-3s; 1s ; 4s', |
michael@0 | 184 | 'dur': '2s ', |
michael@0 | 185 | 'fill': 'freeze' }, |
michael@0 | 186 | 'times': [ [ 0, -100 ], |
michael@0 | 187 | [ 0.5, -100 ], |
michael@0 | 188 | [ 1, 0 ], |
michael@0 | 189 | [ 2, 50 ], |
michael@0 | 190 | [ 3, 100 ], |
michael@0 | 191 | [ 5, 50 ] ] |
michael@0 | 192 | }); |
michael@0 | 193 | |
michael@0 | 194 | // Sorting |
michael@0 | 195 | testCases.push({ |
michael@0 | 196 | 'attr' : { 'begin': '-3s; 110s; 1s; 4s; -5s; -10s', |
michael@0 | 197 | 'end': '111s; -5s; -15s; 6s; -5s; 1.2s', |
michael@0 | 198 | 'dur': '2s ', |
michael@0 | 199 | 'fill': 'freeze' }, |
michael@0 | 200 | 'times': [ [ 0, -100 ], |
michael@0 | 201 | [ 1, 0 ], |
michael@0 | 202 | [ 2, 10 ], |
michael@0 | 203 | [ 4, 0 ], |
michael@0 | 204 | [ 5, 50 ], |
michael@0 | 205 | [ 109, 100 ], |
michael@0 | 206 | [ 110, 0 ], |
michael@0 | 207 | [ 112, 50 ] ] |
michael@0 | 208 | }); |
michael@0 | 209 | |
michael@0 | 210 | for (var i = 0; i < testCases.length; i++) { |
michael@0 | 211 | gSvg.setCurrentTime(0); |
michael@0 | 212 | var test = testCases[i]; |
michael@0 | 213 | |
michael@0 | 214 | // Generate string version of params for output messages |
michael@0 | 215 | var params = ""; |
michael@0 | 216 | for (var name in test.attr) { |
michael@0 | 217 | params += name + '="' + test.attr[name] + '" '; |
michael@0 | 218 | } |
michael@0 | 219 | params = params.trim(); |
michael@0 | 220 | |
michael@0 | 221 | // Create animation elements |
michael@0 | 222 | var anim = createAnim(test.attr); |
michael@0 | 223 | |
michael@0 | 224 | // Run samples |
michael@0 | 225 | if ('times' in test) { |
michael@0 | 226 | for (var j = 0; j < test.times.length; j++) { |
michael@0 | 227 | var curSample = test.times[j]; |
michael@0 | 228 | checkSample(curSample[0], curSample[1], params); |
michael@0 | 229 | } |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | // Check start time |
michael@0 | 233 | if ('startTime' in test) { |
michael@0 | 234 | is(getStartTime(anim), test.startTime, |
michael@0 | 235 | "Got unexpected start time for " + params); |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | anim.parentNode.removeChild(anim); |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | SimpleTest.finish(); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | function createAnim(attr) { |
michael@0 | 245 | var anim = document.createElementNS(svgns,'animate'); |
michael@0 | 246 | anim.setAttribute('attributeName','cx'); |
michael@0 | 247 | anim.setAttribute('from','0'); |
michael@0 | 248 | anim.setAttribute('to','100'); |
michael@0 | 249 | anim.setAttribute('dur','10s'); |
michael@0 | 250 | anim.setAttribute('begin','indefinite'); |
michael@0 | 251 | for (name in attr) { |
michael@0 | 252 | anim.setAttribute(name, attr[name]); |
michael@0 | 253 | } |
michael@0 | 254 | return gCircle.appendChild(anim); |
michael@0 | 255 | } |
michael@0 | 256 | |
michael@0 | 257 | function checkSample(time, expectedValue, params) { |
michael@0 | 258 | gSvg.setCurrentTime(time); |
michael@0 | 259 | var msg = "Unexpected sample value for " + params + |
michael@0 | 260 | " at t=" + time + ": "; |
michael@0 | 261 | is(gCircle.cx.animVal.value, expectedValue); |
michael@0 | 262 | } |
michael@0 | 263 | |
michael@0 | 264 | function getStartTime(anim) { |
michael@0 | 265 | var startTime; |
michael@0 | 266 | try { |
michael@0 | 267 | startTime = anim.getStartTime(); |
michael@0 | 268 | // We round start times to 3 decimal places to make comparisons simpler |
michael@0 | 269 | startTime = parseFloat(startTime.toFixed(3)); |
michael@0 | 270 | } catch(e) { |
michael@0 | 271 | if (e.name == "InvalidStateError" && |
michael@0 | 272 | e.code == DOMException.INVALID_STATE_ERR) { |
michael@0 | 273 | startTime = 'none'; |
michael@0 | 274 | } else { |
michael@0 | 275 | ok(false, "Unexpected exception: " + e); |
michael@0 | 276 | } |
michael@0 | 277 | } |
michael@0 | 278 | return startTime; |
michael@0 | 279 | } |
michael@0 | 280 | |
michael@0 | 281 | function StartTimeTest(beginSpec, expectedStartTime) { |
michael@0 | 282 | return { 'attr' : { 'begin': beginSpec }, |
michael@0 | 283 | 'startTime': expectedStartTime }; |
michael@0 | 284 | } |
michael@0 | 285 | |
michael@0 | 286 | window.addEventListener("load", main, false); |
michael@0 | 287 | ]]> |
michael@0 | 288 | </script> |
michael@0 | 289 | </pre> |
michael@0 | 290 | </body> |
michael@0 | 291 | </html> |