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

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

Issue 12342028: make menus, bubbles, etc. top level windows on aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 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
« no previous file with comments | « ui/views/corewm/window_animations.cc ('k') | ui/views/views.gyp » ('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 "ui/views/corewm/window_animations.h" 5 #include "ui/views/corewm/window_animations.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "ui/aura/client/animation_host.h"
8 #include "ui/aura/test/aura_test_base.h" 9 #include "ui/aura/test/aura_test_base.h"
9 #include "ui/aura/test/test_windows.h" 10 #include "ui/aura/test/test_windows.h"
10 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
11 #include "ui/base/animation/animation_container_element.h" 12 #include "ui/base/animation/animation_container_element.h"
12 #include "ui/compositor/layer.h" 13 #include "ui/compositor/layer.h"
13 #include "ui/compositor/layer_animator.h" 14 #include "ui/compositor/layer_animator.h"
14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 15 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
15 16
16 using aura::Window; 17 using aura::Window;
17 using ui::Layer; 18 using ui::Layer;
18 19
19 namespace views { 20 namespace views {
20 namespace corewm { 21 namespace corewm {
21 22
22 class WindowAnimationsTest : public aura::test::AuraTestBase { 23 class WindowAnimationsTest : public aura::test::AuraTestBase {
23 public: 24 public:
24 WindowAnimationsTest() {} 25 WindowAnimationsTest() {}
25 26
26 virtual void TearDown() OVERRIDE { 27 virtual void TearDown() OVERRIDE {
27 AuraTestBase::TearDown(); 28 AuraTestBase::TearDown();
28 } 29 }
29 30
30 private: 31 private:
31 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest); 32 DISALLOW_COPY_AND_ASSIGN(WindowAnimationsTest);
32 }; 33 };
33 34
34 TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) {
35 scoped_ptr<aura::Window> window(
36 aura::test::CreateTestWindowWithId(0, NULL));
37 window->Show();
38 EXPECT_TRUE(window->layer()->visible());
39
40 // Hiding.
41 SetWindowVisibilityAnimationType(
42 window.get(),
43 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE);
44 AnimateOnChildWindowVisibilityChanged(window.get(), false);
45 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity());
46 EXPECT_FALSE(window->layer()->GetTargetVisibility());
47 EXPECT_FALSE(window->layer()->visible());
48
49 // Showing.
50 SetWindowVisibilityAnimationType(
51 window.get(),
52 WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE);
53 AnimateOnChildWindowVisibilityChanged(window.get(), true);
54 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness());
55 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale());
56 EXPECT_TRUE(window->layer()->visible());
57
58 // Stays shown.
59 ui::AnimationContainerElement* element =
60 static_cast<ui::AnimationContainerElement*>(
61 window->layer()->GetAnimator());
62 element->Step(base::TimeTicks::Now() +
63 base::TimeDelta::FromSeconds(5));
64 EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness());
65 EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale());
66 EXPECT_TRUE(window->layer()->visible());
67 }
68
69 TEST_F(WindowAnimationsTest, LayerTargetVisibility) { 35 TEST_F(WindowAnimationsTest, LayerTargetVisibility) {
70 scoped_ptr<aura::Window> window( 36 scoped_ptr<aura::Window> window(
71 aura::test::CreateTestWindowWithId(0, NULL)); 37 aura::test::CreateTestWindowWithId(0, NULL));
72 38
73 // Layer target visibility changes according to Show/Hide. 39 // Layer target visibility changes according to Show/Hide.
74 window->Show(); 40 window->Show();
75 EXPECT_TRUE(window->layer()->GetTargetVisibility()); 41 EXPECT_TRUE(window->layer()->GetTargetVisibility());
76 window->Hide(); 42 window->Hide();
77 EXPECT_FALSE(window->layer()->GetTargetVisibility()); 43 EXPECT_FALSE(window->layer()->GetTargetVisibility());
78 window->Show(); 44 window->Show();
79 EXPECT_TRUE(window->layer()->GetTargetVisibility()); 45 EXPECT_TRUE(window->layer()->GetTargetVisibility());
80 } 46 }
81 47
82 TEST_F(WindowAnimationsTest, CrossFadeToBounds) { 48 // A simple AnimationHost implementation for the NotifyHideCompleted test.
83 ui::ScopedAnimationDurationScaleMode normal_duration_mode( 49 class NotifyHideCompletedAnimationHost : public aura::client::AnimationHost {
84 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 50 public:
51 NotifyHideCompletedAnimationHost() : hide_completed_(false) {}
52 virtual ~NotifyHideCompletedAnimationHost() {}
85 53
86 scoped_ptr<Window> window( 54 // Overridden from TestWindowDelegate:
87 aura::test::CreateTestWindowWithId(0, NULL)); 55 virtual void OnWindowHidingAnimationCompleted() OVERRIDE {
88 window->SetBounds(gfx::Rect(5, 10, 320, 240)); 56 hide_completed_ = true;
89 window->Show(); 57 }
90 58
91 Layer* old_layer = window->layer(); 59 virtual void SetHostTransitionBounds(const gfx::Rect& bounds) OVERRIDE {}
92 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity());
93 60
94 // Cross fade to a larger size, as in a maximize animation. 61 bool hide_completed() const { return hide_completed_; }
95 CrossFadeToBounds(window.get(), gfx::Rect(0, 0, 640, 480));
96 // Window's layer has been replaced.
97 EXPECT_NE(old_layer, window->layer());
98 // Original layer stays opaque and stretches to new size.
99 EXPECT_EQ(1.0f, old_layer->GetTargetOpacity());
100 EXPECT_EQ("5,10 320x240", old_layer->bounds().ToString());
101 gfx::Transform grow_transform;
102 grow_transform.Translate(-5.f, -10.f);
103 grow_transform.Scale(640.f / 320.f, 480.f / 240.f);
104 EXPECT_EQ(grow_transform, old_layer->GetTargetTransform());
105 // New layer animates in to the identity transform.
106 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
107 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform());
108 62
109 // Run the animations to completion. 63 private:
110 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step( 64 bool hide_completed_;
111 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
112 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())->
113 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
114 65
115 // Cross fade to a smaller size, as in a restore animation. 66 DISALLOW_COPY_AND_ASSIGN(NotifyHideCompletedAnimationHost);
116 old_layer = window->layer(); 67 };
117 CrossFadeToBounds(window.get(), gfx::Rect(5, 10, 320, 240));
118 // Again, window layer has been replaced.
119 EXPECT_NE(old_layer, window->layer());
120 // Original layer fades out and stretches down to new size.
121 EXPECT_EQ(0.0f, old_layer->GetTargetOpacity());
122 EXPECT_EQ("0,0 640x480", old_layer->bounds().ToString());
123 gfx::Transform shrink_transform;
124 shrink_transform.Translate(5.f, 10.f);
125 shrink_transform.Scale(320.f / 640.f, 240.f / 480.f);
126 EXPECT_EQ(shrink_transform, old_layer->GetTargetTransform());
127 // New layer animates in to the identity transform.
128 EXPECT_EQ(1.0f, window->layer()->GetTargetOpacity());
129 EXPECT_EQ(gfx::Transform(), window->layer()->GetTargetTransform());
130 68
131 static_cast<ui::AnimationContainerElement*>(old_layer->GetAnimator())->Step( 69 TEST_F(WindowAnimationsTest, NotifyHideCompleted) {
132 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 70 NotifyHideCompletedAnimationHost animation_host;
133 static_cast<ui::AnimationContainerElement*>(window->layer()->GetAnimator())-> 71 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithId(0, NULL));
134 Step(base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1)); 72 aura::client::SetAnimationHost(window.get(), &animation_host);
73 views::corewm::SetWindowVisibilityAnimationType(
74 window.get(), WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
75 AnimateOnChildWindowVisibilityChanged(window.get(), true);
76 EXPECT_TRUE(window->layer()->visible());
77
78 EXPECT_FALSE(animation_host.hide_completed());
79 AnimateOnChildWindowVisibilityChanged(window.get(), false);
80 EXPECT_TRUE(animation_host.hide_completed());
135 } 81 }
136 82
137 } // namespace internal 83 } // namespace corewm
138 } // namespace ash 84 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/window_animations.cc ('k') | ui/views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698