Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3599)

Unified Diff: cc/trees/layer_tree_host_unittest_animation.cc

Issue 2377223002: CC Animations: Rewrite unit tests to work with AnimationPlayer. (Closed)
Patch Set: Reparent. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/trees/layer_tree_host_common_unittest.cc ('k') | cc/trees/mutator_host_client.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/trees/layer_tree_host_unittest_animation.cc
diff --git a/cc/trees/layer_tree_host_unittest_animation.cc b/cc/trees/layer_tree_host_unittest_animation.cc
index b32fdf7f20880298fae411fe2c4c1706c5014b32..0b3f1b3297e7e1108d020efcef3abad0eeb597ab 100644
--- a/cc/trees/layer_tree_host_unittest_animation.cc
+++ b/cc/trees/layer_tree_host_unittest_animation.cc
@@ -50,11 +50,25 @@ class LayerTreeHostAnimationTest : public LayerTreeTest {
timeline_->AttachPlayer(player_child_.get());
}
+ void GetImplTimelineAndPlayerByID(const LayerTreeHostImpl& host_impl) {
+ AnimationHost* animation_host_impl = host_impl.animation_host();
+ timeline_impl_ = animation_host_impl->GetTimelineById(timeline_id_);
+ EXPECT_TRUE(timeline_impl_);
+ player_impl_ = timeline_impl_->GetPlayerById(player_id_);
+ EXPECT_TRUE(player_impl_);
+ player_child_impl_ = timeline_impl_->GetPlayerById(player_child_id_);
+ EXPECT_TRUE(player_child_impl_);
+ }
+
protected:
scoped_refptr<AnimationTimeline> timeline_;
scoped_refptr<AnimationPlayer> player_;
scoped_refptr<AnimationPlayer> player_child_;
+ scoped_refptr<AnimationTimeline> timeline_impl_;
+ scoped_refptr<AnimationPlayer> player_impl_;
+ scoped_refptr<AnimationPlayer> player_child_impl_;
+
const int timeline_id_;
const int player_id_;
const int player_child_id_;
@@ -162,8 +176,7 @@ class LayerTreeHostAnimationTestAddAnimation
int group) override {
EXPECT_LT(base::TimeTicks(), monotonic_time);
- Animation* animation =
- player_->element_animations()->GetAnimation(TargetProperty::OPACITY);
+ Animation* animation = player_->GetAnimation(TargetProperty::OPACITY);
if (animation)
player_->RemoveAnimation(animation->id());
@@ -296,8 +309,7 @@ class LayerTreeHostAnimationTestAddAnimationWithTimingFunction
timeline_impl->GetPlayerById(player_child_id_);
Animation* animation =
- player_child_impl->element_animations()->GetAnimation(
- TargetProperty::OPACITY);
+ player_child_impl->GetAnimation(TargetProperty::OPACITY);
const FloatAnimationCurve* curve =
animation->curve()->ToFloatAnimationCurve();
@@ -348,10 +360,9 @@ class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes
void NotifyAnimationStarted(base::TimeTicks monotonic_time,
TargetProperty::Type target_property,
int group) override {
- Animation* animation = player_child_->element_animations()->GetAnimation(
- TargetProperty::OPACITY);
+ Animation* animation = player_child_->GetAnimation(TargetProperty::OPACITY);
main_start_time_ = animation->start_time();
- player_child_->element_animations()->RemoveAnimation(animation->id());
+ player_child_->RemoveAnimation(animation->id());
EndTest();
}
@@ -363,8 +374,7 @@ class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes
timeline_impl->GetPlayerById(player_child_id_);
Animation* animation =
- player_child_impl->element_animations()->GetAnimation(
- TargetProperty::OPACITY);
+ player_child_impl->GetAnimation(TargetProperty::OPACITY);
if (!animation)
return;
@@ -399,10 +409,9 @@ class LayerTreeHostAnimationTestAnimationFinishedEvents
void NotifyAnimationFinished(base::TimeTicks monotonic_time,
TargetProperty::Type target_property,
int group) override {
- Animation* animation =
- player_->element_animations()->GetAnimation(TargetProperty::OPACITY);
+ Animation* animation = player_->GetAnimation(TargetProperty::OPACITY);
if (animation)
- player_->element_animations()->RemoveAnimation(animation->id());
+ player_->RemoveAnimation(animation->id());
EndTest();
}
@@ -441,9 +450,9 @@ class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity
scoped_refptr<AnimationPlayer> player_impl =
timeline_impl->GetPlayerById(player_id_);
- Animation* animation_impl = player_impl->element_animations()->GetAnimation(
- TargetProperty::OPACITY);
- player_impl->element_animations()->RemoveAnimation(animation_impl->id());
+ Animation* animation_impl =
+ player_impl->GetAnimation(TargetProperty::OPACITY);
+ player_impl->RemoveAnimation(animation_impl->id());
EndTest();
}
@@ -840,7 +849,22 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
layer_tree()->root_layer()->AddChild(scroll_layer_);
AttachPlayersToTimeline();
- player_child_->AttachElement(scroll_layer_->element_id());
+ }
+
+ AnimationPlayer& ScrollOffsetPlayer(
+ const LayerTreeHostImpl& host_impl,
+ scoped_refptr<FakePictureLayer> layer) const {
+ scoped_refptr<ElementAnimations> element_animations =
+ host_impl.animation_host()->GetElementAnimationsForElementId(
+ layer->element_id());
+ DCHECK(element_animations);
+ DCHECK(element_animations->players_list().might_have_observers());
+
+ ElementAnimations::PlayersList::Iterator it(
+ &element_animations->players_list());
+ AnimationPlayer* player = it.GetNext();
+ DCHECK(player);
+ return *player;
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
@@ -871,12 +895,12 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
// Note that the frame number gets incremented after BeginCommitOnThread but
// before WillCommitCompleteOnThread and CommitCompleteOnThread.
if (host_impl->sync_tree()->source_frame_number() == 0) {
+ GetImplTimelineAndPlayerByID(*host_impl);
// This happens after the impl-only animation is added in
// WillCommitCompleteOnThread.
- Animation* animation =
- host_impl->animation_host()
- ->GetElementAnimationsForElementId(scroll_layer_->element_id())
- ->GetAnimation(TargetProperty::SCROLL_OFFSET);
+ Animation* animation = ScrollOffsetPlayer(*host_impl, scroll_layer_)
+ .GetAnimation(TargetProperty::SCROLL_OFFSET);
+ DCHECK(animation);
ScrollOffsetAnimationCurve* curve =
animation->curve()->ToScrollOffsetAnimationCurve();
@@ -899,10 +923,9 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
if (host_impl->sync_tree()->source_frame_number() == 1) {
- Animation* animation =
- host_impl->animation_host()
- ->GetElementAnimationsForElementId(scroll_layer_->element_id())
- ->GetAnimation(TargetProperty::SCROLL_OFFSET);
+ Animation* animation = ScrollOffsetPlayer(*host_impl, scroll_layer_)
+ .GetAnimation(TargetProperty::SCROLL_OFFSET);
+ DCHECK(animation);
ScrollOffsetAnimationCurve* curve =
animation->curve()->ToScrollOffsetAnimationCurve();
// Verifiy the initial and target position after the scroll offset
@@ -967,8 +990,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval
break;
case 1: {
Animation* animation =
- player_child_->element_animations()
- ->GetAnimation(TargetProperty::SCROLL_OFFSET);
+ player_child_->GetAnimation(TargetProperty::SCROLL_OFFSET);
player_child_->RemoveAnimation(animation->id());
scroll_layer_->SetScrollOffset(final_postion_);
break;
@@ -1025,8 +1047,8 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval
LayerImpl* scroll_layer_impl =
host_impl->active_tree()->LayerById(scroll_layer_->id());
- Animation* animation = player_impl->element_animations()->GetAnimation(
- TargetProperty::SCROLL_OFFSET);
+ Animation* animation =
+ player_impl->GetAnimation(TargetProperty::SCROLL_OFFSET);
if (!animation || animation->run_state() != Animation::RUNNING)
return false;
@@ -1119,21 +1141,18 @@ class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers
if (!player_impl->element_animations())
return;
- Animation* root_animation = player_impl->element_animations()->GetAnimation(
- TargetProperty::OPACITY);
+ Animation* root_animation =
+ player_impl->GetAnimation(TargetProperty::OPACITY);
if (!root_animation || root_animation->run_state() != Animation::RUNNING)
return;
Animation* child_animation =
- player_child_impl->element_animations()->GetAnimation(
- TargetProperty::OPACITY);
+ player_child_impl->GetAnimation(TargetProperty::OPACITY);
EXPECT_EQ(Animation::RUNNING, child_animation->run_state());
EXPECT_EQ(root_animation->start_time(), child_animation->start_time());
- player_impl->element_animations()->AbortAnimations(TargetProperty::OPACITY);
- player_impl->element_animations()->AbortAnimations(
- TargetProperty::TRANSFORM);
- player_child_impl->element_animations()->AbortAnimations(
- TargetProperty::OPACITY);
+ player_impl->AbortAnimations(TargetProperty::OPACITY, false);
+ player_impl->AbortAnimations(TargetProperty::TRANSFORM, false);
+ player_child_impl->AbortAnimations(TargetProperty::OPACITY, false);
EndTest();
}
@@ -1195,8 +1214,7 @@ class LayerTreeHostAnimationTestPendingTreeAnimatesFirstCommit
timeline_impl->GetPlayerById(player_id_);
LayerImpl* child = host_impl->sync_tree()->LayerById(layer_->id());
- Animation* animation = player_impl->element_animations()->GetAnimation(
- TargetProperty::TRANSFORM);
+ Animation* animation = player_impl->GetAnimation(TargetProperty::TRANSFORM);
// The animation should be starting for the first frame.
EXPECT_EQ(Animation::STARTING, animation->run_state());
@@ -1209,8 +1227,7 @@ class LayerTreeHostAnimationTestPendingTreeAnimatesFirstCommit
// And the sync tree layer should know it is animating.
EXPECT_TRUE(child->screen_space_transform_is_animating());
- player_impl->element_animations()->AbortAnimations(
- TargetProperty::TRANSFORM);
+ player_impl->AbortAnimations(TargetProperty::TRANSFORM, false);
EndTest();
}
@@ -1357,21 +1374,20 @@ class LayerTreeHostAnimationTestAddAnimationAfterAnimating
}
void CheckAnimations(LayerTreeHostImpl* host_impl) {
- AnimationHost::ElementToAnimationsMap element_animations_copy =
- host_impl->animation_host()->active_element_animations_for_testing();
- EXPECT_EQ(2u, element_animations_copy.size());
- for (auto& it : element_animations_copy) {
- ElementId id = it.first;
- if (id ==
- host_impl->active_tree()->root_layer_for_testing()->element_id()) {
- Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM);
- EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0);
- } else if (id == layer_->element_id()) {
- Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY);
- EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0);
- }
- EndTest();
- }
+ GetImplTimelineAndPlayerByID(*host_impl);
+
+ EXPECT_EQ(2u, host_impl->animation_host()
+ ->active_element_animations_for_testing()
+ .size());
+
+ Animation* root_anim =
+ player_impl_->GetAnimation(TargetProperty::TRANSFORM);
+ EXPECT_GT((root_anim->start_time() - base::TimeTicks()).InSecondsF(), 0);
+
+ Animation* anim = player_child_impl_->GetAnimation(TargetProperty::OPACITY);
+ EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0);
+
+ EndTest();
}
void AfterTest() override {}
@@ -1408,8 +1424,7 @@ class LayerTreeHostAnimationTestRemoveAnimation
break;
case 2:
Animation* animation =
- player_child_->element_animations()->GetAnimation(
- TargetProperty::TRANSFORM);
+ player_child_->GetAnimation(TargetProperty::TRANSFORM);
player_child_->RemoveAnimation(animation->id());
gfx::Transform transform;
transform.Translate(10.f, 10.f);
@@ -1486,8 +1501,7 @@ class LayerTreeHostAnimationTestIsAnimating
AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5);
break;
case 2:
- Animation* animation = player_->element_animations()->GetAnimation(
- TargetProperty::TRANSFORM);
+ Animation* animation = player_->GetAnimation(TargetProperty::TRANSFORM);
player_->RemoveAnimation(animation->id());
break;
}
@@ -1719,8 +1733,8 @@ class LayerTreeHostAnimationTestChangeAnimationPlayer
timeline_->AttachPlayer(player_child_.get());
player_child_->AttachElement(layer_tree()->root_layer()->element_id());
AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 10, 10);
- Animation* animation = player_child_->element_animations()->GetAnimation(
- TargetProperty::TRANSFORM);
+ Animation* animation =
+ player_child_->GetAnimation(TargetProperty::TRANSFORM);
animation->set_start_time(base::TimeTicks::Now() +
base::TimeDelta::FromSecondsD(1000));
animation->set_fill_mode(Animation::FillMode::NONE);
« no previous file with comments | « cc/trees/layer_tree_host_common_unittest.cc ('k') | cc/trees/mutator_host_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698