Bug 1436659 - Simplify playback rate setting test; r?hiro
I didn't like the way these tests were written so I decided to rewrite them to
make it more clear what they are trying to test.
MozReview-Commit-ID: IBqMUh24crS
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -591733,17 +591733,17 @@
"8a5f14ba7712e33bc2450d9ab9198f4865ef9244",
"testharness"
],
"web-animations/timing-model/animations/reversing-an-animation.html": [
"bba3a71bfcf0b2c9ab38af6a2d0bd98954becf95",
"testharness"
],
"web-animations/timing-model/animations/setting-the-playback-rate-of-an-animation.html": [
- "e1511e242953262d06a393f9507c60e1d357d937",
+ "1e0a0e80e70ca0d71a118f6b958a3f24cfb50ca0",
"testharness"
],
"web-animations/timing-model/animations/setting-the-start-time-of-an-animation.html": [
"80bf466ba3d657200c2f2b6e783c56ba04b87390",
"testharness"
],
"web-animations/timing-model/animations/setting-the-target-effect-of-an-animation.html": [
"13df24037116368b688d7d20c1dffdac027021b3",
--- a/testing/web-platform/tests/web-animations/timing-model/animations/setting-the-playback-rate-of-an-animation.html
+++ b/testing/web-platform/tests/web-animations/timing-model/animations/setting-the-playback-rate-of-an-animation.html
@@ -5,80 +5,48 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="../../testcommon.js"></script>
<body>
<div id="log"></div>
<script>
'use strict';
-function assert_playbackrate(animation,
- previousAnimationCurrentTime,
- previousTimelineCurrentTime,
- description) {
+promise_test(async t => {
+ const animation = createDiv(t).animate(null, 100 * MS_PER_SEC);
+ animation.playbackRate = 2;
+ await animation.ready;
+
+ const previousAnimationCurrentTime = animation.currentTime;
+ const previousTimelineCurrentTime = animation.timeline.currentTime;
+
+ await waitForAnimationFrames(1);
+
const animationCurrentTimeDifference =
animation.currentTime - previousAnimationCurrentTime;
const timelineCurrentTimeDifference =
animation.timeline.currentTime - previousTimelineCurrentTime;
- assert_times_equal(animationCurrentTimeDifference,
- timelineCurrentTimeDifference * animation.playbackRate,
- description);
-}
-
-promise_test(t => {
- const div = createDiv(t);
- const animation = div.animate(null, 100 * MS_PER_SEC);
- return animation.ready.then(() => {
- animation.currentTime = 7 * MS_PER_SEC; // ms
- animation.playbackRate = 0.5;
+ assert_times_equal(
+ animationCurrentTimeDifference,
+ timelineCurrentTimeDifference * animation.playbackRate,
+ 'The current time should increase two times faster than timeline'
+ );
+}, 'The playback rate affects the rate of progress of the current time');
- assert_equals(animation.currentTime, 7 * MS_PER_SEC,
- 'Reducing Animation.playbackRate should not change the currentTime ' +
- 'of a playing animation');
- animation.playbackRate = 2;
- assert_equals(animation.currentTime, 7 * MS_PER_SEC,
- 'Increasing Animation.playbackRate should not change the currentTime ' +
- 'of a playing animation');
- });
-}, 'Test the initial effect of setting playbackRate on currentTime');
-
-promise_test(t => {
- const div = createDiv(t);
- const animation = div.animate(null, 100 * MS_PER_SEC);
+test(t => {
+ const animation = createDiv(t).animate(null, 100 * MS_PER_SEC);
+ animation.currentTime = 50 * MS_PER_SEC;
animation.playbackRate = 2;
- let previousTimelineCurrentTime;
- let previousAnimationCurrentTime;
- return animation.ready.then(() => {
- previousAnimationCurrentTime = animation.currentTime;
- previousTimelineCurrentTime = animation.timeline.currentTime;
- return waitForAnimationFrames(1);
- }).then(() => {
- assert_playbackrate(animation,
- previousAnimationCurrentTime,
- previousTimelineCurrentTime,
- 'animation.currentTime should be 2 times faster than timeline.');
- });
-}, 'Test the effect of setting playbackRate on currentTime');
+ assert_time_equals_literal(animation.currentTime, 50 * MS_PER_SEC);
+}, 'Setting the playback rate while play-pending preserves the current time');
-promise_test(t => {
- const div = createDiv(t);
- const animation = div.animate(null, 100 * MS_PER_SEC);
+promise_test(async t => {
+ const animation = createDiv(t).animate(null, 100 * MS_PER_SEC);
+ animation.currentTime = 50 * MS_PER_SEC;
+ await animation.ready;
animation.playbackRate = 2;
- let previousTimelineCurrentTime;
- let previousAnimationCurrentTime;
- return animation.ready.then(() => {
- previousAnimationCurrentTime = animation.currentTime;
- previousTimelineCurrentTime = animation.timeline.currentTime;
- animation.playbackRate = 1;
- return waitForAnimationFrames(1);
- }).then(() => {
- assert_equals(animation.playbackRate, 1,
- 'sanity check: animation.playbackRate is still 1.');
- assert_playbackrate(animation,
- previousAnimationCurrentTime,
- previousTimelineCurrentTime,
- 'animation.currentTime should be the same speed as timeline now.');
- });
-}, 'Test the effect of setting playbackRate while playing animation');
+ assert_greater_than_equal(animation.currentTime, 50 * MS_PER_SEC);
+ assert_less_than(animation.currentTime, 100 * MS_PER_SEC);
+}, 'Setting the playback rate while playing preserves the current time');
</script>
</body>