Bug 1474247 - Test cases for animations tracked by the pending animation tracker for Animation::SetEffect, Animation::Cancel() and . r?birtles
MozReview-Commit-ID: 4XzAoylcwpS
--- a/dom/animation/test/mochitest.ini
+++ b/dom/animation/test/mochitest.ini
@@ -41,16 +41,17 @@ skip-if = (toolkit == 'android' && debug
[mozilla/test_disabled_properties.html]
[mozilla/test_discrete_animations.html]
[mozilla/test_distance_of_basic_shape.html]
[mozilla/test_distance_of_filter.html]
[mozilla/test_distance_of_transform.html]
[mozilla/test_document_timeline_origin_time_range.html]
[mozilla/test_hide_and_show.html]
[mozilla/test_moz_prefixed_properties.html]
+[mozilla/test_pending_animation_tracker.html]
[mozilla/test_restyles.html]
[mozilla/test_restyling_xhr_doc.html]
[mozilla/test_set_easing.html]
[mozilla/test_transform_limits.html]
[mozilla/test_transition_finish_on_compositor.html]
skip-if = toolkit == 'android'
[mozilla/test_underlying_discrete_value.html]
[mozilla/test_event_listener_leaks.html]
new file mode 100644
--- /dev/null
+++ b/dom/animation/test/mozilla/test_pending_animation_tracker.html
@@ -0,0 +1,78 @@
+<!doctype html>
+<head>
+<meta charset=utf-8>
+<title>Test animations in PendingAnimationTracker</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="../testcommon.js"></script>
+</head>
+<body>
+<div id="log"></div>
+<script>
+"use strict";
+
+test(t => {
+ const target = addDiv(t);
+ const anim = target.animate(null, 100 * MS_PER_SEC);
+ assert_true(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation should be tracked by tracker');
+
+ anim.effect = null;
+
+ assert_false(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation should NOT be tracked by the tracker');
+}, 'Setting null effect removes the animation from the tracker');
+
+test(t => {
+ const target = addDiv(t);
+ const anim = target.animate(null, 100 * MS_PER_SEC);
+ assert_true(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation should be tracked by tracker');
+
+ const newEffect = new KeyframeEffect(target, null);
+ anim.effect = newEffect;
+
+ assert_true(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation should be still tracked by tracker');
+}, 'Setting another effect keeps the pending animation in the tracker');
+
+test(t => {
+ const target = addDiv(t);
+ const anim = target.animate(null, 100 * MS_PER_SEC);
+ assert_true(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation should be tracked by tracker');
+
+ anim.cancel();
+
+ assert_false(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation should NOT be tracked by the tracker');
+}, 'Calling cancel() removes the animation from the tracker');
+
+promise_test(async t => {
+ // Before proceeding this test, make sure following code is _NOT_ processed
+ // between paint and refresh driver's tick. Otherwise, waitForNextFrame below
+ // doesn't ensure that a paint process happens which means that there is
+ // no chance to call TriggerPendingAnimationsOnNextTick to discard the
+ // animation from the pending animation tracker.
+ await waitForNextFrame();
+
+ const target = addDiv(t);
+ const anim = target.animate(null, 100 * MS_PER_SEC);
+
+ assert_true(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation should be tracked by tracker');
+
+ target.remove();
+
+ assert_true(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation is still being tracked by the tracker');
+
+ await waitForNextFrame();
+ assert_false(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+ 'The animation should NOT be tracked by the tracker in the ' +
+ 'next frame');
+}, 'Removing target element from the document removes the animation from ' +
+ 'the tracker in the next tick');
+
+</script>
+</body>