Merge pull request #128 from tschaub/animation

Use requestAnimationFrame where available.
This commit is contained in:
Tim Schaub
2012-01-17 11:56:59 -08:00
11 changed files with 235 additions and 48 deletions
+84
View File
@@ -0,0 +1,84 @@
<!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(7);
t.open_window("Animation.html", function(win) {
win.requestFrame(t);
win.start(t);
win.startDuration(t);
win.stop(t);
});
}
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>
+5 -3
View File
@@ -16,9 +16,11 @@
var originalGetTime = Date.prototype.getTime;
Date.prototype.getTime = function() { return 0 };
var interval = 10; // arbitrary value for tests
var originalSetInterval = window.setInterval;
window.setInterval = function(callback, interval) {
var originalLoopAnimation = OpenLayers.Animation.start;
OpenLayers.Animation.start = function(callback) {
while (!finish) {
var time = new Date().getTime();
Date.prototype.getTime = function() { return time+interval };
@@ -49,7 +51,7 @@
});
Date.prototype.getTime = originalGetTime;
window.setInterval = originalSetInterval;
OpenLayers.Animation.start = originalLoopAnimation;
}
function test_Angle (t) {
+17 -2
View File
@@ -1,7 +1,22 @@
<html>
<head>
<script src="OLLoader.js"></script>
<script type="text/javascript">
<script>
/**
* Because browsers that implement requestAnimationFrame may not execute
* animation functions while a window is not displayed (e.g. in a hidden
* iframe as in these tests), we mask the native implementations here. The
* native requestAnimationFrame functionality is tested in Util.html and
* in PanZoom.html (where a popup is opened before panning). The panTo tests
* here will test the fallback setTimeout implementation for animation.
*/
window.requestAnimationFrame =
window.webkitRequestAnimationFrame =
window.mozRequestAnimationFrame =
window.oRequestAnimationFrame =
window.msRequestAnimationFrame = null;
</script>
<script src="OLLoader.js"></script>
<script type="text/javascript">
var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
var map;
+5 -5
View File
@@ -36,7 +36,7 @@
}
}
tween.start(start, finish, 10, {callbacks: callbacks});
t.ok(tween.interval != null, "interval correctly set");
t.ok(tween.animationId != null, "animationId correctly set");
t.delay_call(0.8, function() {
t.eq(_start, true, "start callback called");
t.eq(_done, true, "finish callback called");
@@ -49,15 +49,15 @@
t.plan(2);
var tween = new OpenLayers.Tween();
tween.interval = window.setInterval(function() {}, 10);
tween.animationId = OpenLayers.Animation.start(function() {});
tween.playing = true;
tween.stop();
t.eq(tween.interval, null, "tween correctly stopped");
t.eq(tween.animationId, null, "tween correctly stopped");
tween.interval = window.setInterval(function() {}, 10);
tween.animationId = OpenLayers.Animation.start(function() {});
tween.playing = false;
tween.stop();
t.ok(tween.interval != null, "stop method doesn't do anything if tween isn't running");
t.ok(tween.animationId != null, "stop method doesn't do anything if tween isn't running");
}
</script>
+1
View File
@@ -1120,6 +1120,7 @@
t.eq(OpenLayers.Util.getFormattedLonLat(-181, "lon"), "179°00'00\"E", "crossing dateline from the west results in correct east coordinate");
t.eq(OpenLayers.Util.getFormattedLonLat(181, "lon"), "179°00'00\"W", "crossing dateline from the east results in correct west coordinate");
}
</script>
</head>
<body>
+1
View File
@@ -1,4 +1,5 @@
<ul id="testlist">
<li>Animation.html</li>
<li>BaseTypes.html</li>
<li>BaseTypes/Bounds.html</li>
<li>BaseTypes/Class.html</li>