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

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

Issue 82573002: Changes sequence of docked animations when evicting windows from dock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes sequence of docked animations (nits) Created 7 years 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
« no previous file with comments | « ash/wm/window_animations.cc ('k') | ui/compositor/layer_animator.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 "ash/wm/window_state.h"
9 #include "ash/wm/workspace_controller.h" 10 #include "ash/wm/workspace_controller.h"
10 #include "base/time/time.h" 11 #include "base/time/time.h"
11 #include "ui/aura/test/test_windows.h" 12 #include "ui/aura/test/test_windows.h"
12 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
13 #include "ui/compositor/layer.h" 14 #include "ui/compositor/layer.h"
15 #include "ui/compositor/layer_animation_observer.h"
14 #include "ui/compositor/layer_animator.h" 16 #include "ui/compositor/layer_animator.h"
15 #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"
16 #include "ui/gfx/animation/animation_container_element.h" 19 #include "ui/gfx/animation/animation_container_element.h"
17 20
18 using aura::Window; 21 using aura::Window;
19 using ui::Layer; 22 using ui::Layer;
20 23
21 namespace ash { 24 namespace ash {
22 namespace internal { 25 namespace internal {
23 26
24 class WindowAnimationsTest : public ash::test::AshTestBase { 27 class WindowAnimationsTest : public ash::test::AshTestBase {
25 public: 28 public:
26 WindowAnimationsTest() {} 29 WindowAnimationsTest() {}
27 30
28 virtual void TearDown() OVERRIDE { 31 virtual void TearDown() OVERRIDE {
29 AshTestBase::TearDown(); 32 AshTestBase::TearDown();
30 } 33 }
31 34
32 private: 35 private:
33 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); 36 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest);
34 }; 37 };
35 38
39 // Listens to animation scheduled notifications. Remembers the transition
40 // duration of the first sequence.
41 class MinimizeAnimationObserver : public ui::LayerAnimationObserver {
42 public:
43 explicit MinimizeAnimationObserver(ui::LayerAnimator* animator)
44 : animator_(animator) {
45 animator_->AddObserver(this);
46 // RemoveObserver is called when the first animation is scheduled and so
47 // there should be no need for now to remove it in destructor.
48 };
49 base::TimeDelta duration() { return duration_; }
50
51 protected:
52 // ui::LayerAnimationObserver:
53 virtual void OnLayerAnimationScheduled(
54 ui::LayerAnimationSequence* sequence) OVERRIDE {
55 duration_ = animator_->GetTransitionDuration();
56 animator_->RemoveObserver(this);
57 }
58 virtual void OnLayerAnimationEnded(
59 ui::LayerAnimationSequence* sequence) OVERRIDE {}
60 virtual void OnLayerAnimationAborted(
61 ui::LayerAnimationSequence* sequence) OVERRIDE {}
62
63 private:
64 ui::LayerAnimator* animator_;
65 base::TimeDelta duration_;
66
67 DISALLOW_COPY_AND_ASSIGN(MinimizeAnimationObserver);
68 };
69
36 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { 70 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) {
37 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 71 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
38 window->Show(); 72 window->Show();
39 EXPECT_TRUE(window->layer()->visible()); 73 EXPECT_TRUE(window->layer()->visible());
40 74
41 // Hiding. 75 // Hiding.
42 views::corewm::SetWindowVisibilityAnimationType( 76 views::corewm::SetWindowVisibilityAnimationType(
43 window.get(), 77 window.get(),
44 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); 78 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE);
45 AnimateOnChildWindowVisibilityChanged(window.get(), false); 79 AnimateOnChildWindowVisibilityChanged(window.get(), false);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // New layer animates in to the identity transform. 160 // New layer animates in to the identity transform.
127 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity()); 161 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
128 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform()); 162 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform());
129 163
130 static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step( 164 static_cast<gfx::AnimationContainerElement*>(old_layer->GetAnimator())->Step(
131 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 165 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
132 static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())-> 166 static_cast<gfx::AnimationContainerElement*>(window->layer()->GetAnimator())->
133 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 167 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
134 } 168 }
135 169
170 TEST_F(WindowAnimationsTest, LockAnimationDuration) {
171 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
172 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
173
174 scoped_ptr<Window> window(CreateTestWindowInShellWithId(0));
175 Layer* layer = window->layer();
176 window->SetBounds(gfx::Rect(5, 10, 320, 240));
177 window->Show();
178
179 // Test that it is possible to override transition duration when it is not
180 // locked.
181 {
182 ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator());
183 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000));
184 {
185 ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator());
186 // Duration is not locked so it gets overridden.
187 settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50));
188 wm::GetWindowState(window.get())->Minimize();
189 EXPECT_TRUE(layer->GetAnimator()->is_animating());
190 // Expect duration from the inner scope
191 EXPECT_EQ(50,
192 layer->GetAnimator()->GetTransitionDuration().InMilliseconds());
193 }
194 window->Show();
195 layer->GetAnimator()->StopAnimating();
196 }
197
198 // Test that it is possible to lock transition duration
199 {
200 ui::ScopedLayerAnimationSettings settings1(layer->GetAnimator());
201 settings1.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000));
202 // Duration is locked in outer scope.
203 settings1.LockTransitionDuration();
204 {
205 ui::ScopedLayerAnimationSettings settings2(layer->GetAnimator());
206 // Transition duration setting is ignored.
207 settings2.SetTransitionDuration(base::TimeDelta::FromMilliseconds(50));
208 wm::GetWindowState(window.get())->Minimize();
209 EXPECT_TRUE(layer->GetAnimator()->is_animating());
210 // Expect duration from the outer scope
211 EXPECT_EQ(1000,
212 layer->GetAnimator()->GetTransitionDuration().InMilliseconds());
213 }
214 window->Show();
215 layer->GetAnimator()->StopAnimating();
216 }
217
218 // Test that duration respects default.
219 {
220 // Query default duration.
221 MinimizeAnimationObserver observer(layer->GetAnimator());
222 wm::GetWindowState(window.get())->Minimize();
223 EXPECT_TRUE(layer->GetAnimator()->is_animating());
224 base::TimeDelta default_duration(observer.duration());
225 window->Show();
226 layer->GetAnimator()->StopAnimating();
227
228 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
229 settings.LockTransitionDuration();
230 // Setting transition duration is ignored since duration is locked
231 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000));
232 wm::GetWindowState(window.get())->Minimize();
233 EXPECT_TRUE(layer->GetAnimator()->is_animating());
234 // Expect default duration (200ms for stock ash minimizing animation).
235 EXPECT_EQ(default_duration.InMilliseconds(),
236 layer->GetAnimator()->GetTransitionDuration().InMilliseconds());
237 window->Show();
238 layer->GetAnimator()->StopAnimating();
239 }
240 }
241
136 } // namespace internal 242 } // namespace internal
137 } // namespace ash 243 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_animations.cc ('k') | ui/compositor/layer_animator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698