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

Side by Side Diff: ui/wm/core/shadow_controller_unittest.cc

Issue 2596743002: Replace WM shadow types (on/off) and styles (small/inactive/active) (Closed)
Patch Set: one more mechanical change Created 3 years, 11 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
« no previous file with comments | « ui/wm/core/shadow_controller.cc ('k') | ui/wm/core/shadow_types.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 "ui/wm/core/shadow_controller.h" 5 #include "ui/wm/core/shadow_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 ASSERT_TRUE(shadow != NULL); 69 ASSERT_TRUE(shadow != NULL);
70 EXPECT_TRUE(shadow->layer()->visible()); 70 EXPECT_TRUE(shadow->layer()->visible());
71 71
72 // The shadow should remain visible after window visibility changes. 72 // The shadow should remain visible after window visibility changes.
73 window->Show(); 73 window->Show();
74 EXPECT_TRUE(shadow->layer()->visible()); 74 EXPECT_TRUE(shadow->layer()->visible());
75 window->Hide(); 75 window->Hide();
76 EXPECT_TRUE(shadow->layer()->visible()); 76 EXPECT_TRUE(shadow->layer()->visible());
77 77
78 // If the shadow is disabled, it should be hidden. 78 // If the shadow is disabled, it should be hidden.
79 SetShadowType(window.get(), SHADOW_TYPE_NONE); 79 SetShadowElevation(window.get(), ShadowElevation::NONE);
80 window->Show(); 80 window->Show();
81 EXPECT_FALSE(shadow->layer()->visible()); 81 EXPECT_FALSE(shadow->layer()->visible());
82 SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR); 82 SetShadowElevation(window.get(), ShadowElevation::MEDIUM);
83 EXPECT_TRUE(shadow->layer()->visible()); 83 EXPECT_TRUE(shadow->layer()->visible());
84 84
85 // The shadow's layer should be a child of the window's layer. 85 // The shadow's layer should be a child of the window's layer.
86 EXPECT_EQ(window->layer(), shadow->layer()->parent()); 86 EXPECT_EQ(window->layer(), shadow->layer()->parent());
87 } 87 }
88 88
89 // Tests that the window's shadow's bounds are updated correctly. 89 // Tests that the window's shadow's bounds are updated correctly.
90 TEST_F(ShadowControllerTest, ShadowBounds) { 90 TEST_F(ShadowControllerTest, ShadowBounds) {
91 std::unique_ptr<aura::Window> window(new aura::Window(NULL)); 91 std::unique_ptr<aura::Window> window(new aura::Window(NULL));
92 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); 92 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
93 window->Init(ui::LAYER_TEXTURED); 93 window->Init(ui::LAYER_TEXTURED);
94 ParentWindow(window.get()); 94 ParentWindow(window.get());
95 window->Show(); 95 window->Show();
96 96
97 const gfx::Rect kOldBounds(20, 30, 400, 300); 97 const gfx::Rect kOldBounds(20, 30, 400, 300);
98 window->SetBounds(kOldBounds); 98 window->SetBounds(kOldBounds);
99 99
100 // 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
101 // 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).
102 SetShadowType(window.get(), SHADOW_TYPE_RECTANGULAR); 102 SetShadowElevation(window.get(), ShadowElevation::MEDIUM);
103 const Shadow* shadow = ShadowController::GetShadowForWindow(window.get()); 103 const Shadow* shadow = ShadowController::GetShadowForWindow(window.get());
104 ASSERT_TRUE(shadow != NULL); 104 ASSERT_TRUE(shadow != NULL);
105 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), 105 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(),
106 shadow->content_bounds().ToString()); 106 shadow->content_bounds().ToString());
107 107
108 // When we change the window's bounds, the shadow's should be updated too. 108 // When we change the window's bounds, the shadow's should be updated too.
109 gfx::Rect kNewBounds(50, 60, 500, 400); 109 gfx::Rect kNewBounds(50, 60, 500, 400);
110 window->SetBounds(kNewBounds); 110 window->SetBounds(kNewBounds);
111 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(), 111 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(),
112 shadow->content_bounds().ToString()); 112 shadow->content_bounds().ToString());
113 } 113 }
114 114
115 // Tests that activating a window changes the shadow style. 115 // Tests that activating a window changes the shadow style.
116 TEST_F(ShadowControllerTest, ShadowStyle) { 116 TEST_F(ShadowControllerTest, ShadowStyle) {
117 std::unique_ptr<aura::Window> window1(new aura::Window(NULL)); 117 std::unique_ptr<aura::Window> window1(new aura::Window(NULL));
118 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL); 118 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL);
119 window1->Init(ui::LAYER_TEXTURED); 119 window1->Init(ui::LAYER_TEXTURED);
120 ParentWindow(window1.get()); 120 ParentWindow(window1.get());
121 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); 121 window1->SetBounds(gfx::Rect(10, 20, 300, 400));
122 window1->Show(); 122 window1->Show();
123 ActivateWindow(window1.get()); 123 ActivateWindow(window1.get());
124 124
125 // window1 is active, so style should have active appearance. 125 // window1 is active, so style should have active appearance.
126 Shadow* shadow1 = ShadowController::GetShadowForWindow(window1.get()); 126 Shadow* shadow1 = ShadowController::GetShadowForWindow(window1.get());
127 ASSERT_TRUE(shadow1 != NULL); 127 ASSERT_TRUE(shadow1 != NULL);
128 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); 128 EXPECT_EQ(ShadowElevation::LARGE, shadow1->desired_elevation());
129 129
130 // Create another window and activate it. 130 // Create another window and activate it.
131 std::unique_ptr<aura::Window> window2(new aura::Window(NULL)); 131 std::unique_ptr<aura::Window> window2(new aura::Window(NULL));
132 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL); 132 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL);
133 window2->Init(ui::LAYER_TEXTURED); 133 window2->Init(ui::LAYER_TEXTURED);
134 ParentWindow(window2.get()); 134 ParentWindow(window2.get());
135 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); 135 window2->SetBounds(gfx::Rect(11, 21, 301, 401));
136 window2->Show(); 136 window2->Show();
137 ActivateWindow(window2.get()); 137 ActivateWindow(window2.get());
138 138
139 // window1 is now inactive, so shadow should go inactive. 139 // window1 is now inactive, so shadow should go inactive.
140 Shadow* shadow2 = ShadowController::GetShadowForWindow(window2.get()); 140 Shadow* shadow2 = ShadowController::GetShadowForWindow(window2.get());
141 ASSERT_TRUE(shadow2 != NULL); 141 ASSERT_TRUE(shadow2 != NULL);
142 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow1->style()); 142 EXPECT_EQ(ShadowElevation::MEDIUM, shadow1->desired_elevation());
143 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow2->style()); 143 EXPECT_EQ(ShadowElevation::LARGE, shadow2->desired_elevation());
144 } 144 }
145 145
146 // Tests that shadow gets updated when the window show state changes. 146 // Tests that shadow gets updated when the window show state changes.
147 TEST_F(ShadowControllerTest, ShowState) { 147 TEST_F(ShadowControllerTest, ShowState) {
148 std::unique_ptr<aura::Window> window(new aura::Window(NULL)); 148 std::unique_ptr<aura::Window> window(new aura::Window(NULL));
149 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); 149 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
150 window->Init(ui::LAYER_TEXTURED); 150 window->Init(ui::LAYER_TEXTURED);
151 ParentWindow(window.get()); 151 ParentWindow(window.get());
152 window->Show(); 152 window->Show();
153 153
154 Shadow* shadow = ShadowController::GetShadowForWindow(window.get()); 154 Shadow* shadow = ShadowController::GetShadowForWindow(window.get());
155 ASSERT_TRUE(shadow != NULL); 155 ASSERT_TRUE(shadow != NULL);
156 EXPECT_EQ(Shadow::STYLE_INACTIVE, shadow->style()); 156 EXPECT_EQ(ShadowElevation::MEDIUM, shadow->desired_elevation());
157 157
158 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 158 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
159 EXPECT_FALSE(shadow->layer()->visible()); 159 EXPECT_FALSE(shadow->layer()->visible());
160 160
161 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 161 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
162 EXPECT_TRUE(shadow->layer()->visible()); 162 EXPECT_TRUE(shadow->layer()->visible());
163 163
164 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 164 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
165 EXPECT_FALSE(shadow->layer()->visible()); 165 EXPECT_FALSE(shadow->layer()->visible());
166 } 166 }
167 167
168 // Tests that we use smaller shadows for tooltips and menus. 168 // Tests that we use smaller shadows for tooltips and menus.
169 TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) { 169 TEST_F(ShadowControllerTest, SmallShadowsForTooltipsAndMenus) {
170 std::unique_ptr<aura::Window> tooltip_window(new aura::Window(NULL)); 170 std::unique_ptr<aura::Window> tooltip_window(new aura::Window(NULL));
171 tooltip_window->SetType(ui::wm::WINDOW_TYPE_TOOLTIP); 171 tooltip_window->SetType(ui::wm::WINDOW_TYPE_TOOLTIP);
172 tooltip_window->Init(ui::LAYER_TEXTURED); 172 tooltip_window->Init(ui::LAYER_TEXTURED);
173 ParentWindow(tooltip_window.get()); 173 ParentWindow(tooltip_window.get());
174 tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400)); 174 tooltip_window->SetBounds(gfx::Rect(10, 20, 300, 400));
175 tooltip_window->Show(); 175 tooltip_window->Show();
176 176
177 Shadow* tooltip_shadow = 177 Shadow* tooltip_shadow =
178 ShadowController::GetShadowForWindow(tooltip_window.get()); 178 ShadowController::GetShadowForWindow(tooltip_window.get());
179 ASSERT_TRUE(tooltip_shadow != NULL); 179 ASSERT_TRUE(tooltip_shadow != NULL);
180 EXPECT_EQ(Shadow::STYLE_SMALL, tooltip_shadow->style()); 180 EXPECT_EQ(ShadowElevation::SMALL, tooltip_shadow->desired_elevation());
181 181
182 std::unique_ptr<aura::Window> menu_window(new aura::Window(NULL)); 182 std::unique_ptr<aura::Window> menu_window(new aura::Window(NULL));
183 menu_window->SetType(ui::wm::WINDOW_TYPE_MENU); 183 menu_window->SetType(ui::wm::WINDOW_TYPE_MENU);
184 menu_window->Init(ui::LAYER_TEXTURED); 184 menu_window->Init(ui::LAYER_TEXTURED);
185 ParentWindow(menu_window.get()); 185 ParentWindow(menu_window.get());
186 menu_window->SetBounds(gfx::Rect(10, 20, 300, 400)); 186 menu_window->SetBounds(gfx::Rect(10, 20, 300, 400));
187 menu_window->Show(); 187 menu_window->Show();
188 188
189 Shadow* menu_shadow = 189 Shadow* menu_shadow =
190 ShadowController::GetShadowForWindow(tooltip_window.get()); 190 ShadowController::GetShadowForWindow(tooltip_window.get());
191 ASSERT_TRUE(menu_shadow != NULL); 191 ASSERT_TRUE(menu_shadow != NULL);
192 EXPECT_EQ(Shadow::STYLE_SMALL, menu_shadow->style()); 192 EXPECT_EQ(ShadowElevation::SMALL, menu_shadow->desired_elevation());
193 } 193 }
194 194
195 // http://crbug.com/120210 - transient parents of certain types of transients 195 // http://crbug.com/120210 - transient parents of certain types of transients
196 // should not lose their shadow when they lose activation to the transient. 196 // should not lose their shadow when they lose activation to the transient.
197 TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) { 197 TEST_F(ShadowControllerTest, TransientParentKeepsActiveShadow) {
198 std::unique_ptr<aura::Window> window1(new aura::Window(NULL)); 198 std::unique_ptr<aura::Window> window1(new aura::Window(NULL));
199 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL); 199 window1->SetType(ui::wm::WINDOW_TYPE_NORMAL);
200 window1->Init(ui::LAYER_TEXTURED); 200 window1->Init(ui::LAYER_TEXTURED);
201 ParentWindow(window1.get()); 201 ParentWindow(window1.get());
202 window1->SetBounds(gfx::Rect(10, 20, 300, 400)); 202 window1->SetBounds(gfx::Rect(10, 20, 300, 400));
203 window1->Show(); 203 window1->Show();
204 ActivateWindow(window1.get()); 204 ActivateWindow(window1.get());
205 205
206 // window1 is active, so style should have active appearance. 206 // window1 is active, so style should have active appearance.
207 Shadow* shadow1 = ShadowController::GetShadowForWindow(window1.get()); 207 Shadow* shadow1 = ShadowController::GetShadowForWindow(window1.get());
208 ASSERT_TRUE(shadow1 != NULL); 208 ASSERT_TRUE(shadow1 != NULL);
209 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); 209 EXPECT_EQ(ShadowElevation::LARGE, shadow1->desired_elevation());
210 210
211 // Create a window that is transient to window1, and that has the 'hide on 211 // Create a window that is transient to window1, and that has the 'hide on
212 // deactivate' property set. Upon activation, window1 should still have an 212 // deactivate' property set. Upon activation, window1 should still have an
213 // active shadow. 213 // active shadow.
214 std::unique_ptr<aura::Window> window2(new aura::Window(NULL)); 214 std::unique_ptr<aura::Window> window2(new aura::Window(NULL));
215 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL); 215 window2->SetType(ui::wm::WINDOW_TYPE_NORMAL);
216 window2->Init(ui::LAYER_TEXTURED); 216 window2->Init(ui::LAYER_TEXTURED);
217 ParentWindow(window2.get()); 217 ParentWindow(window2.get());
218 window2->SetBounds(gfx::Rect(11, 21, 301, 401)); 218 window2->SetBounds(gfx::Rect(11, 21, 301, 401));
219 AddTransientChild(window1.get(), window2.get()); 219 AddTransientChild(window1.get(), window2.get());
220 aura::client::SetHideOnDeactivate(window2.get(), true); 220 aura::client::SetHideOnDeactivate(window2.get(), true);
221 window2->Show(); 221 window2->Show();
222 ActivateWindow(window2.get()); 222 ActivateWindow(window2.get());
223 223
224 // window1 is now inactive, but its shadow should still appear active. 224 // window1 is now inactive, but its shadow should still appear active.
225 EXPECT_EQ(Shadow::STYLE_ACTIVE, shadow1->style()); 225 EXPECT_EQ(ShadowElevation::LARGE, shadow1->desired_elevation());
226 } 226 }
227 227
228 } // namespace wm 228 } // namespace wm
OLDNEW
« no previous file with comments | « ui/wm/core/shadow_controller.cc ('k') | ui/wm/core/shadow_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698