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" | |
10 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/wm/window_state.h" |
11 #include "ash/common/wm/window_state_util.h" | 10 #include "ash/common/wm/window_state_util.h" |
12 #include "ash/common/wm/wm_event.h" | 11 #include "ash/common/wm/wm_event.h" |
13 #include "ash/test/ash_md_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
14 #include "ash/wm/window_state_aura.h" | 13 #include "ash/wm/window_state_aura.h" |
15 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
16 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 15 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
17 #include "ui/aura/client/aura_constants.h" | 16 #include "ui/aura/client/aura_constants.h" |
18 #include "ui/aura/test/test_window_delegate.h" | 17 #include "ui/aura/test/test_window_delegate.h" |
19 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
20 #include "ui/display/manager/display_manager.h" | 19 #include "ui/display/manager/display_manager.h" |
21 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
22 | 21 |
23 namespace ash { | 22 namespace ash { |
(...skipping 22 matching lines...) Expand all Loading... |
46 void DetachState(WindowState* window_state) override {} | 45 void DetachState(WindowState* window_state) override {} |
47 | 46 |
48 private: | 47 private: |
49 WindowStateType state_type_; | 48 WindowStateType state_type_; |
50 | 49 |
51 DISALLOW_COPY_AND_ASSIGN(AlwaysMaximizeTestState); | 50 DISALLOW_COPY_AND_ASSIGN(AlwaysMaximizeTestState); |
52 }; | 51 }; |
53 | 52 |
54 } // namespace | 53 } // namespace |
55 | 54 |
56 using WindowStateTest = test::AshMDTestBase; | 55 using WindowStateTest = test::AshTestBase; |
57 | |
58 INSTANTIATE_TEST_CASE_P( | |
59 /* prefix intentionally left blank due to only one parameterization */, | |
60 WindowStateTest, | |
61 testing::Values(MaterialDesignController::NON_MATERIAL, | |
62 MaterialDesignController::MATERIAL_NORMAL, | |
63 MaterialDesignController::MATERIAL_EXPERIMENTAL)); | |
64 | 56 |
65 // Test that a window gets properly snapped to the display's edges in a | 57 // Test that a window gets properly snapped to the display's edges in a |
66 // multi monitor environment. | 58 // multi monitor environment. |
67 TEST_P(WindowStateTest, SnapWindowBasic) { | 59 TEST_F(WindowStateTest, SnapWindowBasic) { |
68 UpdateDisplay("0+0-500x400, 0+500-600x400"); | 60 UpdateDisplay("0+0-500x400, 0+500-600x400"); |
69 const gfx::Rect kPrimaryDisplayWorkAreaBounds = | 61 const gfx::Rect kPrimaryDisplayWorkAreaBounds = |
70 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 62 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
71 const gfx::Rect kSecondaryDisplayWorkAreaBounds = | 63 const gfx::Rect kSecondaryDisplayWorkAreaBounds = |
72 display_manager()->GetSecondaryDisplay().work_area(); | 64 display_manager()->GetSecondaryDisplay().work_area(); |
73 | 65 |
74 std::unique_ptr<aura::Window> window( | 66 std::unique_ptr<aura::Window> window( |
75 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 67 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
76 WindowState* window_state = GetWindowState(window.get()); | 68 WindowState* window_state = GetWindowState(window.get()); |
77 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); | 69 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); |
(...skipping 21 matching lines...) Expand all Loading... |
99 kSecondaryDisplayWorkAreaBounds.height()); | 91 kSecondaryDisplayWorkAreaBounds.height()); |
100 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 92 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
101 | 93 |
102 window_state->OnWMEvent(&snap_left); | 94 window_state->OnWMEvent(&snap_left); |
103 expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); | 95 expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); |
104 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 96 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
105 } | 97 } |
106 | 98 |
107 // Test how the minimum and maximum size specified by the aura::WindowDelegate | 99 // Test how the minimum and maximum size specified by the aura::WindowDelegate |
108 // affect snapping. | 100 // affect snapping. |
109 TEST_P(WindowStateTest, SnapWindowMinimumSize) { | 101 TEST_F(WindowStateTest, SnapWindowMinimumSize) { |
110 UpdateDisplay("0+0-600x900"); | 102 UpdateDisplay("0+0-600x900"); |
111 const gfx::Rect kWorkAreaBounds = | 103 const gfx::Rect kWorkAreaBounds = |
112 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 104 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
113 | 105 |
114 aura::test::TestWindowDelegate delegate; | 106 aura::test::TestWindowDelegate delegate; |
115 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 107 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
116 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); | 108 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); |
117 | 109 |
118 // It should be possible to snap a window with a minimum size. | 110 // It should be possible to snap a window with a minimum size. |
119 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); | 111 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); |
(...skipping 12 matching lines...) Expand all Loading... |
132 EXPECT_FALSE(window_state->CanSnap()); | 124 EXPECT_FALSE(window_state->CanSnap()); |
133 delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1)); | 125 delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1)); |
134 EXPECT_FALSE(window_state->CanSnap()); | 126 EXPECT_FALSE(window_state->CanSnap()); |
135 delegate.set_maximum_size(gfx::Size()); | 127 delegate.set_maximum_size(gfx::Size()); |
136 window->SetProperty(aura::client::kResizeBehaviorKey, | 128 window->SetProperty(aura::client::kResizeBehaviorKey, |
137 ui::mojom::kResizeBehaviorCanResize); | 129 ui::mojom::kResizeBehaviorCanResize); |
138 EXPECT_FALSE(window_state->CanSnap()); | 130 EXPECT_FALSE(window_state->CanSnap()); |
139 } | 131 } |
140 | 132 |
141 // Test that the minimum size specified by aura::WindowDelegate gets respected. | 133 // Test that the minimum size specified by aura::WindowDelegate gets respected. |
142 TEST_P(WindowStateTest, TestRespectMinimumSize) { | 134 TEST_F(WindowStateTest, TestRespectMinimumSize) { |
143 UpdateDisplay("0+0-1024x768"); | 135 UpdateDisplay("0+0-1024x768"); |
144 | 136 |
145 aura::test::TestWindowDelegate delegate; | 137 aura::test::TestWindowDelegate delegate; |
146 const gfx::Size minimum_size(gfx::Size(500, 300)); | 138 const gfx::Size minimum_size(gfx::Size(500, 300)); |
147 delegate.set_minimum_size(minimum_size); | 139 delegate.set_minimum_size(minimum_size); |
148 | 140 |
149 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 141 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
150 &delegate, -1, gfx::Rect(0, 100, 100, 100))); | 142 &delegate, -1, gfx::Rect(0, 100, 100, 100))); |
151 | 143 |
152 // Check that the window has the correct minimum size. | 144 // Check that the window has the correct minimum size. |
153 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); | 145 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); |
154 | 146 |
155 // Set the size to something bigger - that should work. | 147 // Set the size to something bigger - that should work. |
156 gfx::Rect bigger_bounds(700, 500, 700, 500); | 148 gfx::Rect bigger_bounds(700, 500, 700, 500); |
157 window->SetBounds(bigger_bounds); | 149 window->SetBounds(bigger_bounds); |
158 EXPECT_EQ(bigger_bounds.ToString(), window->bounds().ToString()); | 150 EXPECT_EQ(bigger_bounds.ToString(), window->bounds().ToString()); |
159 | 151 |
160 // Set the size to something smaller - that should only resize to the smallest | 152 // Set the size to something smaller - that should only resize to the smallest |
161 // possible size. | 153 // possible size. |
162 gfx::Rect smaller_bounds(700, 500, 100, 100); | 154 gfx::Rect smaller_bounds(700, 500, 100, 100); |
163 window->SetBounds(smaller_bounds); | 155 window->SetBounds(smaller_bounds); |
164 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); | 156 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); |
165 } | 157 } |
166 | 158 |
167 // Test that the minimum window size specified by aura::WindowDelegate does not | 159 // Test that the minimum window size specified by aura::WindowDelegate does not |
168 // exceed the screen size. | 160 // exceed the screen size. |
169 TEST_P(WindowStateTest, TestIgnoreTooBigMinimumSize) { | 161 TEST_F(WindowStateTest, TestIgnoreTooBigMinimumSize) { |
170 UpdateDisplay("0+0-1024x768"); | 162 UpdateDisplay("0+0-1024x768"); |
171 const gfx::Size work_area_size = | 163 const gfx::Size work_area_size = |
172 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size(); | 164 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size(); |
173 const gfx::Size illegal_size(1280, 960); | 165 const gfx::Size illegal_size(1280, 960); |
174 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); | 166 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); |
175 | 167 |
176 aura::test::TestWindowDelegate delegate; | 168 aura::test::TestWindowDelegate delegate; |
177 const gfx::Size minimum_size(illegal_size); | 169 const gfx::Size minimum_size(illegal_size); |
178 delegate.set_minimum_size(minimum_size); | 170 delegate.set_minimum_size(minimum_size); |
179 | 171 |
180 // The creation should force the window to respect the screen size. | 172 // The creation should force the window to respect the screen size. |
181 std::unique_ptr<aura::Window> window( | 173 std::unique_ptr<aura::Window> window( |
182 CreateTestWindowInShellWithDelegate(&delegate, -1, illegal_bounds)); | 174 CreateTestWindowInShellWithDelegate(&delegate, -1, illegal_bounds)); |
183 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 175 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
184 | 176 |
185 // Trying to set the size to something bigger then the screen size should be | 177 // Trying to set the size to something bigger then the screen size should be |
186 // ignored. | 178 // ignored. |
187 window->SetBounds(illegal_bounds); | 179 window->SetBounds(illegal_bounds); |
188 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 180 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
189 | 181 |
190 // Maximizing the window should not allow it to go bigger than that either. | 182 // Maximizing the window should not allow it to go bigger than that either. |
191 WindowState* window_state = GetWindowState(window.get()); | 183 WindowState* window_state = GetWindowState(window.get()); |
192 window_state->Maximize(); | 184 window_state->Maximize(); |
193 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 185 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
194 } | 186 } |
195 | 187 |
196 // Test that setting the bounds of a snapped window keeps its snapped. | 188 // Test that setting the bounds of a snapped window keeps its snapped. |
197 TEST_P(WindowStateTest, SnapWindowSetBounds) { | 189 TEST_F(WindowStateTest, SnapWindowSetBounds) { |
198 UpdateDisplay("0+0-900x600"); | 190 UpdateDisplay("0+0-900x600"); |
199 const gfx::Rect kWorkAreaBounds = | 191 const gfx::Rect kWorkAreaBounds = |
200 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 192 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
201 | 193 |
202 std::unique_ptr<aura::Window> window( | 194 std::unique_ptr<aura::Window> window( |
203 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 195 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
204 WindowState* window_state = GetWindowState(window.get()); | 196 WindowState* window_state = GetWindowState(window.get()); |
205 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); | 197 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); |
206 window_state->OnWMEvent(&snap_left); | 198 window_state->OnWMEvent(&snap_left); |
207 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); | 199 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); |
208 gfx::Rect expected = | 200 gfx::Rect expected = |
209 gfx::Rect(kWorkAreaBounds.x(), kWorkAreaBounds.y(), | 201 gfx::Rect(kWorkAreaBounds.x(), kWorkAreaBounds.y(), |
210 kWorkAreaBounds.width() / 2, kWorkAreaBounds.height()); | 202 kWorkAreaBounds.width() / 2, kWorkAreaBounds.height()); |
211 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 203 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
212 | 204 |
213 // Snapped windows can have any width. | 205 // Snapped windows can have any width. |
214 expected.set_width(500); | 206 expected.set_width(500); |
215 window->SetBounds(gfx::Rect(10, 10, 500, 300)); | 207 window->SetBounds(gfx::Rect(10, 10, 500, 300)); |
216 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 208 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
217 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); | 209 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); |
218 } | 210 } |
219 | 211 |
220 // Test that snapping left/right preserves the restore bounds. | 212 // Test that snapping left/right preserves the restore bounds. |
221 TEST_P(WindowStateTest, RestoreBounds) { | 213 TEST_F(WindowStateTest, RestoreBounds) { |
222 std::unique_ptr<aura::Window> window( | 214 std::unique_ptr<aura::Window> window( |
223 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 215 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
224 WindowState* window_state = GetWindowState(window.get()); | 216 WindowState* window_state = GetWindowState(window.get()); |
225 | 217 |
226 EXPECT_TRUE(window_state->IsNormalStateType()); | 218 EXPECT_TRUE(window_state->IsNormalStateType()); |
227 | 219 |
228 // 1) Start with restored window with restore bounds set. | 220 // 1) Start with restored window with restore bounds set. |
229 gfx::Rect restore_bounds = window->GetBoundsInScreen(); | 221 gfx::Rect restore_bounds = window->GetBoundsInScreen(); |
230 restore_bounds.set_width(restore_bounds.width() + 1); | 222 restore_bounds.set_width(restore_bounds.width() + 1); |
231 window_state->SetRestoreBoundsInScreen(restore_bounds); | 223 window_state->SetRestoreBoundsInScreen(restore_bounds); |
(...skipping 20 matching lines...) Expand all Loading... |
252 window->GetBoundsInScreen().ToString()); | 244 window->GetBoundsInScreen().ToString()); |
253 EXPECT_EQ(restore_bounds.ToString(), | 245 EXPECT_EQ(restore_bounds.ToString(), |
254 window_state->GetRestoreBoundsInScreen().ToString()); | 246 window_state->GetRestoreBoundsInScreen().ToString()); |
255 | 247 |
256 window_state->Restore(); | 248 window_state->Restore(); |
257 EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 249 EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
258 } | 250 } |
259 | 251 |
260 // Test that maximizing an auto managed window, then snapping it puts the window | 252 // Test that maximizing an auto managed window, then snapping it puts the window |
261 // at the snapped bounds and not at the auto-managed (centered) bounds. | 253 // at the snapped bounds and not at the auto-managed (centered) bounds. |
262 TEST_P(WindowStateTest, AutoManaged) { | 254 TEST_F(WindowStateTest, AutoManaged) { |
263 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 255 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
264 WindowState* window_state = GetWindowState(window.get()); | 256 WindowState* window_state = GetWindowState(window.get()); |
265 window_state->set_window_position_managed(true); | 257 window_state->set_window_position_managed(true); |
266 window->Hide(); | 258 window->Hide(); |
267 window->SetBounds(gfx::Rect(100, 100, 100, 100)); | 259 window->SetBounds(gfx::Rect(100, 100, 100, 100)); |
268 window->Show(); | 260 window->Show(); |
269 | 261 |
270 window_state->Maximize(); | 262 window_state->Maximize(); |
271 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); | 263 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); |
272 window_state->OnWMEvent(&snap_right); | 264 window_state->OnWMEvent(&snap_right); |
273 | 265 |
274 const gfx::Rect kWorkAreaBounds = | 266 const gfx::Rect kWorkAreaBounds = |
275 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 267 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
276 gfx::Rect expected_snapped_bounds( | 268 gfx::Rect expected_snapped_bounds( |
277 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, kWorkAreaBounds.y(), | 269 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, kWorkAreaBounds.y(), |
278 kWorkAreaBounds.width() / 2, kWorkAreaBounds.height()); | 270 kWorkAreaBounds.width() / 2, kWorkAreaBounds.height()); |
279 EXPECT_EQ(expected_snapped_bounds.ToString(), | 271 EXPECT_EQ(expected_snapped_bounds.ToString(), |
280 window->GetBoundsInScreen().ToString()); | 272 window->GetBoundsInScreen().ToString()); |
281 | 273 |
282 // The window should still be auto managed despite being right maximized. | 274 // The window should still be auto managed despite being right maximized. |
283 EXPECT_TRUE(window_state->window_position_managed()); | 275 EXPECT_TRUE(window_state->window_position_managed()); |
284 } | 276 } |
285 | 277 |
286 // Test that the replacement of a State object works as expected. | 278 // Test that the replacement of a State object works as expected. |
287 TEST_P(WindowStateTest, SimpleStateSwap) { | 279 TEST_F(WindowStateTest, SimpleStateSwap) { |
288 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 280 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
289 WindowState* window_state = GetWindowState(window.get()); | 281 WindowState* window_state = GetWindowState(window.get()); |
290 EXPECT_FALSE(window_state->IsMaximized()); | 282 EXPECT_FALSE(window_state->IsMaximized()); |
291 window_state->SetStateObject(std::unique_ptr<WindowState::State>( | 283 window_state->SetStateObject(std::unique_ptr<WindowState::State>( |
292 new AlwaysMaximizeTestState(window_state->GetStateType()))); | 284 new AlwaysMaximizeTestState(window_state->GetStateType()))); |
293 EXPECT_TRUE(window_state->IsMaximized()); | 285 EXPECT_TRUE(window_state->IsMaximized()); |
294 } | 286 } |
295 | 287 |
296 // Test that the replacement of a state object, following a restore with the | 288 // Test that the replacement of a state object, following a restore with the |
297 // original one restores the window to its original state. | 289 // original one restores the window to its original state. |
298 TEST_P(WindowStateTest, StateSwapRestore) { | 290 TEST_F(WindowStateTest, StateSwapRestore) { |
299 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 291 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
300 WindowState* window_state = GetWindowState(window.get()); | 292 WindowState* window_state = GetWindowState(window.get()); |
301 EXPECT_FALSE(window_state->IsMaximized()); | 293 EXPECT_FALSE(window_state->IsMaximized()); |
302 std::unique_ptr<WindowState::State> old( | 294 std::unique_ptr<WindowState::State> old( |
303 window_state->SetStateObject(std::unique_ptr<WindowState::State>( | 295 window_state->SetStateObject(std::unique_ptr<WindowState::State>( |
304 new AlwaysMaximizeTestState(window_state->GetStateType())))); | 296 new AlwaysMaximizeTestState(window_state->GetStateType())))); |
305 EXPECT_TRUE(window_state->IsMaximized()); | 297 EXPECT_TRUE(window_state->IsMaximized()); |
306 window_state->SetStateObject(std::move(old)); | 298 window_state->SetStateObject(std::move(old)); |
307 EXPECT_FALSE(window_state->IsMaximized()); | 299 EXPECT_FALSE(window_state->IsMaximized()); |
308 } | 300 } |
309 | 301 |
310 // Tests that a window that had same bounds as the work area shrinks after the | 302 // Tests that a window that had same bounds as the work area shrinks after the |
311 // window is maximized and then restored. | 303 // window is maximized and then restored. |
312 TEST_P(WindowStateTest, RestoredWindowBoundsShrink) { | 304 TEST_F(WindowStateTest, RestoredWindowBoundsShrink) { |
313 UpdateDisplay("0+0-600x900"); | 305 UpdateDisplay("0+0-600x900"); |
314 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 306 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
315 WindowState* window_state = GetWindowState(window.get()); | 307 WindowState* window_state = GetWindowState(window.get()); |
316 EXPECT_FALSE(window_state->IsMaximized()); | 308 EXPECT_FALSE(window_state->IsMaximized()); |
317 gfx::Rect work_area = | 309 gfx::Rect work_area = |
318 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 310 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
319 | 311 |
320 window->SetBounds(work_area); | 312 window->SetBounds(work_area); |
321 window_state->Maximize(); | 313 window_state->Maximize(); |
322 EXPECT_TRUE(window_state->IsMaximized()); | 314 EXPECT_TRUE(window_state->IsMaximized()); |
323 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); | 315 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); |
324 | 316 |
325 window_state->Restore(); | 317 window_state->Restore(); |
326 EXPECT_FALSE(window_state->IsMaximized()); | 318 EXPECT_FALSE(window_state->IsMaximized()); |
327 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); | 319 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); |
328 EXPECT_TRUE(work_area.Contains(window->bounds())); | 320 EXPECT_TRUE(work_area.Contains(window->bounds())); |
329 } | 321 } |
330 | 322 |
331 TEST_P(WindowStateTest, DoNotResizeMaximizedWindowInFullscreen) { | 323 TEST_F(WindowStateTest, DoNotResizeMaximizedWindowInFullscreen) { |
332 const int height_offset = GetMdMaximizedWindowHeightOffset(); | |
333 | |
334 std::unique_ptr<aura::Window> maximized(CreateTestWindowInShellWithId(0)); | 324 std::unique_ptr<aura::Window> maximized(CreateTestWindowInShellWithId(0)); |
335 std::unique_ptr<aura::Window> fullscreen(CreateTestWindowInShellWithId(1)); | 325 std::unique_ptr<aura::Window> fullscreen(CreateTestWindowInShellWithId(1)); |
336 WindowState* maximized_state = GetWindowState(maximized.get()); | 326 WindowState* maximized_state = GetWindowState(maximized.get()); |
337 maximized_state->Maximize(); | 327 maximized_state->Maximize(); |
338 ASSERT_TRUE(maximized_state->IsMaximized()); | 328 ASSERT_TRUE(maximized_state->IsMaximized()); |
339 EXPECT_EQ(gfx::Rect(0, 0, 800, 553 + height_offset).ToString(), | 329 EXPECT_EQ(gfx::Rect(0, 0, 800, 552).ToString(), |
340 maximized->GetBoundsInScreen().ToString()); | 330 maximized->GetBoundsInScreen().ToString()); |
341 | 331 |
342 // Entering fullscreen mode will not update the maximized window's size | 332 // Entering fullscreen mode will not update the maximized window's size |
343 // under fullscreen. | 333 // under fullscreen. |
344 WMEvent fullscreen_event(WM_EVENT_FULLSCREEN); | 334 WMEvent fullscreen_event(WM_EVENT_FULLSCREEN); |
345 WindowState* fullscreen_state = GetWindowState(fullscreen.get()); | 335 WindowState* fullscreen_state = GetWindowState(fullscreen.get()); |
346 fullscreen_state->OnWMEvent(&fullscreen_event); | 336 fullscreen_state->OnWMEvent(&fullscreen_event); |
347 ASSERT_TRUE(fullscreen_state->IsFullscreen()); | 337 ASSERT_TRUE(fullscreen_state->IsFullscreen()); |
348 ASSERT_TRUE(maximized_state->IsMaximized()); | 338 ASSERT_TRUE(maximized_state->IsMaximized()); |
349 EXPECT_EQ(gfx::Rect(0, 0, 800, 553 + height_offset).ToString(), | 339 EXPECT_EQ(gfx::Rect(0, 0, 800, 552).ToString(), |
350 maximized->GetBoundsInScreen().ToString()); | 340 maximized->GetBoundsInScreen().ToString()); |
351 | 341 |
352 // Updating display size will update the maximum window size. | 342 // Updating display size will update the maximum window size. |
353 UpdateDisplay("900x700"); | 343 UpdateDisplay("900x700"); |
354 EXPECT_EQ("0,0 900x700", maximized->GetBoundsInScreen().ToString()); | 344 EXPECT_EQ("0,0 900x700", maximized->GetBoundsInScreen().ToString()); |
355 fullscreen.reset(); | 345 fullscreen.reset(); |
356 | 346 |
357 // Exiting fullscreen will update the maximized window to the work area. | 347 // Exiting fullscreen will update the maximized window to the work area. |
358 EXPECT_EQ(gfx::Rect(0, 0, 900, 653 + height_offset).ToString(), | 348 EXPECT_EQ(gfx::Rect(0, 0, 900, 652).ToString(), |
359 maximized->GetBoundsInScreen().ToString()); | 349 maximized->GetBoundsInScreen().ToString()); |
360 } | 350 } |
361 | 351 |
362 TEST_P(WindowStateTest, TrustedPinned) { | 352 TEST_F(WindowStateTest, TrustedPinned) { |
363 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 353 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
364 WindowState* window_state = GetWindowState(window.get()); | 354 WindowState* window_state = GetWindowState(window.get()); |
365 EXPECT_FALSE(window_state->IsTrustedPinned()); | 355 EXPECT_FALSE(window_state->IsTrustedPinned()); |
366 wm::PinWindow(window.get(), true /* trusted */); | 356 wm::PinWindow(window.get(), true /* trusted */); |
367 EXPECT_TRUE(window_state->IsTrustedPinned()); | 357 EXPECT_TRUE(window_state->IsTrustedPinned()); |
368 | 358 |
369 gfx::Rect work_area = | 359 gfx::Rect work_area = |
370 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 360 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
371 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); | 361 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); |
372 | 362 |
373 // Sending non-unpin/non-workspace related event should be ignored. | 363 // Sending non-unpin/non-workspace related event should be ignored. |
374 { | 364 { |
375 const WMEvent fullscreen_event(WM_EVENT_FULLSCREEN); | 365 const WMEvent fullscreen_event(WM_EVENT_FULLSCREEN); |
376 window_state->OnWMEvent(&fullscreen_event); | 366 window_state->OnWMEvent(&fullscreen_event); |
377 } | 367 } |
378 EXPECT_TRUE(window_state->IsTrustedPinned()); | 368 EXPECT_TRUE(window_state->IsTrustedPinned()); |
379 | 369 |
380 // Update display triggers workspace event. | 370 // Update display triggers workspace event. |
381 UpdateDisplay("300x200"); | 371 UpdateDisplay("300x200"); |
382 EXPECT_EQ("0,0 300x200", window->GetBoundsInScreen().ToString()); | 372 EXPECT_EQ("0,0 300x200", window->GetBoundsInScreen().ToString()); |
383 | 373 |
384 // Unpin should work. | 374 // Unpin should work. |
385 window_state->Restore(); | 375 window_state->Restore(); |
386 EXPECT_FALSE(window_state->IsTrustedPinned()); | 376 EXPECT_FALSE(window_state->IsTrustedPinned()); |
387 } | 377 } |
388 | 378 |
389 TEST_P(WindowStateTest, AllowSetBoundsInMaximized) { | 379 TEST_F(WindowStateTest, AllowSetBoundsInMaximized) { |
390 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 380 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
391 WindowState* window_state = GetWindowState(window.get()); | 381 WindowState* window_state = GetWindowState(window.get()); |
392 EXPECT_FALSE(window_state->IsMaximized()); | 382 EXPECT_FALSE(window_state->IsMaximized()); |
393 gfx::Rect work_area = | 383 gfx::Rect work_area = |
394 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 384 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
395 gfx::Rect original_bounds(50, 50, 200, 200); | 385 gfx::Rect original_bounds(50, 50, 200, 200); |
396 window->SetBounds(original_bounds); | 386 window->SetBounds(original_bounds); |
397 ASSERT_EQ(original_bounds, window->bounds()); | 387 ASSERT_EQ(original_bounds, window->bounds()); |
398 | 388 |
399 window_state->set_allow_set_bounds_in_maximized(true); | 389 window_state->set_allow_set_bounds_in_maximized(true); |
(...skipping 12 matching lines...) Expand all Loading... |
412 | 402 |
413 window_state->set_allow_set_bounds_in_maximized(false); | 403 window_state->set_allow_set_bounds_in_maximized(false); |
414 window_state->Maximize(); | 404 window_state->Maximize(); |
415 | 405 |
416 EXPECT_TRUE(window_state->IsMaximized()); | 406 EXPECT_TRUE(window_state->IsMaximized()); |
417 EXPECT_EQ(work_area, window->bounds()); | 407 EXPECT_EQ(work_area, window->bounds()); |
418 window->SetBounds(new_bounds); | 408 window->SetBounds(new_bounds); |
419 EXPECT_EQ(work_area, window->bounds()); | 409 EXPECT_EQ(work_area, window->bounds()); |
420 } | 410 } |
421 | 411 |
422 TEST_P(WindowStateTest, FullscreenMinimizedSwitching) { | 412 TEST_F(WindowStateTest, FullscreenMinimizedSwitching) { |
423 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 413 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
424 WindowState* window_state = GetWindowState(window.get()); | 414 WindowState* window_state = GetWindowState(window.get()); |
425 | 415 |
426 ash::wm::ToggleFullScreen(window_state, nullptr); | 416 ash::wm::ToggleFullScreen(window_state, nullptr); |
427 ASSERT_TRUE(window_state->IsFullscreen()); | 417 ASSERT_TRUE(window_state->IsFullscreen()); |
428 | 418 |
429 // Toggling the fullscreen window should restore to normal. | 419 // Toggling the fullscreen window should restore to normal. |
430 ash::wm::ToggleFullScreen(window_state, nullptr); | 420 ash::wm::ToggleFullScreen(window_state, nullptr); |
431 ASSERT_TRUE(window_state->IsNormalStateType()); | 421 ASSERT_TRUE(window_state->IsNormalStateType()); |
432 | 422 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 // return to the state before minimizing and fullscreen. | 457 // return to the state before minimizing and fullscreen. |
468 ash::wm::ToggleFullScreen(window_state, nullptr); | 458 ash::wm::ToggleFullScreen(window_state, nullptr); |
469 ASSERT_TRUE(window_state->IsMaximized()); | 459 ASSERT_TRUE(window_state->IsMaximized()); |
470 } | 460 } |
471 | 461 |
472 // TODO(skuhne): Add more unit test to verify the correctness for the restore | 462 // TODO(skuhne): Add more unit test to verify the correctness for the restore |
473 // operation. | 463 // operation. |
474 | 464 |
475 } // namespace wm | 465 } // namespace wm |
476 } // namespace ash | 466 } // namespace ash |
OLD | NEW |