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