OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "content/browser/web_contents/aura/window_slider.h" | 5 #include "content/browser/web_contents/aura/window_slider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // Tests that the window slide can continue after it is interrupted by another | 334 // Tests that the window slide can continue after it is interrupted by another |
335 // event if the user continues scrolling. | 335 // event if the user continues scrolling. |
336 TEST_F(WindowSliderTest, WindowSlideInterruptedThenContinues) { | 336 TEST_F(WindowSliderTest, WindowSlideInterruptedThenContinues) { |
337 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); | 337 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); |
338 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 338 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
339 WindowSliderDelegateTest slider_delegate; | 339 WindowSliderDelegateTest slider_delegate; |
340 | 340 |
341 ui::ScopedAnimationDurationScaleMode normal_duration_( | 341 ui::ScopedAnimationDurationScaleMode normal_duration_( |
342 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 342 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
343 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 343 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| 344 gfx::AnimationContainerElement* element = animator; |
344 animator->set_disable_timer_for_test(true); | 345 animator->set_disable_timer_for_test(true); |
345 ui::LayerAnimatorTestController test_controller(animator); | 346 ui::LayerAnimatorTestController test_controller(animator); |
346 | 347 |
347 WindowSlider* slider = | 348 WindowSlider* slider = |
348 new WindowSlider(&slider_delegate, root_window(), window.get()); | 349 new WindowSlider(&slider_delegate, root_window(), window.get()); |
349 | 350 |
350 ui::MouseEvent interrupt_event(ui::ET_MOUSE_MOVED, | 351 ui::MouseEvent interrupt_event(ui::ET_MOUSE_MOVED, |
351 gfx::Point(55, 10), | 352 gfx::Point(55, 10), |
352 gfx::Point(55, 10), | 353 gfx::Point(55, 10), |
353 0, 0); | 354 0, 0); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 EXPECT_TRUE(animator->is_animating()); | 421 EXPECT_TRUE(animator->is_animating()); |
421 EXPECT_TRUE(slider_delegate.slide_completing()); | 422 EXPECT_TRUE(slider_delegate.slide_completing()); |
422 EXPECT_FALSE(slider_delegate.created_front_layer()); | 423 EXPECT_FALSE(slider_delegate.created_front_layer()); |
423 EXPECT_FALSE(slider_delegate.slide_completed()); | 424 EXPECT_FALSE(slider_delegate.slide_completed()); |
424 EXPECT_FALSE(slider_delegate.slider_destroyed()); | 425 EXPECT_FALSE(slider_delegate.slider_destroyed()); |
425 | 426 |
426 // Progress the animator to complete the slide animation. | 427 // Progress the animator to complete the slide animation. |
427 ui::ScopedLayerAnimationSettings settings(animator); | 428 ui::ScopedLayerAnimationSettings settings(animator); |
428 base::TimeDelta duration = settings.GetTransitionDuration(); | 429 base::TimeDelta duration = settings.GetTransitionDuration(); |
429 test_controller.StartThreadedAnimationsIfNeeded(); | 430 test_controller.StartThreadedAnimationsIfNeeded(); |
430 animator->Step(gfx::FrameTime::Now() + duration); | 431 element->Step(gfx::FrameTime::Now() + duration); |
431 | 432 |
432 EXPECT_TRUE(slider_delegate.slide_completed()); | 433 EXPECT_TRUE(slider_delegate.slide_completed()); |
433 EXPECT_FALSE(slider_delegate.slider_destroyed()); | 434 EXPECT_FALSE(slider_delegate.slider_destroyed()); |
434 | 435 |
435 window.reset(); | 436 window.reset(); |
436 EXPECT_TRUE(slider_delegate.slider_destroyed()); | 437 EXPECT_TRUE(slider_delegate.slider_destroyed()); |
437 } | 438 } |
438 | 439 |
439 // Tests that the slide works correctly when the owner of the window changes | 440 // Tests that the slide works correctly when the owner of the window changes |
440 // during the duration of the slide. | 441 // during the duration of the slide. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 // the first swipe, ask the delegate to create a new layer, and animate it. | 589 // the first swipe, ask the delegate to create a new layer, and animate it. |
589 TEST_F(WindowSliderTest, SwipeDuringSwipeAnimation) { | 590 TEST_F(WindowSliderTest, SwipeDuringSwipeAnimation) { |
590 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); | 591 scoped_ptr<aura::Window> window(CreateNormalWindow(0, root_window(), NULL)); |
591 window->SetBounds(gfx::Rect(0, 0, 400, 400)); | 592 window->SetBounds(gfx::Rect(0, 0, 400, 400)); |
592 WindowSliderDelegateTest slider_delegate; | 593 WindowSliderDelegateTest slider_delegate; |
593 new WindowSlider(&slider_delegate, root_window(), window.get()); | 594 new WindowSlider(&slider_delegate, root_window(), window.get()); |
594 | 595 |
595 ui::ScopedAnimationDurationScaleMode normal_duration_( | 596 ui::ScopedAnimationDurationScaleMode normal_duration_( |
596 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 597 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
597 ui::LayerAnimator* animator = window->layer()->GetAnimator(); | 598 ui::LayerAnimator* animator = window->layer()->GetAnimator(); |
| 599 gfx::AnimationContainerElement* element = animator; |
598 animator->set_disable_timer_for_test(true); | 600 animator->set_disable_timer_for_test(true); |
599 ui::LayerAnimatorTestController test_controller(animator); | 601 ui::LayerAnimatorTestController test_controller(animator); |
600 | 602 |
601 aura::test::EventGenerator generator(root_window()); | 603 aura::test::EventGenerator generator(root_window()); |
602 | 604 |
603 // Swipe forward so that |window|'s layer is the one animating. | 605 // Swipe forward so that |window|'s layer is the one animating. |
604 generator.GestureScrollSequence( | 606 generator.GestureScrollSequence( |
605 gfx::Point(10, 10), | 607 gfx::Point(10, 10), |
606 gfx::Point(180, 10), | 608 gfx::Point(180, 10), |
607 base::TimeDelta::FromMilliseconds(10), | 609 base::TimeDelta::FromMilliseconds(10), |
608 2); | 610 2); |
609 EXPECT_TRUE(slider_delegate.created_back_layer()); | 611 EXPECT_TRUE(slider_delegate.created_back_layer()); |
610 EXPECT_FALSE(slider_delegate.slide_aborted()); | 612 EXPECT_FALSE(slider_delegate.slide_aborted()); |
611 EXPECT_FALSE(slider_delegate.created_front_layer()); | 613 EXPECT_FALSE(slider_delegate.created_front_layer()); |
612 EXPECT_TRUE(slider_delegate.slide_completing()); | 614 EXPECT_TRUE(slider_delegate.slide_completing()); |
613 EXPECT_FALSE(slider_delegate.slide_completed()); | 615 EXPECT_FALSE(slider_delegate.slide_completed()); |
614 EXPECT_FALSE(slider_delegate.slider_destroyed()); | 616 EXPECT_FALSE(slider_delegate.slider_destroyed()); |
615 ui::ScopedLayerAnimationSettings settings(animator); | 617 ui::ScopedLayerAnimationSettings settings(animator); |
616 base::TimeDelta duration = settings.GetTransitionDuration(); | 618 base::TimeDelta duration = settings.GetTransitionDuration(); |
617 test_controller.StartThreadedAnimationsIfNeeded(); | 619 test_controller.StartThreadedAnimationsIfNeeded(); |
618 base::TimeTicks start_time1 = gfx::FrameTime::Now(); | 620 base::TimeTicks start_time1 = gfx::FrameTime::Now(); |
619 | 621 |
620 animator->Step(start_time1 + duration / 2); | 622 element->Step(start_time1 + duration/2); |
621 EXPECT_FALSE(slider_delegate.slide_completed()); | 623 EXPECT_FALSE(slider_delegate.slide_completed()); |
622 slider_delegate.Reset(); | 624 slider_delegate.Reset(); |
623 // Generate another horizontal swipe while the animation from the previous | 625 // Generate another horizontal swipe while the animation from the previous |
624 // swipe is in progress. | 626 // swipe is in progress. |
625 generator.GestureScrollSequence( | 627 generator.GestureScrollSequence( |
626 gfx::Point(10, 10), | 628 gfx::Point(10, 10), |
627 gfx::Point(180, 10), | 629 gfx::Point(180, 10), |
628 base::TimeDelta::FromMilliseconds(10), | 630 base::TimeDelta::FromMilliseconds(10), |
629 2); | 631 2); |
630 // Performing the second swipe should instantly complete the slide started | 632 // Performing the second swipe should instantly complete the slide started |
631 // by the first swipe and create a new layer. | 633 // by the first swipe and create a new layer. |
632 EXPECT_TRUE(slider_delegate.created_back_layer()); | 634 EXPECT_TRUE(slider_delegate.created_back_layer()); |
633 EXPECT_FALSE(slider_delegate.slide_aborted()); | 635 EXPECT_FALSE(slider_delegate.slide_aborted()); |
634 EXPECT_FALSE(slider_delegate.created_front_layer()); | 636 EXPECT_FALSE(slider_delegate.created_front_layer()); |
635 EXPECT_TRUE(slider_delegate.slide_completing()); | 637 EXPECT_TRUE(slider_delegate.slide_completing()); |
636 EXPECT_TRUE(slider_delegate.slide_completed()); | 638 EXPECT_TRUE(slider_delegate.slide_completed()); |
637 EXPECT_FALSE(slider_delegate.slider_destroyed()); | 639 EXPECT_FALSE(slider_delegate.slider_destroyed()); |
638 test_controller.StartThreadedAnimationsIfNeeded(); | 640 test_controller.StartThreadedAnimationsIfNeeded(); |
639 base::TimeTicks start_time2 = gfx::FrameTime::Now(); | 641 base::TimeTicks start_time2 = gfx::FrameTime::Now(); |
640 slider_delegate.Reset(); | 642 slider_delegate.Reset(); |
641 animator->Step(start_time2 + duration); | 643 element->Step(start_time2 + duration); |
642 // The animation for the second slide should now be completed. | 644 // The animation for the second slide should now be completed. |
643 EXPECT_TRUE(slider_delegate.slide_completed()); | 645 EXPECT_TRUE(slider_delegate.slide_completed()); |
644 slider_delegate.Reset(); | 646 slider_delegate.Reset(); |
645 | 647 |
646 window.reset(); | 648 window.reset(); |
647 EXPECT_TRUE(slider_delegate.slider_destroyed()); | 649 EXPECT_TRUE(slider_delegate.slider_destroyed()); |
648 } | 650 } |
649 | 651 |
650 } // namespace content | 652 } // namespace content |
OLD | NEW |