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