| 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 "ui/views/corewm/window_animations.h" | 5 #include "ui/views/corewm/window_animations.h" |
| 6 | 6 |
| 7 #include "base/time.h" | 7 #include "base/time.h" |
| 8 #include "ui/aura/test/aura_test_base.h" | 8 #include "ui/aura/test/aura_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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 WindowAnimationsTest() {} | 24 WindowAnimationsTest() {} |
| 25 | 25 |
| 26 virtual void TearDown() OVERRIDE { | 26 virtual void TearDown() OVERRIDE { |
| 27 AuraTestBase::TearDown(); | 27 AuraTestBase::TearDown(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 private: | 30 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); | 31 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { | |
| 35 scoped_ptr<aura::Window> window( | |
| 36 aura::test::CreateTestWindowWithId(0, NULL)); | |
| 37 window->Show(); | |
| 38 EXPECT_TRUE(window->layer()->visible()); | |
| 39 | |
| 40 // Hiding. | |
| 41 SetWindowVisibilityAnimationType( | |
| 42 window.get(), | |
| 43 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); | |
| 44 AnimateOnChildWindowVisibilityChanged(window.get(), false); | |
| 45 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | |
| 46 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | |
| 47 EXPECT_FALSE(window->layer()->visible()); | |
| 48 | |
| 49 // Showing. | |
| 50 SetWindowVisibilityAnimationType( | |
| 51 window.get(), | |
| 52 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); | |
| 53 AnimateOnChildWindowVisibilityChanged(window.get(), true); | |
| 54 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); | |
| 55 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); | |
| 56 EXPECT_TRUE(window->layer()->visible()); | |
| 57 | |
| 58 // Stays shown. | |
| 59 ui::AnimationContainerElement* element = | |
| 60 static_cast<ui::AnimationContainerElement*>( | |
| 61 window->layer()->GetAnimator()); | |
| 62 element->Step(base::TimeTicks::Now() + | |
| 63 base::TimeDelta::FromSeconds(5)); | |
| 64 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); | |
| 65 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); | |
| 66 EXPECT_TRUE(window->layer()->visible()); | |
| 67 } | |
| 68 | |
| 69 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { | 34 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { |
| 70 scoped_ptr<aura::Window> window( | 35 scoped_ptr<aura::Window> window( |
| 71 aura::test::CreateTestWindowWithId(0, NULL)); | 36 aura::test::CreateTestWindowWithId(0, NULL)); |
| 72 | 37 |
| 73 // Layer target visibility changes according to Show/Hide. | 38 // Layer target visibility changes according to Show/Hide. |
| 74 window->Show(); | 39 window->Show(); |
| 75 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 40 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 76 window->Hide(); | 41 window->Hide(); |
| 77 EXPECT_FALSE(window->layer()->GetTargetVisibility()); | 42 EXPECT_FALSE(window->layer()->GetTargetVisibility()); |
| 78 window->Show(); | 43 window->Show(); |
| 79 EXPECT_TRUE(window->layer()->GetTargetVisibility()); | 44 EXPECT_TRUE(window->layer()->GetTargetVisibility()); |
| 80 } | 45 } |
| 81 | 46 |
| 82 TEST_F(WindowAnimationsTest, CrossFadeToBounds) { | 47 // A simple WindowDelegate implementation for the NotifyHideCompleted test. |
| 83 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 48 class NotifyHideCompletedDelegate : public aura::test::TestWindowDelegate { |
| 84 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 49 public: |
| 50 NotifyHideCompletedDelegate() : hide_completed_(false) {} |
| 51 virtual ~NotifyHideCompletedDelegate() {} |
| 85 | 52 |
| 86 scoped_ptr<Window> window( | 53 // Overridden from TestWindowDelegate: |
| 87 aura::test::CreateTestWindowWithId(0, NULL)); | 54 virtual void OnWindowHidingAnimationCompleted() OVERRIDE { |
| 88 window->SetBounds(gfx::Rect(5, 10, 320, 240)); | 55 hide_completed_ = true; |
| 89 window->Show(); | 56 } |
| 90 | 57 |
| 91 Layer* old_layer = window->layer(); | 58 bool hide_completed() const { return hide_completed_; } |
| 92 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); | |
| 93 | 59 |
| 94 // Cross fade to a larger size, as in a maximize animation. | 60 private: |
| 95 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480)); | 61 bool hide_completed_; |
| 96 // Window's layer has been replaced. | |
| 97 EXPECT_NE(old_layer, window->layer()); | |
| 98 // Original layer stays opaque and stretches to new size. | |
| 99 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); | |
| 100 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString()); | |
| 101 gfx::Transform grow_transform; | |
| 102 grow_transform.Translate(-5.f, -10.f); | |
| 103 grow_transform.Scale(640.f / 320.f, 480.f / 240.f); | |
| 104 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform()); | |
| 105 // New layer animates in to the identity transform. | |
| 106 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | |
| 107 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); | |
| 108 | 62 |
| 109 // Run the animations to completion. | 63 DISALLOW_COPY_AND_ASSIGN(NotifyHideCompletedDelegate); |
| 110 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step( | 64 }; |
| 111 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | |
| 112 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())-> | |
| 113 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | |
| 114 | 65 |
| 115 // Cross fade to a smaller size, as in a restore animation. | 66 TEST_F(WindowAnimationsTest, NotifyHideCompleted) { |
| 116 old_layer = window->layer(); | 67 NotifyHideCompletedDelegate delegate; |
| 117 CrossFadeToBounds(window.get(), gfx::Rect(5, 10, 320, 240)); | 68 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
| 118 // Again, window layer has been replaced. | 69 &delegate, 0, gfx::Rect(0, 0, 640, 480), NULL)); |
| 119 EXPECT_NE(old_layer, window->layer()); | 70 views::corewm::SetWindowVisibilityAnimationType( |
| 120 // Original layer fades out and stretches down to new size. | 71 window.get(), WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
| 121 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity()); | 72 AnimateOnChildWindowVisibilityChanged(window.get(), true); |
| 122 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString()); | 73 EXPECT_TRUE(window->layer()->visible()); |
| 123 gfx::Transform shrink_transform; | |
| 124 shrink_transform.Translate(5.f, 10.f); | |
| 125 shrink_transform.Scale(320.f / 640.f, 240.f / 480.f); | |
| 126 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform()); | |
| 127 // New layer animates in to the identity transform. | |
| 128 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); | |
| 129 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); | |
| 130 | 74 |
| 131 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step( | 75 EXPECT_FALSE(delegate.hide_completed()); |
| 132 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | 76 AnimateOnChildWindowVisibilityChanged(window.get(), false); |
| 133 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())-> | 77 EXPECT_TRUE(delegate.hide_completed()); |
| 134 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); | |
| 135 } | 78 } |
| 136 | 79 |
| 137 } // namespace internal | 80 } // namespace corewm |
| 138 } // namespace ash | 81 } // namespace views |
| OLD | NEW |