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

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

Issue 10882043: Revert 153291 - Fixes crash introduced @ 153047 (you can hit crash by maximizing a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « ash/wm/window_animations.cc ('k') | ui/compositor/layer_animation_observer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 class WindowAnimationsTest : public ash::test::AshTestBase { 22 typedef ash::test::AshTestBase WindowAnimationsTest;
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 };
34 23
35 TEST_F(WindowAnimationsTest, HideShow) { 24 TEST_F(WindowAnimationsTest, HideShow) {
36 scoped_ptr<aura::Window> window( 25 scoped_ptr<aura::Window> window(
37 aura::test::CreateTestWindowWithId(0, NULL)); 26 aura::test::CreateTestWindowWithId(0, NULL));
38 window->Show(); 27 window->Show();
39 EXPECT_TRUE(window->layer()->visible()); 28 EXPECT_TRUE(window->layer()->visible());
40 // Hiding. 29 // Hiding.
41 SetWindowVisibilityAnimationType( 30 SetWindowVisibilityAnimationType(
42 window.get(), 31 window.get(),
43 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE); 32 WINDOW_VISIBILITY_ANIMATION_TYPE_WORKSPACE_HIDE);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // Layer target visibility changes according to Show/Hide. 133 // Layer target visibility changes according to Show/Hide.
145 window->Show(); 134 window->Show();
146 EXPECT_TRUE(window->layer()->GetTargetVisibility()); 135 EXPECT_TRUE(window->layer()->GetTargetVisibility());
147 window->Hide(); 136 window->Hide();
148 EXPECT_FALSE(window->layer()->GetTargetVisibility()); 137 EXPECT_FALSE(window->layer()->GetTargetVisibility());
149 window->Show(); 138 window->Show();
150 EXPECT_TRUE(window->layer()->GetTargetVisibility()); 139 EXPECT_TRUE(window->layer()->GetTargetVisibility());
151 } 140 }
152 141
153 TEST_F(WindowAnimationsTest, CrossFadeToBounds) { 142 TEST_F(WindowAnimationsTest, CrossFadeToBounds) {
154 ui::LayerAnimator::set_disable_animations_for_test(false); 143 internal::SetDelayedOldLayerDeletionInCrossFadeForTest(true);
155 144
156 scoped_ptr<Window> window( 145 scoped_ptr<Window> window(
157 aura::test::CreateTestWindowWithId(0, NULL)); 146 aura::test::CreateTestWindowWithId(0, NULL));
158 window->SetBounds(gfx::Rect(5, 10, 320, 240)); 147 window->SetBounds(gfx::Rect(5, 10, 320, 240));
159 window->Show(); 148 window->Show();
160 149
161 Layer* old_layer = window->layer(); 150 Layer* old_layer = window->layer();
162 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); 151 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity());
163 152
164 // Cross fade to a larger size, as in a maximize animation. 153 // Cross fade to a larger size, as in a maximize animation.
165 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480)); 154 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480));
166 // Window's layer has been replaced. 155 // Window's layer has been replaced.
167 EXPECT_NE(old_layer, window->layer()); 156 EXPECT_NE(old_layer, window->layer());
168 // Original layer stays opaque and stretches to new size. 157 // Original layer stays opaque and stretches to new size.
169 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity()); 158 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity());
170 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString()); 159 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString());
171 ui::Transform grow_transform; 160 ui::Transform grow_transform;
172 grow_transform.ConcatScale(640.f / 320.f, 480.f / 240.f); 161 grow_transform.ConcatScale(640.f / 320.f, 480.f / 240.f);
173 grow_transform.ConcatTranslate(-5.f, -10.f); 162 grow_transform.ConcatTranslate(-5.f, -10.f);
174 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform()); 163 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform());
175 // New layer animates in to the identity transform. 164 // New layer animates in to the identity transform.
176 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); 165 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
177 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform()); 166 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform());
178 167
179 // Run the animations to completion. 168 // Allow the animation observer to delete itself.
180 old_layer->GetAnimator()->StopAnimating(); 169 RunAllPendingInMessageLoop();
181 window->layer()->GetAnimator()->StopAnimating();
182 170
183 // Cross fade to a smaller size, as in a restore animation. 171 // Cross fade to a smaller size, as in a restore animation.
184 old_layer = window->layer(); 172 old_layer = window->layer();
185 CrossFadeToBounds(window.get(), gfx::Rect(5, 10, 320, 240)); 173 CrossFadeToBounds(window.get(), gfx::Rect(5, 10, 320, 240));
186 // Again, window layer has been replaced. 174 // Again, window layer has been replaced.
187 EXPECT_NE(old_layer, window->layer()); 175 EXPECT_NE(old_layer, window->layer());
188 // Original layer fades out and stretches down to new size. 176 // Original layer fades out and stretches down to new size.
189 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity()); 177 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity());
190 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString()); 178 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString());
191 ui::Transform shrink_transform; 179 ui::Transform shrink_transform;
192 shrink_transform.ConcatScale(320.f / 640.f, 240.f / 480.f); 180 shrink_transform.ConcatScale(320.f / 640.f, 240.f / 480.f);
193 shrink_transform.ConcatTranslate(5.f, 10.f); 181 shrink_transform.ConcatTranslate(5.f, 10.f);
194 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform()); 182 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform());
195 // New layer animates in to the identity transform. 183 // New layer animates in to the identity transform.
196 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); 184 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
197 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform()); 185 EXPECT_EQ(ui::Transform(), window->layer()->GetTargetTransform());
198 186
199 old_layer->GetAnimator()->StopAnimating(); 187 RunAllPendingInMessageLoop();
200 window->layer()->GetAnimator()->StopAnimating(); 188 internal::SetDelayedOldLayerDeletionInCrossFadeForTest(false);
201 } 189 }
202 190
203 TEST_F(WindowAnimationsTest, GetCrossFadeDuration) { 191 TEST_F(WindowAnimationsTest, GetCrossFadeDuration) {
204 gfx::Rect empty; 192 gfx::Rect empty;
205 gfx::Rect screen(0, 0, 1000, 500); 193 gfx::Rect screen(0, 0, 1000, 500);
206 194
207 // No change takes no time. 195 // No change takes no time.
208 EXPECT_EQ(0, GetCrossFadeDuration(empty, empty).InMilliseconds()); 196 EXPECT_EQ(0, GetCrossFadeDuration(empty, empty).InMilliseconds());
209 EXPECT_EQ(0, GetCrossFadeDuration(screen, screen).InMilliseconds()); 197 EXPECT_EQ(0, GetCrossFadeDuration(screen, screen).InMilliseconds());
210 198
(...skipping 16 matching lines...) Expand all
227 // Medium changes take medium time. 215 // Medium changes take medium time.
228 gfx::Rect half_screen(10, 10, 500, 250); 216 gfx::Rect half_screen(10, 10, 500, 250);
229 EXPECT_EQ(kMinimum + kRange * 3 / 4, 217 EXPECT_EQ(kMinimum + kRange * 3 / 4,
230 GetCrossFadeDuration(half_screen, screen).InMilliseconds()); 218 GetCrossFadeDuration(half_screen, screen).InMilliseconds());
231 EXPECT_EQ(kMinimum + kRange * 3 / 4, 219 EXPECT_EQ(kMinimum + kRange * 3 / 4,
232 GetCrossFadeDuration(screen, half_screen).InMilliseconds()); 220 GetCrossFadeDuration(screen, half_screen).InMilliseconds());
233 } 221 }
234 222
235 } // namespace internal 223 } // namespace internal
236 } // namespace ash 224 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_animations.cc ('k') | ui/compositor/layer_animation_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698