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

Side by Side Diff: ui/views/corewm/window_animations_unittest.cc

Issue 180273025: Keep dedicated layers for hiding animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 "ui/views/corewm/window_animations.h" 5 #include "ui/views/corewm/window_animations.h"
6 6
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "ui/aura/client/animation_host.h" 8 #include "ui/aura/client/animation_host.h"
9 #include "ui/aura/test/aura_test_base.h" 9 #include "ui/aura/test/aura_test_base.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/compositor/layer.h" 12 #include "ui/compositor/layer.h"
13 #include "ui/compositor/layer_animator.h" 13 #include "ui/compositor/layer_animator.h"
14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
15 #include "ui/gfx/animation/animation_container_element.h" 15 #include "ui/gfx/animation/animation_container_element.h"
16 #include "ui/gfx/vector2d.h" 16 #include "ui/gfx/vector2d.h"
17 #include "ui/views/corewm/transient_window_manager.h"
18 #include "ui/views/corewm/transient_window_stacking_client.h"
19 #include "ui/views/corewm/window_util.h"
17 20
18 using aura::Window; 21 using aura::Window;
19 using ui::Layer; 22 using ui::Layer;
20 23
21 namespace views { 24 namespace views {
22 namespace corewm { 25 namespace corewm {
26 namespace {
27
28 template<typename T>int GetZPosition(const T* child) {
29 const T* parent = child->parent();
30 const std::vector<T*> children = parent->children();
31 typename std::vector<T*>::const_iterator iter =
32 std::find(children.begin(), children.end(), child);
33 DCHECK(iter != children.end());
34 return iter - children.begin();
35 }
36
37 int GetWindowZPosition(const aura::Window* child) {
38 return GetZPosition<aura::Window>(child);
39 }
40
41 int GetLayerZPosition(const ui::Layer* child) {
42 return GetZPosition<ui::Layer>(child);
43 }
44
45 } // namespace
23 46
24 class WindowAnimationsTest : public aura::test::AuraTestBase { 47 class WindowAnimationsTest : public aura::test::AuraTestBase {
25 public: 48 public:
26 WindowAnimationsTest() {} 49 WindowAnimationsTest() {}
27 50
28 virtual void TearDown() OVERRIDE { 51 virtual void TearDown() OVERRIDE {
29 AuraTestBase::TearDown(); 52 AuraTestBase::TearDown();
30 } 53 }
31 54
32 private: 55 private:
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 EXPECT_FALSE(window->layer()->GetTargetVisibility()); 118 EXPECT_FALSE(window->layer()->GetTargetVisibility());
96 EXPECT_EQ(0, window->layer()->opacity()); 119 EXPECT_EQ(0, window->layer()->opacity());
97 120
98 window->Show(); 121 window->Show();
99 AnimateOnChildWindowVisibilityChanged(window.get(), true); 122 AnimateOnChildWindowVisibilityChanged(window.get(), true);
100 EXPECT_TRUE(window->layer()->GetTargetVisibility()); 123 EXPECT_TRUE(window->layer()->GetTargetVisibility());
101 EXPECT_EQ(1, window->layer()->opacity()); 124 EXPECT_EQ(1, window->layer()->opacity());
102 EXPECT_EQ(gfx::Transform(), window->layer()->transform()); 125 EXPECT_EQ(gfx::Transform(), window->layer()->transform());
103 } 126 }
104 127
128 TEST_F(WindowAnimationsTest, HideAnimationDetachLayers) {
129 scoped_ptr<aura::Window> parent(aura::test::CreateTestWindowWithId(0, NULL));
130
131 scoped_ptr<aura::Window> other(
132 aura::test::CreateTestWindowWithId(1, parent.get()));
133
134 scoped_ptr<aura::Window> animating_window(
135 aura::test::CreateTestWindowWithId(2, parent.get()));
136 SetWindowVisibilityAnimationTransition(animating_window.get(), ANIMATE_HIDE);
137
138 EXPECT_EQ(0, GetWindowZPosition(other.get()));
139 EXPECT_EQ(1, GetWindowZPosition(animating_window.get()));
140 EXPECT_EQ(0, GetLayerZPosition(other->layer()));
141 EXPECT_EQ(1, GetLayerZPosition(animating_window->layer()));
142
143 {
144 ui::ScopedAnimationDurationScaleMode scale_mode(
145 ui::ScopedAnimationDurationScaleMode::FAST_DURATION);
146 ui::Layer* animating_layer = animating_window->layer();
147
148 animating_window->Hide();
149 EXPECT_TRUE(AnimateOnChildWindowVisibilityChanged(
150 animating_window.get(), false));
151 EXPECT_TRUE(animating_layer->GetAnimator()->is_animating());
152 EXPECT_FALSE(animating_layer->delegate());
153
154 // Make sure the Hide animation create another layer, and both are in
155 // the parent layer.
156 EXPECT_NE(animating_window->layer(), animating_layer);
157 EXPECT_TRUE(
158 std::find(parent->layer()->children().begin(),
159 parent->layer()->children().end(),
160 animating_layer) !=
161 parent->layer()->children().end());
162 EXPECT_TRUE(
163 std::find(parent->layer()->children().begin(),
164 parent->layer()->children().end(),
165 animating_window->layer()) !=
166 parent->layer()->children().end());
167 // Current layer must be already hidden.
168 EXPECT_FALSE(animating_window->layer()->visible());
169
170 EXPECT_EQ(1, GetWindowZPosition(animating_window.get()));
171 EXPECT_EQ(1, GetLayerZPosition(animating_window->layer()));
172 EXPECT_EQ(2, GetLayerZPosition(animating_layer));
173
174 parent->StackChildAtTop(other.get());
175 EXPECT_EQ(0, GetWindowZPosition(animating_window.get()));
176 EXPECT_EQ(1, GetWindowZPosition(other.get()));
177
178 EXPECT_EQ(0, GetLayerZPosition(animating_window->layer()));
179 EXPECT_EQ(1, GetLayerZPosition(other->layer()));
180 // Make sure the animating layer is on top.
181 EXPECT_EQ(2, GetLayerZPosition(animating_layer));
182
183 // Animating layer must be gone
184 animating_layer->GetAnimator()->StopAnimating();
185 EXPECT_TRUE(
186 std::find(parent->layer()->children().begin(),
187 parent->layer()->children().end(),
188 animating_layer) ==
189 parent->layer()->children().end());
190 }
191 }
192
193 TEST_F(WindowAnimationsTest, HideAnimationDetachLayersWithTransientChildren) {
194 TransientWindowStackingClient transient_stacking_client;
195
196 scoped_ptr<aura::Window> parent(aura::test::CreateTestWindowWithId(0, NULL));
197
198 scoped_ptr<aura::Window> other(
199 aura::test::CreateTestWindowWithId(1, parent.get()));
200
201 scoped_ptr<aura::Window> animating_window(
202 aura::test::CreateTestWindowWithId(2, parent.get()));
203 SetWindowVisibilityAnimationTransition(animating_window.get(), ANIMATE_HIDE);
204
205 scoped_ptr<aura::Window> transient1(
206 aura::test::CreateTestWindowWithId(3, parent.get()));
207 scoped_ptr<aura::Window> transient2(
208 aura::test::CreateTestWindowWithId(4, parent.get()));
209
210 TransientWindowManager::Get(animating_window.get());
211 AddTransientChild(animating_window.get(), transient1.get());
212 AddTransientChild(animating_window.get(), transient2.get());
213
214 EXPECT_EQ(0, GetWindowZPosition(other.get()));
215 EXPECT_EQ(1, GetWindowZPosition(animating_window.get()));
216 EXPECT_EQ(2, GetWindowZPosition(transient1.get()));
217 EXPECT_EQ(3, GetWindowZPosition(transient2.get()));
218
219 {
220 ui::ScopedAnimationDurationScaleMode scale_mode(
221 ui::ScopedAnimationDurationScaleMode::FAST_DURATION);
222 ui::Layer* animating_layer = animating_window->layer();
223
224 animating_window->Hide();
225 EXPECT_TRUE(AnimateOnChildWindowVisibilityChanged(
226 animating_window.get(), false));
227 EXPECT_TRUE(animating_layer->GetAnimator()->is_animating());
228 EXPECT_FALSE(animating_layer->delegate());
229
230 EXPECT_EQ(1, GetWindowZPosition(animating_window.get()));
231 EXPECT_EQ(2, GetWindowZPosition(transient1.get()));
232 EXPECT_EQ(3, GetWindowZPosition(transient2.get()));
233
234 EXPECT_EQ(1, GetLayerZPosition(animating_window->layer()));
235 EXPECT_EQ(2, GetLayerZPosition(transient1->layer()));
236 EXPECT_EQ(3, GetLayerZPosition(transient2->layer()));
237 EXPECT_EQ(4, GetLayerZPosition(animating_layer));
238
239 parent->StackChildAtTop(other.get());
240
241 EXPECT_EQ(0, GetWindowZPosition(animating_window.get()));
242 EXPECT_EQ(1, GetWindowZPosition(transient1.get()));
243 EXPECT_EQ(2, GetWindowZPosition(transient2.get()));
244 EXPECT_EQ(3, GetWindowZPosition(other.get()));
245
246 EXPECT_EQ(0, GetLayerZPosition(animating_window->layer()));
247 EXPECT_EQ(1, GetLayerZPosition(transient1->layer()));
248 EXPECT_EQ(2, GetLayerZPosition(transient2->layer()));
249 EXPECT_EQ(3, GetLayerZPosition(other->layer()));
250 // Make sure the animating layer is on top of all windows.
251 EXPECT_EQ(4, GetLayerZPosition(animating_layer));
252 }
253 }
254
105 // A simple AnimationHost implementation for the NotifyHideCompleted test. 255 // A simple AnimationHost implementation for the NotifyHideCompleted test.
106 class NotifyHideCompletedAnimationHost : public aura::client::AnimationHost { 256 class NotifyHideCompletedAnimationHost : public aura::client::AnimationHost {
107 public: 257 public:
108 NotifyHideCompletedAnimationHost() : hide_completed_(false) {} 258 NotifyHideCompletedAnimationHost() : hide_completed_(false) {}
109 virtual ~NotifyHideCompletedAnimationHost() {} 259 virtual ~NotifyHideCompletedAnimationHost() {}
110 260
111 // Overridden from TestWindowDelegate: 261 // Overridden from TestWindowDelegate:
112 virtual void OnWindowHidingAnimationCompleted() OVERRIDE { 262 virtual void OnWindowHidingAnimationCompleted() OVERRIDE {
113 hide_completed_ = true; 263 hide_completed_ = true;
114 } 264 }
(...skipping 19 matching lines...) Expand all
134 AnimateOnChildWindowVisibilityChanged(window.get(), true); 284 AnimateOnChildWindowVisibilityChanged(window.get(), true);
135 EXPECT_TRUE(window->layer()->visible()); 285 EXPECT_TRUE(window->layer()->visible());
136 286
137 EXPECT_FALSE(animation_host.hide_completed()); 287 EXPECT_FALSE(animation_host.hide_completed());
138 AnimateOnChildWindowVisibilityChanged(window.get(), false); 288 AnimateOnChildWindowVisibilityChanged(window.get(), false);
139 EXPECT_TRUE(animation_host.hide_completed()); 289 EXPECT_TRUE(animation_host.hide_completed());
140 } 290 }
141 291
142 } // namespace corewm 292 } // namespace corewm
143 } // namespace views 293 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698