OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 382 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); |
383 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 383 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); |
384 reset(*scrollAnimator); | 384 reset(*scrollAnimator); |
385 | 385 |
386 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); | 386 scrollAnimator->userScroll(ScrollByPixel, FloatSize(100, 0)); |
387 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); | 387 EXPECT_EQ(100, scrollAnimator->currentPosition().x()); |
388 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); | 388 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); |
389 reset(*scrollAnimator); | 389 reset(*scrollAnimator); |
390 } | 390 } |
391 | 391 |
| 392 // Test that cancelling an animation resets the animation state. |
| 393 // See crbug.com/598548. |
| 394 TEST(ScrollAnimatorTest, CancellingAnimationResetsState) |
| 395 { |
| 396 OwnPtrWillBeRawPtr<MockScrollableArea> scrollableArea = |
| 397 MockScrollableArea::create(true); |
| 398 OwnPtrWillBeRawPtr<ScrollAnimator> scrollAnimator = adoptPtrWillBeNoop( |
| 399 new ScrollAnimator(scrollableArea.get(), getMockedTime)); |
| 400 |
| 401 EXPECT_CALL(*scrollableArea, minimumScrollPosition()).Times(AtLeast(1)) |
| 402 .WillRepeatedly(Return(IntPoint())); |
| 403 EXPECT_CALL(*scrollableArea, maximumScrollPosition()).Times(AtLeast(1)) |
| 404 .WillRepeatedly(Return(IntPoint(1000, 1000))); |
| 405 // Called from first userScroll, setCurrentPosition, and second userScroll. |
| 406 EXPECT_CALL(*scrollableArea, setScrollOffset(_, _)).Times(3); |
| 407 // Called from userScroll, updateCompositorAnimations. |
| 408 EXPECT_CALL(*scrollableArea, registerForAnimation()).Times(4); |
| 409 EXPECT_CALL(*scrollableArea, scheduleAnimation()).Times(AtLeast(1)) |
| 410 .WillRepeatedly(Return(true)); |
| 411 |
| 412 EXPECT_EQ(0, scrollAnimator->currentPosition().x()); |
| 413 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); |
| 414 |
| 415 // WaitingToSendToCompositor |
| 416 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); |
| 417 EXPECT_EQ(scrollAnimator->m_runState, |
| 418 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor
); |
| 419 |
| 420 // RunningOnMainThread |
| 421 gMockedTime += 0.05; |
| 422 scrollAnimator->updateCompositorAnimations(); |
| 423 EXPECT_EQ(scrollAnimator->m_runState, |
| 424 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
| 425 scrollAnimator->tickAnimation(getMockedTime()); |
| 426 EXPECT_EQ(scrollAnimator->m_runState, |
| 427 ScrollAnimatorCompositorCoordinator::RunState::RunningOnMainThread); |
| 428 |
| 429 // Amount scrolled so far. |
| 430 float offsetX = scrollAnimator->currentPosition().x(); |
| 431 |
| 432 // Interrupt user scroll. |
| 433 scrollAnimator->cancelAnimation(); |
| 434 EXPECT_EQ(scrollAnimator->m_runState, |
| 435 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 436 |
| 437 // Another userScroll after modified scroll offset. |
| 438 scrollAnimator->setCurrentPosition(FloatPoint(offsetX + 15, 0)); |
| 439 scrollAnimator->userScroll(ScrollByLine, FloatSize(10, 0)); |
| 440 EXPECT_EQ(scrollAnimator->m_runState, |
| 441 ScrollAnimatorCompositorCoordinator::RunState::WaitingToSendToCompositor
); |
| 442 |
| 443 // Finish scroll animation. |
| 444 gMockedTime += 1.0; |
| 445 scrollAnimator->updateCompositorAnimations(); |
| 446 scrollAnimator->tickAnimation(getMockedTime()); |
| 447 EXPECT_EQ(scrollAnimator->m_runState, |
| 448 ScrollAnimatorCompositorCoordinator::RunState::PostAnimationCleanup); |
| 449 |
| 450 EXPECT_EQ(offsetX + 15 + 10, scrollAnimator->currentPosition().x()); |
| 451 EXPECT_EQ(0, scrollAnimator->currentPosition().y()); |
| 452 reset(*scrollAnimator); |
| 453 } |
| 454 |
392 } // namespace blink | 455 } // namespace blink |
OLD | NEW |