| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 // Scrollbar should fade out over kFadeDuration. | 194 // Scrollbar should fade out over kFadeDuration. |
| 195 scrollbar_controller_->Animate(time); | 195 scrollbar_controller_->Animate(time); |
| 196 time += kFadeDuration; | 196 time += kFadeDuration; |
| 197 scrollbar_controller_->Animate(time); | 197 scrollbar_controller_->Animate(time); |
| 198 | 198 |
| 199 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 199 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Scroll content. Move the mouse near the scrollbar and confirm it becomes | 202 // Scroll content. Move the mouse near the scrollbar and confirm it becomes |
| 203 // thick. Ensure it fades out after that. | 203 // thick. Ensure it remains visible as long as the mouse is near the scrollbar. |
| 204 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndFadeOut) { | 204 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearAndDontFadeOut) { |
| 205 base::TimeTicks time; | 205 base::TimeTicks time; |
| 206 time += base::TimeDelta::FromSeconds(1); | 206 time += base::TimeDelta::FromSeconds(1); |
| 207 | 207 |
| 208 scrollbar_controller_->DidScrollBegin(); | 208 scrollbar_controller_->DidScrollBegin(); |
| 209 scrollbar_controller_->DidScrollUpdate(false); | 209 scrollbar_controller_->DidScrollUpdate(false); |
| 210 scrollbar_controller_->DidScrollEnd(); | 210 scrollbar_controller_->DidScrollEnd(); |
| 211 | 211 |
| 212 // An animation should have been enqueued. | 212 // An animation should have been enqueued. |
| 213 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 213 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 214 EXPECT_FALSE(client_.start_fade().is_null()); | 214 EXPECT_FALSE(client_.start_fade().is_null()); |
| 215 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 215 | 216 |
| 216 // Now move the mouse near the scrollbar. This should cancel the currently | 217 // Now move the mouse near the scrollbar. This should cancel the currently |
| 217 // queued fading animation and start animating thickness. | 218 // queued fading animation and start animating thickness. |
| 218 scrollbar_controller_->DidMouseMoveNear(1); | 219 scrollbar_controller_->DidMouseMoveNear(1); |
| 219 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 220 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 220 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 221 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 221 scrollbar_layer_->thumb_thickness_scale_factor()); | 222 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 222 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 223 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 223 | 224 |
| 224 // Scrollbar should become thick. | 225 // Scrollbar should become thick. |
| 225 scrollbar_controller_->Animate(time); | 226 scrollbar_controller_->Animate(time); |
| 226 time += kThinningDuration; | 227 time += kThinningDuration; |
| 227 scrollbar_controller_->Animate(time); | 228 scrollbar_controller_->Animate(time); |
| 228 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 229 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 230 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 230 | 231 |
| 231 // Once the thickening animation is complete, it should enqueue the delayed | 232 // Mouse is still near the Scrollbar. Once the thickness animation is |
| 232 // fade animation. | 233 // complete, the queued delayed fade animation should be either cancelled or |
| 233 EXPECT_FALSE(client_.start_fade().is_null()); | 234 // null. |
| 234 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 235 EXPECT_TRUE(client_.start_fade().is_null() || |
| 236 client_.start_fade().IsCancelled()); |
| 235 } | 237 } |
| 236 | 238 |
| 237 // Scroll content. Move the mouse over the scrollbar and confirm it becomes | 239 // Scroll content. Move the mouse over the scrollbar and confirm it becomes |
| 238 // thick. Ensure it fades out after that. | 240 // thick. Ensure it remains visible as long as the mouse is over the scrollbar. |
| 239 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndFadeOut) { | 241 TEST_F(ScrollbarAnimationControllerThinningTest, MoveOverAndDontFadeOut) { |
| 240 base::TimeTicks time; | 242 base::TimeTicks time; |
| 241 time += base::TimeDelta::FromSeconds(1); | 243 time += base::TimeDelta::FromSeconds(1); |
| 242 | 244 |
| 243 scrollbar_controller_->DidScrollBegin(); | 245 scrollbar_controller_->DidScrollBegin(); |
| 244 scrollbar_controller_->DidScrollUpdate(false); | 246 scrollbar_controller_->DidScrollUpdate(false); |
| 245 scrollbar_controller_->DidScrollEnd(); | 247 scrollbar_controller_->DidScrollEnd(); |
| 246 | 248 |
| 247 // An animation should have been enqueued. | 249 // An animation should have been enqueued. |
| 248 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 250 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 249 EXPECT_FALSE(client_.start_fade().is_null()); | 251 EXPECT_FALSE(client_.start_fade().is_null()); |
| 252 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 250 | 253 |
| 251 // Now move the mouse over the scrollbar. This should cancel the currently | 254 // Now move the mouse over the scrollbar. This should cancel the currently |
| 252 // queued fading animation and start animating thickness. | 255 // queued fading animation and start animating thickness. |
| 253 scrollbar_controller_->DidMouseMoveNear(0); | 256 scrollbar_controller_->DidMouseMoveNear(0); |
| 254 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 257 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 255 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 258 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 256 scrollbar_layer_->thumb_thickness_scale_factor()); | 259 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 257 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 260 EXPECT_TRUE(client_.start_fade().IsCancelled()); |
| 258 | 261 |
| 259 // Scrollbar should become thick. | 262 // Scrollbar should become thick. |
| 260 scrollbar_controller_->Animate(time); | 263 scrollbar_controller_->Animate(time); |
| 261 time += kThinningDuration; | 264 time += kThinningDuration; |
| 262 scrollbar_controller_->Animate(time); | 265 scrollbar_controller_->Animate(time); |
| 263 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 266 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 264 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 267 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 265 | 268 |
| 266 // Once the thickening animation is complete, it should enqueue the delayed | 269 // Mouse is still over the Scrollbar. Once the thickness animation is |
| 267 // fade animation. | 270 // complete, the queued delayed fade animation should be either null or |
| 268 EXPECT_FALSE(client_.start_fade().is_null()); | 271 // cancelled. |
| 269 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 272 EXPECT_TRUE(client_.start_fade().is_null() || |
| 273 client_.start_fade().IsCancelled()); |
| 270 } | 274 } |
| 271 | 275 |
| 272 // Make sure a scrollbar captured before the thickening animation doesn't try | 276 // Make sure a scrollbar captured before the thickening animation doesn't try |
| 273 // to fade out. | 277 // to fade out. |
| 274 TEST_F(ScrollbarAnimationControllerThinningTest, | 278 TEST_F(ScrollbarAnimationControllerThinningTest, |
| 275 DontFadeWhileCapturedBeforeThick) { | 279 DontFadeWhileCapturedBeforeThick) { |
| 276 base::TimeTicks time; | 280 base::TimeTicks time; |
| 277 time += base::TimeDelta::FromSeconds(1); | 281 time += base::TimeDelta::FromSeconds(1); |
| 278 | 282 |
| 279 scrollbar_controller_->DidScrollBegin(); | 283 scrollbar_controller_->DidScrollBegin(); |
| 280 scrollbar_controller_->DidScrollUpdate(false); | 284 scrollbar_controller_->DidScrollUpdate(false); |
| 281 scrollbar_controller_->DidScrollEnd(); | 285 scrollbar_controller_->DidScrollEnd(); |
| 282 | 286 |
| 283 // An animation should have been enqueued. | 287 // An animation should have been enqueued. |
| 284 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 288 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 285 EXPECT_FALSE(client_.start_fade().is_null()); | 289 EXPECT_FALSE(client_.start_fade().is_null()); |
| 286 | 290 |
| 287 // Now move the mouse over the scrollbar and capture it. It should become | 291 // Now move the mouse over the scrollbar and capture it. It should become |
| 288 // thick without need for an animation. | 292 // thick without need for an animation. |
| 289 scrollbar_controller_->DidMouseMoveNear(0); | 293 scrollbar_controller_->DidMouseMoveNear(0); |
| 290 scrollbar_controller_->DidMouseDown(); | 294 scrollbar_controller_->DidMouseDown(); |
| 291 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 295 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 292 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 296 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 293 | 297 |
| 294 // The fade animation should have been cancelled. | 298 // The fade animation should have been cleared or cancelled. |
| 295 EXPECT_FALSE(client_.start_fade().is_null()); | 299 EXPECT_TRUE(client_.start_fade().is_null() || |
| 296 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 300 client_.start_fade().IsCancelled()); |
| 297 } | 301 } |
| 298 | 302 |
| 299 // Make sure a scrollbar captured after a thickening animation doesn't try to | 303 // Make sure a scrollbar captured after a thickening animation doesn't try to |
| 300 // fade out. | 304 // fade out. |
| 301 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { | 305 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeWhileCaptured) { |
| 302 base::TimeTicks time; | 306 base::TimeTicks time; |
| 303 time += base::TimeDelta::FromSeconds(1); | 307 time += base::TimeDelta::FromSeconds(1); |
| 304 | 308 |
| 305 scrollbar_controller_->DidScrollBegin(); | 309 scrollbar_controller_->DidScrollBegin(); |
| 306 scrollbar_controller_->DidScrollUpdate(false); | 310 scrollbar_controller_->DidScrollUpdate(false); |
| 307 scrollbar_controller_->DidScrollEnd(); | 311 scrollbar_controller_->DidScrollEnd(); |
| 308 | 312 |
| 309 // An animation should have been enqueued. | 313 // An animation should have been enqueued. |
| 310 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 314 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 311 EXPECT_FALSE(client_.start_fade().is_null()); | 315 EXPECT_FALSE(client_.start_fade().is_null()); |
| 316 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 312 | 317 |
| 313 // Now move the mouse over the scrollbar and animate it until it's thick. | 318 // Now move the mouse over the scrollbar and animate it until it's thick. |
| 314 scrollbar_controller_->DidMouseMoveNear(0); | 319 scrollbar_controller_->DidMouseMoveNear(0); |
| 315 scrollbar_controller_->Animate(time); | 320 scrollbar_controller_->Animate(time); |
| 316 time += kThinningDuration; | 321 time += kThinningDuration; |
| 317 scrollbar_controller_->Animate(time); | 322 scrollbar_controller_->Animate(time); |
| 318 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 323 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 319 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 324 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 320 | 325 |
| 321 // Since the scrollbar became thick, it should have queued up a fade. | 326 // Since the mouse is over the scrollbar, it should either clear or cancel the |
| 322 EXPECT_FALSE(client_.start_fade().is_null()); | 327 // queued fade. |
| 323 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 328 EXPECT_TRUE(client_.start_fade().is_null() || |
| 329 client_.start_fade().IsCancelled()); |
| 324 | 330 |
| 325 // Make sure capturing the scrollbar stops the fade. | 331 // Make sure the queued fade animation is still null or cancelled after |
| 332 // capturing the scrollbar. |
| 326 scrollbar_controller_->DidMouseDown(); | 333 scrollbar_controller_->DidMouseDown(); |
| 327 EXPECT_FALSE(client_.start_fade().is_null()); | 334 EXPECT_TRUE(client_.start_fade().is_null() || |
| 328 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 335 client_.start_fade().IsCancelled()); |
| 329 } | 336 } |
| 330 | 337 |
| 331 // Make sure releasing a captured scrollbar causes it to fade out. | 338 // Make sure releasing a captured scrollbar when the mouse isn't near it, causes |
| 332 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleased) { | 339 // the scrollbar to fade out. |
| 340 TEST_F(ScrollbarAnimationControllerThinningTest, FadeAfterReleasedFar) { |
| 333 base::TimeTicks time; | 341 base::TimeTicks time; |
| 334 time += base::TimeDelta::FromSeconds(1); | 342 time += base::TimeDelta::FromSeconds(1); |
| 335 | 343 |
| 336 scrollbar_controller_->DidScrollBegin(); | 344 scrollbar_controller_->DidScrollBegin(); |
| 337 scrollbar_controller_->DidScrollUpdate(false); | 345 scrollbar_controller_->DidScrollUpdate(false); |
| 338 scrollbar_controller_->DidScrollEnd(); | 346 scrollbar_controller_->DidScrollEnd(); |
| 339 | 347 |
| 340 // An animation should have been enqueued. | 348 // An animation should have been enqueued. |
| 341 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 349 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 342 EXPECT_FALSE(client_.start_fade().is_null()); | 350 EXPECT_FALSE(client_.start_fade().is_null()); |
| 351 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 343 | 352 |
| 344 // Now move the mouse over the scrollbar and capture it. | 353 // Now move the mouse over the scrollbar and capture it. |
| 345 scrollbar_controller_->DidMouseMoveNear(0); | 354 scrollbar_controller_->DidMouseMoveNear(0); |
| 346 scrollbar_controller_->DidMouseDown(); | 355 scrollbar_controller_->DidMouseDown(); |
| 347 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 356 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 348 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 357 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 349 | 358 |
| 350 // Since the scrollbar became thick, it should have queued up a fade. | 359 // Since the mouse is still near the scrollbar, the queued fade should be |
| 351 EXPECT_FALSE(client_.start_fade().is_null()); | 360 // either null or cancelled. |
| 352 EXPECT_TRUE(client_.start_fade().IsCancelled()); | 361 EXPECT_TRUE(client_.start_fade().is_null() || |
| 362 client_.start_fade().IsCancelled()); |
| 353 | 363 |
| 364 // Now move the mouse away from the scrollbar and release it. |
| 365 scrollbar_controller_->DidMouseMoveNear( |
| 366 kDefaultMouseMoveDistanceToTriggerAnimation + 1); |
| 354 scrollbar_controller_->DidMouseUp(); | 367 scrollbar_controller_->DidMouseUp(); |
| 368 |
| 369 scrollbar_controller_->Animate(time); |
| 370 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 371 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 372 time += kThinningDuration; |
| 373 scrollbar_controller_->Animate(time); |
| 374 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 375 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 376 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 377 |
| 378 // The thickness animation is complete, a fade out must be queued. |
| 355 EXPECT_FALSE(client_.start_fade().is_null()); | 379 EXPECT_FALSE(client_.start_fade().is_null()); |
| 356 EXPECT_FALSE(client_.start_fade().IsCancelled()); | 380 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 357 } | 381 } |
| 358 | 382 |
| 359 // Make sure moving near a scrollbar while it's fading out causes it to reset | 383 // Make sure releasing a captured scrollbar when the mouse is near/over it, |
| 360 // the opacity and thicken. | 384 // doesn't cause the scrollbar to fade out. |
| 361 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { | 385 TEST_F(ScrollbarAnimationControllerThinningTest, DontFadeAfterReleasedNear) { |
| 362 base::TimeTicks time; | 386 base::TimeTicks time; |
| 363 time += base::TimeDelta::FromSeconds(1); | 387 time += base::TimeDelta::FromSeconds(1); |
| 364 | 388 |
| 365 scrollbar_controller_->DidScrollBegin(); | 389 scrollbar_controller_->DidScrollBegin(); |
| 366 scrollbar_controller_->DidScrollUpdate(false); | 390 scrollbar_controller_->DidScrollUpdate(false); |
| 367 scrollbar_controller_->DidScrollEnd(); | 391 scrollbar_controller_->DidScrollEnd(); |
| 368 | 392 |
| 369 // An animation should have been enqueued. Start it. | 393 // An animation should have been enqueued. |
| 370 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 394 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 371 EXPECT_FALSE(client_.start_fade().is_null()); | 395 EXPECT_FALSE(client_.start_fade().is_null()); |
| 372 client_.start_fade().Run(); | 396 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 373 | 397 |
| 374 scrollbar_controller_->Animate(time); | 398 // Now move the mouse over the scrollbar and capture it. |
| 399 scrollbar_controller_->DidMouseMoveNear(0); |
| 400 scrollbar_controller_->DidMouseDown(); |
| 375 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 401 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 402 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 376 | 403 |
| 377 // Proceed half way through the fade out animation. | 404 // Since the mouse is over the scrollbar, the queued fade must be either |
| 378 time += kFadeDuration / 2; | 405 // null or cancelled. |
| 379 scrollbar_controller_->Animate(time); | 406 EXPECT_TRUE(client_.start_fade().is_null() || |
| 380 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | 407 client_.start_fade().IsCancelled()); |
| 381 | 408 |
| 382 // Now move the mouse near the scrollbar. It should reset opacity to 1 | 409 // Mouse is still near the scrollbar, releasing it shouldn't do anything. |
| 383 // instantly and start animating to thick. | 410 scrollbar_controller_->DidMouseUp(); |
| 384 scrollbar_controller_->DidMouseMoveNear(1); | 411 EXPECT_TRUE(client_.start_fade().is_null() || |
| 385 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 412 client_.start_fade().IsCancelled()); |
| 386 EXPECT_FLOAT_EQ(kIdleThicknessScale, | |
| 387 scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 388 | |
| 389 scrollbar_controller_->Animate(time); | |
| 390 time += kThinningDuration; | |
| 391 scrollbar_controller_->Animate(time); | |
| 392 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 413 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 393 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 414 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 394 } | 415 } |
| 395 | 416 |
| 396 // Make sure capturing a scrollbar while it's fading out causes it to reset the | 417 // Make sure moving near a scrollbar while it's fading out causes it to reset |
| 397 // opacity and thicken instantly. | 418 // the opacity and thicken. |
| 398 TEST_F(ScrollbarAnimationControllerThinningTest, CaptureScrollbarWhileFading) { | 419 TEST_F(ScrollbarAnimationControllerThinningTest, MoveNearScrollbarWhileFading) { |
| 399 base::TimeTicks time; | 420 base::TimeTicks time; |
| 400 time += base::TimeDelta::FromSeconds(1); | 421 time += base::TimeDelta::FromSeconds(1); |
| 401 | 422 |
| 402 scrollbar_controller_->DidScrollBegin(); | 423 scrollbar_controller_->DidScrollBegin(); |
| 403 scrollbar_controller_->DidScrollUpdate(false); | 424 scrollbar_controller_->DidScrollUpdate(false); |
| 404 scrollbar_controller_->DidScrollEnd(); | 425 scrollbar_controller_->DidScrollEnd(); |
| 405 | 426 |
| 406 // Move mouse over the scrollbar. | |
| 407 scrollbar_controller_->DidMouseMoveNear(0); | |
| 408 scrollbar_controller_->Animate(time); | |
| 409 time += kThinningDuration; | |
| 410 scrollbar_controller_->Animate(time); | |
| 411 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 412 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 413 | |
| 414 // A fade animation should have been enqueued. Start it. | 427 // A fade animation should have been enqueued. Start it. |
| 415 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 428 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 416 EXPECT_FALSE(client_.start_fade().is_null()); | 429 EXPECT_FALSE(client_.start_fade().is_null()); |
| 417 client_.start_fade().Run(); | 430 client_.start_fade().Run(); |
| 418 | 431 |
| 419 scrollbar_controller_->Animate(time); | 432 scrollbar_controller_->Animate(time); |
| 420 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 433 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 421 | 434 |
| 422 // Proceed half way through the fade out animation. | 435 // Proceed half way through the fade out animation. |
| 423 time += kFadeDuration / 2; | 436 time += kFadeDuration / 2; |
| 424 scrollbar_controller_->Animate(time); | 437 scrollbar_controller_->Animate(time); |
| 425 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); | 438 EXPECT_FLOAT_EQ(0.5f, scrollbar_layer_->Opacity()); |
| 426 | 439 |
| 427 // Now capture the scrollbar. It should reset opacity to 1 instantly. | 440 // Now move the mouse near the scrollbar. It should reset opacity to 1 |
| 428 scrollbar_controller_->DidMouseDown(); | 441 // instantly and start animating to thick. |
| 442 scrollbar_controller_->DidMouseMoveNear(1); |
| 443 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 444 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 445 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 446 |
| 447 scrollbar_controller_->Animate(time); |
| 448 time += kThinningDuration; |
| 449 scrollbar_controller_->Animate(time); |
| 429 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 450 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 430 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 451 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 431 } | 452 } |
| 432 | 453 |
| 433 // Make sure we can't capture scrollbar that's completely faded out | 454 // Make sure we can't capture scrollbar that's completely faded out. |
| 434 TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { | 455 TEST_F(ScrollbarAnimationControllerThinningTest, TestCantCaptureWhenFaded) { |
| 435 base::TimeTicks time; | 456 base::TimeTicks time; |
| 436 time += base::TimeDelta::FromSeconds(1); | 457 time += base::TimeDelta::FromSeconds(1); |
| 437 | 458 |
| 438 scrollbar_controller_->DidScrollBegin(); | 459 scrollbar_controller_->DidScrollBegin(); |
| 439 scrollbar_controller_->DidScrollUpdate(false); | 460 scrollbar_controller_->DidScrollUpdate(false); |
| 440 scrollbar_controller_->DidScrollEnd(); | 461 scrollbar_controller_->DidScrollEnd(); |
| 441 | 462 |
| 442 // Move mouse over the scrollbar. | |
| 443 scrollbar_controller_->DidMouseMoveNear(0); | |
| 444 scrollbar_controller_->Animate(time); | |
| 445 time += kThinningDuration; | |
| 446 scrollbar_controller_->Animate(time); | |
| 447 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | |
| 448 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | |
| 449 | |
| 450 // A fade animation should have been enqueued. Start it. | |
| 451 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 463 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 452 EXPECT_FALSE(client_.start_fade().is_null()); | 464 EXPECT_FALSE(client_.start_fade().is_null()); |
| 465 EXPECT_FALSE(client_.start_fade().IsCancelled()); |
| 453 client_.start_fade().Run(); | 466 client_.start_fade().Run(); |
| 454 scrollbar_controller_->Animate(time); | 467 scrollbar_controller_->Animate(time); |
| 455 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 468 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 456 | 469 |
| 457 // Fade the scrollbar out completely. | 470 // Fade the scrollbar out completely. |
| 458 time += kFadeDuration; | 471 time += kFadeDuration; |
| 459 scrollbar_controller_->Animate(time); | 472 scrollbar_controller_->Animate(time); |
| 460 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 473 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 461 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 474 |
| 475 // Move mouse over the scrollbar. It shouldn't thicken the scrollbar since |
| 476 // it's completely faded out. |
| 477 scrollbar_controller_->DidMouseMoveNear(0); |
| 478 scrollbar_controller_->Animate(time); |
| 479 time += kThinningDuration; |
| 480 scrollbar_controller_->Animate(time); |
| 481 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 482 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 483 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 462 | 484 |
| 463 client_.start_fade().Reset(); | 485 client_.start_fade().Reset(); |
| 464 | 486 |
| 465 // Now try to capture the scrollbar. It shouldn't do anything since it's | 487 // Now try to capture the scrollbar. It shouldn't do anything since it's |
| 466 // completely faded out. | 488 // completely faded out. |
| 467 scrollbar_controller_->DidMouseDown(); | 489 scrollbar_controller_->DidMouseDown(); |
| 468 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 490 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 469 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 491 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 492 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 470 EXPECT_TRUE(client_.start_fade().is_null()); | 493 EXPECT_TRUE(client_.start_fade().is_null()); |
| 471 | 494 |
| 472 // Similarly, releasing the scrollbar should have no effect. | 495 // Similarly, releasing the scrollbar should have no effect. |
| 473 scrollbar_controller_->DidMouseUp(); | 496 scrollbar_controller_->DidMouseUp(); |
| 474 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 497 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); |
| 475 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 498 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 499 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 476 EXPECT_TRUE(client_.start_fade().is_null()); | 500 EXPECT_TRUE(client_.start_fade().is_null()); |
| 477 } | 501 } |
| 478 | 502 |
| 479 // Initiate a scroll when the pointer is already near the scrollbar. It should | 503 // Initiate a scroll when the pointer is already near the scrollbar. It should |
| 480 // appear thick and remain thick. | 504 // appear thick and remain thick. |
| 481 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { | 505 TEST_F(ScrollbarAnimationControllerThinningTest, ScrollWithMouseNear) { |
| 482 base::TimeTicks time; | 506 base::TimeTicks time; |
| 483 time += base::TimeDelta::FromSeconds(1); | 507 time += base::TimeDelta::FromSeconds(1); |
| 484 | 508 |
| 485 scrollbar_controller_->DidMouseMoveNear(1); | 509 scrollbar_controller_->DidMouseMoveNear(1); |
| 486 scrollbar_controller_->Animate(time); | 510 scrollbar_controller_->Animate(time); |
| 487 time += kThinningDuration; | 511 time += kThinningDuration; |
| 488 | 512 |
| 489 // Since the scrollbar isn't visible yet (because we haven't scrolled), we | 513 // Since the scrollbar isn't visible yet (because we haven't scrolled), we |
| 490 // shouldn't have applied the thickening. | 514 // shouldn't have applied the thickening. |
| 491 scrollbar_controller_->Animate(time); | 515 scrollbar_controller_->Animate(time); |
| 492 EXPECT_FLOAT_EQ(kIdleThicknessScale, | 516 EXPECT_FLOAT_EQ(kIdleThicknessScale, |
| 493 scrollbar_layer_->thumb_thickness_scale_factor()); | 517 scrollbar_layer_->thumb_thickness_scale_factor()); |
| 494 | 518 |
| 495 scrollbar_controller_->DidScrollBegin(); | 519 scrollbar_controller_->DidScrollBegin(); |
| 496 scrollbar_controller_->DidScrollUpdate(false); | 520 scrollbar_controller_->DidScrollUpdate(false); |
| 497 | 521 |
| 498 // Now that we've received a scroll, we should be thick without an animation. | 522 // Now that we've received a scroll, we should be thick without an animation. |
| 499 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 523 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 500 | 524 |
| 501 // An animation for the fade should have been enqueued. | 525 // An animation for the fade should be either null or cancelled, since |
| 526 // mouse is still near the scrollbar. |
| 502 scrollbar_controller_->DidScrollEnd(); | 527 scrollbar_controller_->DidScrollEnd(); |
| 503 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); | 528 EXPECT_EQ(kDelayBeforeStarting, client_.delay()); |
| 504 EXPECT_FALSE(client_.start_fade().is_null()); | 529 EXPECT_TRUE(client_.start_fade().is_null() || |
| 530 client_.start_fade().IsCancelled()); |
| 505 | 531 |
| 506 client_.start_fade().Run(); | |
| 507 scrollbar_controller_->Animate(time); | 532 scrollbar_controller_->Animate(time); |
| 508 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); | 533 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 509 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 534 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 510 | 535 |
| 511 // Scrollbar should still be thick, even though the scrollbar fades out. | 536 // Scrollbar should still be thick and visible. |
| 512 time += kFadeDuration; | 537 time += kFadeDuration; |
| 513 scrollbar_controller_->Animate(time); | 538 scrollbar_controller_->Animate(time); |
| 514 EXPECT_FLOAT_EQ(0.0f, scrollbar_layer_->Opacity()); | 539 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->Opacity()); |
| 515 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); | 540 EXPECT_FLOAT_EQ(1.0f, scrollbar_layer_->thumb_thickness_scale_factor()); |
| 516 } | 541 } |
| 517 | 542 |
| 518 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when | 543 // Move the pointer near the scrollbar. Confirm it gets thick and narrow when |
| 519 // moved away. | 544 // moved away. |
| 520 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) { | 545 TEST_F(ScrollbarAnimationControllerThinningTest, MouseNear) { |
| 521 base::TimeTicks time; | 546 base::TimeTicks time; |
| 522 time += base::TimeDelta::FromSeconds(1); | 547 time += base::TimeDelta::FromSeconds(1); |
| 523 | 548 |
| 524 // Scroll to make the scrollbars visible. | 549 // Scroll to make the scrollbars visible. |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 // Calling DidScrollUpdate without a begin (i.e. update from commit) should | 1009 // Calling DidScrollUpdate without a begin (i.e. update from commit) should |
| 985 // also notify. | 1010 // also notify. |
| 986 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); | 1011 EXPECT_CALL(client_, DidChangeScrollbarVisibility()).Times(1); |
| 987 scrollbar_controller_->DidScrollUpdate(false); | 1012 scrollbar_controller_->DidScrollUpdate(false); |
| 988 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); | 1013 EXPECT_FALSE(scrollbar_controller_->ScrollbarsHidden()); |
| 989 Mock::VerifyAndClearExpectations(&client_); | 1014 Mock::VerifyAndClearExpectations(&client_); |
| 990 } | 1015 } |
| 991 | 1016 |
| 992 } // namespace | 1017 } // namespace |
| 993 } // namespace cc | 1018 } // namespace cc |
| OLD | NEW |