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

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

Issue 2957093003: Don't fade in overlay scrollbar when user interacting the content under scrollbar. (Closed)
Patch Set: Created 3 years, 5 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
« no previous file with comments | « cc/input/scrollbar_animation_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 705
706 // Now try to capture the scrollbar. It shouldn't do anything since it's 706 // Now try to capture the scrollbar. It shouldn't do anything since it's
707 // completely faded out. 707 // completely faded out.
708 scrollbar_controller_->DidMouseDown(); 708 scrollbar_controller_->DidMouseDown();
709 ExpectScrollbarsOpacity(0); 709 ExpectScrollbarsOpacity(0);
710 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 710 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
711 EXPECT_FLOAT_EQ(kIdleThicknessScale, 711 EXPECT_FLOAT_EQ(kIdleThicknessScale,
712 h_scrollbar_layer_->thumb_thickness_scale_factor()); 712 h_scrollbar_layer_->thumb_thickness_scale_factor());
713 EXPECT_TRUE(client_.start_fade().is_null()); 713 EXPECT_TRUE(client_.start_fade().is_null());
714 714
715 // Similarly, releasing the scrollbar should have no effect. 715 // Similarly, releasing the scrollbar should have no effect but trigger a fade
716 // in.
716 scrollbar_controller_->DidMouseUp(); 717 scrollbar_controller_->DidMouseUp();
717 ExpectScrollbarsOpacity(0); 718 ExpectScrollbarsOpacity(0);
718 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 719 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
719 EXPECT_FLOAT_EQ(kIdleThicknessScale, 720 EXPECT_FLOAT_EQ(kIdleThicknessScale,
720 h_scrollbar_layer_->thumb_thickness_scale_factor()); 721 h_scrollbar_layer_->thumb_thickness_scale_factor());
721 EXPECT_TRUE(client_.start_fade().is_null()); 722
723 // An fade in animation should have been enqueued.
724 EXPECT_FALSE(client_.start_fade().is_null());
725 EXPECT_FALSE(client_.start_fade().IsCancelled());
726 EXPECT_EQ(kFadeDelay, client_.delay());
727
728 // Play the delay animation.
729 client_.start_fade().Run();
730 EXPECT_TRUE(client_.start_fade().IsCancelled());
731
732 scrollbar_controller_->Animate(time);
733 time += kFadeDuration;
734 scrollbar_controller_->Animate(time);
735
736 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
722 } 737 }
723 738
724 // Initiate a scroll when the pointer is already near the scrollbar. It should 739 // Initiate a scroll when the pointer is already near the scrollbar. It should
725 // appear thick and remain thick. 740 // appear thick and remain thick.
726 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ScrollWithMouseNear) { 741 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, ScrollWithMouseNear) {
727 base::TimeTicks time; 742 base::TimeTicks time;
728 time += base::TimeDelta::FromSeconds(1); 743 time += base::TimeDelta::FromSeconds(1);
729 744
730 scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0)); 745 scrollbar_controller_->DidMouseMove(NearVerticalScrollbarBegin(-1, 0));
731 scrollbar_controller_->Animate(time); 746 scrollbar_controller_->Animate(time);
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 EXPECT_FALSE(client_.start_fade().is_null()); 1096 EXPECT_FALSE(client_.start_fade().is_null());
1082 EXPECT_EQ(kFadeDelay, client_.delay()); 1097 EXPECT_EQ(kFadeDelay, client_.delay());
1083 } 1098 }
1084 1099
1085 // Scrollbars should schedule a delay fade in when mouse hover the show 1100 // Scrollbars should schedule a delay fade in when mouse hover the show
1086 // scrollbar region of a hidden scrollbar. 1101 // scrollbar region of a hidden scrollbar.
1087 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverFadeIn) { 1102 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, BasicMouseHoverFadeIn) {
1088 base::TimeTicks time; 1103 base::TimeTicks time;
1089 time += base::TimeDelta::FromSeconds(1); 1104 time += base::TimeDelta::FromSeconds(1);
1090 1105
1091 // Move mouse hover the fade in scrollbar region of scrollbar. 1106 // Move mouse over the fade in region of scrollbar.
1092 scrollbar_controller_->DidMouseMove( 1107 scrollbar_controller_->DidMouseMove(
1093 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0)); 1108 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
1094 1109
1095 // An fade in animation should have been enqueued. 1110 // An fade in animation should have been enqueued.
1096 EXPECT_FALSE(client_.start_fade().is_null()); 1111 EXPECT_FALSE(client_.start_fade().is_null());
1097 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1112 EXPECT_FALSE(client_.start_fade().IsCancelled());
1098 EXPECT_EQ(kFadeDelay, client_.delay()); 1113 EXPECT_EQ(kFadeDelay, client_.delay());
1099 1114
1100 // Play the delay animation. 1115 // Play the delay animation.
1101 client_.start_fade().Run(); 1116 client_.start_fade().Run();
(...skipping 13 matching lines...) Expand all
1115 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 1130 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1116 } 1131 }
1117 1132
1118 // Scrollbars should not schedule a new delay fade in when the mouse hovers 1133 // Scrollbars should not schedule a new delay fade in when the mouse hovers
1119 // inside a scrollbar already scheduled a delay fade in. 1134 // inside a scrollbar already scheduled a delay fade in.
1120 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1135 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1121 MouseHoverScrollbarAndMoveInside) { 1136 MouseHoverScrollbarAndMoveInside) {
1122 base::TimeTicks time; 1137 base::TimeTicks time;
1123 time += base::TimeDelta::FromSeconds(1); 1138 time += base::TimeDelta::FromSeconds(1);
1124 1139
1125 // Move mouse hover the fade in scrollbar region of scrollbar. 1140 // Move mouse over the fade in region of scrollbar.
1126 scrollbar_controller_->DidMouseMove( 1141 scrollbar_controller_->DidMouseMove(
1127 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0)); 1142 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
1128 1143
1129 // An fade in animation should have been enqueued. 1144 // An fade in animation should have been enqueued.
1130 EXPECT_FALSE(client_.start_fade().is_null()); 1145 EXPECT_FALSE(client_.start_fade().is_null());
1131 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1146 EXPECT_FALSE(client_.start_fade().IsCancelled());
1132 EXPECT_EQ(kFadeDelay, client_.delay()); 1147 EXPECT_EQ(kFadeDelay, client_.delay());
1133 1148
1134 base::Closure& fade = client_.start_fade(); 1149 base::Closure& fade = client_.start_fade();
1135 // Move mouse still hover the fade in scrollbar region of scrollbar should not 1150 // Move mouse still hover the fade in region of scrollbar should not
1136 // post a new fade in. 1151 // post a new fade in.
1137 scrollbar_controller_->DidMouseMove( 1152 scrollbar_controller_->DidMouseMove(
1138 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 2, 0)); 1153 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 2, 0));
1139 1154
1140 EXPECT_TRUE(fade.Equals(client_.start_fade())); 1155 EXPECT_TRUE(fade.Equals(client_.start_fade()));
1141 } 1156 }
1142 1157
1143 // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then 1158 // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then
1144 // move far away. 1159 // move far away.
1145 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1160 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1146 MouseHoverThenOutShouldCancelFadeIn) { 1161 MouseHoverThenOutShouldCancelFadeIn) {
1147 base::TimeTicks time; 1162 base::TimeTicks time;
1148 time += base::TimeDelta::FromSeconds(1); 1163 time += base::TimeDelta::FromSeconds(1);
1149 1164
1150 // Move mouse hover the fade in scrollbar region of scrollbar. 1165 // Move mouse over the fade in region of scrollbar.
1151 scrollbar_controller_->DidMouseMove( 1166 scrollbar_controller_->DidMouseMove(
1152 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0)); 1167 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
1153 1168
1154 // An fade in animation should have been enqueued. 1169 // An fade in animation should have been enqueued.
1155 EXPECT_FALSE(client_.start_fade().is_null()); 1170 EXPECT_FALSE(client_.start_fade().is_null());
1156 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1171 EXPECT_FALSE(client_.start_fade().IsCancelled());
1157 EXPECT_EQ(kFadeDelay, client_.delay()); 1172 EXPECT_EQ(kFadeDelay, client_.delay());
1158 1173
1159 // Move mouse far away,delay fade in should be canceled. 1174 // Move mouse far away,delay fade in should be canceled.
1160 scrollbar_controller_->DidMouseMove( 1175 scrollbar_controller_->DidMouseMove(
1161 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn, 0)); 1176 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn, 0));
1162 1177
1163 EXPECT_TRUE(client_.start_fade().is_null() || 1178 EXPECT_TRUE(client_.start_fade().is_null() ||
1164 client_.start_fade().IsCancelled()); 1179 client_.start_fade().IsCancelled());
1165 } 1180 }
1166 1181
1167 // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then 1182 // Scrollbars should cancel delay fade in when mouse hover hidden scrollbar then
1168 // move out of window. 1183 // move out of window.
1169 TEST_F(ScrollbarAnimationControllerAuraOverlayTest, 1184 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1170 MouseHoverThenLeaveShouldCancelShowThenEnterShouldFadeIn) { 1185 MouseHoverThenLeaveShouldCancelShowThenEnterShouldFadeIn) {
1171 base::TimeTicks time; 1186 base::TimeTicks time;
1172 time += base::TimeDelta::FromSeconds(1); 1187 time += base::TimeDelta::FromSeconds(1);
1173 1188
1174 // Move mouse hover the fade in scrollbar region of scrollbar. 1189 // Move mouse over the fade in region of scrollbar.
1175 scrollbar_controller_->DidMouseMove( 1190 scrollbar_controller_->DidMouseMove(
1176 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0)); 1191 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
1177 1192
1178 // An fade in animation should have been enqueued. 1193 // An fade in animation should have been enqueued.
1179 EXPECT_FALSE(client_.start_fade().is_null()); 1194 EXPECT_FALSE(client_.start_fade().is_null());
1180 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1195 EXPECT_FALSE(client_.start_fade().IsCancelled());
1181 EXPECT_EQ(kFadeDelay, client_.delay()); 1196 EXPECT_EQ(kFadeDelay, client_.delay());
1182 1197
1183 // Move mouse out of window,delay fade in should be canceled. 1198 // Move mouse out of window,delay fade in should be canceled.
1184 scrollbar_controller_->DidMouseLeave(); 1199 scrollbar_controller_->DidMouseLeave();
1185 EXPECT_TRUE(client_.start_fade().is_null() || 1200 EXPECT_TRUE(client_.start_fade().is_null() ||
1186 client_.start_fade().IsCancelled()); 1201 client_.start_fade().IsCancelled());
1187 1202
1188 // Move mouse hover the fade in scrollbar region of scrollbar. 1203 // Move mouse over the fade in region of scrollbar.
1189 scrollbar_controller_->DidMouseMove( 1204 scrollbar_controller_->DidMouseMove(
1190 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0)); 1205 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
1191 1206
1192 // An fade in animation should have been enqueued. 1207 // An fade in animation should have been enqueued.
1193 EXPECT_FALSE(client_.start_fade().is_null()); 1208 EXPECT_FALSE(client_.start_fade().is_null());
1194 EXPECT_FALSE(client_.start_fade().IsCancelled()); 1209 EXPECT_FALSE(client_.start_fade().IsCancelled());
1210 EXPECT_EQ(kFadeDelay, client_.delay());
1211
1212 // Play the delay animation.
1213 client_.start_fade().Run();
1214 EXPECT_TRUE(client_.start_fade().IsCancelled());
1215
1216 scrollbar_controller_->Animate(time);
1217 time += kFadeDuration;
1218 scrollbar_controller_->Animate(time);
1219
1220 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1221 }
1222
1223 // Make sure mouse down will cancel hover fade in timer, then mouse move with
1224 // press will not trigger hover fade in, mouse release near will trigger new
1225 // hover fade in.
1226 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1227 MouseHoverThenMouseDownShouldCancelFadeInThenReleaseNearShouldFadeIn) {
1228 base::TimeTicks time;
1229 time += base::TimeDelta::FromSeconds(1);
1230
1231 // Move mouse over the fade in region of scrollbar.
1232 scrollbar_controller_->DidMouseMove(
1233 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
1234
1235 // An fade in animation should have been enqueued.
1236 EXPECT_FALSE(client_.start_fade().is_null());
1237 EXPECT_FALSE(client_.start_fade().IsCancelled());
1238 EXPECT_EQ(kFadeDelay, client_.delay());
1239
1240 // Mouse down,delay fade in should be canceled.
1241 scrollbar_controller_->DidMouseDown();
1242 EXPECT_TRUE(client_.start_fade().is_null() ||
1243 client_.start_fade().IsCancelled());
1244
1245 // Move mouse hover the fade in region of scrollbar with press.
1246 scrollbar_controller_->DidMouseMove(
1247 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
1248
1249 // Should not have delay fade animation.
1250 EXPECT_TRUE(client_.start_fade().is_null() ||
1251 client_.start_fade().IsCancelled());
1252
1253 // Mouse up.
1254 scrollbar_controller_->DidMouseUp();
1255
1256 // An fade in animation should have been enqueued.
1257 EXPECT_FALSE(client_.start_fade().is_null());
1258 EXPECT_FALSE(client_.start_fade().IsCancelled());
1195 EXPECT_EQ(kFadeDelay, client_.delay()); 1259 EXPECT_EQ(kFadeDelay, client_.delay());
1196 1260
1197 // Play the delay animation. 1261 // Play the delay animation.
1198 client_.start_fade().Run(); 1262 client_.start_fade().Run();
1199 EXPECT_TRUE(client_.start_fade().IsCancelled()); 1263 EXPECT_TRUE(client_.start_fade().IsCancelled());
1200 1264
1201 scrollbar_controller_->Animate(time); 1265 scrollbar_controller_->Animate(time);
1202 time += kFadeDuration; 1266 time += kFadeDuration;
1203 scrollbar_controller_->Animate(time); 1267 scrollbar_controller_->Animate(time);
1204 1268
1205 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); 1269 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden());
1206 } 1270 }
1207 1271
1272 // Make sure mouse down will cancel hover fade in timer, then mouse move with
1273 // press will not trigger hover fade in, mouse release far will not trigger new
1274 // hover fade in.
1275 TEST_F(ScrollbarAnimationControllerAuraOverlayTest,
1276 MouseReleaseFarShouldNotFadeIn) {
1277 base::TimeTicks time;
1278 time += base::TimeDelta::FromSeconds(1);
1279
1280 // Move mouse over the fade in region of scrollbar.
1281 scrollbar_controller_->DidMouseMove(
1282 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn + 1, 0));
1283
1284 // An fade in animation should have been enqueued.
1285 EXPECT_FALSE(client_.start_fade().is_null());
1286 EXPECT_FALSE(client_.start_fade().IsCancelled());
1287 EXPECT_EQ(kFadeDelay, client_.delay());
1288
1289 // Mouse down,delay fade in should be canceled.
1290 scrollbar_controller_->DidMouseDown();
1291 EXPECT_TRUE(client_.start_fade().is_null() ||
1292 client_.start_fade().IsCancelled());
1293
1294 // Move mouse far from hover the fade in region of scrollbar with
1295 // press.
1296 scrollbar_controller_->DidMouseMove(
1297 NearVerticalScrollbarBegin(-kMouseMoveDistanceToTriggerFadeIn, 0));
1298
1299 // Should not have delay fade animation.
1300 EXPECT_TRUE(client_.start_fade().is_null() ||
1301 client_.start_fade().IsCancelled());
1302
1303 // Mouse up.
1304 scrollbar_controller_->DidMouseUp();
1305
1306 // Should not have delay fade animation.
1307 EXPECT_TRUE(client_.start_fade().is_null() ||
1308 client_.start_fade().IsCancelled());
1309 }
1310
1208 class ScrollbarAnimationControllerAndroidTest 1311 class ScrollbarAnimationControllerAndroidTest
1209 : public testing::Test, 1312 : public testing::Test,
1210 public ScrollbarAnimationControllerClient { 1313 public ScrollbarAnimationControllerClient {
1211 public: 1314 public:
1212 ScrollbarAnimationControllerAndroidTest() 1315 ScrollbarAnimationControllerAndroidTest()
1213 : host_impl_(&task_runner_provider_, &task_graph_runner_), 1316 : host_impl_(&task_runner_provider_, &task_graph_runner_),
1214 did_request_redraw_(false), 1317 did_request_redraw_(false),
1215 did_request_animate_(false) {} 1318 did_request_animate_(false) {}
1216 1319
1217 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade, 1320 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade,
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1778 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1676 1779
1677 time += base::TimeDelta::FromSeconds(1); 1780 time += base::TimeDelta::FromSeconds(1);
1678 scrollbar_controller_->DidScrollEnd(); 1781 scrollbar_controller_->DidScrollEnd();
1679 EXPECT_FALSE(did_request_animate_); 1782 EXPECT_FALSE(did_request_animate_);
1680 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity()); 1783 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1681 } 1784 }
1682 1785
1683 } // namespace 1786 } // namespace
1684 } // namespace cc 1787 } // namespace cc
OLDNEW
« no previous file with comments | « cc/input/scrollbar_animation_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698