Bug 1474247 - Check mPendingState instead of mPendingReadyTime in Animation::ReschedulePendingTasks(). r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Thu, 12 Jul 2018 17:05:34 +0900
changeset 817226 271e2a75da1fc01b5fa5ebce0a4e7a33c4f18b43
parent 817225 721c9ea67538310b8c1467f5fd0e370e4576d305
child 817227 eab044f9156aaa35cd4fafb2652671cea8a4c222
push id115993
push userhikezoe@mozilla.com
push dateThu, 12 Jul 2018 08:06:50 +0000
reviewersbirtles
bugs1474247
milestone63.0a1
Bug 1474247 - Check mPendingState instead of mPendingReadyTime in Animation::ReschedulePendingTasks(). r?birtles When the pending animation having no target element sets a new effect having a target element associated with a document, PendingAnimationTracker has to start tracking the animation regardless of mPendingReadyTime. MozReview-Commit-ID: DxmbXtLhjCT
dom/animation/Animation.cpp
dom/animation/test/mozilla/test_pending_animation_tracker.html
--- a/dom/animation/Animation.cpp
+++ b/dom/animation/Animation.cpp
@@ -1459,29 +1459,31 @@ Animation::ResetPendingTasks()
     mReady->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
     mReady = nullptr;
   }
 }
 
 void
 Animation::ReschedulePendingTasks()
 {
-  if (mPendingReadyTime.IsNull()) {
+  if (mPendingState == PendingState::NotPending) {
     return;
   }
 
   mPendingReadyTime.SetNull();
 
   nsIDocument* doc = GetRenderedDocument();
   if (doc) {
     PendingAnimationTracker* tracker =
       doc->GetOrCreatePendingAnimationTracker();
-    if (mPendingState == PendingState::PlayPending) {
+    if (mPendingState == PendingState::PlayPending &&
+        !tracker->IsWaitingToPlay(*this)) {
       tracker->AddPlayPending(*this);
-    } else {
+    } else if (mPendingState == PendingState::PausePending &&
+               !tracker->IsWaitingToPause(*this)) {
       tracker->AddPausePending(*this);
     }
   }
 }
 
 bool
 Animation::IsPossiblyOrphanedPendingAnimation() const
 {
--- a/dom/animation/test/mozilla/test_pending_animation_tracker.html
+++ b/dom/animation/test/mozilla/test_pending_animation_tracker.html
@@ -32,16 +32,32 @@ test(t => {
   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 effect = new KeyframeEffect(null, null);
+  const anim = new Animation(effect);
+  anim.play();
+  assert_false(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+               'The orphaned animation should NOT be tracked by tracker');
+
+  const target = addDiv(t);
+  const newEffect = new KeyframeEffect(target, null);
+  anim.effect = newEffect;
+
+  assert_true(SpecialPowers.DOMWindowUtils.isAnimationInPendingTracker(anim),
+              'The animation should be now tracked by tracker');
+}, 'Setting effect having target element starts being tracked by 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),