dom/smil/test/test_smilKeySplines.xhtml

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <html xmlns="http://www.w3.org/1999/xhtml">
michael@0 2 <head>
michael@0 3 <title>Test for SMIL keySplines</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 keySplines **/
michael@0 19
michael@0 20 /* Global Variables */
michael@0 21 const svgns="http://www.w3.org/2000/svg";
michael@0 22 var svg = document.getElementById("svg");
michael@0 23 var circle = document.getElementById('circle');
michael@0 24
michael@0 25 SimpleTest.waitForExplicitFinish();
michael@0 26
michael@0 27 function createAnim() {
michael@0 28 var anim = document.createElementNS(svgns,'animate');
michael@0 29 anim.setAttribute('attributeName','cx');
michael@0 30 anim.setAttribute('dur','10s');
michael@0 31 anim.setAttribute('begin','0s');
michael@0 32 anim.setAttribute('fill', 'freeze');
michael@0 33 return circle.appendChild(anim);
michael@0 34 }
michael@0 35
michael@0 36 function main() {
michael@0 37 ok(svg.animationsPaused(), "should be paused by <svg> load handler");
michael@0 38 is(svg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
michael@0 39
michael@0 40 var tests =
michael@0 41 [ testSimpleA, // these first four are from SVG 1.1
michael@0 42 testSimpleB,
michael@0 43 testSimpleC,
michael@0 44 testSimpleD,
michael@0 45 testSimpleE, // bug 501569
michael@0 46 testMultipleIntervalsA,
michael@0 47 testMultipleIntervalsB,
michael@0 48 testMultipleIntervalsC,
michael@0 49 testOneValue,
michael@0 50 testFromTo,
michael@0 51 testWrongNumSplines,
michael@0 52 testToAnimation,
michael@0 53 testOkSyntax,
michael@0 54 testBadSyntaxA,
michael@0 55 testBadSyntaxB
michael@0 56 ];
michael@0 57 for (var i = 0; i < tests.length; i++) {
michael@0 58 var anim = createAnim();
michael@0 59 svg.setCurrentTime(0);
michael@0 60 tests[i](anim);
michael@0 61 anim.parentNode.removeChild(anim);
michael@0 62 }
michael@0 63 SimpleTest.finish();
michael@0 64 }
michael@0 65
michael@0 66 function checkSample(time, expectedValue) {
michael@0 67 svg.setCurrentTime(time);
michael@0 68 is(circle.cx.animVal.value, expectedValue);
michael@0 69 }
michael@0 70
michael@0 71 function checkSampleRough(time, expectedValue, precision) {
michael@0 72 const defaultPrecision = 0.00001;
michael@0 73 if (typeof precision == "undefined") {
michael@0 74 precision = defaultPrecision;
michael@0 75 }
michael@0 76 svg.setCurrentTime(time);
michael@0 77 var diff = Math.abs(expectedValue - circle.cx.animVal.value);
michael@0 78 ok(diff <= precision,
michael@0 79 "Unexpected sample value got " + circle.cx.animVal.value
michael@0 80 + ", expected " + expectedValue + " [error is " + diff
michael@0 81 + ", tolerance is " + precision + "]");
michael@0 82 }
michael@0 83
michael@0 84 /*
michael@0 85 * These first four tests are the examples given in SVG 1.1, section 19.2.7
michael@0 86 */
michael@0 87
michael@0 88 function testSimpleA(anim) {
michael@0 89 anim.setAttribute('dur','4s');
michael@0 90 anim.setAttribute('values', '10; 20');
michael@0 91 anim.setAttribute('keyTimes', '0; 1');
michael@0 92 anim.setAttribute('calcMode', 'spline');
michael@0 93 anim.setAttribute('keySplines', '0 0 1 1');
michael@0 94 checkSample(0, 10);
michael@0 95 checkSample(1, 12.5);
michael@0 96 checkSample(2, 15);
michael@0 97 checkSample(3, 17.5);
michael@0 98 checkSample(4, 20);
michael@0 99 }
michael@0 100
michael@0 101 function testSimpleB(anim) {
michael@0 102 anim.setAttribute('dur','4s');
michael@0 103 anim.setAttribute('values', '10; 20');
michael@0 104 anim.setAttribute('keyTimes', '0; 1');
michael@0 105 anim.setAttribute('calcMode', 'spline');
michael@0 106 anim.setAttribute('keySplines', '.5 0 .5 1');
michael@0 107 checkSample(0, 10);
michael@0 108 checkSampleRough(1, 11.058925);
michael@0 109 checkSample(2, 15);
michael@0 110 checkSampleRough(3, 18.941075);
michael@0 111 checkSample(4, 20);
michael@0 112 }
michael@0 113
michael@0 114 function testSimpleC(anim) {
michael@0 115 anim.setAttribute('dur','4s');
michael@0 116 anim.setAttribute('values', '10; 20');
michael@0 117 anim.setAttribute('keyTimes', '0; 1');
michael@0 118 anim.setAttribute('calcMode', 'spline');
michael@0 119 anim.setAttribute('keySplines', '0 .75 .25 1');
michael@0 120 checkSample(0, 10);
michael@0 121 checkSampleRough(1, 18.101832);
michael@0 122 checkSampleRough(2, 19.413430);
michael@0 123 checkSampleRough(3, 19.886504);
michael@0 124 checkSample(4, 20);
michael@0 125 }
michael@0 126
michael@0 127 function testSimpleD(anim) {
michael@0 128 anim.setAttribute('dur','4s');
michael@0 129 anim.setAttribute('values', '10; 20');
michael@0 130 anim.setAttribute('keyTimes', '0; 1');
michael@0 131 anim.setAttribute('calcMode', 'spline');
michael@0 132 anim.setAttribute('keySplines', '1 0 .25 .25');
michael@0 133 checkSample(0, 10);
michael@0 134 checkSampleRough(1, 10.076925);
michael@0 135 checkSampleRough(2, 10.644369);
michael@0 136 checkSampleRough(3, 16.908699);
michael@0 137 checkSample(4, 20);
michael@0 138 }
michael@0 139
michael@0 140 // Bug 501569 -- nsSMILKeySpline(1, 0, 0, 1) miscalculates values just under 0.5
michael@0 141 function testSimpleE(anim) {
michael@0 142 anim.setAttribute('dur','10s');
michael@0 143 anim.setAttribute('values', '0; 10');
michael@0 144 anim.setAttribute('keyTimes', '0; 1');
michael@0 145 anim.setAttribute('calcMode', 'spline');
michael@0 146 anim.setAttribute('keySplines', '1 0 0 1');
michael@0 147 checkSample(0, 0);
michael@0 148 checkSampleRough(0.001, 0);
michael@0 149 checkSampleRough(4.95, 3.409174);
michael@0 150 checkSampleRough(4.98, 3.819443);
michael@0 151 checkSampleRough(4.99, 4.060174);
michael@0 152 checkSampleRough(4.999, 4.562510);
michael@0 153 checkSample(5, 5);
michael@0 154 checkSampleRough(5.001, 5.437490);
michael@0 155 checkSampleRough(5.01, 5.939826);
michael@0 156 checkSampleRough(5.015, 6.075002);
michael@0 157 checkSampleRough(5.02, 6.180557);
michael@0 158 checkSampleRough(9.9999, 10);
michael@0 159 checkSample(10, 10);
michael@0 160 }
michael@0 161
michael@0 162 function testMultipleIntervalsA(anim) {
michael@0 163 anim.setAttribute('dur','4s');
michael@0 164 anim.setAttribute('values', '10; 20; 30');
michael@0 165 anim.setAttribute('keyTimes', '0; 0.25; 1');
michael@0 166 anim.setAttribute('calcMode', 'spline');
michael@0 167 anim.setAttribute('keySplines', '0 0 1 1; .5 0 .5 1;');
michael@0 168 checkSample(0.5, 15);
michael@0 169 checkSampleRough(0.999, 20, 0.02);
michael@0 170 checkSample(1, 20);
michael@0 171 checkSampleRough(1.001, 20, 0.05);
michael@0 172 checkSample(2.5, 25);
michael@0 173 checkSampleRough(3.25, 29, 0.1);
michael@0 174 }
michael@0 175
michael@0 176 function testMultipleIntervalsB(anim) {
michael@0 177 // as above but without keyTimes
michael@0 178 anim.setAttribute('dur','4s');
michael@0 179 anim.setAttribute('values', '10; 20; 30');
michael@0 180 anim.setAttribute('calcMode', 'spline');
michael@0 181 anim.setAttribute('keySplines', '0 0 1 1; .5 0 .5 1;');
michael@0 182 checkSample(1, 15);
michael@0 183 checkSampleRough(1.999, 20, 0.01);
michael@0 184 checkSample(2, 20);
michael@0 185 checkSampleRough(2.001, 20, 0.01);
michael@0 186 checkSample(3, 25);
michael@0 187 checkSampleRough(3.5, 29, 0.1);
michael@0 188 }
michael@0 189
michael@0 190 function testMultipleIntervalsC(anim) {
michael@0 191 // test some unusual (but valid) syntax
michael@0 192 anim.setAttribute('dur','4s');
michael@0 193 anim.setAttribute('values', '10; 20; 30');
michael@0 194 anim.setAttribute('calcMode', 'spline');
michael@0 195 anim.setAttribute('keySplines', ' 0 .75 0.25 1 ; 1, 0 ,.25 .25 \t');
michael@0 196 checkSampleRough(3.5, 26.9, 0.2);
michael@0 197 }
michael@0 198
michael@0 199 function testOneValue(anim) {
michael@0 200 anim.setAttribute('dur','4s');
michael@0 201 anim.setAttribute('values', '5');
michael@0 202 anim.setAttribute('calcMode', 'spline');
michael@0 203 anim.setAttribute('keySplines', '0 0 1 1');
michael@0 204 checkSample(0, 5);
michael@0 205 checkSample(1.5, 5);
michael@0 206 }
michael@0 207
michael@0 208 function testFromTo(anim) {
michael@0 209 anim.setAttribute('dur','4s');
michael@0 210 anim.setAttribute('from', '10');
michael@0 211 anim.setAttribute('to', '20');
michael@0 212 anim.setAttribute('calcMode', 'spline');
michael@0 213 anim.setAttribute('keySplines', '.5 0 .5 1');
michael@0 214 checkSample(0, 10);
michael@0 215 checkSampleRough(1, 11, 0.1);
michael@0 216 }
michael@0 217
michael@0 218 function testWrongNumSplines(anim) {
michael@0 219 anim.setAttribute('dur','4s');
michael@0 220 anim.setAttribute('from', '10');
michael@0 221 anim.setAttribute('to', '20');
michael@0 222 anim.setAttribute('calcMode', 'spline');
michael@0 223 anim.setAttribute('keySplines', '.5 0 .5 1; 0 0 1 1');
michael@0 224 // animation is in error, should do nothing
michael@0 225 checkSample(1.5, -100);
michael@0 226 }
michael@0 227
michael@0 228 function testToAnimation(anim) {
michael@0 229 anim.setAttribute('dur','4s');
michael@0 230 anim.setAttribute('to', '20');
michael@0 231 anim.setAttribute('calcMode', 'spline');
michael@0 232 anim.setAttribute('keySplines', '.5 0 .5 1');
michael@0 233 checkSample(0, -100);
michael@0 234 checkSampleRough(1, -87.3, 0.1);
michael@0 235 }
michael@0 236
michael@0 237 function testOkSyntax(anim) {
michael@0 238 var okStrs = ['0,0,0,0', // all commas
michael@0 239 ' 0 0 , 0 ,0 ', // mix of separators
michael@0 240 '0 0 0 0;', // trailing semi-colon
michael@0 241 '0 0 0 0 ;']; // " "
michael@0 242
michael@0 243 for (var i = 0; i < okStrs.length; i++) {
michael@0 244 testAnim = createAnim();
michael@0 245 testAnim.setAttribute('dur','4s');
michael@0 246 testAnim.setAttribute('from', '0');
michael@0 247 testAnim.setAttribute('to', '20');
michael@0 248 testAnim.setAttribute('calcMode', 'spline');
michael@0 249 testAnim.setAttribute('keySplines', okStrs[i]);
michael@0 250 checkSample(4, 20);
michael@0 251 testAnim.parentNode.removeChild(testAnim);
michael@0 252 }
michael@0 253 }
michael@0 254
michael@0 255 function testBadSyntaxA(anim) {
michael@0 256 var badStrs = ['', // empty
michael@0 257 ' ', // whitespace only
michael@0 258 '0,1.1,0,0', // bad range
michael@0 259 '0,0,0,-0.1', // " "
michael@0 260 ' 0 0 , 0 0 ,', // stray comma
michael@0 261 '1-1 0 0', // path-style separators
michael@0 262 '0 0 0', // wrong number of values
michael@0 263 '0 0 0 0 0', // " "
michael@0 264 '0 0 0 0 0 0 0 0', // " "
michael@0 265 '0 0 0; 0 0 0 0', // " "
michael@0 266 '0 0 0; 0', // mis-placed semi-colon
michael@0 267 ';0 0 0 0']; // " "
michael@0 268
michael@0 269 for (var i = 0; i < badStrs.length; i++) {
michael@0 270 testAnim = createAnim();
michael@0 271 testAnim.setAttribute('dur','4s');
michael@0 272 testAnim.setAttribute('from', '0');
michael@0 273 testAnim.setAttribute('to', '20');
michael@0 274 testAnim.setAttribute('calcMode', 'spline');
michael@0 275 testAnim.setAttribute('keySplines', badStrs[i]);
michael@0 276 checkSample(4, -100);
michael@0 277 testAnim.parentNode.removeChild(testAnim);
michael@0 278 }
michael@0 279 }
michael@0 280
michael@0 281 function testBadSyntaxB(anim) {
michael@0 282 // test some illegal syntax
michael@0 283 anim.setAttribute('dur','4s');
michael@0 284 anim.setAttribute('values', '10; 20; 30');
michael@0 285 anim.setAttribute('calcMode', 'spline');
michael@0 286 anim.setAttribute('keySplines', ' 0 .75 0.25 1 ; 1, A0 ,.25 .25 \t');
michael@0 287 // animation is in error, should do nothing
michael@0 288 checkSample(3.5, -100);
michael@0 289 }
michael@0 290
michael@0 291 window.addEventListener("load", main, false);
michael@0 292 ]]>
michael@0 293 </script>
michael@0 294 </pre>
michael@0 295 </body>
michael@0 296 </html>

mercurial