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

Make pause() on idle animations set their current time according to playbackRate #480

Merged
merged 3 commits into from
Jul 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,21 @@
return 'finished';
return 'running';
},
_rewind: function() {
if (this._playbackRate >= 0) {
this._currentTime = 0;
} else if (this._totalDuration < Infinity) {
this._currentTime = this._totalDuration;
} else {
throw new DOMException(
'Unable to rewind negative playback rate animation with infinite duration',
'InvalidStateError');
}
},
play: function() {
this._paused = false;
if (this._isFinished || this._idle) {
if (this._playbackRate >= 0) {
this._currentTime = 0;
} else if (this._totalDuration < Infinity) {
this._currentTime = this._totalDuration;
} else {
throw new DOMException(
'Unable to rewind negative playback rate animation with infinite duration',
'InvalidStateError');
}
this._rewind();
this._startTime = null;
}
this._finishedFlag = false;
Expand All @@ -167,6 +170,9 @@
pause: function() {
if (!this._isFinished && !this._paused && !this._idle) {
this._currentTimePending = true;
} else if (this._idle) {
this._rewind();
this._idle = false;
}
this._startTime = null;
this._paused = true;
Expand Down
4 changes: 2 additions & 2 deletions test/js/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,8 @@ suite('animation', function() {
assert.equal(a.startTime, null);
tick(1);
a.pause();
assert.equal(a.playState, 'idle');
assert.equal(a.currentTime, null);
assert.equal(a.playState, 'paused');
assert.equal(a.currentTime, 0);
assert.equal(a.startTime, null);
});
test('Animations ignore NaN times', function() {
Expand Down
10 changes: 2 additions & 8 deletions test/web-platform-tests-expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,7 @@ module.exports = {

'test/web-platform-tests/web-animations/interfaces/Animation/pause.html': {
'pause() from idle':
'assert_equals: currentTime is set to 0 expected (number) 0 but got (object) null',

'pause() from idle with a negative playbackRate':
'assert_equals: currentTime is set to the effect end expected (number) 1000000 but got (object) null',

'pause() from idle with a negative playbackRate and endless effect':
'assert_throws: Expect InvalidStateError exception on calling pause() from idle with a negative playbackRate and infinite-duration animation function "function () {\n"use strict";\n animation.pause(); }" did not throw',
'assert_equals: initially pause-pending expected "pending" but got "paused"',
},

'test/web-platform-tests/web-animations/interfaces/Animation/playbackRate.html': {
Expand Down Expand Up @@ -1435,7 +1429,7 @@ module.exports = {
'Animation with null timeline is not supported',

'Setting the start time resolves a pending pause task':
'assert_equals: Animation is in pause-pending state expected "pending" but got "idle"',
'assert_equals: Animation is in pause-pending state expected "pending" but got "paused"',

'Setting the start time updates the finished state':
'assert_equals: Seeked to finished state using the startTime expected "finished" but got "idle"',
Expand Down