Moving animation methods out of Util.js.
Animation methods get their own module, giving methods more sensible names: * `OpenLayers.Animation.requestFrame` (was `OpenLayers.Util.requestAnimationFrame`) * `OpenLayers.Animation.start` (was `OpenLayers.Util.startAnimation`) * `OpenLayers.Animation.stop` (was `OpenLayers.Util.stopAnimation`)
This commit is contained in:
78
tests/Animation.html
Normal file
78
tests/Animation.html
Normal file
@@ -0,0 +1,78 @@
|
||||
<!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_requestFrame(t) {
|
||||
t.plan(2);
|
||||
|
||||
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 test_start(t) {
|
||||
t.plan(1);
|
||||
|
||||
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 test_start_duration(t) {
|
||||
t.plan(2);
|
||||
|
||||
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 test_stop(t) {
|
||||
t.plan(2);
|
||||
|
||||
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>
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
var interval = 10; // arbitrary value for tests
|
||||
|
||||
var originalLoopAnimation = OpenLayers.Util.startAnimation;
|
||||
OpenLayers.Util.startAnimation = function(callback) {
|
||||
var originalLoopAnimation = OpenLayers.Animation.start;
|
||||
OpenLayers.Animation.start = function(callback) {
|
||||
while (!finish) {
|
||||
var time = new Date().getTime();
|
||||
Date.prototype.getTime = function() { return time+interval };
|
||||
@@ -51,7 +51,7 @@
|
||||
});
|
||||
|
||||
Date.prototype.getTime = originalGetTime;
|
||||
OpenLayers.Util.startAnimation = originalLoopAnimation;
|
||||
OpenLayers.Animation.start = originalLoopAnimation;
|
||||
}
|
||||
|
||||
function test_Angle (t) {
|
||||
|
||||
@@ -49,12 +49,12 @@
|
||||
t.plan(2);
|
||||
|
||||
var tween = new OpenLayers.Tween();
|
||||
tween.animationId = OpenLayers.Util.startAnimation(function() {});
|
||||
tween.animationId = OpenLayers.Animation.start(function() {});
|
||||
tween.playing = true;
|
||||
tween.stop();
|
||||
t.eq(tween.animationId, null, "tween correctly stopped");
|
||||
|
||||
tween.animationId = OpenLayers.Util.startAnimation(function() {});
|
||||
tween.animationId = OpenLayers.Animation.start(function() {});
|
||||
tween.playing = false;
|
||||
tween.stop();
|
||||
t.ok(tween.animationId != null, "stop method doesn't do anything if tween isn't running");
|
||||
|
||||
@@ -1121,68 +1121,6 @@
|
||||
t.eq(OpenLayers.Util.getFormattedLonLat(181, "lon"), "179°00'00\"W", "crossing dateline from the east results in correct west coordinate");
|
||||
}
|
||||
|
||||
function test_requestAnimationFrame(t) {
|
||||
t.plan(2);
|
||||
|
||||
t.eq(typeof OpenLayers.Util.requestAnimationFrame, "function", "requestAnimationFrame is a function");
|
||||
|
||||
var calls = 0;
|
||||
OpenLayers.Util.requestAnimationFrame(function() {
|
||||
++calls;
|
||||
});
|
||||
t.delay_call(0.1, function() {
|
||||
t.ok(calls > 0, "callback called: " + calls);
|
||||
});
|
||||
}
|
||||
|
||||
function test_startAnimation(t) {
|
||||
t.plan(1);
|
||||
|
||||
var calls = 0;
|
||||
var id = OpenLayers.Util.startAnimation(function() {
|
||||
++calls;
|
||||
});
|
||||
t.delay_call(0.1, function() {
|
||||
t.ok(calls > 1, "looped: " + calls);
|
||||
OpenLayers.Util.stopAnimation(id);
|
||||
});
|
||||
}
|
||||
|
||||
function test_startAnimation_duration(t) {
|
||||
t.plan(2);
|
||||
|
||||
var calls = 0;
|
||||
var id = OpenLayers.Util.startAnimation(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 test_stopAnimation(t) {
|
||||
t.plan(2);
|
||||
|
||||
var calls = 0;
|
||||
var id = OpenLayers.Util.startAnimation(function() {
|
||||
++calls;
|
||||
});
|
||||
var first;
|
||||
t.delay_call(0.2, function() {
|
||||
first = calls;
|
||||
t.ok(calls > 1, "looped: " + calls);
|
||||
OpenLayers.Util.stopAnimation(id);
|
||||
});
|
||||
t.delay_call(0.3, function() {
|
||||
t.eq(calls, first, "not being called any more");
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user