Skip to content

Commit

Permalink
Merge pull request #480 from alancutter/fixPauseHtml
Browse files Browse the repository at this point in the history
Make pause() on idle animations set their current time according to playbackRate
  • Loading branch information
suzyh authored Jul 29, 2016
2 parents 46f41d1 + e44d7c9 commit c25d407
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
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

0 comments on commit c25d407

Please sign in to comment.