Commit 16fdc860 authored by Majid Valipour's avatar Majid Valipour Committed by Commit Bot

[cc] cleanup worklet animation tests

- Move two tests for AnimationHost/WorkletAnimation interactions to animation_host_unittests
- Remove unnecessary complexity related to creating and testing an impl instance.
  These tests don't need to distinguish between main/impl instances at all.

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I928e664ddf4fab8496fbbe3a09fcdcd120c875fb
Reviewed-on: https://chromium-review.googlesource.com/1133770Reviewed-by: default avatarStephen McGruer <smcgruer@chromium.org>
Commit-Queue: Majid Valipour <majidvp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578405}
parent c7c6a230
...@@ -183,5 +183,60 @@ TEST_F(AnimationHostTest, LayerTreeMutatorUpdateTakesEffectInSameFrame) { ...@@ -183,5 +183,60 @@ TEST_F(AnimationHostTest, LayerTreeMutatorUpdateTakesEffectInSameFrame) {
element_id_, ElementListType::ACTIVE, expected_opacity); element_id_, ElementListType::ACTIVE, expected_opacity);
} }
TEST_F(AnimationHostTest, LayerTreeMutatorsIsMutatedWithCorrectInputState) {
AttachWorkletAnimation();
MockLayerTreeMutator* mock_mutator = new NiceMock<MockLayerTreeMutator>();
host_impl_->SetLayerTreeMutator(
base::WrapUnique<LayerTreeMutator>(mock_mutator));
ON_CALL(*mock_mutator, HasAnimators()).WillByDefault(Return(true));
const float start_opacity = .7f;
const float end_opacity = .3f;
const double duration = 1.;
AddOpacityTransitionToAnimation(worklet_animation_.get(), duration,
start_opacity, end_opacity, true);
host_->PushPropertiesTo(host_impl_);
host_impl_->ActivateAnimations();
EXPECT_CALL(*mock_mutator, MutateRef(_));
base::TimeTicks time;
time += base::TimeDelta::FromSecondsD(0.1);
TickAnimationsTransferEvents(time, 0u);
}
TEST_F(AnimationHostTest, LayerTreeMutatorsIsMutatedOnlyWhenInputChanges) {
AttachWorkletAnimation();
MockLayerTreeMutator* mock_mutator = new NiceMock<MockLayerTreeMutator>();
host_impl_->SetLayerTreeMutator(
base::WrapUnique<LayerTreeMutator>(mock_mutator));
ON_CALL(*mock_mutator, HasAnimators()).WillByDefault(Return(true));
const float start_opacity = .7f;
const float end_opacity = .3f;
const double duration = 1.;
AddOpacityTransitionToAnimation(worklet_animation_.get(), duration,
start_opacity, end_opacity, true);
host_->PushPropertiesTo(host_impl_);
host_impl_->ActivateAnimations();
EXPECT_CALL(*mock_mutator, MutateRef(_)).Times(1);
base::TimeTicks time;
time += base::TimeDelta::FromSecondsD(0.1);
TickAnimationsTransferEvents(time, 0u);
// The time has not changed which means worklet animation input is the same.
// Ticking animations again should not result in mutator being asked to
// mutate.
TickAnimationsTransferEvents(time, 0u);
}
} // namespace } // namespace
} // namespace cc } // namespace cc
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "cc/animation/scroll_timeline.h" #include "cc/animation/scroll_timeline.h"
#include "cc/test/animation_test_common.h" #include "cc/test/animation_test_common.h"
#include "cc/test/animation_timelines_test_common.h" #include "cc/test/animation_timelines_test_common.h"
#include "cc/test/mock_layer_tree_mutator.h"
#include "cc/trees/property_tree.h" #include "cc/trees/property_tree.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -34,24 +33,16 @@ class WorkletAnimationTest : public AnimationTimelinesTest { ...@@ -34,24 +33,16 @@ class WorkletAnimationTest : public AnimationTimelinesTest {
void AttachWorkletAnimation() { void AttachWorkletAnimation() {
client_.RegisterElement(element_id_, ElementListType::ACTIVE); client_.RegisterElement(element_id_, ElementListType::ACTIVE);
client_impl_.RegisterElement(element_id_, ElementListType::PENDING);
client_impl_.RegisterElement(element_id_, ElementListType::ACTIVE);
worklet_animation_ = WorkletAnimation::Create( worklet_animation_ = WrapRefCounted(
worklet_animation_id_, "test_name", nullptr, nullptr); new WorkletAnimation(1, worklet_animation_id_, "test_name", nullptr,
int cc_id = worklet_animation_->id(); nullptr, true /* controlling instance*/));
worklet_animation_->AttachElement(element_id_); worklet_animation_->AttachElement(element_id_);
host_->AddAnimationTimeline(timeline_); host_->AddAnimationTimeline(timeline_);
timeline_->AttachAnimation(worklet_animation_); timeline_->AttachAnimation(worklet_animation_);
host_->PushPropertiesTo(host_impl_);
timeline_impl_ = host_impl_->GetTimelineById(timeline_id_);
worklet_animation_impl_ =
ToWorkletAnimation(timeline_impl_->GetAnimationById(cc_id));
} }
scoped_refptr<WorkletAnimation> worklet_animation_; scoped_refptr<WorkletAnimation> worklet_animation_;
scoped_refptr<WorkletAnimation> worklet_animation_impl_;
WorkletAnimationId worklet_animation_id_{11, 12}; WorkletAnimationId worklet_animation_id_{11, 12};
}; };
...@@ -78,7 +69,7 @@ TEST_F(WorkletAnimationTest, NonImplInstanceDoesNotTickKeyframe) { ...@@ -78,7 +69,7 @@ TEST_F(WorkletAnimationTest, NonImplInstanceDoesNotTickKeyframe) {
worklet_animation->Tick(base::TimeTicks()); worklet_animation->Tick(base::TimeTicks());
} }
TEST_F(WorkletAnimationTest, LocalTimeIsUsedWithAnimations) { TEST_F(WorkletAnimationTest, LocalTimeIsUsedWhenTicking) {
AttachWorkletAnimation(); AttachWorkletAnimation();
const float start_opacity = .7f; const float start_opacity = .7f;
...@@ -90,80 +81,21 @@ TEST_F(WorkletAnimationTest, LocalTimeIsUsedWithAnimations) { ...@@ -90,80 +81,21 @@ TEST_F(WorkletAnimationTest, LocalTimeIsUsedWithAnimations) {
AddOpacityTransitionToAnimation(worklet_animation_.get(), duration, AddOpacityTransitionToAnimation(worklet_animation_.get(), duration,
start_opacity, end_opacity, true); start_opacity, end_opacity, true);
// Push the opacity animation to the impl thread. KeyframeModel* keyframe_model =
host_->PushPropertiesTo(host_impl_); worklet_animation_->GetKeyframeModel(TargetProperty::OPACITY);
host_impl_->ActivateAnimations(); // Impl side animation don't need synchronized start time.
keyframe_model->set_needs_synchronized_start_time(false);
base::TimeDelta local_time = base::TimeDelta::FromSecondsD(duration / 2); base::TimeDelta local_time = base::TimeDelta::FromSecondsD(duration / 2);
worklet_animation_impl_->SetOutputState({worklet_animation_id_, local_time}); worklet_animation_->SetOutputState({worklet_animation_id_, local_time});
TickAnimationsTransferEvents(base::TimeTicks(), 0u); worklet_animation_->Tick(base::TimeTicks());
TestLayer* layer = TestLayer* layer =
client_.FindTestLayer(element_id_, ElementListType::ACTIVE); client_.FindTestLayer(element_id_, ElementListType::ACTIVE);
EXPECT_FALSE(layer->is_property_mutated(TargetProperty::OPACITY)); EXPECT_TRUE(layer->is_property_mutated(TargetProperty::OPACITY));
client_impl_.ExpectOpacityPropertyMutated( client_.ExpectOpacityPropertyMutated(element_id_, ElementListType::ACTIVE,
element_id_, ElementListType::ACTIVE, expected_opacity); expected_opacity);
}
// Tests that verify interaction of AnimationHost with LayerTreeMutator.
// TODO(majidvp): Perhaps moves these to AnimationHostTest.
TEST_F(WorkletAnimationTest, LayerTreeMutatorsIsMutatedWithCorrectInputState) {
AttachWorkletAnimation();
MockLayerTreeMutator* mock_mutator = new NiceMock<MockLayerTreeMutator>();
host_impl_->SetLayerTreeMutator(
base::WrapUnique<LayerTreeMutator>(mock_mutator));
ON_CALL(*mock_mutator, HasAnimators()).WillByDefault(Return(true));
const float start_opacity = .7f;
const float end_opacity = .3f;
const double duration = 1.;
AddOpacityTransitionToAnimation(worklet_animation_.get(), duration,
start_opacity, end_opacity, true);
host_->PushPropertiesTo(host_impl_);
host_impl_->ActivateAnimations();
EXPECT_CALL(*mock_mutator, MutateRef(_));
base::TimeTicks time;
time += base::TimeDelta::FromSecondsD(0.1);
TickAnimationsTransferEvents(time, 0u);
Mock::VerifyAndClearExpectations(mock_mutator);
}
TEST_F(WorkletAnimationTest, LayerTreeMutatorsIsMutatedOnlyWhenInputChanges) {
AttachWorkletAnimation();
MockLayerTreeMutator* mock_mutator = new NiceMock<MockLayerTreeMutator>();
host_impl_->SetLayerTreeMutator(
base::WrapUnique<LayerTreeMutator>(mock_mutator));
ON_CALL(*mock_mutator, HasAnimators()).WillByDefault(Return(true));
const float start_opacity = .7f;
const float end_opacity = .3f;
const double duration = 1.;
AddOpacityTransitionToAnimation(worklet_animation_.get(), duration,
start_opacity, end_opacity, true);
host_->PushPropertiesTo(host_impl_);
host_impl_->ActivateAnimations();
EXPECT_CALL(*mock_mutator, MutateRef(_)).Times(1);
base::TimeTicks time;
time += base::TimeDelta::FromSecondsD(0.1);
TickAnimationsTransferEvents(time, 0u);
// The time has not changed which means worklet animation input is the same.
// Ticking animations again should not result in mutator being asked to
// mutate.
TickAnimationsTransferEvents(time, 0u);
Mock::VerifyAndClearExpectations(mock_mutator);
} }
TEST_F(WorkletAnimationTest, CurrentTimeCorrectlyUsesScrollTimeline) { TEST_F(WorkletAnimationTest, CurrentTimeCorrectlyUsesScrollTimeline) {
...@@ -217,14 +149,9 @@ TEST_F(WorkletAnimationTest, ...@@ -217,14 +149,9 @@ TEST_F(WorkletAnimationTest,
} }
// This test verifies that worklet animation state is properly updated. // This test verifies that worklet animation state is properly updated.
TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) { TEST_F(WorkletAnimationTest, UpdateInputStateProducesCorrectState) {
AttachWorkletAnimation(); AttachWorkletAnimation();
MockLayerTreeMutator* mock_mutator = new NiceMock<MockLayerTreeMutator>();
host_impl_->SetLayerTreeMutator(
base::WrapUnique<LayerTreeMutator>(mock_mutator));
ON_CALL(*mock_mutator, HasAnimators()).WillByDefault(Return(true));
const float start_opacity = .7f; const float start_opacity = .7f;
const float end_opacity = .3f; const float end_opacity = .3f;
const double duration = 1.; const double duration = 1.;
...@@ -233,20 +160,15 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) { ...@@ -233,20 +160,15 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) {
worklet_animation_.get(), duration, start_opacity, end_opacity, true); worklet_animation_.get(), duration, start_opacity, end_opacity, true);
ScrollTree scroll_tree; ScrollTree scroll_tree;
std::unique_ptr<MutatorEvents> events = host_->CreateEvents();
std::unique_ptr<MutatorInputState> state = std::unique_ptr<MutatorInputState> state =
std::make_unique<MutatorInputState>(); std::make_unique<MutatorInputState>();
host_->PushPropertiesTo(host_impl_);
host_impl_->ActivateAnimations();
KeyframeModel* keyframe_model = KeyframeModel* keyframe_model =
worklet_animation_impl_->GetKeyframeModel(TargetProperty::OPACITY); worklet_animation_->GetKeyframeModel(TargetProperty::OPACITY);
ASSERT_TRUE(keyframe_model); ASSERT_TRUE(keyframe_model);
base::TimeTicks time; base::TimeTicks time;
worklet_animation_impl_->UpdateInputState(state.get(), time, scroll_tree, worklet_animation_->UpdateInputState(state.get(), time, scroll_tree, true);
true);
std::unique_ptr<AnimationWorkletInput> input = std::unique_ptr<AnimationWorkletInput> input =
state->TakeWorkletState(worklet_animation_id_.scope_id); state->TakeWorkletState(worklet_animation_id_.scope_id);
EXPECT_EQ(input->added_and_updated_animations.size(), 1u); EXPECT_EQ(input->added_and_updated_animations.size(), 1u);
...@@ -258,8 +180,7 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) { ...@@ -258,8 +180,7 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) {
// UpdateInputState above. // UpdateInputState above.
state.reset(new MutatorInputState()); state.reset(new MutatorInputState());
time += base::TimeDelta::FromSecondsD(0.1); time += base::TimeDelta::FromSecondsD(0.1);
worklet_animation_impl_->UpdateInputState(state.get(), time, scroll_tree, worklet_animation_->UpdateInputState(state.get(), time, scroll_tree, true);
true);
input = state->TakeWorkletState(worklet_animation_id_.scope_id); input = state->TakeWorkletState(worklet_animation_id_.scope_id);
EXPECT_EQ(input->added_and_updated_animations.size(), 0u); EXPECT_EQ(input->added_and_updated_animations.size(), 0u);
EXPECT_EQ(input->updated_animations.size(), 1u); EXPECT_EQ(input->updated_animations.size(), 1u);
...@@ -270,8 +191,7 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) { ...@@ -270,8 +191,7 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) {
keyframe_model->SetRunState(KeyframeModel::FINISHED, time); keyframe_model->SetRunState(KeyframeModel::FINISHED, time);
state.reset(new MutatorInputState()); state.reset(new MutatorInputState());
time += base::TimeDelta::FromSecondsD(0.1); time += base::TimeDelta::FromSecondsD(0.1);
worklet_animation_impl_->UpdateInputState(state.get(), time, scroll_tree, worklet_animation_->UpdateInputState(state.get(), time, scroll_tree, true);
true);
input = state->TakeWorkletState(worklet_animation_id_.scope_id); input = state->TakeWorkletState(worklet_animation_id_.scope_id);
EXPECT_EQ(input->added_and_updated_animations.size(), 0u); EXPECT_EQ(input->added_and_updated_animations.size(), 0u);
EXPECT_EQ(input->updated_animations.size(), 1u); EXPECT_EQ(input->updated_animations.size(), 1u);
...@@ -279,11 +199,10 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) { ...@@ -279,11 +199,10 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) {
// WorkletAnimation sets state to REMOVED when JavaScript fires cancel() which // WorkletAnimation sets state to REMOVED when JavaScript fires cancel() which
// leads to RemoveKeyframeModel. // leads to RemoveKeyframeModel.
worklet_animation_impl_->RemoveKeyframeModel(keyframe_model_id); worklet_animation_->RemoveKeyframeModel(keyframe_model_id);
host_impl_->UpdateAnimationState(true, events.get()); worklet_animation_->UpdateState(true, nullptr);
state.reset(new MutatorInputState()); state.reset(new MutatorInputState());
worklet_animation_impl_->UpdateInputState(state.get(), time, scroll_tree, worklet_animation_->UpdateInputState(state.get(), time, scroll_tree, true);
true);
input = state->TakeWorkletState(worklet_animation_id_.scope_id); input = state->TakeWorkletState(worklet_animation_id_.scope_id);
EXPECT_EQ(input->added_and_updated_animations.size(), 0u); EXPECT_EQ(input->added_and_updated_animations.size(), 0u);
EXPECT_EQ(input->updated_animations.size(), 0u); EXPECT_EQ(input->updated_animations.size(), 0u);
...@@ -295,11 +214,6 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) { ...@@ -295,11 +214,6 @@ TEST_F(WorkletAnimationTest, WorkletAnimationStateTestWithSingleKeyframeModel) {
TEST_F(WorkletAnimationTest, SkipUnchangedAnimations) { TEST_F(WorkletAnimationTest, SkipUnchangedAnimations) {
AttachWorkletAnimation(); AttachWorkletAnimation();
MockLayerTreeMutator* mock_mutator = new NiceMock<MockLayerTreeMutator>();
host_impl_->SetLayerTreeMutator(
base::WrapUnique<LayerTreeMutator>(mock_mutator));
ON_CALL(*mock_mutator, HasAnimators()).WillByDefault(Return(true));
const float start_opacity = .7f; const float start_opacity = .7f;
const float end_opacity = .3f; const float end_opacity = .3f;
const double duration = 1.; const double duration = 1.;
...@@ -308,16 +222,11 @@ TEST_F(WorkletAnimationTest, SkipUnchangedAnimations) { ...@@ -308,16 +222,11 @@ TEST_F(WorkletAnimationTest, SkipUnchangedAnimations) {
worklet_animation_.get(), duration, start_opacity, end_opacity, true); worklet_animation_.get(), duration, start_opacity, end_opacity, true);
ScrollTree scroll_tree; ScrollTree scroll_tree;
std::unique_ptr<MutatorEvents> events = host_->CreateEvents();
std::unique_ptr<MutatorInputState> state = std::unique_ptr<MutatorInputState> state =
std::make_unique<MutatorInputState>(); std::make_unique<MutatorInputState>();
host_->PushPropertiesTo(host_impl_);
host_impl_->ActivateAnimations();
base::TimeTicks time; base::TimeTicks time;
worklet_animation_impl_->UpdateInputState(state.get(), time, scroll_tree, worklet_animation_->UpdateInputState(state.get(), time, scroll_tree, true);
true);
std::unique_ptr<AnimationWorkletInput> input = std::unique_ptr<AnimationWorkletInput> input =
state->TakeWorkletState(worklet_animation_id_.scope_id); state->TakeWorkletState(worklet_animation_id_.scope_id);
EXPECT_EQ(input->added_and_updated_animations.size(), 1u); EXPECT_EQ(input->added_and_updated_animations.size(), 1u);
...@@ -325,25 +234,22 @@ TEST_F(WorkletAnimationTest, SkipUnchangedAnimations) { ...@@ -325,25 +234,22 @@ TEST_F(WorkletAnimationTest, SkipUnchangedAnimations) {
state.reset(new MutatorInputState()); state.reset(new MutatorInputState());
// No update on the input state if input time stays the same. // No update on the input state if input time stays the same.
worklet_animation_impl_->UpdateInputState(state.get(), time, scroll_tree, worklet_animation_->UpdateInputState(state.get(), time, scroll_tree, true);
true);
input = state->TakeWorkletState(worklet_animation_id_.scope_id); input = state->TakeWorkletState(worklet_animation_id_.scope_id);
EXPECT_FALSE(input); EXPECT_FALSE(input);
state.reset(new MutatorInputState()); state.reset(new MutatorInputState());
// Different input time causes the input state to be updated. // Different input time causes the input state to be updated.
time += base::TimeDelta::FromSecondsD(0.1); time += base::TimeDelta::FromSecondsD(0.1);
worklet_animation_impl_->UpdateInputState(state.get(), time, scroll_tree, worklet_animation_->UpdateInputState(state.get(), time, scroll_tree, true);
true);
input = state->TakeWorkletState(worklet_animation_id_.scope_id); input = state->TakeWorkletState(worklet_animation_id_.scope_id);
EXPECT_EQ(input->updated_animations.size(), 1u); EXPECT_EQ(input->updated_animations.size(), 1u);
state.reset(new MutatorInputState()); state.reset(new MutatorInputState());
// Input state gets updated when the worklet animation is to be removed even // Input state gets updated when the worklet animation is to be removed even
// the input time doesn't change. // the input time doesn't change.
worklet_animation_impl_->RemoveKeyframeModel(keyframe_model_id); worklet_animation_->RemoveKeyframeModel(keyframe_model_id);
worklet_animation_impl_->UpdateInputState(state.get(), time, scroll_tree, worklet_animation_->UpdateInputState(state.get(), time, scroll_tree, true);
true);
input = state->TakeWorkletState(worklet_animation_id_.scope_id); input = state->TakeWorkletState(worklet_animation_id_.scope_id);
EXPECT_EQ(input->updated_animations.size(), 0u); EXPECT_EQ(input->updated_animations.size(), 0u);
EXPECT_EQ(input->removed_animations.size(), 1u); EXPECT_EQ(input->removed_animations.size(), 1u);
......
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