diff options
Diffstat (limited to 'chromium/cc/input/scrollbar_animation_controller_unittest.cc')
-rw-r--r-- | chromium/cc/input/scrollbar_animation_controller_unittest.cc | 229 |
1 files changed, 99 insertions, 130 deletions
diff --git a/chromium/cc/input/scrollbar_animation_controller_unittest.cc b/chromium/cc/input/scrollbar_animation_controller_unittest.cc index 0836aeb1afa..d88bbdbf5b5 100644 --- a/chromium/cc/input/scrollbar_animation_controller_unittest.cc +++ b/chromium/cc/input/scrollbar_animation_controller_unittest.cc @@ -5,10 +5,8 @@ #include "cc/input/scrollbar_animation_controller.h" #include "cc/layers/solid_color_scrollbar_layer_impl.h" -#include "cc/test/fake_impl_task_runner_provider.h" -#include "cc/test/fake_layer_tree_host_impl.h" #include "cc/test/geometry_test_utils.h" -#include "cc/test/test_task_graph_runner.h" +#include "cc/test/layer_tree_impl_test_base.h" #include "cc/trees/layer_tree_impl.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -58,11 +56,11 @@ class MockScrollbarAnimationControllerClient LayerTreeHostImpl* host_impl_; }; -class ScrollbarAnimationControllerAuraOverlayTest : public testing::Test { +class ScrollbarAnimationControllerAuraOverlayTest + : public LayerTreeImplTestBase, + public testing::Test { public: - ScrollbarAnimationControllerAuraOverlayTest() - : host_impl_(&task_runner_provider_, &task_graph_runner_), - client_(&host_impl_) {} + ScrollbarAnimationControllerAuraOverlayTest() : client_(host_impl()) {} void ExpectScrollbarsOpacity(float opacity) { EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); @@ -75,57 +73,47 @@ class ScrollbarAnimationControllerAuraOverlayTest : public testing::Test { const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); void SetUp() override { - std::unique_ptr<LayerImpl> scroll_layer = - LayerImpl::Create(host_impl_.active_tree(), 1); - std::unique_ptr<LayerImpl> clip = - LayerImpl::Create(host_impl_.active_tree(), 2); - clip_layer_ = clip.get(); - scroll_layer->SetElementId( - LayerIdToElementIdForTesting(scroll_layer->id())); - LayerImpl* scroll_layer_ptr = scroll_layer.get(); - const int kTrackStart = 0; const int kTrackLength = 100; const bool kIsLeftSideVerticalScrollbar = false; - const bool kIsOverlayScrollbar = true; - - std::unique_ptr<SolidColorScrollbarLayerImpl> h_scrollbar = - SolidColorScrollbarLayerImpl::Create( - host_impl_.active_tree(), 3, HORIZONTAL, kThumbThickness, - kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); - h_scrollbar->test_properties()->opacity = 0.0f; - std::unique_ptr<SolidColorScrollbarLayerImpl> v_scrollbar = - SolidColorScrollbarLayerImpl::Create( - host_impl_.active_tree(), 4, VERTICAL, kThumbThickness, kTrackStart, - kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); - v_scrollbar->test_properties()->opacity = 0.0f; - v_scrollbar_layer_ = v_scrollbar.get(); - h_scrollbar_layer_ = h_scrollbar.get(); - - scroll_layer->test_properties()->AddChild(std::move(v_scrollbar)); - scroll_layer->test_properties()->AddChild(std::move(h_scrollbar)); - clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); - host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); + + scroll_layer_ = AddLayer<LayerImpl>(); + h_scrollbar_layer_ = AddLayer<SolidColorScrollbarLayerImpl>( + HORIZONTAL, kThumbThickness, kTrackStart, kIsLeftSideVerticalScrollbar); + v_scrollbar_layer_ = AddLayer<SolidColorScrollbarLayerImpl>( + VERTICAL, kThumbThickness, kTrackStart, kIsLeftSideVerticalScrollbar); + SetElementIdsForTesting(); + + clip_layer_ = root_layer(); + clip_layer_->SetBounds(gfx::Size(100, 100)); + + scroll_layer_->SetScrollable(gfx::Size(100, 100)); + scroll_layer_->SetBounds(gfx::Size(200, 200)); + CopyProperties(clip_layer_, scroll_layer_); + CreateTransformNode(scroll_layer_); + CreateScrollNode(scroll_layer_); v_scrollbar_layer_->SetBounds(gfx::Size(kThumbThickness, kTrackLength)); - v_scrollbar_layer_->test_properties()->position = gfx::PointF(90, 0); - v_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); - v_scrollbar_layer_->test_properties()->opacity_can_animate = true; + v_scrollbar_layer_->SetScrollElementId(scroll_layer_->element_id()); + CopyProperties(scroll_layer_, v_scrollbar_layer_); + v_scrollbar_layer_->SetOffsetToTransformParent(gfx::Vector2dF(90, 0)); + auto& v_scrollbar_effect = CreateEffectNode(v_scrollbar_layer_); + v_scrollbar_effect.opacity = 0.f; + v_scrollbar_effect.has_potential_opacity_animation = true; h_scrollbar_layer_->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); - h_scrollbar_layer_->test_properties()->position = gfx::PointF(0, 90); - h_scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); - h_scrollbar_layer_->test_properties()->opacity_can_animate = true; + h_scrollbar_layer_->SetScrollElementId(scroll_layer_->element_id()); + CopyProperties(scroll_layer_, h_scrollbar_layer_); + h_scrollbar_layer_->SetOffsetToTransformParent(gfx::Vector2dF(0, 90)); + auto& h_scrollbar_effect = CreateEffectNode(h_scrollbar_layer_); + h_scrollbar_effect.opacity = 0.f; + h_scrollbar_effect.has_potential_opacity_animation = true; - clip_layer_->SetBounds(gfx::Size(100, 100)); - scroll_layer_ptr->SetScrollable(gfx::Size(100, 100)); - scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); - host_impl_.active_tree()->UpdateScrollbarGeometries(); + UpdateActiveTreeDrawProperties(); scrollbar_controller_ = ScrollbarAnimationController:: CreateScrollbarAnimationControllerAuraOverlay( - scroll_layer_ptr->element_id(), &client_, kFadeDelay, kFadeDuration, + scroll_layer_->element_id(), &client_, kFadeDelay, kFadeDuration, kThinningDuration, 0.0f); v_scrollbar_layer_->SetCurrentPos(0); h_scrollbar_layer_->SetCurrentPos(0); @@ -153,11 +141,9 @@ class ScrollbarAnimationControllerAuraOverlayTest : public testing::Test { return p; } - FakeImplTaskRunnerProvider task_runner_provider_; - TestTaskGraphRunner task_graph_runner_; - FakeLayerTreeHostImpl host_impl_; std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; LayerImpl* clip_layer_; + LayerImpl* scroll_layer_; SolidColorScrollbarLayerImpl* v_scrollbar_layer_; SolidColorScrollbarLayerImpl* h_scrollbar_layer_; NiceMock<MockScrollbarAnimationControllerClient> client_; @@ -185,16 +171,17 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, AppearOnResize) { // Make the Layer non-scrollable, scrollbar disappears. clip_layer_->SetBounds(gfx::Size(200, 200)); - LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); - scroll_layer->SetScrollable(gfx::Size(200, 200)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + scroll_layer_->SetScrollable(gfx::Size(200, 200)); + GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 200); + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollUpdate(); ExpectScrollbarsOpacity(0); // Make the layer scrollable, scrollbar appears again. clip_layer_->SetBounds(gfx::Size(100, 100)); - scroll_layer->SetScrollable(gfx::Size(100, 100)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + scroll_layer_->SetScrollable(gfx::Size(100, 100)); + GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 100); + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollUpdate(); ExpectScrollbarsOpacity(1); } @@ -204,15 +191,14 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, HideOnResize) { base::TimeTicks time; time += base::TimeDelta::FromSeconds(1); - LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); - ASSERT_TRUE(scroll_layer); - EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); + EXPECT_EQ(gfx::Size(200, 200), scroll_layer_->bounds()); // Shrink along X axis, horizontal scrollbar should appear. clip_layer_->SetBounds(gfx::Size(100, 200)); EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds()); - scroll_layer->SetScrollable(gfx::Size(100, 200)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + scroll_layer_->SetScrollable(gfx::Size(100, 200)); + GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 200); + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); @@ -225,8 +211,9 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, HideOnResize) { // should disappear. clip_layer_->SetBounds(gfx::Size(200, 100)); EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds()); - scroll_layer->SetScrollable(gfx::Size(200, 100)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + scroll_layer_->SetScrollable(gfx::Size(200, 100)); + GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 100); + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); @@ -1363,13 +1350,12 @@ TEST_F(ScrollbarAnimationControllerAuraOverlayTest, TickmakrsShowHide) { } class ScrollbarAnimationControllerAndroidTest - : public testing::Test, + : public LayerTreeImplTestBase, + public testing::Test, public ScrollbarAnimationControllerClient { public: ScrollbarAnimationControllerAndroidTest() - : host_impl_(&task_runner_provider_, &task_graph_runner_), - did_request_redraw_(false), - did_request_animate_(false) {} + : did_request_redraw_(false), did_request_animate_(false) {} void PostDelayedScrollbarAnimationTask(base::OnceClosure start_fade, base::TimeDelta delay) override { @@ -1383,7 +1369,7 @@ class ScrollbarAnimationControllerAndroidTest did_request_animate_ = true; } ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const override { - return host_impl_.ScrollbarsFor(scroll_element_id); + return host_impl()->ScrollbarsFor(scroll_element_id); } void DidChangeScrollbarVisibility() override {} @@ -1391,47 +1377,38 @@ class ScrollbarAnimationControllerAndroidTest void SetUp() override { const int kTrackStart = 0; const bool kIsLeftSideVerticalScrollbar = false; - const bool kIsOverlayScrollbar = true; // Allow opacity animations. - - std::unique_ptr<LayerImpl> scroll_layer = - LayerImpl::Create(host_impl_.active_tree(), 1); - std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar = - SolidColorScrollbarLayerImpl::Create( - host_impl_.active_tree(), 2, orientation(), kThumbThickness, - kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); - scrollbar->test_properties()->opacity = 0.0f; - scrollbar_layer_ = scrollbar.get(); - scrollbar_layer_->test_properties()->opacity_can_animate = true; - std::unique_ptr<LayerImpl> root = - LayerImpl::Create(host_impl_.active_tree(), 3); - - scroll_layer->SetScrollable(gfx::Size(100, 100)); - scroll_layer->SetElementId( - LayerIdToElementIdForTesting(scroll_layer->id())); - LayerImpl* scroll_layer_ptr = scroll_layer.get(); - scroll_layer->test_properties()->AddChild(std::move(scrollbar)); - root->test_properties()->AddChild(std::move(scroll_layer)); - host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); - - scrollbar_layer_->SetScrollElementId(scroll_layer_ptr->element_id()); - scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); - DCHECK(host_impl_.active_tree()->ScrollbarGeometriesNeedUpdate()); - host_impl_.active_tree()->UpdateScrollbarGeometries(); + + LayerImpl* root = root_layer(); + scroll_layer_ = AddLayer<LayerImpl>(); + scrollbar_layer_ = AddLayer<SolidColorScrollbarLayerImpl>( + orientation(), kThumbThickness, kTrackStart, + kIsLeftSideVerticalScrollbar); + SetElementIdsForTesting(); + + scroll_layer_->SetBounds(gfx::Size(200, 200)); + scroll_layer_->SetScrollable(gfx::Size(100, 100)); + CopyProperties(root, scroll_layer_); + CreateTransformNode(scroll_layer_); + CreateScrollNode(scroll_layer_); + + scrollbar_layer_->SetScrollElementId(scroll_layer_->element_id()); + CopyProperties(scroll_layer_, scrollbar_layer_); + auto& scrollbar_effect = CreateEffectNode(scrollbar_layer_); + scrollbar_effect.opacity = 0.f; + scrollbar_effect.has_potential_opacity_animation = true; + + UpdateActiveTreeDrawProperties(); scrollbar_controller_ = ScrollbarAnimationController::CreateScrollbarAnimationControllerAndroid( - scroll_layer_ptr->element_id(), this, - base::TimeDelta::FromSeconds(2), base::TimeDelta::FromSeconds(3), - 0.0f); + scroll_layer_->element_id(), this, base::TimeDelta::FromSeconds(2), + base::TimeDelta::FromSeconds(3), 0.0f); } virtual ScrollbarOrientation orientation() const { return HORIZONTAL; } - FakeImplTaskRunnerProvider task_runner_provider_; - TestTaskGraphRunner task_graph_runner_; - FakeLayerTreeHostImpl host_impl_; std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; + LayerImpl* scroll_layer_; SolidColorScrollbarLayerImpl* scrollbar_layer_; base::OnceClosure start_fade_; @@ -1490,15 +1467,14 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, } TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) { - LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); - ASSERT_TRUE(scroll_layer); - EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); + EXPECT_EQ(gfx::Size(200, 200), scroll_layer_->bounds()); EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); // Shrink along X axis, horizontal scrollbar should appear. - scroll_layer->SetScrollable(gfx::Size(100, 200)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + scroll_layer_->SetScrollable(gfx::Size(100, 200)); + GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 200); + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); scrollbar_controller_->DidScrollUpdate(); @@ -1507,8 +1483,9 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) { // Shrink along Y axis and expand along X, horizontal scrollbar // should disappear. - scroll_layer->SetScrollable(gfx::Size(200, 100)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + scroll_layer_->SetScrollable(gfx::Size(200, 100)); + GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 100); + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); @@ -1519,15 +1496,14 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnResize) { } TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) { - LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); - ASSERT_TRUE(scroll_layer); - EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); + EXPECT_EQ(gfx::Size(200, 200), scroll_layer_->bounds()); EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); // Shrink along X axis, vertical scrollbar should remain invisible. - scroll_layer->SetScrollable(gfx::Size(100, 200)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + scroll_layer_->SetScrollable(gfx::Size(100, 200)); + GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(100, 200); + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); scrollbar_controller_->DidScrollUpdate(); @@ -1535,8 +1511,9 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) { scrollbar_controller_->DidScrollEnd(); // Shrink along Y axis and expand along X, vertical scrollbar should appear. - scroll_layer->SetScrollable(gfx::Size(200, 100)); - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + scroll_layer_->SetScrollable(gfx::Size(200, 100)); + GetScrollNode(scroll_layer_)->container_bounds = gfx::Size(200, 100); + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); @@ -1549,10 +1526,8 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnResize) { TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnUserNonScrollableHorz) { EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); - LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); - ASSERT_TRUE(scroll_layer); - scroll_layer->test_properties()->user_scrollable_horizontal = false; - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + GetScrollNode(scroll_layer_)->user_scrollable_horizontal = false; + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); @@ -1565,10 +1540,8 @@ TEST_F(ScrollbarAnimationControllerAndroidTest, HideOnUserNonScrollableHorz) { TEST_F(ScrollbarAnimationControllerAndroidTest, ShowOnUserNonScrollableVert) { EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); - LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); - ASSERT_TRUE(scroll_layer); - scroll_layer->test_properties()->user_scrollable_vertical = false; - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + GetScrollNode(scroll_layer_)->user_scrollable_vertical = false; + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); @@ -1582,10 +1555,8 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest, HideOnUserNonScrollableVert) { EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); - LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); - ASSERT_TRUE(scroll_layer); - scroll_layer->test_properties()->user_scrollable_vertical = false; - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + GetScrollNode(scroll_layer_)->user_scrollable_vertical = false; + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); @@ -1599,10 +1570,8 @@ TEST_F(VerticalScrollbarAnimationControllerAndroidTest, ShowOnUserNonScrollableHorz) { EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation()); - LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); - ASSERT_TRUE(scroll_layer); - scroll_layer->test_properties()->user_scrollable_horizontal = false; - host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); + GetScrollNode(scroll_layer_)->user_scrollable_horizontal = false; + UpdateActiveTreeDrawProperties(); scrollbar_controller_->DidScrollBegin(); |