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/wm/window_state.h" | 5 #include "ash/wm/window_state.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
10 #include "ash/shell.h" | |
11 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
12 #include "ash/wm/window_state.h" | 11 #include "ash/wm/window_state.h" |
13 #include "ash/wm/wm_event.h" | 12 #include "ash/wm/wm_event.h" |
14 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
15 #include "ui/aura/test/test_window_delegate.h" | 14 #include "ui/aura/test/test_window_delegate.h" |
16 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/gfx/screen.h" |
17 | 17 |
18 namespace ash { | 18 namespace ash { |
19 namespace wm { | 19 namespace wm { |
20 namespace { | 20 namespace { |
21 | 21 |
22 class AlwaysMaximizeTestState : public WindowState::State { | 22 class AlwaysMaximizeTestState : public WindowState::State { |
23 public: | 23 public: |
24 explicit AlwaysMaximizeTestState(WindowStateType initial_state_type) | 24 explicit AlwaysMaximizeTestState(WindowStateType initial_state_type) |
25 : state_type_(initial_state_type) {} | 25 : state_type_(initial_state_type) {} |
26 ~AlwaysMaximizeTestState() override {} | 26 ~AlwaysMaximizeTestState() override {} |
(...skipping 24 matching lines...) Expand all Loading... |
51 typedef test::AshTestBase WindowStateTest; | 51 typedef test::AshTestBase WindowStateTest; |
52 | 52 |
53 // Test that a window gets properly snapped to the display's edges in a | 53 // Test that a window gets properly snapped to the display's edges in a |
54 // multi monitor environment. | 54 // multi monitor environment. |
55 TEST_F(WindowStateTest, SnapWindowBasic) { | 55 TEST_F(WindowStateTest, SnapWindowBasic) { |
56 if (!SupportsMultipleDisplays()) | 56 if (!SupportsMultipleDisplays()) |
57 return; | 57 return; |
58 | 58 |
59 UpdateDisplay("0+0-500x400, 0+500-600x400"); | 59 UpdateDisplay("0+0-500x400, 0+500-600x400"); |
60 const gfx::Rect kPrimaryDisplayWorkAreaBounds = | 60 const gfx::Rect kPrimaryDisplayWorkAreaBounds = |
61 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 61 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
62 const gfx::Rect kSecondaryDisplayWorkAreaBounds = | 62 const gfx::Rect kSecondaryDisplayWorkAreaBounds = |
63 ScreenUtil::GetSecondaryDisplay().work_area(); | 63 ScreenUtil::GetSecondaryDisplay().work_area(); |
64 | 64 |
65 scoped_ptr<aura::Window> window( | 65 scoped_ptr<aura::Window> window( |
66 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 66 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
67 WindowState* window_state = GetWindowState(window.get()); | 67 WindowState* window_state = GetWindowState(window.get()); |
68 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); | 68 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); |
69 window_state->OnWMEvent(&snap_left); | 69 window_state->OnWMEvent(&snap_left); |
70 gfx::Rect expected = gfx::Rect( | 70 gfx::Rect expected = gfx::Rect( |
71 kPrimaryDisplayWorkAreaBounds.x(), | 71 kPrimaryDisplayWorkAreaBounds.x(), |
(...skipping 26 matching lines...) Expand all Loading... |
98 } | 98 } |
99 | 99 |
100 // Test how the minimum and maximum size specified by the aura::WindowDelegate | 100 // Test how the minimum and maximum size specified by the aura::WindowDelegate |
101 // affect snapping. | 101 // affect snapping. |
102 TEST_F(WindowStateTest, SnapWindowMinimumSize) { | 102 TEST_F(WindowStateTest, SnapWindowMinimumSize) { |
103 if (!SupportsHostWindowResize()) | 103 if (!SupportsHostWindowResize()) |
104 return; | 104 return; |
105 | 105 |
106 UpdateDisplay("0+0-600x900"); | 106 UpdateDisplay("0+0-600x900"); |
107 const gfx::Rect kWorkAreaBounds = | 107 const gfx::Rect kWorkAreaBounds = |
108 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 108 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
109 | 109 |
110 aura::test::TestWindowDelegate delegate; | 110 aura::test::TestWindowDelegate delegate; |
111 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 111 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
112 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); | 112 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); |
113 | 113 |
114 // It should be possible to snap a window with a minimum size. | 114 // It should be possible to snap a window with a minimum size. |
115 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); | 115 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); |
116 WindowState* window_state = GetWindowState(window.get()); | 116 WindowState* window_state = GetWindowState(window.get()); |
117 EXPECT_TRUE(window_state->CanSnap()); | 117 EXPECT_TRUE(window_state->CanSnap()); |
118 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); | 118 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 | 165 |
166 // Test that the minimum window size specified by aura::WindowDelegate does not | 166 // Test that the minimum window size specified by aura::WindowDelegate does not |
167 // exceed the screen size. | 167 // exceed the screen size. |
168 TEST_F(WindowStateTest, TestIgnoreTooBigMinimumSize) { | 168 TEST_F(WindowStateTest, TestIgnoreTooBigMinimumSize) { |
169 if (!SupportsHostWindowResize()) | 169 if (!SupportsHostWindowResize()) |
170 return; | 170 return; |
171 | 171 |
172 UpdateDisplay("0+0-1024x768"); | 172 UpdateDisplay("0+0-1024x768"); |
173 const gfx::Size work_area_size = | 173 const gfx::Size work_area_size = |
174 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area().size(); | 174 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area().size(); |
175 const gfx::Size illegal_size(1280, 960); | 175 const gfx::Size illegal_size(1280, 960); |
176 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); | 176 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); |
177 | 177 |
178 aura::test::TestWindowDelegate delegate; | 178 aura::test::TestWindowDelegate delegate; |
179 const gfx::Size minimum_size(illegal_size); | 179 const gfx::Size minimum_size(illegal_size); |
180 delegate.set_minimum_size(minimum_size); | 180 delegate.set_minimum_size(minimum_size); |
181 | 181 |
182 // The creation should force the window to respect the screen size. | 182 // The creation should force the window to respect the screen size. |
183 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 183 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
184 &delegate, -1, illegal_bounds)); | 184 &delegate, -1, illegal_bounds)); |
(...skipping 10 matching lines...) Expand all Loading... |
195 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 195 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
196 } | 196 } |
197 | 197 |
198 // Test that setting the bounds of a snapped window keeps its snapped. | 198 // Test that setting the bounds of a snapped window keeps its snapped. |
199 TEST_F(WindowStateTest, SnapWindowSetBounds) { | 199 TEST_F(WindowStateTest, SnapWindowSetBounds) { |
200 if (!SupportsHostWindowResize()) | 200 if (!SupportsHostWindowResize()) |
201 return; | 201 return; |
202 | 202 |
203 UpdateDisplay("0+0-900x600"); | 203 UpdateDisplay("0+0-900x600"); |
204 const gfx::Rect kWorkAreaBounds = | 204 const gfx::Rect kWorkAreaBounds = |
205 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 205 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
206 | 206 |
207 scoped_ptr<aura::Window> window( | 207 scoped_ptr<aura::Window> window( |
208 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 208 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
209 WindowState* window_state = GetWindowState(window.get()); | 209 WindowState* window_state = GetWindowState(window.get()); |
210 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); | 210 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); |
211 window_state->OnWMEvent(&snap_left); | 211 window_state->OnWMEvent(&snap_left); |
212 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); | 212 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); |
213 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), | 213 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), |
214 kWorkAreaBounds.y(), | 214 kWorkAreaBounds.y(), |
215 kWorkAreaBounds.width() / 2, | 215 kWorkAreaBounds.width() / 2, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 window_state->set_window_position_managed(true); | 271 window_state->set_window_position_managed(true); |
272 window->Hide(); | 272 window->Hide(); |
273 window->SetBounds(gfx::Rect(100, 100, 100, 100)); | 273 window->SetBounds(gfx::Rect(100, 100, 100, 100)); |
274 window->Show(); | 274 window->Show(); |
275 | 275 |
276 window_state->Maximize(); | 276 window_state->Maximize(); |
277 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); | 277 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); |
278 window_state->OnWMEvent(&snap_right); | 278 window_state->OnWMEvent(&snap_right); |
279 | 279 |
280 const gfx::Rect kWorkAreaBounds = | 280 const gfx::Rect kWorkAreaBounds = |
281 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 281 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
282 gfx::Rect expected_snapped_bounds( | 282 gfx::Rect expected_snapped_bounds( |
283 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, | 283 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, |
284 kWorkAreaBounds.y(), | 284 kWorkAreaBounds.y(), |
285 kWorkAreaBounds.width() / 2, | 285 kWorkAreaBounds.width() / 2, |
286 kWorkAreaBounds.height()); | 286 kWorkAreaBounds.height()); |
287 EXPECT_EQ(expected_snapped_bounds.ToString(), | 287 EXPECT_EQ(expected_snapped_bounds.ToString(), |
288 window->GetBoundsInScreen().ToString()); | 288 window->GetBoundsInScreen().ToString()); |
289 | 289 |
290 // The window should still be auto managed despite being right maximized. | 290 // The window should still be auto managed despite being right maximized. |
291 EXPECT_TRUE(window_state->window_position_managed()); | 291 EXPECT_TRUE(window_state->window_position_managed()); |
(...skipping 24 matching lines...) Expand all Loading... |
316 EXPECT_FALSE(window_state->IsMaximized()); | 316 EXPECT_FALSE(window_state->IsMaximized()); |
317 } | 317 } |
318 | 318 |
319 // Tests that a window that had same bounds as the work area shrinks after the | 319 // Tests that a window that had same bounds as the work area shrinks after the |
320 // window is maximized and then restored. | 320 // window is maximized and then restored. |
321 TEST_F(WindowStateTest, RestoredWindowBoundsShrink) { | 321 TEST_F(WindowStateTest, RestoredWindowBoundsShrink) { |
322 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 322 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
323 WindowState* window_state = GetWindowState(window.get()); | 323 WindowState* window_state = GetWindowState(window.get()); |
324 EXPECT_FALSE(window_state->IsMaximized()); | 324 EXPECT_FALSE(window_state->IsMaximized()); |
325 gfx::Rect work_area = | 325 gfx::Rect work_area = |
326 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 326 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
327 | 327 |
328 window->SetBounds(work_area); | 328 window->SetBounds(work_area); |
329 window_state->Maximize(); | 329 window_state->Maximize(); |
330 EXPECT_TRUE(window_state->IsMaximized()); | 330 EXPECT_TRUE(window_state->IsMaximized()); |
331 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); | 331 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); |
332 | 332 |
333 window_state->Restore(); | 333 window_state->Restore(); |
334 EXPECT_FALSE(window_state->IsMaximized()); | 334 EXPECT_FALSE(window_state->IsMaximized()); |
335 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); | 335 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); |
336 EXPECT_TRUE(work_area.Contains(window->bounds())); | 336 EXPECT_TRUE(work_area.Contains(window->bounds())); |
(...skipping 26 matching lines...) Expand all Loading... |
363 | 363 |
364 // Exitting fullscreen will update the maximized widnow to the work area. | 364 // Exitting fullscreen will update the maximized widnow to the work area. |
365 EXPECT_EQ("0,0 900x653", maximized->GetBoundsInScreen().ToString()); | 365 EXPECT_EQ("0,0 900x653", maximized->GetBoundsInScreen().ToString()); |
366 } | 366 } |
367 | 367 |
368 // TODO(skuhne): Add more unit test to verify the correctness for the restore | 368 // TODO(skuhne): Add more unit test to verify the correctness for the restore |
369 // operation. | 369 // operation. |
370 | 370 |
371 } // namespace wm | 371 } // namespace wm |
372 } // namespace ash | 372 } // namespace ash |
OLD | NEW |