| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ash/wm/window_animations.h" | 5 #include "ash/wm/window_animations.h" |
| 6 | 6 |
| 7 #include "ash/shell_window_ids.h" | 7 #include "ash/shell_window_ids.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ui/aura/test/test_windows.h" | 9 #include "ui/aura/test/test_windows.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/base/animation/animation_container_element.h" | 11 #include "ui/base/animation/animation_container_element.h" |
| 12 #include "ui/compositor/layer.h" | 12 #include "ui/compositor/layer.h" |
| 13 #include "ui/compositor/layer_animator.h" | 13 #include "ui/compositor/layer_animator.h" |
| 14 | 14 |
| 15 using aura::Window; |
| 16 using ui::Layer; |
| 17 |
| 15 namespace ash { | 18 namespace ash { |
| 16 namespace internal { | 19 namespace internal { |
| 17 | 20 |
| 18 typedef ash::test::AshTestBase WindowAnimationsWorkspaceTest; | 21 typedef ash::test::AshTestBase WindowAnimationsTest; |
| 19 | 22 |
| 20 TEST_F(WindowAnimationsWorkspaceTest, HideShow) { | 23 TEST_F(WindowAnimationsTest, HideShow) { |
| 21 aura::Window* default_container = | 24 aura::Window* default_container = |
| 22 ash::Shell::GetInstance()->GetContainer( | 25 ash::Shell::GetInstance()->GetContainer( |
| 23 internal::kShellWindowId_DefaultContainer); | 26 internal::kShellWindowId_DefaultContainer); |
| 24 scoped_ptr<aura::Window> window( | 27 scoped_ptr<aura::Window> window( |
| 25 aura::test::CreateTestWindowWithId(0, default_container)); | 28 aura::test::CreateTestWindowWithId(0, default_container)); |
| 26 window->Show(); | 29 window->Show(); |
| 27 EXPECT_TRUE(window->layer()->visible()); | 30 EXPECT_TRUE(window->layer()->visible()); |
| 28 // Hiding. | 31 // Hiding. |
| 29 SetWindowVisibilityAnimationType( | 32 SetWindowVisibilityAnimationType( |
| 30 window.get(), | 33 window.get(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 47 ui::AnimationContainerElement* element = | 50 ui::AnimationContainerElement* element = |
| 48 static_cast<ui::AnimationContainerElement*>( | 51 static_cast<ui::AnimationContainerElement*>( |
| 49 window->layer()->GetAnimator()); | 52 window->layer()->GetAnimator()); |
| 50 element->Step(base::TimeTicks::Now() + | 53 element->Step(base::TimeTicks::Now() + |
| 51 base::TimeDelta::FromSeconds(5)); | 54 base::TimeDelta::FromSeconds(5)); |
| 52 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 55 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
| 53 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 56 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 54 EXPECT_TRUE(window->layer()->visible()); | 57 EXPECT_TRUE(window->layer()->visible()); |
| 55 } | 58 } |
| 56 | 59 |
| 57 TEST_F(WindowAnimationsWorkspaceTest, ShowHide) { | 60 TEST_F(WindowAnimationsTest, ShowHide) { |
| 58 aura::Window* default_container = | 61 aura::Window* default_container = |
| 59 ash::Shell::GetInstance()->GetContainer( | 62 ash::Shell::GetInstance()->GetContainer( |
| 60 internal::kShellWindowId_DefaultContainer); | 63 internal::kShellWindowId_DefaultContainer); |
| 61 scoped_ptr<aura::Window> window( | 64 scoped_ptr<aura::Window> window( |
| 62 aura::test::CreateTestWindowWithId(0, default_container)); | 65 aura::test::CreateTestWindowWithId(0, default_container)); |
| 63 window->Show(); | 66 window->Show(); |
| 64 EXPECT_TRUE(window->layer()->visible()); | 67 EXPECT_TRUE(window->layer()->visible()); |
| 65 // Showing -- should be a no-op. | 68 // Showing -- should be a no-op. |
| 66 SetWindowVisibilityAnimationType( | 69 SetWindowVisibilityAnimationType( |
| 67 window.get(), | 70 window.get(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 84 ui::AnimationContainerElement* element = | 87 ui::AnimationContainerElement* element = |
| 85 static_cast<ui::AnimationContainerElement*>( | 88 static_cast<ui::AnimationContainerElement*>( |
| 86 window->layer()->GetAnimator()); | 89 window->layer()->GetAnimator()); |
| 87 element->Step(base::TimeTicks::Now() + | 90 element->Step(base::TimeTicks::Now() + |
| 88 base::TimeDelta::FromSeconds(5)); | 91 base::TimeDelta::FromSeconds(5)); |
| 89 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | 92 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); |
| 90 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 93 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
| 91 EXPECT_FALSE(window->layer()->visible()); | 94 EXPECT_FALSE(window->layer()->visible()); |
| 92 } | 95 } |
| 93 | 96 |
| 94 TEST_F(WindowAnimationsWorkspaceTest, LayerTargetVisibility) { | 97 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { |
| 95 aura::Window* default_container = | 98 aura::Window* default_container = |
| 96 ash::Shell::GetInstance()->GetContainer( | 99 ash::Shell::GetInstance()->GetContainer( |
| 97 internal::kShellWindowId_DefaultContainer); | 100 internal::kShellWindowId_DefaultContainer); |
| 98 scoped_ptr<aura::Window> window( | 101 scoped_ptr<aura::Window> window( |
| 99 aura::test::CreateTestWindowWithId(0, default_container)); | 102 aura::test::CreateTestWindowWithId(0, default_container)); |
| 100 | 103 |
| 101 // Layer target visibility changes according to Show/Hide. | 104 // Layer target visibility changes according to Show/Hide. |
| 102 window->Show(); | 105 window->Show(); |
| 103 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 106 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 104 window->Hide(); | 107 window->Hide(); |
| 105 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 108 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
| 106 window->Show(); | 109 window->Show(); |
| 107 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 110 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 108 } | 111 } |
| 109 | 112 |
| 113 TEST_F(WindowAnimationsTest, CrossFadeToBounds) { |
| 114 Window* default_container = |
| 115 ash::Shell::GetInstance()->GetContainer( |
| 116 internal::kShellWindowId_DefaultContainer); |
| 117 scoped_ptr<Window> window( |
| 118 aura::test::CreateTestWindowWithId(0, default_container)); |
| 119 window->SetBounds(gfx::Rect(5, 10, 320, 240)); |
| 120 window->Show(); |
| 121 |
| 122 Layer* old_layer = window->layer(); |
| 123 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); |
| 124 |
| 125 // Cross fade to a larger size, as in a maximize animation. |
| 126 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480)); |
| 127 // Window's layer has been replaced. |
| 128 EXPECT_NE(old_layer, window->layer()); |
| 129 // Original layer stays opaque and stretches to new size. |
| 130 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); |
| 131 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString()); |
| 132 ui::Transform grow_transform; |
| 133 grow_transform.ConcatScale(640.f / 320.f, 480.f / 240.f); |
| 134 grow_transform.ConcatTranslate(-5.f, -10.f); |
| 135 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform()); |
| 136 // New layer animates in to the identity transform. |
| 137 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
| 138 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform()); |
| 139 |
| 140 // Allow the animation observer to delete itself. |
| 141 RunAllPendingInMessageLoop(); |
| 142 |
| 143 // Cross fade to a smaller size, as in a restore animation. |
| 144 old_layer = window->layer(); |
| 145 CrossFadeToBounds(window.get(), gfx::Rect(5, 10, 320, 240)); |
| 146 // Again, window layer has been replaced. |
| 147 EXPECT_NE(old_layer, window->layer()); |
| 148 // Original layer fades out and stretches down to new size. |
| 149 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity()); |
| 150 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString()); |
| 151 ui::Transform shrink_transform; |
| 152 shrink_transform.ConcatScale(320.f / 640.f, 240.f / 480.f); |
| 153 shrink_transform.ConcatTranslate(5.f, 10.f); |
| 154 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform()); |
| 155 // New layer animates in to the identity transform. |
| 156 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
| 157 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform()); |
| 158 |
| 159 RunAllPendingInMessageLoop(); |
| 160 } |
| 161 |
| 110 } // namespace internal | 162 } // namespace internal |
| 111 } // namespace ash | 163 } // namespace ash |
| OLD | NEW |