Bug 1267893 part 1 - Add assert_times_equal for comparing times while allowing for a degree of imprecision
MozReview-Commit-ID: LAuCLmchBHa
--- a/testing/web-platform/tests/web-animations/animation-effect-timing/duration.html
+++ b/testing/web-platform/tests/web-animations/animation-effect-timing/duration.html
@@ -10,21 +10,20 @@
<div id="log"></div>
<script>
'use strict';
test(function(t) {
var div = createDiv(t);
var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
anim.effect.timing.duration = 123.45;
- assert_approx_equals(anim.effect.timing.duration, 123.45, 0.000001,
- 'set duration 123.45');
- assert_approx_equals(anim.effect.getComputedTiming().duration, 123.45,
- 0.000001,
- 'getComputedTiming() after set duration 123.45');
+ assert_times_equal(anim.effect.timing.duration, 123.45,
+ 'set duration 123.45');
+ assert_times_equal(anim.effect.getComputedTiming().duration, 123.45,
+ 'getComputedTiming() after set duration 123.45');
}, 'set duration 123.45');
test(function(t) {
var div = createDiv(t);
var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
anim.effect.timing.duration = 'auto';
assert_equals(anim.effect.timing.duration, 'auto', 'set duration \'auto\'');
assert_equals(anim.effect.getComputedTiming().duration, 0,
--- a/testing/web-platform/tests/web-animations/animation-effect-timing/endDelay.html
+++ b/testing/web-platform/tests/web-animations/animation-effect-timing/endDelay.html
@@ -10,21 +10,20 @@
<div id="log"></div>
<script>
'use strict';
test(function(t) {
var div = createDiv(t);
var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
anim.effect.timing.endDelay = 123.45;
- assert_approx_equals(anim.effect.timing.endDelay, 123.45, 0.000001,
- 'set endDelay 123.45');
- assert_approx_equals(anim.effect.getComputedTiming().endDelay, 123.45,
- 0.000001,
- 'getComputedTiming() after set endDelay 123.45');
+ assert_times_equal(anim.effect.timing.endDelay, 123.45,
+ 'set endDelay 123.45');
+ assert_times_equal(anim.effect.getComputedTiming().endDelay, 123.45,
+ 'getComputedTiming() after set endDelay 123.45');
}, 'set endDelay 123.45');
test(function(t) {
var div = createDiv(t);
var anim = div.animate({ opacity: [ 0, 1 ] }, 2000);
anim.effect.timing.endDelay = -1000;
assert_equals(anim.effect.timing.endDelay, -1000, 'set endDelay -1000');
assert_equals(anim.effect.getComputedTiming().endDelay, -1000,
--- a/testing/web-platform/tests/web-animations/animation/finish.html
+++ b/testing/web-platform/tests/web-animations/animation/finish.html
@@ -91,42 +91,40 @@ promise_test(function(t) {
var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC);
animation.pause();
return animation.ready.then(function() {
animation.finish();
assert_equals(animation.playState, 'finished',
'The play state of a paused animation should become ' +
'"finished" after finish() is called');
- assert_approx_equals(animation.startTime,
- animation.timeline.currentTime - 100 * MS_PER_SEC,
- 0.0001,
- 'The start time of a paused animation should be set ' +
- 'after calling finish()');
+ assert_times_equal(animation.startTime,
+ animation.timeline.currentTime - 100 * MS_PER_SEC,
+ 'The start time of a paused animation should be set ' +
+ 'after calling finish()');
});
}, 'Test finish() while paused');
test(function(t) {
var div = createDiv(t);
var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC);
animation.pause();
// Update playbackRate so we can test that the calculated startTime
// respects it
animation.playbackRate = 2;
// While animation is still pause-pending call finish()
animation.finish();
assert_equals(animation.playState, 'finished',
'The play state of a pause-pending animation should become ' +
'"finished" after finish() is called');
- assert_approx_equals(animation.startTime,
- animation.timeline.currentTime - 100 * MS_PER_SEC / 2,
- 0.0001,
- 'The start time of a pause-pending animation should ' +
- 'be set after calling finish()');
+ assert_times_equal(animation.startTime,
+ animation.timeline.currentTime - 100 * MS_PER_SEC / 2,
+ 'The start time of a pause-pending animation should ' +
+ 'be set after calling finish()');
}, 'Test finish() while pause-pending with positive playbackRate');
test(function(t) {
var div = createDiv(t);
var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC);
animation.pause();
animation.playbackRate = -2;
animation.finish();
@@ -143,21 +141,20 @@ test(function(t) {
var div = createDiv(t);
var animation = div.animate(gKeyFrames, 100 * MS_PER_SEC);
animation.playbackRate = 0.5;
animation.finish();
assert_equals(animation.playState, 'finished',
'The play state of a play-pending animation should become ' +
'"finished" after finish() is called');
- assert_approx_equals(animation.startTime,
- animation.timeline.currentTime - 100 * MS_PER_SEC / 0.5,
- 0.0001,
- 'The start time of a play-pending animation should ' +
- 'be set after calling finish()');
+ assert_times_equal(animation.startTime,
+ animation.timeline.currentTime - 100 * MS_PER_SEC / 0.5,
+ 'The start time of a play-pending animation should ' +
+ 'be set after calling finish()');
}, 'Test finish() while play-pending');
// FIXME: Add a test for when we are play-pending without an active timeline.
// - In that case even after calling finish() we should still be pending but
// the current time should be updated
promise_test(function(t) {
var div = createDiv(t);
--- a/testing/web-platform/tests/web-animations/testcommon.js
+++ b/testing/web-platform/tests/web-animations/testcommon.js
@@ -3,19 +3,33 @@ Distributed under both the W3C Test Suit
3-clause BSD License [2]. To contribute to a W3C Test Suite, see the
policies and contribution forms [3].
[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license
[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license
[3] http://www.w3.org/2004/10/27-testcases
*/
-"use strict";
+'use strict';
+
var MS_PER_SEC = 1000;
+// The recommended minimum precision to use for time values[1].
+//
+// [1] https://w3c.github.io/web-animations/#precision-of-time-values
+var TIME_PRECISION = 0.000001;
+
+// Allow implementations to substitute an alternative method for comparing
+// times based on their precision requirements.
+if (!window.assert_times_equal) {
+ window.assert_times_equal = function(actual, expected, description) {
+ assert_approx_equals(actual, expected, TIME_PRECISION, description);
+ }
+}
+
// creates div element, appends it to the document body and
// removes the created element during test cleanup
function createDiv(test, doc) {
if (!doc) {
doc = document;
}
var div = doc.createElement('div');
doc.body.appendChild(div);