OLD | NEW |
---|---|
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/shadow_controller.h" | 5 #include "ui/views/corewm/shadow_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/shell.h" | 10 #include "ui/aura/test/aura_test_base.h" |
Daniel Erat
2012/11/13 22:40:01
nit: alphabetize
| |
11 #include "ash/test/ash_test_base.h" | |
12 #include "ash/wm/shadow.h" | |
13 #include "ash/wm/shadow_types.h" | |
14 #include "ash/wm/window_properties.h" | |
15 #include "ash/wm/window_util.h" | 11 #include "ash/wm/window_util.h" |
16 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
17 #include "ui/aura/client/activation_client.h" | 13 #include "ui/aura/client/activation_client.h" |
18 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
19 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
20 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
17 #include "ui/views/corewm/shadow.h" | |
18 #include "ui/views/corewm/shadow_types.h" | |
21 | 19 |
22 namespace ash { | 20 namespace views { |
23 namespace internal { | 21 namespace corewm { |
24 | 22 |
25 typedef ash::test::AshTestBase ShadowControllerTest; | 23 class ShadowControllerTest : public aura::test::AuraTestBase { |
24 public: | |
25 ShadowControllerTest() {} | |
26 virtual ~ShadowControllerTest() {} | |
27 | |
28 virtual void SetUp() OVERRIDE { | |
29 AuraTestBase::SetUp(); | |
30 shadow_controller_.reset(new ShadowController(root_window())); | |
31 } | |
32 virtual void TearDown() OVERRIDE { | |
33 shadow_controller_.reset(); | |
34 AuraTestBase::TearDown(); | |
35 } | |
36 | |
37 protected: | |
38 ShadowController* shadow_controller() { return shadow_controller_.get(); } | |
39 | |
40 void ActivateWindow(aura::Window* window) { | |
41 DCHECK(window); | |
42 DCHECK(window->GetRootWindow()); | |
43 aura::client::GetActivationClient(window->GetRootWindow())->ActivateWindow( | |
44 window); | |
45 } | |
46 | |
47 private: | |
48 scoped_ptr<ShadowController> shadow_controller_; | |
49 | |
50 DISALLOW_COPY_AND_ASSIGN(ShadowControllerTest); | |
51 }; | |
26 | 52 |
27 // Tests that various methods in Window update the Shadow object as expected. | 53 // Tests that various methods in Window update the Shadow object as expected. |
28 TEST_F(ShadowControllerTest, Shadow) { | 54 TEST_F(ShadowControllerTest, Shadow) { |
29 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 55 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
30 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 56 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
31 window->Init(ui::LAYER_TEXTURED); | 57 window->Init(ui::LAYER_TEXTURED); |
32 window->SetParent(NULL); | 58 window->SetParent(NULL); |
33 | 59 |
34 // We should create the shadow before the window is visible (the shadow's | 60 // We should create the shadow before the window is visible (the shadow's |
35 // layer won't get drawn yet since it's a child of the window's layer). | 61 // layer won't get drawn yet since it's a child of the window's layer). |
36 internal::ShadowController::TestApi api( | 62 ShadowController::TestApi api(shadow_controller()); |
37 ash::Shell::GetInstance()->shadow_controller()); | 63 const Shadow* shadow = api.GetShadowForWindow(window.get()); |
38 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); | |
39 ASSERT_TRUE(shadow != NULL); | 64 ASSERT_TRUE(shadow != NULL); |
40 EXPECT_TRUE(shadow->layer()->visible()); | 65 EXPECT_TRUE(shadow->layer()->visible()); |
41 | 66 |
42 // The shadow should remain visible after window visibility changes. | 67 // The shadow should remain visible after window visibility changes. |
43 window->Show(); | 68 window->Show(); |
44 EXPECT_TRUE(shadow->layer()->visible()); | 69 EXPECT_TRUE(shadow->layer()->visible()); |
45 window->Hide(); | 70 window->Hide(); |
46 EXPECT_TRUE(shadow->layer()->visible()); | 71 EXPECT_TRUE(shadow->layer()->visible()); |
47 | 72 |
48 // If the shadow is disabled, it should be hidden. | 73 // If the shadow is disabled, it should be hidden. |
49 internal::SetShadowType(window.get(), internal::SHADOW_TYPE_NONE); | 74 SetShadowType(window.get(), SHADOW_TYPE_NONE); |
50 window->Show(); | 75 window->Show(); |
51 EXPECT_FALSE(shadow->layer()->visible()); | 76 EXPECT_FALSE(shadow->layer()->visible()); |
52 internal::SetShadowType(window.get(), internal::SHADOW_TYPE_RECTANGULAR); | 77 SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR); |
53 EXPECT_TRUE(shadow->layer()->visible()); | 78 EXPECT_TRUE(shadow->layer()->visible()); |
54 | 79 |
55 // The shadow's layer should be a child of the window's layer. | 80 // The shadow's layer should be a child of the window's layer. |
56 EXPECT_EQ(window->layer(), shadow->layer()->parent()); | 81 EXPECT_EQ(window->layer(), shadow->layer()->parent()); |
57 | 82 |
58 window->parent()->RemoveChild(window.get()); | 83 window->parent()->RemoveChild(window.get()); |
59 aura::Window* window_ptr = window.get(); | 84 aura::Window* window_ptr = window.get(); |
60 window.reset(); | 85 window.reset(); |
61 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); | 86 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); |
62 } | 87 } |
63 | 88 |
64 // Tests that the window's shadow's bounds are updated correctly. | 89 // Tests that the window's shadow's bounds are updated correctly. |
65 TEST_F(ShadowControllerTest, ShadowBounds) { | 90 TEST_F(ShadowControllerTest, ShadowBounds) { |
66 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 91 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
67 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 92 window->SetType(aura::client::WINDOW_TYPE_NORMAL); |
68 window->Init(ui::LAYER_TEXTURED); | 93 window->Init(ui::LAYER_TEXTURED); |
69 window->SetParent(NULL); | 94 window->SetParent(NULL); |
70 window->Show(); | 95 window->Show(); |
71 | 96 |
72 const gfx::Rect kOldBounds(20, 30, 400, 300); | 97 const gfx::Rect kOldBounds(20, 30, 400, 300); |
73 window->SetBounds(kOldBounds); | 98 window->SetBounds(kOldBounds); |
74 | 99 |
75 // When the shadow is first created, it should use the window's size (but | 100 // When the shadow is first created, it should use the window's size (but |
76 // remain at the origin, since it's a child of the window's layer). | 101 // remain at the origin, since it's a child of the window's layer). |
77 internal::SetShadowType(window.get(), internal::SHADOW_TYPE_RECTANGULAR); | 102 SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR); |
78 internal::ShadowController::TestApi api( | 103 ShadowController::TestApi api(shadow_controller()); |
79 ash::Shell::GetInstance()->shadow_controller()); | 104 const Shadow* shadow = api.GetShadowForWindow(window.get()); |
80 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); | |
81 ASSERT_TRUE(shadow != NULL); | 105 ASSERT_TRUE(shadow != NULL); |
82 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), | 106 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), |
83 shadow->content_bounds().ToString()); | 107 shadow->content_bounds().ToString()); |
84 | 108 |
85 // When we change the window's bounds, the shadow's should be updated too. | 109 // When we change the window's bounds, the shadow's should be updated too. |
86 gfx::Rect kNewBounds(50, 60, 500, 400); | 110 gfx::Rect kNewBounds(50, 60, 500, 400); |
87 window->SetBounds(kNewBounds); | 111 window->SetBounds(kNewBounds); |
88 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(), | 112 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(), |
89 shadow->content_bounds().ToString()); | 113 shadow->content_bounds().ToString()); |
90 } | 114 } |
91 | 115 |
92 // Tests that activating a window changes the shadow style. | 116 // Tests that activating a window changes the shadow style. |
93 TEST_F(ShadowControllerTest, ShadowStyle) { | 117 TEST_F(ShadowControllerTest, ShadowStyle) { |
94 ShadowController::TestApi api( | 118 ShadowController::TestApi api(shadow_controller()); |
95 ash::Shell::GetInstance()->shadow_controller()); | |
96 | 119 |
97 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); | 120 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); |
98 window1->SetType(aura::client::WINDOW_TYPE_NORMAL); | 121 window1->SetType(aura::client::WINDOW_TYPE_NORMAL); |
99 window1->Init(ui::LAYER_TEXTURED); | 122 window1->Init(ui::LAYER_TEXTURED); |
100 window1->SetParent(NULL); | 123 window1->SetParent(NULL); |
101 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); | 124 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); |
102 window1->Show(); | 125 window1->Show(); |
103 wm::ActivateWindow(window1.get()); | 126 ActivateWindow(window1.get()); |
104 | 127 |
105 // window1 is active, so style should have active appearance. | 128 // window1 is active, so style should have active appearance. |
106 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); | 129 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); |
107 ASSERT_TRUE(shadow1 != NULL); | 130 ASSERT_TRUE(shadow1 != NULL); |
108 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 131 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
109 | 132 |
110 // Create another window and activate it. | 133 // Create another window and activate it. |
111 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); | 134 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); |
112 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); | 135 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); |
113 window2->Init(ui::LAYER_TEXTURED); | 136 window2->Init(ui::LAYER_TEXTURED); |
114 window2->SetParent(NULL); | 137 window2->SetParent(NULL); |
115 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); | 138 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); |
116 window2->Show(); | 139 window2->Show(); |
117 wm::ActivateWindow(window2.get()); | 140 ActivateWindow(window2.get()); |
118 | 141 |
119 // window1 is now inactive, so shadow should go inactive. | 142 // window1 is now inactive, so shadow should go inactive. |
120 Shadow* shadow2 = api.GetShadowForWindow(window2.get()); | 143 Shadow* shadow2 = api.GetShadowForWindow(window2.get()); |
121 ASSERT_TRUE(shadow2 != NULL); | 144 ASSERT_TRUE(shadow2 != NULL); |
122 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow1->style()); | 145 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow1->style()); |
123 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style()); | 146 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style()); |
124 } | 147 } |
125 | 148 |
126 // Tests that we use smaller shadows for tooltips and menus. | 149 // Tests that we use smaller shadows for tooltips and menus. |
127 TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) { | 150 TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) { |
128 ShadowController::TestApi api( | 151 ShadowController::TestApi api(shadow_controller()); |
129 ash::Shell::GetInstance()->shadow_controller()); | |
130 | 152 |
131 scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL)); | 153 scoped_ptr<aura::Window> tooltip_window(new aura::Window(NULL)); |
132 tooltip_window->SetType(aura::client::WINDOW_TYPE_TOOLTIP); | 154 tooltip_window->SetType(aura::client::WINDOW_TYPE_TOOLTIP); |
133 tooltip_window->Init(ui::LAYER_TEXTURED); | 155 tooltip_window->Init(ui::LAYER_TEXTURED); |
134 tooltip_window->SetParent(NULL); | 156 tooltip_window->SetParent(NULL); |
135 tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400)); | 157 tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400)); |
136 tooltip_window->Show(); | 158 tooltip_window->Show(); |
137 | 159 |
138 Shadow* tooltip_shadow = api.GetShadowForWindow(tooltip_window.get()); | 160 Shadow* tooltip_shadow = api.GetShadowForWindow(tooltip_window.get()); |
139 ASSERT_TRUE(tooltip_shadow != NULL); | 161 ASSERT_TRUE(tooltip_shadow != NULL); |
140 EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style()); | 162 EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style()); |
141 | 163 |
142 scoped_ptr<aura::Window> menu_window(new aura::Window(NULL)); | 164 scoped_ptr<aura::Window> menu_window(new aura::Window(NULL)); |
143 menu_window->SetType(aura::client::WINDOW_TYPE_MENU); | 165 menu_window->SetType(aura::client::WINDOW_TYPE_MENU); |
144 menu_window->Init(ui::LAYER_TEXTURED); | 166 menu_window->Init(ui::LAYER_TEXTURED); |
145 menu_window->SetParent(NULL); | 167 menu_window->SetParent(NULL); |
146 menu_window->SetBounds(gfx::Rect(10, 20, 300, 400)); | 168 menu_window->SetBounds(gfx::Rect(10, 20, 300, 400)); |
147 menu_window->Show(); | 169 menu_window->Show(); |
148 | 170 |
149 Shadow* menu_shadow = api.GetShadowForWindow(tooltip_window.get()); | 171 Shadow* menu_shadow = api.GetShadowForWindow(tooltip_window.get()); |
150 ASSERT_TRUE(menu_shadow != NULL); | 172 ASSERT_TRUE(menu_shadow != NULL); |
151 EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style()); | 173 EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style()); |
152 } | 174 } |
153 | 175 |
154 // http://crbug.com/120210 - transient parents of certain types of transients | 176 // http://crbug.com/120210 - transient parents of certain types of transients |
155 // should not lose their shadow when they lose activation to the transient. | 177 // should not lose their shadow when they lose activation to the transient. |
156 TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) { | 178 TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) { |
157 ShadowController::TestApi api( | 179 ShadowController::TestApi api(shadow_controller()); |
158 ash::Shell::GetInstance()->shadow_controller()); | |
159 | 180 |
160 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); | 181 scoped_ptr<aura::Window> window1(new aura::Window(NULL)); |
161 window1->SetType(aura::client::WINDOW_TYPE_NORMAL); | 182 window1->SetType(aura::client::WINDOW_TYPE_NORMAL); |
162 window1->Init(ui::LAYER_TEXTURED); | 183 window1->Init(ui::LAYER_TEXTURED); |
163 window1->SetParent(NULL); | 184 window1->SetParent(NULL); |
164 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); | 185 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); |
165 window1->Show(); | 186 window1->Show(); |
166 wm::ActivateWindow(window1.get()); | 187 ActivateWindow(window1.get()); |
167 | 188 |
168 // window1 is active, so style should have active appearance. | 189 // window1 is active, so style should have active appearance. |
169 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); | 190 Shadow* shadow1 = api.GetShadowForWindow(window1.get()); |
170 ASSERT_TRUE(shadow1 != NULL); | 191 ASSERT_TRUE(shadow1 != NULL); |
171 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 192 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
172 | 193 |
173 // Create a window that is transient to window1, and that has the 'hide on | 194 // Create a window that is transient to window1, and that has the 'hide on |
174 // deactivate' property set. Upon activation, window1 should still have an | 195 // deactivate' property set. Upon activation, window1 should still have an |
175 // active shadow. | 196 // active shadow. |
176 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); | 197 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); |
177 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); | 198 window2->SetType(aura::client::WINDOW_TYPE_NORMAL); |
178 window2->Init(ui::LAYER_TEXTURED); | 199 window2->Init(ui::LAYER_TEXTURED); |
179 window2->SetParent(NULL); | 200 window2->SetParent(NULL); |
180 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); | 201 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); |
181 window1->AddTransientChild(window2.get()); | 202 window1->AddTransientChild(window2.get()); |
182 aura::client::SetHideOnDeactivate(window2.get(), true); | 203 aura::client::SetHideOnDeactivate(window2.get(), true); |
183 window2->Show(); | 204 window2->Show(); |
184 wm::ActivateWindow(window2.get()); | 205 ActivateWindow(window2.get()); |
185 | 206 |
186 // window1 is now inactive, but its shadow should still appear active. | 207 // window1 is now inactive, but its shadow should still appear active. |
187 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); | 208 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); |
188 } | 209 } |
189 | 210 |
190 } // namespace internal | 211 } // namespace corewm |
191 } // namespace ash | 212 } // namespace views |
OLD | NEW |