Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/input/scrollbar_animation_controller_thinning.h" | 5 #include "cc/input/scrollbar_animation_controller_thinning.h" |
| 6 | 6 |
| 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | 7 #include "cc/layers/solid_color_scrollbar_layer_impl.h" |
| 8 #include "cc/test/fake_impl_task_runner_provider.h" | 8 #include "cc/test/fake_impl_task_runner_provider.h" |
| 9 #include "cc/test/fake_layer_tree_host_impl.h" | 9 #include "cc/test/fake_layer_tree_host_impl.h" |
| 10 #include "cc/test/geometry_test_utils.h" | 10 #include "cc/test/geometry_test_utils.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, | 60 host_impl_.active_tree(), kId, HORIZONTAL, kThumbThickness, |
| 61 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); | 61 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
| 62 scrollbar_layer_ = scrollbar.get(); | 62 scrollbar_layer_ = scrollbar.get(); |
| 63 | 63 |
| 64 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); | 64 scroll_layer->test_properties()->AddChild(std::move(scrollbar)); |
| 65 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); | 65 clip_layer_->test_properties()->AddChild(std::move(scroll_layer)); |
| 66 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); | 66 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); |
| 67 | 67 |
| 68 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); | 68 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); |
| 69 scrollbar_layer_->test_properties()->opacity_can_animate = true; | 69 scrollbar_layer_->test_properties()->opacity_can_animate = true; |
| 70 | |
|
bokan
2016/09/23 20:15:17
Nit: spurious new line
| |
| 70 clip_layer_->SetBounds(gfx::Size(100, 100)); | 71 clip_layer_->SetBounds(gfx::Size(100, 100)); |
| 71 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); | 72 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); |
| 72 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); | 73 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); |
| 73 | 74 |
| 74 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( | 75 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( |
| 75 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2), | 76 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2), |
| 76 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); | 77 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3)); |
| 77 } | 78 } |
| 78 | 79 |
| 79 FakeImplTaskRunnerProvider task_runner_provider_; | 80 FakeImplTaskRunnerProvider task_runner_provider_; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 90 bool did_request_animate_; | 91 bool did_request_animate_; |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 // Check initialization of scrollbar. | 94 // Check initialization of scrollbar. |
| 94 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { | 95 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { |
| 95 scrollbar_controller_->Animate(base::TimeTicks()); | 96 scrollbar_controller_->Animate(base::TimeTicks()); |
| 96 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); | 97 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); |
| 97 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); | 98 EXPECT_FLOAT_EQ(0.4f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 98 } | 99 } |
| 99 | 100 |
| 101 // Check that scrollbar appears again, when the layer becomes scrollable. | |
| 102 TEST_F(ScrollbarAnimationControllerThinningTest, AppearOnResize) { | |
| 103 scrollbar_controller_->DidScrollUpdate(false); | |
| 104 // Make the Layer non-scrollable, scrollbar disappears. | |
| 105 clip_layer_->SetBounds(gfx::Size(200, 200)); | |
| 106 scrollbar_controller_->DidScrollUpdate(false); | |
| 107 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | |
| 108 // Make the layer scrollable, scrollbar appears again. | |
| 109 clip_layer_->SetBounds(gfx::Size(100, 100)); | |
| 110 scrollbar_controller_->DidScrollUpdate(false); | |
|
bokan
2016/09/23 20:15:18
DidScrollUpdate gets called when we scroll though,
sahel
2016/09/23 20:25:11
It get's called when we are scrolling, AND during
bokan
2016/09/23 20:26:03
Got it. Thanks!
| |
| 111 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); | |
| 112 } | |
| 113 | |
| 100 // Check that scrollbar disappears when the layer becomes non-scrollable. | 114 // Check that scrollbar disappears when the layer becomes non-scrollable. |
| 101 TEST_F(ScrollbarAnimationControllerThinningTest, HideOnResize) { | 115 TEST_F(ScrollbarAnimationControllerThinningTest, HideOnResize) { |
| 102 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); | 116 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1); |
| 103 ASSERT_TRUE(scroll_layer); | 117 ASSERT_TRUE(scroll_layer); |
| 104 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); | 118 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds()); |
| 105 | 119 |
| 106 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); | 120 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation()); |
| 107 | 121 |
| 108 // Shrink along X axis, horizontal scrollbar should appear. | 122 // Shrink along X axis, horizontal scrollbar should appear. |
| 109 clip_layer_->SetBounds(gfx::Size(100, 200)); | 123 clip_layer_->SetBounds(gfx::Size(100, 200)); |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 | 395 |
| 382 time += base::TimeDelta::FromSeconds(1); | 396 time += base::TimeDelta::FromSeconds(1); |
| 383 scrollbar_controller_->Animate(time); | 397 scrollbar_controller_->Animate(time); |
| 384 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); | 398 EXPECT_FLOAT_EQ(0.7f, scrollbar_layer_->Opacity()); |
| 385 // The thickness now gets big again. | 399 // The thickness now gets big again. |
| 386 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 400 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 387 } | 401 } |
| 388 | 402 |
| 389 } // namespace | 403 } // namespace |
| 390 } // namespace cc | 404 } // namespace cc |
| OLD | NEW |