| 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 | |
| 18 namespace ash { | 15 namespace ash { |
| 19 namespace internal { | 16 namespace internal { |
| 20 | 17 |
| 21 typedef ash::test::AshTestBase WindowAnimationsTest; | 18 typedef ash::test::AshTestBase WindowAnimationsWorkspaceTest; |
| 22 | 19 |
| 23 TEST_F(WindowAnimationsTest, HideShow) { | 20 TEST_F(WindowAnimationsWorkspaceTest, HideShow) { |
| 24 aura::Window* default_container = | 21 aura::Window* default_container = |
| 25 ash::Shell::GetInstance()->GetContainer( | 22 ash::Shell::GetInstance()->GetContainer( |
| 26 internal::kShellWindowId_DefaultContainer); | 23 internal::kShellWindowId_DefaultContainer); |
| 27 scoped_ptr<aura::Window> window( | 24 scoped_ptr<aura::Window> window( |
| 28 aura::test::CreateTestWindowWithId(0, default_container)); | 25 aura::test::CreateTestWindowWithId(0, default_container)); |
| 29 window->Show(); | 26 window->Show(); |
| 30 EXPECT_TRUE(window->layer()->visible()); | 27 EXPECT_TRUE(window->layer()->visible()); |
| 31 // Hiding. | 28 // Hiding. |
| 32 SetWindowVisibilityAnimationType( | 29 SetWindowVisibilityAnimationType( |
| 33 window.get(), | 30 window.get(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 ui::AnimationContainerElement* element = | 47 ui::AnimationContainerElement* element = |
| 51 static_cast<ui::AnimationContainerElement*>( | 48 static_cast<ui::AnimationContainerElement*>( |
| 52 window->layer()->GetAnimator()); | 49 window->layer()->GetAnimator()); |
| 53 element->Step(base::TimeTicks::Now() + | 50 element->Step(base::TimeTicks::Now() + |
| 54 base::TimeDelta::FromSeconds(5)); | 51 base::TimeDelta::FromSeconds(5)); |
| 55 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 52 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
| 56 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 53 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 57 EXPECT_TRUE(window->layer()->visible()); | 54 EXPECT_TRUE(window->layer()->visible()); |
| 58 } | 55 } |
| 59 | 56 |
| 60 TEST_F(WindowAnimationsTest, ShowHide) { | 57 TEST_F(WindowAnimationsWorkspaceTest, ShowHide) { |
| 61 aura::Window* default_container = | 58 aura::Window* default_container = |
| 62 ash::Shell::GetInstance()->GetContainer( | 59 ash::Shell::GetInstance()->GetContainer( |
| 63 internal::kShellWindowId_DefaultContainer); | 60 internal::kShellWindowId_DefaultContainer); |
| 64 scoped_ptr<aura::Window> window( | 61 scoped_ptr<aura::Window> window( |
| 65 aura::test::CreateTestWindowWithId(0, default_container)); | 62 aura::test::CreateTestWindowWithId(0, default_container)); |
| 66 window->Show(); | 63 window->Show(); |
| 67 EXPECT_TRUE(window->layer()->visible()); | 64 EXPECT_TRUE(window->layer()->visible()); |
| 68 // Showing -- should be a no-op. | 65 // Showing -- should be a no-op. |
| 69 SetWindowVisibilityAnimationType( | 66 SetWindowVisibilityAnimationType( |
| 70 window.get(), | 67 window.get(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 87 ui::AnimationContainerElement* element = | 84 ui::AnimationContainerElement* element = |
| 88 static_cast<ui::AnimationContainerElement*>( | 85 static_cast<ui::AnimationContainerElement*>( |
| 89 window->layer()->GetAnimator()); | 86 window->layer()->GetAnimator()); |
| 90 element->Step(base::TimeTicks::Now() + | 87 element->Step(base::TimeTicks::Now() + |
| 91 base::TimeDelta::FromSeconds(5)); | 88 base::TimeDelta::FromSeconds(5)); |
| 92 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | 89 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); |
| 93 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 90 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
| 94 EXPECT_FALSE(window->layer()->visible()); | 91 EXPECT_FALSE(window->layer()->visible()); |
| 95 } | 92 } |
| 96 | 93 |
| 97 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { | 94 TEST_F(WindowAnimationsWorkspaceTest, LayerTargetVisibility) { |
| 98 aura::Window* default_container = | 95 aura::Window* default_container = |
| 99 ash::Shell::GetInstance()->GetContainer( | 96 ash::Shell::GetInstance()->GetContainer( |
| 100 internal::kShellWindowId_DefaultContainer); | 97 internal::kShellWindowId_DefaultContainer); |
| 101 scoped_ptr<aura::Window> window( | 98 scoped_ptr<aura::Window> window( |
| 102 aura::test::CreateTestWindowWithId(0, default_container)); | 99 aura::test::CreateTestWindowWithId(0, default_container)); |
| 103 | 100 |
| 104 // Layer target visibility changes according to Show/Hide. | 101 // Layer target visibility changes according to Show/Hide. |
| 105 window->Show(); | 102 window->Show(); |
| 106 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 103 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 107 window->Hide(); | 104 window->Hide(); |
| 108 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 105 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
| 109 window->Show(); | 106 window->Show(); |
| 110 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 107 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 111 } | 108 } |
| 112 | 109 |
| 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 | |
| 162 } // namespace internal | 110 } // namespace internal |
| 163 } // namespace ash | 111 } // namespace ash |
| OLD | NEW |