OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/wm/window_state.h" | 5 #include "ash/common/wm/window_state.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/common/material_design/material_design_controller.h" | |
9 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
10 #include "ash/common/wm/wm_event.h" | 11 #include "ash/common/wm/wm_event.h" |
11 #include "ash/screen_util.h" | 12 #include "ash/screen_util.h" |
12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_md_test_base.h" |
13 #include "ash/wm/window_state_aura.h" | 14 #include "ash/wm/window_state_aura.h" |
14 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
15 #include "ui/aura/test/test_window_delegate.h" | 16 #include "ui/aura/test/test_window_delegate.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
18 | 19 |
19 namespace ash { | 20 namespace ash { |
20 namespace wm { | 21 namespace wm { |
21 namespace { | 22 namespace { |
22 | 23 |
(...skipping 19 matching lines...) Expand all Loading... | |
42 void DetachState(WindowState* window_state) override {} | 43 void DetachState(WindowState* window_state) override {} |
43 | 44 |
44 private: | 45 private: |
45 WindowStateType state_type_; | 46 WindowStateType state_type_; |
46 | 47 |
47 DISALLOW_COPY_AND_ASSIGN(AlwaysMaximizeTestState); | 48 DISALLOW_COPY_AND_ASSIGN(AlwaysMaximizeTestState); |
48 }; | 49 }; |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 typedef test::AshTestBase WindowStateTest; | 53 using WindowStateTest = test::AshMDTestBase; |
54 | |
55 // Note: First argument is optional and intentionally left blank. | |
56 // (it's a prefix for the generated test cases) | |
57 INSTANTIATE_TEST_CASE_P( | |
58 , | |
59 WindowStateTest, | |
60 testing::Values(MaterialDesignController::NON_MATERIAL, | |
61 MaterialDesignController::MATERIAL_NORMAL, | |
62 MaterialDesignController::MATERIAL_EXPERIMENTAL)); | |
53 | 63 |
54 // Test that a window gets properly snapped to the display's edges in a | 64 // Test that a window gets properly snapped to the display's edges in a |
55 // multi monitor environment. | 65 // multi monitor environment. |
56 TEST_F(WindowStateTest, SnapWindowBasic) { | 66 TEST_P(WindowStateTest, SnapWindowBasic) { |
57 if (!SupportsMultipleDisplays()) | 67 if (!SupportsMultipleDisplays()) |
58 return; | 68 return; |
59 | 69 |
60 UpdateDisplay("0+0-500x400, 0+500-600x400"); | 70 UpdateDisplay("0+0-500x400, 0+500-600x400"); |
61 const gfx::Rect kPrimaryDisplayWorkAreaBounds = | 71 const gfx::Rect kPrimaryDisplayWorkAreaBounds = |
62 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 72 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
63 const gfx::Rect kSecondaryDisplayWorkAreaBounds = | 73 const gfx::Rect kSecondaryDisplayWorkAreaBounds = |
64 ScreenUtil::GetSecondaryDisplay().work_area(); | 74 ScreenUtil::GetSecondaryDisplay().work_area(); |
65 | 75 |
66 std::unique_ptr<aura::Window> window( | 76 std::unique_ptr<aura::Window> window( |
(...skipping 26 matching lines...) Expand all Loading... | |
93 kSecondaryDisplayWorkAreaBounds.height()); | 103 kSecondaryDisplayWorkAreaBounds.height()); |
94 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 104 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
95 | 105 |
96 window_state->OnWMEvent(&snap_left); | 106 window_state->OnWMEvent(&snap_left); |
97 expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); | 107 expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); |
98 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 108 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
99 } | 109 } |
100 | 110 |
101 // Test how the minimum and maximum size specified by the aura::WindowDelegate | 111 // Test how the minimum and maximum size specified by the aura::WindowDelegate |
102 // affect snapping. | 112 // affect snapping. |
103 TEST_F(WindowStateTest, SnapWindowMinimumSize) { | 113 TEST_P(WindowStateTest, SnapWindowMinimumSize) { |
104 if (!SupportsHostWindowResize()) | 114 if (!SupportsHostWindowResize()) |
105 return; | 115 return; |
106 | 116 |
107 UpdateDisplay("0+0-600x900"); | 117 UpdateDisplay("0+0-600x900"); |
108 const gfx::Rect kWorkAreaBounds = | 118 const gfx::Rect kWorkAreaBounds = |
109 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 119 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
110 | 120 |
111 aura::test::TestWindowDelegate delegate; | 121 aura::test::TestWindowDelegate delegate; |
112 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 122 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
113 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); | 123 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); |
(...skipping 15 matching lines...) Expand all Loading... | |
129 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); | 139 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); |
130 EXPECT_FALSE(window_state->CanSnap()); | 140 EXPECT_FALSE(window_state->CanSnap()); |
131 delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1)); | 141 delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1)); |
132 EXPECT_FALSE(window_state->CanSnap()); | 142 EXPECT_FALSE(window_state->CanSnap()); |
133 delegate.set_maximum_size(gfx::Size()); | 143 delegate.set_maximum_size(gfx::Size()); |
134 window->SetProperty(aura::client::kCanMaximizeKey, false); | 144 window->SetProperty(aura::client::kCanMaximizeKey, false); |
135 EXPECT_FALSE(window_state->CanSnap()); | 145 EXPECT_FALSE(window_state->CanSnap()); |
136 } | 146 } |
137 | 147 |
138 // Test that the minimum size specified by aura::WindowDelegate gets respected. | 148 // Test that the minimum size specified by aura::WindowDelegate gets respected. |
139 TEST_F(WindowStateTest, TestRespectMinimumSize) { | 149 TEST_P(WindowStateTest, TestRespectMinimumSize) { |
140 if (!SupportsHostWindowResize()) | 150 if (!SupportsHostWindowResize()) |
141 return; | 151 return; |
142 | 152 |
143 UpdateDisplay("0+0-1024x768"); | 153 UpdateDisplay("0+0-1024x768"); |
144 | 154 |
145 aura::test::TestWindowDelegate delegate; | 155 aura::test::TestWindowDelegate delegate; |
146 const gfx::Size minimum_size(gfx::Size(500, 300)); | 156 const gfx::Size minimum_size(gfx::Size(500, 300)); |
147 delegate.set_minimum_size(minimum_size); | 157 delegate.set_minimum_size(minimum_size); |
148 | 158 |
149 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 159 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
150 &delegate, -1, gfx::Rect(0, 100, 100, 100))); | 160 &delegate, -1, gfx::Rect(0, 100, 100, 100))); |
151 | 161 |
152 // Check that the window has the correct minimum size. | 162 // Check that the window has the correct minimum size. |
153 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); | 163 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); |
154 | 164 |
155 // Set the size to something bigger - that should work. | 165 // Set the size to something bigger - that should work. |
156 gfx::Rect bigger_bounds(700, 500, 700, 500); | 166 gfx::Rect bigger_bounds(700, 500, 700, 500); |
157 window->SetBounds(bigger_bounds); | 167 window->SetBounds(bigger_bounds); |
158 EXPECT_EQ(bigger_bounds.ToString(), window->bounds().ToString()); | 168 EXPECT_EQ(bigger_bounds.ToString(), window->bounds().ToString()); |
159 | 169 |
160 // Set the size to something smaller - that should only resize to the smallest | 170 // Set the size to something smaller - that should only resize to the smallest |
161 // possible size. | 171 // possible size. |
162 gfx::Rect smaller_bounds(700, 500, 100, 100); | 172 gfx::Rect smaller_bounds(700, 500, 100, 100); |
163 window->SetBounds(smaller_bounds); | 173 window->SetBounds(smaller_bounds); |
164 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); | 174 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); |
165 } | 175 } |
166 | 176 |
167 // Test that the minimum window size specified by aura::WindowDelegate does not | 177 // Test that the minimum window size specified by aura::WindowDelegate does not |
168 // exceed the screen size. | 178 // exceed the screen size. |
169 TEST_F(WindowStateTest, TestIgnoreTooBigMinimumSize) { | 179 TEST_P(WindowStateTest, TestIgnoreTooBigMinimumSize) { |
170 if (!SupportsHostWindowResize()) | 180 if (!SupportsHostWindowResize()) |
171 return; | 181 return; |
172 | 182 |
173 UpdateDisplay("0+0-1024x768"); | 183 UpdateDisplay("0+0-1024x768"); |
174 const gfx::Size work_area_size = | 184 const gfx::Size work_area_size = |
175 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size(); | 185 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size(); |
176 const gfx::Size illegal_size(1280, 960); | 186 const gfx::Size illegal_size(1280, 960); |
177 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); | 187 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); |
178 | 188 |
179 aura::test::TestWindowDelegate delegate; | 189 aura::test::TestWindowDelegate delegate; |
(...skipping 10 matching lines...) Expand all Loading... | |
190 window->SetBounds(illegal_bounds); | 200 window->SetBounds(illegal_bounds); |
191 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 201 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
192 | 202 |
193 // Maximizing the window should not allow it to go bigger than that either. | 203 // Maximizing the window should not allow it to go bigger than that either. |
194 WindowState* window_state = GetWindowState(window.get()); | 204 WindowState* window_state = GetWindowState(window.get()); |
195 window_state->Maximize(); | 205 window_state->Maximize(); |
196 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 206 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
197 } | 207 } |
198 | 208 |
199 // Test that setting the bounds of a snapped window keeps its snapped. | 209 // Test that setting the bounds of a snapped window keeps its snapped. |
200 TEST_F(WindowStateTest, SnapWindowSetBounds) { | 210 TEST_P(WindowStateTest, SnapWindowSetBounds) { |
201 if (!SupportsHostWindowResize()) | 211 if (!SupportsHostWindowResize()) |
202 return; | 212 return; |
203 | 213 |
204 UpdateDisplay("0+0-900x600"); | 214 UpdateDisplay("0+0-900x600"); |
205 const gfx::Rect kWorkAreaBounds = | 215 const gfx::Rect kWorkAreaBounds = |
206 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 216 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
207 | 217 |
208 std::unique_ptr<aura::Window> window( | 218 std::unique_ptr<aura::Window> window( |
209 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 219 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
210 WindowState* window_state = GetWindowState(window.get()); | 220 WindowState* window_state = GetWindowState(window.get()); |
211 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); | 221 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); |
212 window_state->OnWMEvent(&snap_left); | 222 window_state->OnWMEvent(&snap_left); |
213 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); | 223 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); |
214 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), | 224 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), |
215 kWorkAreaBounds.y(), | 225 kWorkAreaBounds.y(), |
216 kWorkAreaBounds.width() / 2, | 226 kWorkAreaBounds.width() / 2, |
217 kWorkAreaBounds.height()); | 227 kWorkAreaBounds.height()); |
218 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 228 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
219 | 229 |
220 // Snapped windows can have any width. | 230 // Snapped windows can have any width. |
221 expected.set_width(500); | 231 expected.set_width(500); |
222 window->SetBounds(gfx::Rect(10, 10, 500, 300)); | 232 window->SetBounds(gfx::Rect(10, 10, 500, 300)); |
223 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 233 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
224 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); | 234 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); |
225 } | 235 } |
226 | 236 |
227 // Test that snapping left/right preserves the restore bounds. | 237 // Test that snapping left/right preserves the restore bounds. |
228 TEST_F(WindowStateTest, RestoreBounds) { | 238 TEST_P(WindowStateTest, RestoreBounds) { |
229 std::unique_ptr<aura::Window> window( | 239 std::unique_ptr<aura::Window> window( |
230 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 240 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
231 WindowState* window_state = GetWindowState(window.get()); | 241 WindowState* window_state = GetWindowState(window.get()); |
232 | 242 |
233 EXPECT_TRUE(window_state->IsNormalStateType()); | 243 EXPECT_TRUE(window_state->IsNormalStateType()); |
234 | 244 |
235 // 1) Start with restored window with restore bounds set. | 245 // 1) Start with restored window with restore bounds set. |
236 gfx::Rect restore_bounds = window->GetBoundsInScreen(); | 246 gfx::Rect restore_bounds = window->GetBoundsInScreen(); |
237 restore_bounds.set_width(restore_bounds.width() + 1); | 247 restore_bounds.set_width(restore_bounds.width() + 1); |
238 window_state->SetRestoreBoundsInScreen(restore_bounds); | 248 window_state->SetRestoreBoundsInScreen(restore_bounds); |
(...skipping 20 matching lines...) Expand all Loading... | |
259 window->GetBoundsInScreen().ToString()); | 269 window->GetBoundsInScreen().ToString()); |
260 EXPECT_EQ(restore_bounds.ToString(), | 270 EXPECT_EQ(restore_bounds.ToString(), |
261 window_state->GetRestoreBoundsInScreen().ToString()); | 271 window_state->GetRestoreBoundsInScreen().ToString()); |
262 | 272 |
263 window_state->Restore(); | 273 window_state->Restore(); |
264 EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 274 EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
265 } | 275 } |
266 | 276 |
267 // Test that maximizing an auto managed window, then snapping it puts the window | 277 // Test that maximizing an auto managed window, then snapping it puts the window |
268 // at the snapped bounds and not at the auto-managed (centered) bounds. | 278 // at the snapped bounds and not at the auto-managed (centered) bounds. |
269 TEST_F(WindowStateTest, AutoManaged) { | 279 TEST_P(WindowStateTest, AutoManaged) { |
270 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 280 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
271 WindowState* window_state = GetWindowState(window.get()); | 281 WindowState* window_state = GetWindowState(window.get()); |
272 window_state->set_window_position_managed(true); | 282 window_state->set_window_position_managed(true); |
273 window->Hide(); | 283 window->Hide(); |
274 window->SetBounds(gfx::Rect(100, 100, 100, 100)); | 284 window->SetBounds(gfx::Rect(100, 100, 100, 100)); |
275 window->Show(); | 285 window->Show(); |
276 | 286 |
277 window_state->Maximize(); | 287 window_state->Maximize(); |
278 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); | 288 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); |
279 window_state->OnWMEvent(&snap_right); | 289 window_state->OnWMEvent(&snap_right); |
280 | 290 |
281 const gfx::Rect kWorkAreaBounds = | 291 const gfx::Rect kWorkAreaBounds = |
282 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 292 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
283 gfx::Rect expected_snapped_bounds( | 293 gfx::Rect expected_snapped_bounds( |
284 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, | 294 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, |
285 kWorkAreaBounds.y(), | 295 kWorkAreaBounds.y(), |
286 kWorkAreaBounds.width() / 2, | 296 kWorkAreaBounds.width() / 2, |
287 kWorkAreaBounds.height()); | 297 kWorkAreaBounds.height()); |
288 EXPECT_EQ(expected_snapped_bounds.ToString(), | 298 EXPECT_EQ(expected_snapped_bounds.ToString(), |
289 window->GetBoundsInScreen().ToString()); | 299 window->GetBoundsInScreen().ToString()); |
290 | 300 |
291 // The window should still be auto managed despite being right maximized. | 301 // The window should still be auto managed despite being right maximized. |
292 EXPECT_TRUE(window_state->window_position_managed()); | 302 EXPECT_TRUE(window_state->window_position_managed()); |
293 } | 303 } |
294 | 304 |
295 // Test that the replacement of a State object works as expected. | 305 // Test that the replacement of a State object works as expected. |
296 TEST_F(WindowStateTest, SimpleStateSwap) { | 306 TEST_P(WindowStateTest, SimpleStateSwap) { |
297 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 307 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
298 WindowState* window_state = GetWindowState(window.get()); | 308 WindowState* window_state = GetWindowState(window.get()); |
299 EXPECT_FALSE(window_state->IsMaximized()); | 309 EXPECT_FALSE(window_state->IsMaximized()); |
300 window_state->SetStateObject(std::unique_ptr<WindowState::State>( | 310 window_state->SetStateObject(std::unique_ptr<WindowState::State>( |
301 new AlwaysMaximizeTestState(window_state->GetStateType()))); | 311 new AlwaysMaximizeTestState(window_state->GetStateType()))); |
302 EXPECT_TRUE(window_state->IsMaximized()); | 312 EXPECT_TRUE(window_state->IsMaximized()); |
303 } | 313 } |
304 | 314 |
305 // Test that the replacement of a state object, following a restore with the | 315 // Test that the replacement of a state object, following a restore with the |
306 // original one restores the window to its original state. | 316 // original one restores the window to its original state. |
307 TEST_F(WindowStateTest, StateSwapRestore) { | 317 TEST_P(WindowStateTest, StateSwapRestore) { |
308 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 318 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
309 WindowState* window_state = GetWindowState(window.get()); | 319 WindowState* window_state = GetWindowState(window.get()); |
310 EXPECT_FALSE(window_state->IsMaximized()); | 320 EXPECT_FALSE(window_state->IsMaximized()); |
311 std::unique_ptr<WindowState::State> old( | 321 std::unique_ptr<WindowState::State> old( |
312 window_state->SetStateObject(std::unique_ptr<WindowState::State>( | 322 window_state->SetStateObject(std::unique_ptr<WindowState::State>( |
313 new AlwaysMaximizeTestState(window_state->GetStateType())))); | 323 new AlwaysMaximizeTestState(window_state->GetStateType())))); |
314 EXPECT_TRUE(window_state->IsMaximized()); | 324 EXPECT_TRUE(window_state->IsMaximized()); |
315 window_state->SetStateObject(std::move(old)); | 325 window_state->SetStateObject(std::move(old)); |
316 EXPECT_FALSE(window_state->IsMaximized()); | 326 EXPECT_FALSE(window_state->IsMaximized()); |
317 } | 327 } |
318 | 328 |
319 // Tests that a window that had same bounds as the work area shrinks after the | 329 // Tests that a window that had same bounds as the work area shrinks after the |
320 // window is maximized and then restored. | 330 // window is maximized and then restored. |
321 TEST_F(WindowStateTest, RestoredWindowBoundsShrink) { | 331 TEST_P(WindowStateTest, RestoredWindowBoundsShrink) { |
tdanderson
2016/06/21 19:52:21
This test fails on CrOS with GetParam() == 2 (MATE
James Cook
2016/06/21 22:17:54
Hmm. I'm not sure what you mean by "stale display
varkha
2016/06/22 16:40:18
Maybe you need AshTestBase::SupportsHostWindowResi
tdanderson
2016/06/22 16:51:55
I think that is what's happening, but I am unsucce
msw
2016/06/22 17:06:08
Sorry, but I have little to add here. I excluded t
tdanderson
2016/06/22 19:15:46
Thanks for the comments, I have used SupportsHostW
msw
2016/06/22 19:26:08
Great to hear! Lmk if you'd like me to follow up w
| |
322 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 332 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
323 WindowState* window_state = GetWindowState(window.get()); | 333 WindowState* window_state = GetWindowState(window.get()); |
324 EXPECT_FALSE(window_state->IsMaximized()); | 334 EXPECT_FALSE(window_state->IsMaximized()); |
325 gfx::Rect work_area = | 335 gfx::Rect work_area = |
326 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 336 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
327 | 337 |
328 window->SetBounds(work_area); | 338 window->SetBounds(work_area); |
329 window_state->Maximize(); | 339 window_state->Maximize(); |
330 EXPECT_TRUE(window_state->IsMaximized()); | 340 EXPECT_TRUE(window_state->IsMaximized()); |
331 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); | 341 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); |
332 | 342 |
333 window_state->Restore(); | 343 window_state->Restore(); |
334 EXPECT_FALSE(window_state->IsMaximized()); | 344 EXPECT_FALSE(window_state->IsMaximized()); |
335 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); | 345 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); |
336 EXPECT_TRUE(work_area.Contains(window->bounds())); | 346 EXPECT_TRUE(work_area.Contains(window->bounds())); |
337 } | 347 } |
338 | 348 |
339 TEST_F(WindowStateTest, DoNotResizeMaximizedWindowInFullscreen) { | 349 TEST_P(WindowStateTest, DoNotResizeMaximizedWindowInFullscreen) { |
340 if (!SupportsHostWindowResize()) | 350 if (!SupportsHostWindowResize()) |
341 return; | 351 return; |
352 const int height_offset = GetMdMaximizedWindowHeightOffset(); | |
342 | 353 |
343 std::unique_ptr<aura::Window> maximized(CreateTestWindowInShellWithId(0)); | 354 std::unique_ptr<aura::Window> maximized(CreateTestWindowInShellWithId(0)); |
344 std::unique_ptr<aura::Window> fullscreen(CreateTestWindowInShellWithId(1)); | 355 std::unique_ptr<aura::Window> fullscreen(CreateTestWindowInShellWithId(1)); |
345 WindowState* maximized_state = GetWindowState(maximized.get()); | 356 WindowState* maximized_state = GetWindowState(maximized.get()); |
346 maximized_state->Maximize(); | 357 maximized_state->Maximize(); |
347 ASSERT_TRUE(maximized_state->IsMaximized()); | 358 ASSERT_TRUE(maximized_state->IsMaximized()); |
348 EXPECT_EQ("0,0 800x553", maximized->GetBoundsInScreen().ToString()); | 359 EXPECT_EQ(gfx::Rect(0, 0, 800, 553 + height_offset).ToString(), |
360 maximized->GetBoundsInScreen().ToString()); | |
349 | 361 |
350 // Entering fullscreen mode will not update the maximized window's size | 362 // Entering fullscreen mode will not update the maximized window's size |
351 // under fullscreen. | 363 // under fullscreen. |
352 WMEvent fullscreen_event(WM_EVENT_FULLSCREEN); | 364 WMEvent fullscreen_event(WM_EVENT_FULLSCREEN); |
353 WindowState* fullscreen_state = GetWindowState(fullscreen.get()); | 365 WindowState* fullscreen_state = GetWindowState(fullscreen.get()); |
354 fullscreen_state->OnWMEvent(&fullscreen_event); | 366 fullscreen_state->OnWMEvent(&fullscreen_event); |
355 ASSERT_TRUE(fullscreen_state->IsFullscreen()); | 367 ASSERT_TRUE(fullscreen_state->IsFullscreen()); |
356 ASSERT_TRUE(maximized_state->IsMaximized()); | 368 ASSERT_TRUE(maximized_state->IsMaximized()); |
357 EXPECT_EQ("0,0 800x553", maximized->GetBoundsInScreen().ToString()); | 369 EXPECT_EQ(gfx::Rect(0, 0, 800, 553 + height_offset).ToString(), |
370 maximized->GetBoundsInScreen().ToString()); | |
358 | 371 |
359 // Updating display size will update the maximum window size. | 372 // Updating display size will update the maximum window size. |
360 UpdateDisplay("900x700"); | 373 UpdateDisplay("900x700"); |
361 EXPECT_EQ("0,0 900x700", maximized->GetBoundsInScreen().ToString()); | 374 EXPECT_EQ("0,0 900x700", maximized->GetBoundsInScreen().ToString()); |
362 fullscreen.reset(); | 375 fullscreen.reset(); |
363 | 376 |
364 // Exitting fullscreen will update the maximized widnow to the work area. | 377 // Exiting fullscreen will update the maximized widnow to the work area. |
James Cook
2016/06/21 22:17:54
nit: while you're here, widnow -> window
tdanderson
2016/06/22 16:51:55
Done.
| |
365 EXPECT_EQ("0,0 900x653", maximized->GetBoundsInScreen().ToString()); | 378 EXPECT_EQ(gfx::Rect(0, 0, 900, 653 + height_offset).ToString(), |
379 maximized->GetBoundsInScreen().ToString()); | |
366 } | 380 } |
367 | 381 |
368 // TODO(skuhne): Add more unit test to verify the correctness for the restore | 382 // TODO(skuhne): Add more unit test to verify the correctness for the restore |
369 // operation. | 383 // operation. |
370 | 384 |
371 } // namespace wm | 385 } // namespace wm |
372 } // namespace ash | 386 } // namespace ash |
OLD | NEW |