[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / ash / wm / window_animations_unittest.cc
blob2f9d95cb79488666d85f53ed8a2927d4f78157e7
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.
5 #include "ash/wm/window_animations.h"
7 #include "ash/shell_window_ids.h"
8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/workspace_controller.h"
10 #include "base/time.h"
11 #include "ui/aura/test/test_windows.h"
12 #include "ui/aura/window.h"
13 #include "ui/base/animation/animation_container_element.h"
14 #include "ui/compositor/layer.h"
15 #include "ui/compositor/layer_animator.h"
17 using aura::Window;
18 using ui::Layer;
20 namespace ash {
21 namespace internal {
23 class WindowAnimationsTest : public ash::test::AshTestBase {
24 public:
25 WindowAnimationsTest() {}
27 virtual void TearDown() OVERRIDE {
28 ui::LayerAnimator::set_disable_animations_for_test(true);
29 AshTestBase::TearDown();
32 private:
33 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest);
36 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) {
37 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
38 window->Show();
39 EXPECT_TRUE(window->layer()->visible());
41 // Hiding.
42 views::corewm::SetWindowVisibilityAnimationType(
43 window.get(),
44 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE);
45 AnimateOnChildWindowVisibilityChanged(window.get(), false);
46 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity());
47 EXPECT_FALSE(window->layer()->GetTargetVisibility());
48 EXPECT_FALSE(window->layer()->visible());
50 // Showing.
51 views::corewm::SetWindowVisibilityAnimationType(
52 window.get(),
53 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE);
54 AnimateOnChildWindowVisibilityChanged(window.get(), true);
55 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness());
56 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale());
57 EXPECT_TRUE(window->layer()->visible());
59 // Stays shown.
60 ui::AnimationContainerElement* element =
61 static_cast<ui::AnimationContainerElement*>(
62 window->layer()->GetAnimator());
63 element->Step(base::TimeTicks::Now() +
64 base::TimeDelta::FromSeconds(5));
65 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness());
66 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale());
67 EXPECT_TRUE(window->layer()->visible());
70 TEST_F(WindowAnimationsTest, LayerTargetVisibility) {
71 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
73 // Layer target visibility changes according to Show/Hide.
74 window->Show();
75 EXPECT_TRUE(window->layer()->GetTargetVisibility());
76 window->Hide();
77 EXPECT_FALSE(window->layer()->GetTargetVisibility());
78 window->Show();
79 EXPECT_TRUE(window->layer()->GetTargetVisibility());
82 TEST_F(WindowAnimationsTest, CrossFadeToBounds) {
83 ui::LayerAnimator::set_disable_animations_for_test(false);
85 scoped_ptr<Window> window(CreateTestWindowInShellWithId(0));
86 window->SetBounds(gfx::Rect(5, 10, 320, 240));
87 window->Show();
89 Layer* old_layer = window->layer();
90 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity());
92 // Cross fade to a larger size, as in a maximize animation.
93 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480));
94 // Window's layer has been replaced.
95 EXPECT_NE(old_layer, window->layer());
96 // Original layer stays opaque and stretches to new size.
97 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity());
98 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString());
99 gfx::Transform grow_transform;
100 grow_transform.Translate(-5.f, -10.f);
101 grow_transform.Scale(640.f / 320.f, 480.f / 240.f);
102 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform());
103 // New layer animates in to the identity transform.
104 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
105 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform());
107 // Run the animations to completion.
108 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step(
109 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
110 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())->
111 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
113 // Cross fade to a smaller size, as in a restore animation.
114 old_layer = window->layer();
115 CrossFadeToBounds(window.get(), gfx::Rect(5, 10, 320, 240));
116 // Again, window layer has been replaced.
117 EXPECT_NE(old_layer, window->layer());
118 // Original layer fades out and stretches down to new size.
119 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity());
120 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString());
121 gfx::Transform shrink_transform;
122 shrink_transform.Translate(5.f, 10.f);
123 shrink_transform.Scale(320.f / 640.f, 240.f / 480.f);
124 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform());
125 // New layer animates in to the identity transform.
126 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
127 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform());
129 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step(
130 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
131 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())->
132 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
135 } // namespace internal
136 } // namespace ash