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

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

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