Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added timing constructor test #220

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion target-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
'test/js/group-constructors.js',
'test/js/group-player.js',
'test/js/group-player-finish-event.js',
'test/js/timeline.js');
'test/js/timeline.js',
'test/js/timing.js');

// This object specifies the source and test files for different Web Animation build targets.
var targetConfig = {
Expand Down
140 changes: 140 additions & 0 deletions test/js/timing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
suite('timing-tests', function() {
setup(function() {
document.timeline._players = [];
});

test('changing timing iterations mid-animation', function() {
var animation = new Animation(document.body, [], { duration: 1000 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timing.js is a minifill test, but the Animation constructor is only in the maxifill.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


// TODO: access internal _timing for now, until .timing is properly generated
var timing = animation._timing;

assert.equal(timing.duration, 1000);
assert.equal(timing.iterations, 1.0);

var player = document.timeline.play(animation);
tick(50);
assert.equal(player.currentTime, 0);

tick(350);
assert.equal(player.currentTime, 300);

timing.iterations = 0.5;
animation.timing.iterations = 0.5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI these don't work because we don't yet support these maxifill feature (exposed timing, modifiable timing). They're not on the roadmap for the m39 release.

tick(850);
assert.equal(player.currentTime, 500);
});

test('immediate pause and play later', function() {
var animation = new Animation(document.body, [], { duration: 1000 });
var player = document.timeline.play(animation);
player.pause();

tick(50);
assert(!player.currentTime);
assert(!player.startTime);

tick(150);
assert(!player.currentTime);
assert(!player.startTime);

player.play();

tick(250);
assert.equal(player.currentTime, 100);
assert.equal(player.startTime, 150);
});

test('composing playbackRate', function() {
var target = document.createElement('div');
target.style.position = 'absolute';
document.body.appendChild(target);

var timing = { duration: 1000, playbackRate: 0.5 };
var animation = new Animation(target, [
{ left: '0px' },
{ left: '1000px' }
], timing);

// 0.5 * 2.0 == 1, so offsetLeft==currentTime
var group = new AnimationGroup([animation], { playbackRate: 2.0 });
var player = document.timeline.play(animation);

tick(50);
assert.equal(player.startTime, 50);

tick(150);
assert.equal(player.currentTime, 100);
assert.equal(target.offsetLeft, 100);
});

test('player playbackRate', function() {
var target = document.createElement('div');
target.style.position = 'absolute';
document.body.appendChild(target);

var timing = { duration: 1000, playbackRate: 0.5 };
var animation = new Animation(target, [
{ left: '0px' },
{ left: '1000px' }
], timing);

var player = document.timeline.play(animation);

// 0.5 * 2.0 == 1, so offsetLeft==currentTime
player.playbackRate = 2.0;

tick(50);
assert.equal(player.startTime, 50);

tick(150);
assert.equal(player.currentTime, 100);
assert.equal(target.offsetLeft, 100);
});

test('pause and scrub', function() {
// note that this functions natively. However, note that AnimationGroup
// is not native on M41, so it still fails there.
var animation = new Animation(document.body, [], { duration: 1000 });
var player = document.timeline.play(animation);
player.pause();

player.currentTime = 500;
assert.equal(player.currentTime, 500);
});

test('pause and scrub group', function() {
// note that this functions natively. However, note that AnimationGroup
// is not native on M41, so it still fails there.
var animation = new Animation(document.body, [], { duration: 1000 });
var group = new AnimationGroup([animation]);
var player = document.timeline.play(group);
player.pause();

player.currentTime = 500;
assert.equal(player.currentTime, 500);
});

test('pause, scrub and play', function() {
var target = document.createElement('div');
document.body.appendChild(target);

var animation = new Animation(target, [
{ background: 'blue' },
{ background: 'red' }
], { duration: 1000 });
var player = document.timeline.play(animation);
tick(100);
player.pause();

player.currentTime = 200;
// http://www.w3.org/TR/web-animations/#the-current-time-of-a-player
// currentTime should now mean 'hold time' - this allows scrubbing.
assert.equal(player.currentTime, 200);
player.play();

tick(200);
assert.equal(player.currentTime, 300);
assert.equal(player.startTime, -100);
});
});