Chromium Code Reviews| 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 "base/time.h" | 9 #include "base/time.h" |
| 10 #include "ui/aura/test/test_windows.h" | 10 #include "ui/aura/test/test_windows.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/base/animation/animation_container_element.h" | 12 #include "ui/base/animation/animation_container_element.h" |
| 13 #include "ui/compositor/layer.h" | 13 #include "ui/compositor/layer.h" |
| 14 #include "ui/compositor/layer_animator.h" | 14 #include "ui/compositor/layer_animator.h" |
| 15 | 15 |
| 16 using aura::Window; | 16 using aura::Window; |
| 17 using ui::Layer; | 17 using ui::Layer; |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 namespace internal { | 20 namespace internal { |
| 21 | 21 |
| 22 typedef ash::test::AshTestBase WindowAnimationsTest; | 22 class WindowAnimationsTest : public ash::test::AshTestBase { |
| 23 public: | |
| 24 WindowAnimationsTest() {} | |
| 25 | |
| 26 virtual void TearDown() OVERRIDE { | |
| 27 ui::LayerAnimator::set_disable_animations_for_test(true); | |
| 28 AshTestBase::TearDown(); | |
| 29 } | |
| 30 | |
| 31 private: | |
| 32 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); | |
| 33 }; | |
| 23 | 34 |
| 24 TEST_F(WindowAnimationsTest, HideShow) { | 35 TEST_F(WindowAnimationsTest, HideShow) { |
| 25 scoped_ptr<aura::Window> window( | 36 scoped_ptr<aura::Window> window( |
| 26 aura::test::CreateTestWindowWithId(0, NULL)); | 37 aura::test::CreateTestWindowWithId(0, NULL)); |
| 27 window->Show(); | 38 window->Show(); |
| 28 EXPECT_TRUE(window->layer()->visible()); | 39 EXPECT_TRUE(window->layer()->visible()); |
| 29 // Hiding. | 40 // Hiding. |
| 30 SetWindowVisibilityAnimationType( | 41 SetWindowVisibilityAnimationType( |
| 31 window.get(), | 42 window.get(), |
| 32 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE); | 43 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 // Layer target visibility changes according to Show/Hide. | 144 // Layer target visibility changes according to Show/Hide. |
| 134 window->Show(); | 145 window->Show(); |
| 135 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 146 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 136 window->Hide(); | 147 window->Hide(); |
| 137 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 148 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
| 138 window->Show(); | 149 window->Show(); |
| 139 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 150 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 140 } | 151 } |
| 141 | 152 |
| 142 TEST_F(WindowAnimationsTest, CrossFadeToBounds) { | 153 TEST_F(WindowAnimationsTest, CrossFadeToBounds) { |
| 143 internal::SetDelayedOldLayerDeletionInCrossFadeForTest(true); | 154 ui::LayerAnimator::set_disable_animations_for_test(false); |
| 144 | 155 |
| 145 scoped_ptr<Window> window( | 156 scoped_ptr<Window> window( |
| 146 aura::test::CreateTestWindowWithId(0, NULL)); | 157 aura::test::CreateTestWindowWithId(0, NULL)); |
| 147 window->SetBounds(gfx::Rect(5, 10, 320, 240)); | 158 window->SetBounds(gfx::Rect(5, 10, 320, 240)); |
| 148 window->Show(); | 159 window->Show(); |
| 149 | 160 |
| 150 Layer* old_layer = window->layer(); | 161 Layer* old_layer = window->layer(); |
| 151 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); | 162 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); |
| 152 | 163 |
| 153 // Cross fade to a larger size, as in a maximize animation. | 164 // Cross fade to a larger size, as in a maximize animation. |
| 154 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480)); | 165 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480)); |
| 155 // Window's layer has been replaced. | 166 // Window's layer has been replaced. |
| 156 EXPECT_NE(old_layer, window->layer()); | 167 EXPECT_NE(old_layer, window->layer()); |
| 157 // Original layer stays opaque and stretches to new size. | 168 // Original layer stays opaque and stretches to new size. |
| 158 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); | 169 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); |
| 159 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString()); | 170 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString()); |
| 160 ui::Transform grow_transform; | 171 ui::Transform grow_transform; |
| 161 grow_transform.ConcatScale(640.f / 320.f, 480.f / 240.f); | 172 grow_transform.ConcatScale(640.f / 320.f, 480.f / 240.f); |
| 162 grow_transform.ConcatTranslate(-5.f, -10.f); | 173 grow_transform.ConcatTranslate(-5.f, -10.f); |
| 163 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform()); | 174 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform()); |
| 164 // New layer animates in to the identity transform. | 175 // New layer animates in to the identity transform. |
| 165 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 176 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
| 166 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform()); | 177 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform()); |
| 167 | 178 |
| 168 // Allow the animation observer to delete itself. | 179 // Run the animations to completion. |
| 169 RunAllPendingInMessageLoop(); | 180 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step( |
|
sky
2012/08/25 16:01:43
The old code is fine, but this better matches what
| |
| 181 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | |
| 182 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())-> | |
| 183 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | |
| 170 | 184 |
| 171 // Cross fade to a smaller size, as in a restore animation. | 185 // Cross fade to a smaller size, as in a restore animation. |
| 172 old_layer = window->layer(); | 186 old_layer = window->layer(); |
| 173 CrossFadeToBounds(window.get(), gfx::Rect(5, 10, 320, 240)); | 187 CrossFadeToBounds(window.get(), gfx::Rect(5, 10, 320, 240)); |
| 174 // Again, window layer has been replaced. | 188 // Again, window layer has been replaced. |
| 175 EXPECT_NE(old_layer, window->layer()); | 189 EXPECT_NE(old_layer, window->layer()); |
| 176 // Original layer fades out and stretches down to new size. | 190 // Original layer fades out and stretches down to new size. |
| 177 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity()); | 191 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity()); |
| 178 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString()); | 192 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString()); |
| 179 ui::Transform shrink_transform; | 193 ui::Transform shrink_transform; |
| 180 shrink_transform.ConcatScale(320.f / 640.f, 240.f / 480.f); | 194 shrink_transform.ConcatScale(320.f / 640.f, 240.f / 480.f); |
| 181 shrink_transform.ConcatTranslate(5.f, 10.f); | 195 shrink_transform.ConcatTranslate(5.f, 10.f); |
| 182 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform()); | 196 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform()); |
| 183 // New layer animates in to the identity transform. | 197 // New layer animates in to the identity transform. |
| 184 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | 198 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); |
| 185 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform()); | 199 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform()); |
| 186 | 200 |
| 187 RunAllPendingInMessageLoop(); | 201 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step( |
| 188 internal::SetDelayedOldLayerDeletionInCrossFadeForTest(false); | 202 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); |
| 203 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())-> | |
| 204 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | |
| 189 } | 205 } |
| 190 | 206 |
| 191 TEST_F(WindowAnimationsTest, GetCrossFadeDuration) { | 207 TEST_F(WindowAnimationsTest, GetCrossFadeDuration) { |
| 192 gfx::Rect empty; | 208 gfx::Rect empty; |
| 193 gfx::Rect screen(0, 0, 1000, 500); | 209 gfx::Rect screen(0, 0, 1000, 500); |
| 194 | 210 |
| 195 // No change takes no time. | 211 // No change takes no time. |
| 196 EXPECT_EQ(0, GetCrossFadeDuration(empty, empty).InMilliseconds()); | 212 EXPECT_EQ(0, GetCrossFadeDuration(empty, empty).InMilliseconds()); |
| 197 EXPECT_EQ(0, GetCrossFadeDuration(screen, screen).InMilliseconds()); | 213 EXPECT_EQ(0, GetCrossFadeDuration(screen, screen).InMilliseconds()); |
| 198 | 214 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 215 // Medium changes take medium time. | 231 // Medium changes take medium time. |
| 216 gfx::Rect half_screen(10, 10, 500, 250); | 232 gfx::Rect half_screen(10, 10, 500, 250); |
| 217 EXPECT_EQ(kMinimum + kRange * 3 / 4, | 233 EXPECT_EQ(kMinimum + kRange * 3 / 4, |
| 218 GetCrossFadeDuration(half_screen, screen).InMilliseconds()); | 234 GetCrossFadeDuration(half_screen, screen).InMilliseconds()); |
| 219 EXPECT_EQ(kMinimum + kRange * 3 / 4, | 235 EXPECT_EQ(kMinimum + kRange * 3 / 4, |
| 220 GetCrossFadeDuration(screen, half_screen).InMilliseconds()); | 236 GetCrossFadeDuration(screen, half_screen).InMilliseconds()); |
| 221 } | 237 } |
| 222 | 238 |
| 223 } // namespace internal | 239 } // namespace internal |
| 224 } // namespace ash | 240 } // namespace ash |
| OLD | NEW |