Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(356)

Side by Side Diff: ash/wm/window_animations_unittest.cc

Issue 291843012: compositor: Tick the UI animations from cc, instead of from timer callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ash/wm/window_state.h" 9 #include "ash/wm/window_state.h"
10 #include "ash/wm/workspace_controller.h" 10 #include "ash/wm/workspace_controller.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "ui/aura/test/test_windows.h" 12 #include "ui/aura/test/test_windows.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/compositor/layer.h" 14 #include "ui/compositor/layer.h"
15 #include "ui/compositor/layer_animation_observer.h" 15 #include "ui/compositor/layer_animation_observer.h"
16 #include "ui/compositor/layer_animator.h" 16 #include "ui/compositor/layer_animator.h"
17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 17 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
18 #include "ui/compositor/scoped_layer_animation_settings.h" 18 #include "ui/compositor/scoped_layer_animation_settings.h"
19 #include "ui/gfx/animation/animation_container_element.h"
20 19
21 using aura::Window; 20 using aura::Window;
22 using ui::Layer; 21 using ui::Layer;
23 22
24 namespace ash { 23 namespace ash {
25 class WindowAnimationsTest : public ash::test::AshTestBase { 24 class WindowAnimationsTest : public ash::test::AshTestBase {
26 public: 25 public:
27 WindowAnimationsTest() {} 26 WindowAnimationsTest() {}
28 27
29 virtual void TearDown() OVERRIDE { 28 virtual void TearDown() OVERRIDE {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Showing. 81 // Showing.
83 ::wm::SetWindowVisibilityAnimationType( 82 ::wm::SetWindowVisibilityAnimationType(
84 window.get(), 83 window.get(),
85 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); 84 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE);
86 AnimateOnChildWindowVisibilityChanged(window.get(), true); 85 AnimateOnChildWindowVisibilityChanged(window.get(), true);
87 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); 86 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness());
88 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); 87 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale());
89 EXPECT_TRUE(window->layer()->visible()); 88 EXPECT_TRUE(window->layer()->visible());
90 89
91 // Stays shown. 90 // Stays shown.
92 gfx::AnimationContainerElement* element = 91 window->layer()->GetAnimator()->Step(base::TimeTicks::Now() +
93 static_cast<gfx::AnimationContainerElement*>( 92 base::TimeDelta::FromSeconds(5));
94 window->layer()->GetAnimator());
95 element->Step(base::TimeTicks::Now() +
96 base::TimeDelta::FromSeconds(5));
97 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); 93 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness());
98 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); 94 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale());
99 EXPECT_TRUE(window->layer()->visible()); 95 EXPECT_TRUE(window->layer()->visible());
100 } 96 }
101 97
102 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { 98 TEST_F(WindowAnimationsTest, LayerTargetVisibility) {
103 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 99 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
104 100
105 // Layer target visibility changes according to Show/Hide. 101 // Layer target visibility changes according to Show/Hide.
106 window->Show(); 102 window->Show();
(...skipping 27 matching lines...) Expand all
134 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString()); 130 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString());
135 gfx::Transform grow_transform; 131 gfx::Transform grow_transform;
136 grow_transform.Translate(-5.f, -10.f); 132 grow_transform.Translate(-5.f, -10.f);
137 grow_transform.Scale(640.f / 320.f, 480.f / 240.f); 133 grow_transform.Scale(640.f / 320.f, 480.f / 240.f);
138 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform()); 134 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform());
139 // New layer animates in to the identity transform. 135 // New layer animates in to the identity transform.
140 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); 136 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
141 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); 137 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform());
142 138
143 // Run the animations to completion. 139 // Run the animations to completion.
144 static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( 140 old_layer->GetAnimator()->Step(base::TimeTicks::Now() +
145 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 141 base::TimeDelta::FromSeconds(1));
146 static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> 142 window->layer()->GetAnimator()->Step(base::TimeTicks::Now() +
147 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 143 base::TimeDelta::FromSeconds(1));
148 144
149 // Cross fade to a smaller size, as in a restore animation. 145 // Cross fade to a smaller size, as in a restore animation.
150 old_layer = window->layer(); 146 old_layer = window->layer();
151 GetWindowState(window.get())->SetBoundsDirectCrossFade( 147 GetWindowState(window.get())->SetBoundsDirectCrossFade(
152 gfx::Rect(5, 10, 320, 240)); 148 gfx::Rect(5, 10, 320, 240));
153 // Again, window layer has been replaced. 149 // Again, window layer has been replaced.
154 EXPECT_NE(old_layer, window->layer()); 150 EXPECT_NE(old_layer, window->layer());
155 // Original layer fades out and stretches down to new size. 151 // Original layer fades out and stretches down to new size.
156 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity()); 152 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity());
157 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString()); 153 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString());
158 gfx::Transform shrink_transform; 154 gfx::Transform shrink_transform;
159 shrink_transform.Translate(5.f, 10.f); 155 shrink_transform.Translate(5.f, 10.f);
160 shrink_transform.Scale(320.f / 640.f, 240.f / 480.f); 156 shrink_transform.Scale(320.f / 640.f, 240.f / 480.f);
161 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform()); 157 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform());
162 // New layer animates in to the identity transform. 158 // New layer animates in to the identity transform.
163 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); 159 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
164 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); 160 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform());
165 161
166 static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( 162 old_layer->GetAnimator()->Step(base::TimeTicks::Now() +
167 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 163 base::TimeDelta::FromSeconds(1));
168 static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> 164 window->layer()->GetAnimator()->Step(base::TimeTicks::Now() +
169 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 165 base::TimeDelta::FromSeconds(1));
170 } 166 }
171 167
172 } // namespace wm 168 } // namespace wm
173 169
174 TEST_F(WindowAnimationsTest, LockAnimationDuration) { 170 TEST_F(WindowAnimationsTest, LockAnimationDuration) {
175 ui::ScopedAnimationDurationScaleMode normal_duration_mode( 171 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
176 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 172 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
177 173
178 scoped_ptr<Window> window(CreateTestWindowInShellWithId(0)); 174 scoped_ptr<Window> window(CreateTestWindowInShellWithId(0));
179 Layer* layer = window->layer(); 175 Layer* layer = window->layer();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 EXPECT_TRUE(layer->GetAnimator()->is_animating()); 237 EXPECT_TRUE(layer->GetAnimator()->is_animating());
242 // Expect default duration (200ms for stock ash minimizing animation). 238 // Expect default duration (200ms for stock ash minimizing animation).
243 EXPECT_EQ(default_duration.InMilliseconds(), 239 EXPECT_EQ(default_duration.InMilliseconds(),
244 layer->GetAnimator()->GetTransitionDuration().InMilliseconds()); 240 layer->GetAnimator()->GetTransitionDuration().InMilliseconds());
245 window->Show(); 241 window->Show();
246 layer->GetAnimator()->StopAnimating(); 242 layer->GetAnimator()->StopAnimating();
247 } 243 }
248 } 244 }
249 245
250 } // namespace ash 246 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_layout_manager_unittest.cc ('k') | content/browser/web_contents/aura/window_slider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698