Skip to content

Commit

Permalink
Merge pull request #475 from alancutter/throwReversePlayInfiniteDuration
Browse files Browse the repository at this point in the history
Throw InvalidStateError when calling play() on a finished, reversed, infinite duration animation
  • Loading branch information
suzyh authored Jul 27, 2016
2 parents 245aaa2 + 667eba2 commit 1bc45f1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
15 changes: 13 additions & 2 deletions src/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@
this._playbackRate = value;
this._startTime = null;
if (this.playState != 'paused' && this.playState != 'idle') {
this.play();
this._finishedFlag = false;
this._idle = false;
this._ensureAlive();
scope.invalidateEffects();
}
if (oldCurrentTime != null) {
this.currentTime = oldCurrentTime;
Expand All @@ -141,7 +144,15 @@
play: function() {
this._paused = false;
if (this._isFinished || this._idle) {
this._currentTime = this._playbackRate > 0 ? 0 : this._totalDuration;
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._startTime = null;
}
this._finishedFlag = false;
Expand Down
3 changes: 0 additions & 3 deletions src/web-animations-next-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@
this._forEachChild(function(childAnimation) {
childAnimation.playbackRate = value;
});
if (this.playState != 'paused' && this.playState != 'idle') {
this.play();
}
if (oldCurrentTime !== null) {
this.currentTime = oldCurrentTime;
}
Expand Down
12 changes: 2 additions & 10 deletions test/web-platform-tests-expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ module.exports = {
'KeyframeEffectReadOnly is not defined',

'Test finish() while pause-pending with negative playbackRate':
'assert_equals: The start time of a pause-pending animation should be set after calling finish() expected (undefined) undefined but got (number) 100000',
'assert_equals: The play state of a pause-pending animation should become "finished" after finish() is called expected "finished" but got "paused"',

'Test finish() while pause-pending with positive playbackRate':
'assert_approx_equals: The start time of a pause-pending animation should be set after calling finish() expected NaN +/- 0.0005 but got 0',
'assert_equals: The play state of a pause-pending animation should become "finished" after finish() is called expected "finished" but got "paused"',

'Test finish() while paused':
'assert_equals: The play state of a paused animation should become "finished" after finish() is called expected "finished" but got "paused"',
Expand Down Expand Up @@ -226,11 +226,6 @@ module.exports = {
'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',
},

'test/web-platform-tests/web-animations/interfaces/Animation/play.html': {
'play() throws when seeking an infinite-duration animation played in reverse':
'assert_throws: Expected InvalidStateError exception on calling play() with a negative playbackRate and infinite-duration animation function "function () {\n"use strict";\n animation.play(); }" did not throw',
},

'test/web-platform-tests/web-animations/interfaces/Animation/playState.html': {
'Animation.playState is \'paused\' after cancelling an animation, seeking it makes it paused':
'assert_equals: After seeking an idle animation, it is effectively paused expected "paused" but got "idle"',
Expand All @@ -254,9 +249,6 @@ module.exports = {
'reverse() when playbackRate > 0 and currentTime < 0':
'assert_equals: reverse() should start playing from the animation effect end if the playbackRate > 0 and the currentTime < 0 expected 100000 but got -200000',

'reverse() when playbackRate > 0 and currentTime < 0 and the target effect end is positive infinity':
'assert_throws: reverse() should throw InvalidStateError if the playbackRate > 0 and the currentTime < 0 and the target effect is positive infinity function "function () {\n"use strict";\n animation.reverse(); }" did not throw',

'reverse() when playbackRate > 0 and currentTime > effect end':
'assert_equals: reverse() should start playing from the animation effect end if the playbackRate > 0 and the currentTime > effect end expected 100000 but got 200000',
},
Expand Down

0 comments on commit 1bc45f1

Please sign in to comment.