Commit 81d741b1 authored by Stephen McGruer's avatar Stephen McGruer Committed by Commit Bot

Web Animations: Fix bug with Document::getAnimations

Per spec, we should exclude effects that do not target an element in
the called document:

https://drafts.csswg.org/web-animations-1/#dom-document-getanimations

Bug: 828424
Change-Id: I41405d82184b17c1185931e34735a5f946573844
Reviewed-on: https://chromium-review.googlesource.com/992812
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: default avatarXida Chen <xidachen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548156}
parent c5266e44
This is a testharness.js-based test.
PASS Test document.getAnimations for non-animated content
PASS Test document.getAnimations for script-generated animations
PASS Test the order of document.getAnimations with script generated animations
FAIL Test document.getAnimations with null target assert_equals: document.getAnimations() only returns animations targeting elements in this document expected 0 but got 3
Harness: the test ran to completion.
......@@ -41,6 +41,19 @@ test(t => {
'getAnimations() returns running animations');
}, 'Test the order of document.getAnimations with script generated animations')
test(t => {
// This element exists but is not a descendent of any document, so isn't
// picked up by getAnimations.
const div = document.createElement('div');
const anim = div.animate(gKeyFrames, 100 * MS_PER_SEC);
assert_equals(document.getAnimations().length, 0);
// Now connect the div; it should appear in the list of animations.
document.body.appendChild(div);
t.add_cleanup(() => { div.remove(); });
assert_equals(document.getAnimations().length, 1);
}, 'Test document.getAnimations for a disconnected node');
test(t => {
const effect = new KeyframeEffect(null, gKeyFrames, 100 * MS_PER_SEC);
const anim = new Animation(effect, document.timeline);
......
......@@ -117,12 +117,24 @@ Animation* DocumentTimeline::Play(AnimationEffect* child) {
}
HeapVector<Member<Animation>> DocumentTimeline::getAnimations() {
// This method implements the Document::getAnimations method defined in the
// web-animations-1 spec.
// https://drafts.csswg.org/web-animations-1/#dom-document-getanimations
document_->UpdateStyleAndLayoutTree();
HeapVector<Member<Animation>> animations;
for (const auto& animation : animations_) {
if (animation->effect() &&
(animation->effect()->IsCurrent() || animation->effect()->IsInEffect()))
animations.push_back(animation);
if (!animation->effect() || (!animation->effect()->IsCurrent() &&
!animation->effect()->IsInEffect())) {
continue;
}
if (animation->effect()->IsKeyframeEffect()) {
Element* target = ToKeyframeEffect(animation->effect())->target();
if (!target || !target->isConnected() ||
document_ != target->GetDocument()) {
continue;
}
}
animations.push_back(animation);
}
std::sort(animations.begin(), animations.end(), CompareAnimations);
return animations;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment