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

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

Issue 2692243005: Merge Compositor's ScrollbarAnimationControllers into single class (Closed)
Patch Set: Created 3 years, 10 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_thinning.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
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip)); 103 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip));
104 104
105 v_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); 105 v_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
106 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id()); 106 h_scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
107 v_scrollbar_layer_->test_properties()->opacity_can_animate = true; 107 v_scrollbar_layer_->test_properties()->opacity_can_animate = true;
108 h_scrollbar_layer_->test_properties()->opacity_can_animate = true; 108 h_scrollbar_layer_->test_properties()->opacity_can_animate = true;
109 clip_layer_->SetBounds(gfx::Size(100, 100)); 109 clip_layer_->SetBounds(gfx::Size(100, 100));
110 scroll_layer_ptr->SetBounds(gfx::Size(200, 200)); 110 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
111 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting(); 111 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
112 112
113 scrollbar_controller_ = ScrollbarAnimationControllerThinning::Create( 113 scrollbar_controller_ = ScrollbarAnimationController::
114 scroll_layer_ptr->id(), &client_, kDelayBeforeStarting, 114 CreateScrollbarAnimationControllerThinning(
115 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration); 115 scroll_layer_ptr->id(), &client_, kDelayBeforeStarting,
116 kResizeDelayBeforeStarting, kFadeDuration, kThinningDuration);
116 } 117 }
117 118
118 FakeImplTaskRunnerProvider task_runner_provider_; 119 FakeImplTaskRunnerProvider task_runner_provider_;
119 TestTaskGraphRunner task_graph_runner_; 120 TestTaskGraphRunner task_graph_runner_;
120 FakeLayerTreeHostImpl host_impl_; 121 FakeLayerTreeHostImpl host_impl_;
121 std::unique_ptr<ScrollbarAnimationControllerThinning> scrollbar_controller_; 122 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
122 LayerImpl* clip_layer_; 123 LayerImpl* clip_layer_;
123 SolidColorScrollbarLayerImpl* v_scrollbar_layer_; 124 SolidColorScrollbarLayerImpl* v_scrollbar_layer_;
124 SolidColorScrollbarLayerImpl* h_scrollbar_layer_; 125 SolidColorScrollbarLayerImpl* h_scrollbar_layer_;
125 NiceMock<MockScrollbarAnimationControllerClient> client_; 126 NiceMock<MockScrollbarAnimationControllerClient> client_;
126 }; 127 };
127 128
128 // Check initialization of scrollbar. Should start off invisible and thin. 129 // Check initialization of scrollbar. Should start off invisible and thin.
129 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) { 130 TEST_F(ScrollbarAnimationControllerThinningTest, Idle) {
130 ExpectScrollbarsOpacity(0); 131 ExpectScrollbarsOpacity(0);
131 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden()); 132 EXPECT_TRUE(scrollbar_controller_->ScrollbarsHidden());
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 611
611 scrollbar_controller_->DidScrollBegin(); 612 scrollbar_controller_->DidScrollBegin();
612 scrollbar_controller_->DidScrollUpdate(false); 613 scrollbar_controller_->DidScrollUpdate(false);
613 614
614 // Now that we've received a scroll, we should be thick without an animation. 615 // Now that we've received a scroll, we should be thick without an animation.
615 ExpectScrollbarsOpacity(1); 616 ExpectScrollbarsOpacity(1);
616 617
617 // An animation for the fade should be either null or cancelled, since 618 // An animation for the fade should be either null or cancelled, since
618 // mouse is still near the scrollbar. 619 // mouse is still near the scrollbar.
619 scrollbar_controller_->DidScrollEnd(); 620 scrollbar_controller_->DidScrollEnd();
620 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
621 EXPECT_TRUE(client_.start_fade().is_null() || 621 EXPECT_TRUE(client_.start_fade().is_null() ||
622 client_.start_fade().IsCancelled()); 622 client_.start_fade().IsCancelled());
623 623
624 scrollbar_controller_->Animate(time); 624 scrollbar_controller_->Animate(time);
625 ExpectScrollbarsOpacity(1); 625 ExpectScrollbarsOpacity(1);
626 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor()); 626 EXPECT_FLOAT_EQ(1, v_scrollbar_layer_->thumb_thickness_scale_factor());
627 EXPECT_FLOAT_EQ(kIdleThicknessScale, 627 EXPECT_FLOAT_EQ(kIdleThicknessScale,
628 h_scrollbar_layer_->thumb_thickness_scale_factor()); 628 h_scrollbar_layer_->thumb_thickness_scale_factor());
629 629
630 // Scrollbar should still be thick and visible. 630 // Scrollbar should still be thick and visible.
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 client_.start_fade().IsCancelled()); 965 client_.start_fade().IsCancelled());
966 966
967 // Mouse leave. 967 // Mouse leave.
968 scrollbar_controller_->DidMouseLeave(); 968 scrollbar_controller_->DidMouseLeave();
969 969
970 // An animation should have been enqueued. 970 // An animation should have been enqueued.
971 EXPECT_FALSE(client_.start_fade().is_null()); 971 EXPECT_FALSE(client_.start_fade().is_null());
972 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); 972 EXPECT_EQ(kDelayBeforeStarting, client_.delay());
973 } 973 }
974 974
975 class ScrollbarAnimationControllerLinearFadeTest
976 : public testing::Test,
977 public ScrollbarAnimationControllerClient {
978 public:
979 ScrollbarAnimationControllerLinearFadeTest()
980 : host_impl_(&task_runner_provider_, &task_graph_runner_),
981 did_request_redraw_(false),
982 did_request_animate_(false) {}
983
984 void PostDelayedScrollbarAnimationTask(const base::Closure& start_fade,
985 base::TimeDelta delay) override {
986 start_fade_ = start_fade;
987 delay_ = delay;
988 }
989 void SetNeedsRedrawForScrollbarAnimation() override {
990 did_request_redraw_ = true;
991 }
992 void SetNeedsAnimateForScrollbarAnimation() override {
993 did_request_animate_ = true;
994 }
995 ScrollbarSet ScrollbarsFor(int scroll_layer_id) const override {
996 return host_impl_.ScrollbarsFor(scroll_layer_id);
997 }
998 void DidChangeScrollbarVisibility() override {}
999
1000 protected:
1001 void SetUp() override {
1002 const int kThumbThickness = 10;
1003 const int kTrackStart = 0;
1004 const bool kIsLeftSideVerticalScrollbar = false;
1005 const bool kIsOverlayScrollbar = true; // Allow opacity animations.
1006
1007 std::unique_ptr<LayerImpl> scroll_layer =
1008 LayerImpl::Create(host_impl_.active_tree(), 1);
1009 std::unique_ptr<SolidColorScrollbarLayerImpl> scrollbar =
1010 SolidColorScrollbarLayerImpl::Create(
1011 host_impl_.active_tree(), 2, orientation(), kThumbThickness,
1012 kTrackStart, kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
1013 scrollbar_layer_ = scrollbar.get();
1014 scrollbar_layer_->test_properties()->opacity_can_animate = true;
1015 std::unique_ptr<LayerImpl> clip =
1016 LayerImpl::Create(host_impl_.active_tree(), 3);
1017 clip_layer_ = clip.get();
1018 scroll_layer->SetScrollClipLayer(clip_layer_->id());
1019 LayerImpl* scroll_layer_ptr = scroll_layer.get();
1020 scroll_layer->test_properties()->AddChild(std::move(scrollbar));
1021 clip->test_properties()->AddChild(std::move(scroll_layer));
1022 host_impl_.active_tree()->SetRootLayerForTesting(std::move(clip));
1023
1024 scrollbar_layer_->SetScrollLayerId(scroll_layer_ptr->id());
1025 clip_layer_->SetBounds(gfx::Size(100, 100));
1026 scroll_layer_ptr->SetBounds(gfx::Size(200, 200));
1027 host_impl_.active_tree()->BuildLayerListAndPropertyTreesForTesting();
1028
1029 scrollbar_controller_ = ScrollbarAnimationController::
1030 CreateScrollbarAnimationControllerLinearFade(
1031 scroll_layer_ptr->id(), this, base::TimeDelta::FromSeconds(2),
1032 base::TimeDelta::FromSeconds(5), base::TimeDelta::FromSeconds(3));
1033 }
1034
1035 virtual ScrollbarOrientation orientation() const { return HORIZONTAL; }
1036
1037 FakeImplTaskRunnerProvider task_runner_provider_;
1038 TestTaskGraphRunner task_graph_runner_;
1039 FakeLayerTreeHostImpl host_impl_;
1040 std::unique_ptr<ScrollbarAnimationController> scrollbar_controller_;
1041 LayerImpl* clip_layer_;
1042 SolidColorScrollbarLayerImpl* scrollbar_layer_;
1043
1044 base::Closure start_fade_;
1045 base::TimeDelta delay_;
1046 bool did_request_redraw_;
1047 bool did_request_animate_;
1048 };
1049
1050 class VerticalScrollbarAnimationControllerLinearFadeTest
1051 : public ScrollbarAnimationControllerLinearFadeTest {
1052 protected:
1053 ScrollbarOrientation orientation() const override { return VERTICAL; }
1054 };
1055
1056 TEST_F(ScrollbarAnimationControllerLinearFadeTest, DelayAnimationOnResize) {
1057 scrollbar_layer_->layer_tree_impl()
1058 ->property_trees()
1059 ->effect_tree.OnOpacityAnimated(0.0f,
1060 scrollbar_layer_->effect_tree_index(),
1061 scrollbar_layer_->layer_tree_impl());
1062 scrollbar_controller_->DidScrollBegin();
1063 scrollbar_controller_->DidScrollUpdate(true);
1064 scrollbar_controller_->DidScrollEnd();
1065 // Normal Animation delay of 2 seconds.
1066 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1067 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(2));
1068
1069 scrollbar_layer_->layer_tree_impl()
1070 ->property_trees()
1071 ->effect_tree.OnOpacityAnimated(0.0f,
1072 scrollbar_layer_->effect_tree_index(),
1073 scrollbar_layer_->layer_tree_impl());
1074 scrollbar_controller_->DidScrollUpdate(true);
1075 // Delay animation on resize to 5 seconds.
1076 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1077 EXPECT_EQ(delay_, base::TimeDelta::FromSeconds(5));
1078 }
1079
1080 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HiddenInBegin) {
1081 scrollbar_layer_->layer_tree_impl()
1082 ->property_trees()
1083 ->effect_tree.OnOpacityAnimated(0.0f,
1084 scrollbar_layer_->effect_tree_index(),
1085 scrollbar_layer_->layer_tree_impl());
1086 scrollbar_controller_->Animate(base::TimeTicks());
1087 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1088 }
1089
1090 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
1091 HiddenAfterNonScrollingGesture) {
1092 scrollbar_layer_->layer_tree_impl()
1093 ->property_trees()
1094 ->effect_tree.OnOpacityAnimated(0.0f,
1095 scrollbar_layer_->effect_tree_index(),
1096 scrollbar_layer_->layer_tree_impl());
1097 scrollbar_controller_->DidScrollBegin();
1098
1099 base::TimeTicks time;
1100 time += base::TimeDelta::FromSeconds(100);
1101 scrollbar_controller_->Animate(time);
1102 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1103 scrollbar_controller_->DidScrollEnd();
1104
1105 EXPECT_TRUE(start_fade_.Equals(base::Closure()));
1106
1107 time += base::TimeDelta::FromSeconds(100);
1108 scrollbar_controller_->Animate(time);
1109 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1110 }
1111
1112 TEST_F(ScrollbarAnimationControllerLinearFadeTest, HideOnResize) {
1113 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
1114 ASSERT_TRUE(scroll_layer);
1115 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds());
1116
1117 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());
1118
1119 // Shrink along X axis, horizontal scrollbar should appear.
1120 clip_layer_->SetBounds(gfx::Size(100, 200));
1121 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds());
1122
1123 scrollbar_controller_->DidScrollBegin();
1124
1125 scrollbar_controller_->DidScrollUpdate(false);
1126 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1127
1128 scrollbar_controller_->DidScrollEnd();
1129
1130 // Shrink along Y axis and expand along X, horizontal scrollbar
1131 // should disappear.
1132 clip_layer_->SetBounds(gfx::Size(200, 100));
1133 EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds());
1134
1135 scrollbar_controller_->DidScrollBegin();
1136
1137 scrollbar_controller_->DidScrollUpdate(false);
1138 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1139
1140 scrollbar_controller_->DidScrollEnd();
1141 }
1142
1143 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest, HideOnResize) {
1144 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
1145 ASSERT_TRUE(scroll_layer);
1146 EXPECT_EQ(gfx::Size(200, 200), scroll_layer->bounds());
1147
1148 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation());
1149
1150 // Shrink along X axis, vertical scrollbar should remain invisible.
1151 clip_layer_->SetBounds(gfx::Size(100, 200));
1152 EXPECT_EQ(gfx::Size(100, 200), clip_layer_->bounds());
1153
1154 scrollbar_controller_->DidScrollBegin();
1155
1156 scrollbar_controller_->DidScrollUpdate(false);
1157 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1158
1159 scrollbar_controller_->DidScrollEnd();
1160
1161 // Shrink along Y axis and expand along X, vertical scrollbar should appear.
1162 clip_layer_->SetBounds(gfx::Size(200, 100));
1163 EXPECT_EQ(gfx::Size(200, 100), clip_layer_->bounds());
1164
1165 scrollbar_controller_->DidScrollBegin();
1166
1167 scrollbar_controller_->DidScrollUpdate(false);
1168 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1169
1170 scrollbar_controller_->DidScrollEnd();
1171 }
1172
1173 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
1174 HideOnUserNonScrollableHorz) {
1175 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());
1176
1177 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
1178 ASSERT_TRUE(scroll_layer);
1179 scroll_layer->set_user_scrollable_horizontal(false);
1180
1181 scrollbar_controller_->DidScrollBegin();
1182
1183 scrollbar_controller_->DidScrollUpdate(false);
1184 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1185
1186 scrollbar_controller_->DidScrollEnd();
1187 }
1188
1189 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
1190 ShowOnUserNonScrollableVert) {
1191 EXPECT_EQ(HORIZONTAL, scrollbar_layer_->orientation());
1192
1193 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
1194 ASSERT_TRUE(scroll_layer);
1195 scroll_layer->set_user_scrollable_vertical(false);
1196
1197 scrollbar_controller_->DidScrollBegin();
1198
1199 scrollbar_controller_->DidScrollUpdate(false);
1200 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1201
1202 scrollbar_controller_->DidScrollEnd();
1203 }
1204
1205 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest,
1206 HideOnUserNonScrollableVert) {
1207 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation());
1208
1209 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
1210 ASSERT_TRUE(scroll_layer);
1211 scroll_layer->set_user_scrollable_vertical(false);
1212
1213 scrollbar_controller_->DidScrollBegin();
1214
1215 scrollbar_controller_->DidScrollUpdate(false);
1216 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1217
1218 scrollbar_controller_->DidScrollEnd();
1219 }
1220
1221 TEST_F(VerticalScrollbarAnimationControllerLinearFadeTest,
1222 ShowOnUserNonScrollableHorz) {
1223 EXPECT_EQ(VERTICAL, scrollbar_layer_->orientation());
1224
1225 LayerImpl* scroll_layer = host_impl_.active_tree()->LayerById(1);
1226 ASSERT_TRUE(scroll_layer);
1227 scroll_layer->set_user_scrollable_horizontal(false);
1228
1229 scrollbar_controller_->DidScrollBegin();
1230
1231 scrollbar_controller_->DidScrollUpdate(false);
1232 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1233
1234 scrollbar_controller_->DidScrollEnd();
1235 }
1236
1237 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByScrollingGesture) {
1238 base::TimeTicks time;
1239 time += base::TimeDelta::FromSeconds(1);
1240 scrollbar_controller_->DidScrollBegin();
1241 EXPECT_FALSE(did_request_animate_);
1242
1243 scrollbar_controller_->DidScrollUpdate(false);
1244 EXPECT_FALSE(did_request_animate_);
1245 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1246
1247 EXPECT_TRUE(start_fade_.Equals(base::Closure()));
1248
1249 time += base::TimeDelta::FromSeconds(100);
1250
1251 scrollbar_controller_->Animate(time);
1252 EXPECT_FALSE(did_request_animate_);
1253 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1254 scrollbar_controller_->DidScrollEnd();
1255 EXPECT_FALSE(did_request_animate_);
1256 start_fade_.Run();
1257 EXPECT_TRUE(did_request_animate_);
1258 did_request_animate_ = false;
1259
1260 time += base::TimeDelta::FromSeconds(2);
1261 scrollbar_controller_->Animate(time);
1262 EXPECT_TRUE(did_request_animate_);
1263 did_request_animate_ = false;
1264 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1265
1266 time += base::TimeDelta::FromSeconds(1);
1267 scrollbar_controller_->Animate(time);
1268 EXPECT_TRUE(did_request_animate_);
1269 did_request_animate_ = false;
1270 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1271
1272 time += base::TimeDelta::FromSeconds(1);
1273 scrollbar_controller_->Animate(time);
1274 EXPECT_TRUE(did_request_animate_);
1275 did_request_animate_ = false;
1276 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
1277
1278 time += base::TimeDelta::FromSeconds(1);
1279
1280 scrollbar_controller_->DidScrollBegin();
1281 scrollbar_controller_->DidScrollUpdate(false);
1282 scrollbar_controller_->DidScrollEnd();
1283
1284 start_fade_.Run();
1285 EXPECT_TRUE(did_request_animate_);
1286 did_request_animate_ = false;
1287
1288 time += base::TimeDelta::FromSeconds(2);
1289 scrollbar_controller_->Animate(time);
1290 EXPECT_TRUE(did_request_animate_);
1291 did_request_animate_ = false;
1292 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1293
1294 time += base::TimeDelta::FromSeconds(1);
1295 scrollbar_controller_->Animate(time);
1296 EXPECT_TRUE(did_request_animate_);
1297 did_request_animate_ = false;
1298 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1299
1300 time += base::TimeDelta::FromSeconds(1);
1301 scrollbar_controller_->Animate(time);
1302 EXPECT_TRUE(did_request_animate_);
1303 did_request_animate_ = false;
1304 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
1305
1306 time += base::TimeDelta::FromSeconds(1);
1307 scrollbar_controller_->Animate(time);
1308 EXPECT_FALSE(did_request_animate_);
1309 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1310 }
1311
1312 TEST_F(ScrollbarAnimationControllerLinearFadeTest, AwakenByProgrammaticScroll) {
1313 base::TimeTicks time;
1314 time += base::TimeDelta::FromSeconds(1);
1315 scrollbar_controller_->DidScrollUpdate(false);
1316 EXPECT_FALSE(did_request_animate_);
1317
1318 start_fade_.Run();
1319 EXPECT_TRUE(did_request_animate_);
1320 did_request_animate_ = false;
1321 scrollbar_controller_->Animate(time);
1322 EXPECT_TRUE(did_request_animate_);
1323 did_request_animate_ = false;
1324 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1325
1326 time += base::TimeDelta::FromSeconds(1);
1327 scrollbar_controller_->Animate(time);
1328 EXPECT_TRUE(did_request_animate_);
1329 did_request_animate_ = false;
1330 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1331 scrollbar_controller_->DidScrollUpdate(false);
1332 EXPECT_FALSE(did_request_animate_);
1333
1334 start_fade_.Run();
1335 EXPECT_TRUE(did_request_animate_);
1336 did_request_animate_ = false;
1337 time += base::TimeDelta::FromSeconds(2);
1338 scrollbar_controller_->Animate(time);
1339 EXPECT_TRUE(did_request_animate_);
1340 did_request_animate_ = false;
1341 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1342
1343 time += base::TimeDelta::FromSeconds(1);
1344 scrollbar_controller_->Animate(time);
1345 EXPECT_TRUE(did_request_animate_);
1346 did_request_animate_ = false;
1347 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1348
1349 time += base::TimeDelta::FromSeconds(1);
1350 scrollbar_controller_->Animate(time);
1351 EXPECT_TRUE(did_request_animate_);
1352 did_request_animate_ = false;
1353 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
1354
1355 time += base::TimeDelta::FromSeconds(1);
1356 scrollbar_controller_->DidScrollUpdate(false);
1357 start_fade_.Run();
1358 time += base::TimeDelta::FromSeconds(1);
1359 scrollbar_controller_->Animate(time);
1360 EXPECT_TRUE(did_request_animate_);
1361 did_request_animate_ = false;
1362 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1363
1364 time += base::TimeDelta::FromSeconds(1);
1365 scrollbar_controller_->Animate(time);
1366 EXPECT_TRUE(did_request_animate_);
1367 did_request_animate_ = false;
1368 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1369
1370 time += base::TimeDelta::FromSeconds(1);
1371 scrollbar_controller_->Animate(time);
1372 EXPECT_TRUE(did_request_animate_);
1373 did_request_animate_ = false;
1374 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
1375
1376 time += base::TimeDelta::FromSeconds(1);
1377 scrollbar_controller_->Animate(time);
1378 EXPECT_FALSE(did_request_animate_);
1379 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1380 }
1381
1382 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
1383 AnimationPreservedByNonScrollingGesture) {
1384 base::TimeTicks time;
1385 time += base::TimeDelta::FromSeconds(1);
1386 scrollbar_controller_->DidScrollUpdate(false);
1387 start_fade_.Run();
1388 EXPECT_TRUE(did_request_animate_);
1389 did_request_animate_ = false;
1390 scrollbar_controller_->Animate(time);
1391 EXPECT_TRUE(did_request_animate_);
1392 did_request_animate_ = false;
1393 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1394
1395 time += base::TimeDelta::FromSeconds(1);
1396 scrollbar_controller_->Animate(time);
1397 EXPECT_TRUE(did_request_animate_);
1398 did_request_animate_ = false;
1399 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1400
1401 scrollbar_controller_->DidScrollBegin();
1402 EXPECT_FALSE(did_request_animate_);
1403 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1404
1405 time += base::TimeDelta::FromSeconds(1);
1406 scrollbar_controller_->Animate(time);
1407 EXPECT_TRUE(did_request_animate_);
1408 did_request_animate_ = false;
1409 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
1410
1411 scrollbar_controller_->DidScrollEnd();
1412 EXPECT_FALSE(did_request_animate_);
1413 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
1414
1415 time += base::TimeDelta::FromSeconds(1);
1416 scrollbar_controller_->Animate(time);
1417 EXPECT_FALSE(did_request_animate_);
1418 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity());
1419 }
1420
1421 TEST_F(ScrollbarAnimationControllerLinearFadeTest,
1422 AnimationOverriddenByScrollingGesture) {
1423 base::TimeTicks time;
1424 time += base::TimeDelta::FromSeconds(1);
1425 scrollbar_controller_->DidScrollUpdate(false);
1426 EXPECT_FALSE(did_request_animate_);
1427 start_fade_.Run();
1428 EXPECT_TRUE(did_request_animate_);
1429 did_request_animate_ = false;
1430 scrollbar_controller_->Animate(time);
1431 EXPECT_TRUE(did_request_animate_);
1432 did_request_animate_ = false;
1433 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity());
1434
1435 time += base::TimeDelta::FromSeconds(1);
1436 scrollbar_controller_->Animate(time);
1437 EXPECT_TRUE(did_request_animate_);
1438 did_request_animate_ = false;
1439 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1440
1441 scrollbar_controller_->DidScrollBegin();
1442 EXPECT_FLOAT_EQ(2.0f / 3.0f, scrollbar_layer_->Opacity());
1443
1444 time += base::TimeDelta::FromSeconds(1);
1445 scrollbar_controller_->Animate(time);
1446 EXPECT_TRUE(did_request_animate_);
1447 did_request_animate_ = false;
1448 EXPECT_FLOAT_EQ(1.0f / 3.0f, scrollbar_layer_->Opacity());
1449
1450 time += base::TimeDelta::FromSeconds(1);
1451 scrollbar_controller_->DidScrollUpdate(false);
1452 EXPECT_FALSE(did_request_animate_);
1453 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1454
1455 time += base::TimeDelta::FromSeconds(1);
1456 scrollbar_controller_->DidScrollEnd();
1457 EXPECT_FALSE(did_request_animate_);
1458 EXPECT_FLOAT_EQ(1, scrollbar_layer_->Opacity());
1459 }
1460
975 } // namespace 1461 } // namespace
976 } // namespace cc 1462 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698