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

Side by Side Diff: cc/input/scrollbar_animation_controller_unittest.cc

Issue 2816923002: change overlay scrollbar hover show to hover fade in (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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.h" 5 #include "cc/input/scrollbar_animation_controller.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"
11 #include "cc/test/test_task_graph_runner.h" 11 #include "cc/test/test_task_graph_runner.h"
12 #include "cc/trees/layer_tree_impl.h" 12 #include "cc/trees/layer_tree_impl.h"
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 using testing::AtLeast; 16 using testing::AtLeast;
17 using testing::Mock; 17 using testing::Mock;
18 using testing::NiceMock; 18 using testing::NiceMock;
19 using testing::_; 19 using testing::_;
20 20
21 namespace cc { 21 namespace cc {
22 namespace { 22 namespace {
23 23
24 const float kIdleThicknessScale = 24 const float kIdleThicknessScale =
25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale; 25 SingleScrollbarAnimationControllerThinning::kIdleThicknessScale;
26 const float kDefaultMouseMoveDistanceToTriggerAnimation = 26 const float kDefaultMouseMoveDistanceToTriggerAnimation =
27 SingleScrollbarAnimationControllerThinning:: 27 SingleScrollbarAnimationControllerThinning::
28 kDefaultMouseMoveDistanceToTriggerAnimation; 28 kDefaultMouseMoveDistanceToTriggerAnimation;
29 const float kMouseMoveDistanceToTriggerShow = 29 const float kMouseMoveDistanceToTriggerFadeIn =
30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerShow; 30 ScrollbarAnimationController::kMouseMoveDistanceToTriggerFadeIn;
31 const int kThumbThickness = 10; 31 const int kThumbThickness = 10;
32 32
33 class MockScrollbarAnimationControllerClient 33 class MockScrollbarAnimationControllerClient
34 : public ScrollbarAnimationControllerClient { 34 : public ScrollbarAnimationControllerClient {
35 public: 35 public:
36 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl) 36 explicit MockScrollbarAnimationControllerClient(LayerTreeHostImpl* host_impl)
37 : host_impl_(host_impl) {} 37 : host_impl_(host_impl) {}
38 virtual ~MockScrollbarAnimationControllerClient() {} 38 virtual ~MockScrollbarAnimationControllerClient() {}
39 39
40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, 40 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade,
(...skipping 25 matching lines...) Expand all
66 66
67 void ExpectScrollbarsOpacity(float opacity) { 67 void ExpectScrollbarsOpacity(float opacity) {
68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity()); 68 EXPECT_FLOAT_EQ(opacity, v_scrollbar_layer_->Opacity());
69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity()); 69 EXPECT_FLOAT_EQ(opacity, h_scrollbar_layer_->Opacity());
70 } 70 }
71 71
72 protected: 72 protected:
73 const base::TimeDelta kShowDelay = base::TimeDelta::FromSeconds(4); 73 const base::TimeDelta kShowDelay = base::TimeDelta::FromSeconds(4);
74 const base::TimeDelta kFadeOutDelay = base::TimeDelta::FromSeconds(2); 74 const base::TimeDelta kFadeOutDelay = base::TimeDelta::FromSeconds(2);
75 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5); 75 const base::TimeDelta kResizeFadeOutDelay = base::TimeDelta::FromSeconds(5);
76 const base::TimeDelta kFadeInDuration = base::TimeDelta::FromSeconds(3);
76 const base::TimeDelta kFadeOutDuration = base::TimeDelta::FromSeconds(3); 77 const base::TimeDelta kFadeOutDuration = base::TimeDelta::FromSeconds(3);
77 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2); 78 const base::TimeDelta kThinningDuration = base::TimeDelta::FromSeconds(2);
78 79
79 void SetUp() override { 80 void SetUp() override {
80 std::unique_ptr<LayerImpl> scroll_layer = 81 std::unique_ptr<LayerImpl> scroll_layer =
81 LayerImpl::Create(host_impl_.active_tree(), 1); 82 LayerImpl::Create(host_impl_.active_tree(), 1);
82 std::unique_ptr<LayerImpl> clip = 83 std::unique_ptr<LayerImpl> clip =
83 LayerImpl::Create(host_impl_.active_tree(), 2); 84 LayerImpl::Create(host_impl_.active_tree(), 2);
84 clip_layer_ = clip.get(); 85 clip_layer_ = clip.get();
85 scroll_layer->SetScrollClipLayer(clip_layer_->id()); 86 scroll_layer->SetScrollClipLayer(clip_layer_->id());
(...skipping 23 matching lines...) Expand all
109 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); 110 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
110 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; 111 v_scrollbar_layer_->test_properties()->opacity_can_animate = true;
111 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; 112 h_scrollbar_layer_->test_properties()->opacity_can_animate = true;
112 clip_layer_->SetBounds(gfx::Size(100, 100)); 113 clip_layer_->SetBounds(gfx::Size(100, 100));
113 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); 114 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
114 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); 115 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
115 116
116 scrollbar_controller_ = ScrollbarAnimationController:: 117 scrollbar_controller_ = ScrollbarAnimationController::
117 CreateScrollbarAnimationControllerAuraOverlay( 118 CreateScrollbarAnimationControllerAuraOverlay(
118 scroll_layer_ptr->id(), &client_, kShowDelay, kFadeOutDelay, 119 scroll_layer_ptr->id(), &client_, kShowDelay, kFadeOutDelay,
119 kResizeFadeOutDelay, kFadeOutDuration, kThinningDuration); 120 kResizeFadeOutDelay, kFadeInDuration, kFadeOutDuration,
121 kThinningDuration);
120 } 122 }
121 123
122 FakeImplTaskRunnerProvider task_runner_provider_; 124 FakeImplTaskRunnerProvider task_runner_provider_;
123 TestTaskGraphRunner task_graph_runner_; 125 TestTaskGraphRunner task_graph_runner_;
124 FakeLayerTreeHostImpl host_impl_; 126 FakeLayerTreeHostImpl host_impl_;
125 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_; 127 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
126 LayerImpl* clip_layer_; 128 LayerImpl* clip_layer_;
127 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; 129 SolidColorScrollbarLayerImpl* v_scrollbar_layer_;
128 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; 130 SolidColorScrollbarLayerImpl* h_scrollbar_layer_;
129 NiceMock<MockScrollbarAnimationControllerClient> client_; 131 NiceMock<MockScrollbarAnimationControllerClient> client_;
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 client_.start_fade().IsCancelled()); 1001 client_.start_fade().IsCancelled());
1000 1002
1001 // Mouse leave. 1003 // Mouse leave.
1002 scrollbar_controller_->DidMouseLeave(); 1004 scrollbar_controller_->DidMouseLeave();
1003 1005
1004 // An fade out animation should have been enqueued. 1006 // An fade out animation should have been enqueued.
1005 EXPECT_FALSE(client_.start_fade().is_null()); 1007 EXPECT_FALSE(client_.start_fade().is_null());
1006 EXPECT_EQ(kFadeOutDelay, client_.delay()); 1008 EXPECT_EQ(kFadeOutDelay, client_.delay());
1007 } 1009 }
1008 1010
1009 // Scrollbars should schedule a delay show when mouse hover the show scrollbar 1011 // Scrollbars should schedule a delay fade in when mouse hover the show
1010 // region of a hidden scrollbar. 1012 // scrollbar region of a hidden scrollbar.
1011 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverShow) { 1013 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverFadeIn) {
1012 base::TimeTicks time; 1014 base::TimeTicks time;
1013 time += base::TimeDelta::FromSeconds(1); 1015 time += base::TimeDelta::FromSeconds(1);
1014 1016
1015 // Move mouse hover the show scrollbar region of scrollbar. 1017 // Move mouse hover the fade in scrollbar region of scrollbar.
1016 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1018 scrollbar_controller_->DidMouseMoveNear(
1017 kMouseMoveDistanceToTriggerShow - 1); 1019 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1018 1020
1019 // An show animation should have been enqueued. 1021 // An fade in animation should have been enqueued.
1020 EXPECT_FALSE(client_.start_fade().is_null()); 1022 EXPECT_FALSE(client_.start_fade().is_null());
1021 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1023 EXPECT_FALSE(client_.start_fade().IsCancelled());
1022 EXPECT_EQ(kShowDelay, client_.delay()); 1024 EXPECT_EQ(kShowDelay, client_.delay());
1023 1025
1024 // Play the delay animation. 1026 // Play the delay animation.
1025 client_.start_fade().Run(); 1027 client_.start_fade().Run();
1026 EXPECT_TRUE(client_.start_fade().IsCancelled()); 1028 EXPECT_TRUE(client_.start_fade().IsCancelled());
1029
1030 scrollbar_controller_->Animate(time);
1031 time += kFadeInDuration;
bokan 2017/04/13 14:38:14 Please add a step in here before the animation fin
chaopeng 2017/04/13 15:15:37 Done.
1032 scrollbar_controller_->Animate(time);
1033
1027 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 1034 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1028 } 1035 }
1029 1036
1030 // Scrollbars should not schedule a new delay show when the mouse hovers inside 1037 // Scrollbars should not schedule a new delay fade in when the mouse hovers
1031 // a scrollbar already scheduled a delay show. 1038 // inside a scrollbar already scheduled a delay fade in.
1032 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1039 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1033 MouseHoverScrollbarAndMoveInside) { 1040 MouseHoverScrollbarAndMoveInside) {
1034 base::TimeTicks time; 1041 base::TimeTicks time;
1035 time += base::TimeDelta::FromSeconds(1); 1042 time += base::TimeDelta::FromSeconds(1);
1036 1043
1037 // Move mouse hover the show scrollbar region of scrollbar. 1044 // Move mouse hover the fade in scrollbar region of scrollbar.
1038 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1045 scrollbar_controller_->DidMouseMoveNear(
1039 kMouseMoveDistanceToTriggerShow - 1); 1046 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1040 1047
1041 // An show animation should have been enqueued. 1048 // An fade in animation should have been enqueued.
1042 EXPECT_FALSE(client_.start_fade().is_null()); 1049 EXPECT_FALSE(client_.start_fade().is_null());
1043 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1050 EXPECT_FALSE(client_.start_fade().IsCancelled());
1044 EXPECT_EQ(kShowDelay, client_.delay()); 1051 EXPECT_EQ(kShowDelay, client_.delay());
1045 1052
1046 base::Closure& fade = client_.start_fade(); 1053 base::Closure& fade = client_.start_fade();
1047 // Move mouse still hover the show scrollbar region of scrollbar should not 1054 // Move mouse still hover the fade in scrollbar region of scrollbar should not
1048 // post a new show. 1055 // post a new show.
1049 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1056 scrollbar_controller_->DidMouseMoveNear(
1050 kMouseMoveDistanceToTriggerShow - 2); 1057 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 2);
1051 1058
1052 EXPECT_TRUE(fade.Equals(client_.start_fade())); 1059 EXPECT_TRUE(fade.Equals(client_.start_fade()));
1053 } 1060 }
1054 1061
1055 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then 1062 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then
1056 // move far away. 1063 // move far away.
1057 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1064 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1058 MouseHoverThenOutShouldCancelShow) { 1065 MouseHoverThenOutShouldCancelShow) {
1059 base::TimeTicks time; 1066 base::TimeTicks time;
1060 time += base::TimeDelta::FromSeconds(1); 1067 time += base::TimeDelta::FromSeconds(1);
1061 1068
1062 // Move mouse hover the show scrollbar region of scrollbar. 1069 // Move mouse hover the fade in scrollbar region of scrollbar.
1063 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1070 scrollbar_controller_->DidMouseMoveNear(
1064 kMouseMoveDistanceToTriggerShow - 1); 1071 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1065 1072
1066 // An show animation should have been enqueued. 1073 // An fade in animation should have been enqueued.
1067 EXPECT_FALSE(client_.start_fade().is_null()); 1074 EXPECT_FALSE(client_.start_fade().is_null());
1068 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1075 EXPECT_FALSE(client_.start_fade().IsCancelled());
1069 EXPECT_EQ(kShowDelay, client_.delay()); 1076 EXPECT_EQ(kShowDelay, client_.delay());
1070 1077
1071 // Move mouse far away,delay show should be canceled. 1078 // Move mouse far away,delay show should be canceled.
1072 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1079 scrollbar_controller_->DidMouseMoveNear(VERTICAL,
1073 kMouseMoveDistanceToTriggerShow); 1080 kMouseMoveDistanceToTriggerFadeIn);
1074 EXPECT_TRUE(client_.start_fade().is_null() || 1081 EXPECT_TRUE(client_.start_fade().is_null() ||
1075 client_.start_fade().IsCancelled()); 1082 client_.start_fade().IsCancelled());
1076 } 1083 }
1077 1084
1078 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then 1085 // Scrollbars should cancel delay show when mouse hover hidden scrollbar then
1079 // move out of window. 1086 // move out of window.
1080 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1087 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1081 MouseHoverThenLeaveShouldCancelShowThenEnterShouldShow) { 1088 MouseHoverThenLeaveShouldCancelShowThenEnterShouldShow) {
1082 base::TimeTicks time; 1089 base::TimeTicks time;
1083 time += base::TimeDelta::FromSeconds(1); 1090 time += base::TimeDelta::FromSeconds(1);
1084 1091
1085 // Move mouse hover the show scrollbar region of scrollbar. 1092 // Move mouse hover the fade in scrollbar region of scrollbar.
1086 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1093 scrollbar_controller_->DidMouseMoveNear(
1087 kMouseMoveDistanceToTriggerShow - 1); 1094 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1088 1095
1089 // An show animation should have been enqueued. 1096 // An fade in animation should have been enqueued.
1090 EXPECT_FALSE(client_.start_fade().is_null()); 1097 EXPECT_FALSE(client_.start_fade().is_null());
1091 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1098 EXPECT_FALSE(client_.start_fade().IsCancelled());
1092 EXPECT_EQ(kShowDelay, client_.delay()); 1099 EXPECT_EQ(kShowDelay, client_.delay());
1093 1100
1094 // Move mouse out of window,delay show should be canceled. 1101 // Move mouse out of window,delay show should be canceled.
1095 scrollbar_controller_->DidMouseLeave(); 1102 scrollbar_controller_->DidMouseLeave();
1096 EXPECT_TRUE(client_.start_fade().is_null() || 1103 EXPECT_TRUE(client_.start_fade().is_null() ||
1097 client_.start_fade().IsCancelled()); 1104 client_.start_fade().IsCancelled());
1098 1105
1099 // Move mouse hover the show scrollbar region of scrollbar. 1106 // Move mouse hover the fade in scrollbar region of scrollbar.
1100 scrollbar_controller_->DidMouseMoveNear(VERTICAL, 1107 scrollbar_controller_->DidMouseMoveNear(
1101 kMouseMoveDistanceToTriggerShow - 1); 1108 VERTICAL, kMouseMoveDistanceToTriggerFadeIn - 1);
1102 1109
1103 // An show animation should have been enqueued. 1110 // An fade in animation should have been enqueued.
1104 EXPECT_FALSE(client_.start_fade().is_null()); 1111 EXPECT_FALSE(client_.start_fade().is_null());
1105 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1112 EXPECT_FALSE(client_.start_fade().IsCancelled());
1106 EXPECT_EQ(kShowDelay, client_.delay()); 1113 EXPECT_EQ(kShowDelay, client_.delay());
1107 1114
1108 // Play the delay animation. 1115 // Play the delay animation.
1109 client_.start_fade().Run(); 1116 client_.start_fade().Run();
1110 EXPECT_TRUE(client_.start_fade().IsCancelled()); 1117 EXPECT_TRUE(client_.start_fade().IsCancelled());
1118
1119 scrollbar_controller_->Animate(time);
1120 time += kFadeInDuration;
1121 scrollbar_controller_->Animate(time);
1122
1111 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 1123 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1112 } 1124 }
1113 1125
1114 class ScrollbarAnimationControllerAndroidTest 1126 class ScrollbarAnimationControllerAndroidTest
1115 : public testing::Test, 1127 : public testing::Test,
1116 public ScrollbarAnimationControllerClient { 1128 public ScrollbarAnimationControllerClient {
1117 public: 1129 public:
1118 ScrollbarAnimationControllerAndroidTest() 1130 ScrollbarAnimationControllerAndroidTest()
1119 : host_impl_(&task_runner_provider_, &task_graph_runner_), 1131 : host_impl_(&task_runner_provider_, &task_graph_runner_),
1120 did_request_redraw_(false), 1132 did_request_redraw_(false),
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
1594 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1606 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1595 1607
1596 time += base::TimeDelta::FromSeconds(1); 1608 time += base::TimeDelta::FromSeconds(1);
1597 scrollbar_controller_->DidScrollEnd(); 1609 scrollbar_controller_->DidScrollEnd();
1598 EXPECT_FALSE(did_request_animate_); 1610 EXPECT_FALSE(did_request_animate_);
1599 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1611 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1600 } 1612 }
1601 1613
1602 } // namespace 1614 } // namespace
1603 } // namespace cc 1615 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698