Files
openlayers/tests/Animation.html
2012-03-04 22:45:38 +01:00

95 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Animation.js Tests</title>
<script>
// dependencies for tests
var OpenLayers = [
"OpenLayers/Animation.js"
];
</script>
<script src="OLLoader.js"></script>
<script>
function test_all(t) {
t.plan(8);
t.ok(OpenLayers.Animation.isNative !== undefined, "isNative is set.");
function doIt(win) {
win.requestFrame(t);
win.start(t);
win.startDuration(t);
win.stop(t);
}
// Test in an extra window in Firefox, and directly in other browsers.
// This is needed because requestAnimationFrame does not work
// correctly in Firefox in a hidden IFrame.
if (window.mozRequestAnimationFrame) {
t.open_window("Animation.html", doIt);
} else {
doIt(window);
}
}
function requestFrame(t) {
t.eq(typeof OpenLayers.Animation.requestFrame, "function", "requestFrame is a function");
var calls = 0;
OpenLayers.Animation.requestFrame(function() {
++calls;
});
t.delay_call(0.1, function() {
t.ok(calls > 0, "callback called: " + calls);
});
}
function start(t) {
var calls = 0;
var id = OpenLayers.Animation.start(function() {
++calls;
});
t.delay_call(0.1, function() {
t.ok(calls > 1, "looped: " + calls);
OpenLayers.Animation.stop(id);
});
}
function startDuration(t) {
var calls = 0;
var id = OpenLayers.Animation.start(function() {
++calls;
}, 100);
var first;
t.delay_call(0.2, function() {
first = calls;
t.ok(calls > 1, "looped: " + calls);
});
t.delay_call(0.3, function() {
t.eq(calls, first, "not being called any more");
});
}
function stop(t) {
var calls = 0;
var id = OpenLayers.Animation.start(function() {
++calls;
});
var first;
t.delay_call(0.2, function() {
first = calls;
t.ok(calls > 1, "looped: " + calls);
OpenLayers.Animation.stop(id);
});
t.delay_call(0.3, function() {
t.eq(calls, first, "not being called any more");
});
}
</script>