| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/corewm/window_animations.h" | |
| 6 | |
| 7 #include "base/time/time.h" | |
| 8 #include "ui/aura/client/animation_host.h" | |
| 9 #include "ui/aura/test/aura_test_base.h" | |
| 10 #include "ui/aura/test/test_windows.h" | |
| 11 #include "ui/aura/window.h" | |
| 12 #include "ui/compositor/layer.h" | |
| 13 #include "ui/compositor/layer_animator.h" | |
| 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
| 15 #include "ui/gfx/animation/animation_container_element.h" | |
| 16 #include "ui/gfx/vector2d.h" | |
| 17 | |
| 18 using aura::Window; | |
| 19 using ui::Layer; | |
| 20 | |
| 21 namespace views { | |
| 22 namespace corewm { | |
| 23 | |
| 24 class WindowAnimationsTest : public aura::test::AuraTestBase { | |
| 25 public: | |
| 26 WindowAnimationsTest() {} | |
| 27 | |
| 28 virtual void TearDown() OVERRIDE { | |
| 29 AuraTestBase::TearDown(); | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); | |
| 34 }; | |
| 35 | |
| 36 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { | |
| 37 scoped_ptr<aura::Window> window( | |
| 38 aura::test::CreateTestWindowWithId(0, NULL)); | |
| 39 | |
| 40 // Layer target visibility changes according to Show/Hide. | |
| 41 window->Show(); | |
| 42 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
| 43 window->Hide(); | |
| 44 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | |
| 45 window->Show(); | |
| 46 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
| 47 } | |
| 48 | |
| 49 TEST_F(WindowAnimationsTest, LayerTargetVisibility_AnimateShow) { | |
| 50 // Tests if opacity and transform are reset when only show animation is | |
| 51 // enabled. See also LayerTargetVisibility_AnimateHide. | |
| 52 // Since the window is not visible after Hide() is called, opacity and | |
| 53 // transform shouldn't matter in case of ANIMATE_SHOW, but we reset them | |
| 54 // to keep consistency. | |
| 55 | |
| 56 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL)); | |
| 57 SetWindowVisibilityAnimationTransition(window.get(), ANIMATE_SHOW); | |
| 58 | |
| 59 // Layer target visibility and opacity change according to Show/Hide. | |
| 60 window->Show(); | |
| 61 AnimateOnChildWindowVisibilityChanged(window.get(), true); | |
| 62 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
| 63 EXPECT_EQ(1, window->layer()->opacity()); | |
| 64 | |
| 65 window->Hide(); | |
| 66 AnimateOnChildWindowVisibilityChanged(window.get(), false); | |
| 67 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | |
| 68 EXPECT_EQ(0, window->layer()->opacity()); | |
| 69 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); | |
| 70 | |
| 71 window->Show(); | |
| 72 AnimateOnChildWindowVisibilityChanged(window.get(), true); | |
| 73 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
| 74 EXPECT_EQ(1, window->layer()->opacity()); | |
| 75 } | |
| 76 | |
| 77 TEST_F(WindowAnimationsTest, LayerTargetVisibility_AnimateHide) { | |
| 78 // Tests if opacity and transform are reset when only hide animation is | |
| 79 // enabled. Hide animation changes opacity and transform in addition to | |
| 80 // visibility, so we need to reset not only visibility but also opacity | |
| 81 // and transform to show the window. | |
| 82 | |
| 83 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL)); | |
| 84 SetWindowVisibilityAnimationTransition(window.get(), ANIMATE_HIDE); | |
| 85 | |
| 86 // Layer target visibility and opacity change according to Show/Hide. | |
| 87 window->Show(); | |
| 88 AnimateOnChildWindowVisibilityChanged(window.get(), true); | |
| 89 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
| 90 EXPECT_EQ(1, window->layer()->opacity()); | |
| 91 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); | |
| 92 | |
| 93 window->Hide(); | |
| 94 AnimateOnChildWindowVisibilityChanged(window.get(), false); | |
| 95 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | |
| 96 EXPECT_EQ(0, window->layer()->opacity()); | |
| 97 | |
| 98 window->Show(); | |
| 99 AnimateOnChildWindowVisibilityChanged(window.get(), true); | |
| 100 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | |
| 101 EXPECT_EQ(1, window->layer()->opacity()); | |
| 102 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); | |
| 103 } | |
| 104 | |
| 105 // A simple AnimationHost implementation for the NotifyHideCompleted test. | |
| 106 class NotifyHideCompletedAnimationHost : public aura::client::AnimationHost { | |
| 107 public: | |
| 108 NotifyHideCompletedAnimationHost() : hide_completed_(false) {} | |
| 109 virtual ~NotifyHideCompletedAnimationHost() {} | |
| 110 | |
| 111 // Overridden from TestWindowDelegate: | |
| 112 virtual void OnWindowHidingAnimationCompleted() OVERRIDE { | |
| 113 hide_completed_ = true; | |
| 114 } | |
| 115 | |
| 116 virtual void SetHostTransitionOffsets( | |
| 117 const gfx::Vector2d& top_left, | |
| 118 const gfx::Vector2d& bottom_right) OVERRIDE {} | |
| 119 | |
| 120 bool hide_completed() const { return hide_completed_; } | |
| 121 | |
| 122 private: | |
| 123 bool hide_completed_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(NotifyHideCompletedAnimationHost); | |
| 126 }; | |
| 127 | |
| 128 TEST_F(WindowAnimationsTest, NotifyHideCompleted) { | |
| 129 NotifyHideCompletedAnimationHost animation_host; | |
| 130 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL)); | |
| 131 aura::client::SetAnimationHost(window.get(), &animation_host); | |
| 132 views::corewm::SetWindowVisibilityAnimationType( | |
| 133 window.get(), WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | |
| 134 AnimateOnChildWindowVisibilityChanged(window.get(), true); | |
| 135 EXPECT_TRUE(window->layer()->visible()); | |
| 136 | |
| 137 EXPECT_FALSE(animation_host.hide_completed()); | |
| 138 AnimateOnChildWindowVisibilityChanged(window.get(), false); | |
| 139 EXPECT_TRUE(animation_host.hide_completed()); | |
| 140 } | |
| 141 | |
| 142 } // namespace corewm | |
| 143 } // namespace views | |
| OLD | NEW |