gecko/content/smil/test/test_smilTiming.xhtml

194 lines
5.0 KiB
HTML
Raw Normal View History

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test for SMIL timing</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="120px" height="120px"
onload="this.pauseAnimations()">
<circle cx="-100" cy="20" r="15" fill="blue" id="circle"/>
</svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[
/** Test for SMIL timing **/
/* Global Variables */
const svgns = "http://www.w3.org/2000/svg";
var gSvg = document.getElementById("svg");
var gCircle = document.getElementById('circle');
SimpleTest.waitForExplicitFinish();
function main() {
ok(gSvg.animationsPaused(), "should be paused by <svg> load handler");
is(gSvg.getCurrentTime(), 0, "should be paused at 0 in <svg> load handler");
var testCases = Array();
// List syntax
testCases.push(StartTimeTest('3', 3));
testCases.push(StartTimeTest('3;', 3));
testCases.push(StartTimeTest('3; ', 3));
testCases.push(StartTimeTest('3 ; ', 3));
testCases.push(StartTimeTest('3;;', 'none'));
testCases.push(StartTimeTest('3;; ', 'none'));
testCases.push(StartTimeTest(';3', 'none'));
testCases.push(StartTimeTest(' ;3', 'none'));
testCases.push(StartTimeTest('3;4', 3));
testCases.push(StartTimeTest(' 3 ; 4 ', 3));
// List syntax on end times
testCases.push({
'attr' : { 'begin': '0s',
'end': '1s; 2s' },
'times': [ [ 0, 0 ],
[ 1, -100 ] ]
});
testCases.push({
'attr' : { 'begin': '0s',
'end': '1s; 2s; ' },
'times': [ [ 0, 0 ],
[ 1, -100 ] ]
});
testCases.push({
'attr' : { 'begin': '0s',
'end': '3s; 2s' },
'times': [ [ 0, 0 ],
[ 1, 10 ],
[ 2, -100 ] ]
});
// Simple case
testCases.push({
'attr' : { 'begin': '3s' },
'times': [ [ 0, -100 ],
[ 4, 10 ] ]
});
// Multiple begins
testCases.push({
'attr' : { 'begin': '2s; 6s',
'dur': '2s' },
'times': [ [ 0, -100 ],
[ 3, 50 ],
[ 4, -100 ],
[ 7, 50 ],
[ 8, -100 ] ]
});
// Negative begins
testCases.push({
'attr' : { 'begin': '-3s; 1s ; 4s',
'dur': '2s ',
'fill': 'freeze' },
'times': [ [ 0, -100 ],
[ 0.5, -100 ],
[ 1, 0 ],
[ 2, 50 ],
[ 3, 100 ],
[ 5, 50 ] ]
});
// Sorting
testCases.push({
'attr' : { 'begin': '-3s; 110s; 1s; 4s; -5s; -10s',
'end': '111s; -5s; -15s; 6s; -5s; 1.2s',
'dur': '2s ',
'fill': 'freeze' },
'times': [ [ 0, -100 ],
[ 1, 0 ],
[ 2, 10 ],
[ 4, 0 ],
[ 5, 50 ],
[ 109, 100 ],
[ 110, 0 ],
[ 112, 50 ] ]
});
for (var i = 0; i < testCases.length; i++) {
gSvg.setCurrentTime(0);
var test = testCases[i];
// Generate string version of params for output messages
var params = "";
for (var name in test.attr) {
params += name + '="' + test.attr[name] + '" ';
}
params = params.trim();
// Create animation elements
var anim = createAnim(test.attr);
// Run samples
if ('times' in test) {
for (var j = 0; j < test.times.length; j++) {
var curSample = test.times[j];
checkSample(curSample[0], curSample[1], params);
}
}
// Check start time
if ('startTime' in test) {
is(getStartTime(anim), test.startTime,
"Got unexpected start time for " + params);
}
anim.parentNode.removeChild(anim);
}
SimpleTest.finish();
}
function createAnim(attr) {
var anim = document.createElementNS(svgns,'animate');
anim.setAttribute('attributeName','cx');
anim.setAttribute('from','0');
anim.setAttribute('to','100');
anim.setAttribute('dur','10s');
anim.setAttribute('begin','indefinite');
for (name in attr) {
anim.setAttribute(name, attr[name]);
}
return gCircle.appendChild(anim);
}
function checkSample(time, expectedValue, params) {
gSvg.setCurrentTime(time);
var msg = "Unexpected sample value for " + params +
" at t=" + time + ": ";
is(gCircle.cx.animVal.value, expectedValue);
}
function getStartTime(anim) {
var startTime;
try {
startTime = anim.getStartTime();
// We round start times to 3 decimal places to make comparisons simpler
startTime = parseFloat(startTime.toFixed(3));
} catch(e) {
if (e.code == DOMException.INVALID_STATE_ERR) {
startTime = 'none';
} else {
ok(false, "Unexpected exception: " + e);
}
}
return startTime;
}
function StartTimeTest(beginSpec, expectedStartTime) {
return { 'attr' : { 'begin': beginSpec },
'startTime': expectedStartTime };
}
window.addEventListener("load", main, false);
]]>
</script>
</pre>
</body>
</html>