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/material_design/material_design_controller.h" |
10 #include "ash/common/wm/window_state.h" | 10 #include "ash/common/wm/window_state.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 100 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
101 | 101 |
102 window_state->OnWMEvent(&snap_left); | 102 window_state->OnWMEvent(&snap_left); |
103 expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); | 103 expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); |
104 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); | 104 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); |
105 } | 105 } |
106 | 106 |
107 // Test how the minimum and maximum size specified by the aura::WindowDelegate | 107 // Test how the minimum and maximum size specified by the aura::WindowDelegate |
108 // affect snapping. | 108 // affect snapping. |
109 TEST_P(WindowStateTest, SnapWindowMinimumSize) { | 109 TEST_P(WindowStateTest, SnapWindowMinimumSize) { |
110 if (!SupportsHostWindowResize()) | |
111 return; | |
112 | |
113 UpdateDisplay("0+0-600x900"); | 110 UpdateDisplay("0+0-600x900"); |
114 const gfx::Rect kWorkAreaBounds = | 111 const gfx::Rect kWorkAreaBounds = |
115 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 112 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
116 | 113 |
117 aura::test::TestWindowDelegate delegate; | 114 aura::test::TestWindowDelegate delegate; |
118 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 115 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
119 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); | 116 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); |
120 | 117 |
121 // It should be possible to snap a window with a minimum size. | 118 // It should be possible to snap a window with a minimum size. |
122 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); | 119 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); |
(...skipping 12 matching lines...) Expand all Loading... |
135 EXPECT_FALSE(window_state->CanSnap()); | 132 EXPECT_FALSE(window_state->CanSnap()); |
136 delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1)); | 133 delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1)); |
137 EXPECT_FALSE(window_state->CanSnap()); | 134 EXPECT_FALSE(window_state->CanSnap()); |
138 delegate.set_maximum_size(gfx::Size()); | 135 delegate.set_maximum_size(gfx::Size()); |
139 window->SetProperty(aura::client::kCanMaximizeKey, false); | 136 window->SetProperty(aura::client::kCanMaximizeKey, false); |
140 EXPECT_FALSE(window_state->CanSnap()); | 137 EXPECT_FALSE(window_state->CanSnap()); |
141 } | 138 } |
142 | 139 |
143 // Test that the minimum size specified by aura::WindowDelegate gets respected. | 140 // Test that the minimum size specified by aura::WindowDelegate gets respected. |
144 TEST_P(WindowStateTest, TestRespectMinimumSize) { | 141 TEST_P(WindowStateTest, TestRespectMinimumSize) { |
145 if (!SupportsHostWindowResize()) | |
146 return; | |
147 | |
148 UpdateDisplay("0+0-1024x768"); | 142 UpdateDisplay("0+0-1024x768"); |
149 | 143 |
150 aura::test::TestWindowDelegate delegate; | 144 aura::test::TestWindowDelegate delegate; |
151 const gfx::Size minimum_size(gfx::Size(500, 300)); | 145 const gfx::Size minimum_size(gfx::Size(500, 300)); |
152 delegate.set_minimum_size(minimum_size); | 146 delegate.set_minimum_size(minimum_size); |
153 | 147 |
154 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( | 148 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( |
155 &delegate, -1, gfx::Rect(0, 100, 100, 100))); | 149 &delegate, -1, gfx::Rect(0, 100, 100, 100))); |
156 | 150 |
157 // Check that the window has the correct minimum size. | 151 // Check that the window has the correct minimum size. |
158 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); | 152 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); |
159 | 153 |
160 // Set the size to something bigger - that should work. | 154 // Set the size to something bigger - that should work. |
161 gfx::Rect bigger_bounds(700, 500, 700, 500); | 155 gfx::Rect bigger_bounds(700, 500, 700, 500); |
162 window->SetBounds(bigger_bounds); | 156 window->SetBounds(bigger_bounds); |
163 EXPECT_EQ(bigger_bounds.ToString(), window->bounds().ToString()); | 157 EXPECT_EQ(bigger_bounds.ToString(), window->bounds().ToString()); |
164 | 158 |
165 // Set the size to something smaller - that should only resize to the smallest | 159 // Set the size to something smaller - that should only resize to the smallest |
166 // possible size. | 160 // possible size. |
167 gfx::Rect smaller_bounds(700, 500, 100, 100); | 161 gfx::Rect smaller_bounds(700, 500, 100, 100); |
168 window->SetBounds(smaller_bounds); | 162 window->SetBounds(smaller_bounds); |
169 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); | 163 EXPECT_EQ(minimum_size.ToString(), window->bounds().size().ToString()); |
170 } | 164 } |
171 | 165 |
172 // 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 |
173 // exceed the screen size. | 167 // exceed the screen size. |
174 TEST_P(WindowStateTest, TestIgnoreTooBigMinimumSize) { | 168 TEST_P(WindowStateTest, TestIgnoreTooBigMinimumSize) { |
175 if (!SupportsHostWindowResize()) | |
176 return; | |
177 | |
178 UpdateDisplay("0+0-1024x768"); | 169 UpdateDisplay("0+0-1024x768"); |
179 const gfx::Size work_area_size = | 170 const gfx::Size work_area_size = |
180 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size(); | 171 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size(); |
181 const gfx::Size illegal_size(1280, 960); | 172 const gfx::Size illegal_size(1280, 960); |
182 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); | 173 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); |
183 | 174 |
184 aura::test::TestWindowDelegate delegate; | 175 aura::test::TestWindowDelegate delegate; |
185 const gfx::Size minimum_size(illegal_size); | 176 const gfx::Size minimum_size(illegal_size); |
186 delegate.set_minimum_size(minimum_size); | 177 delegate.set_minimum_size(minimum_size); |
187 | 178 |
188 // The creation should force the window to respect the screen size. | 179 // The creation should force the window to respect the screen size. |
189 std::unique_ptr<aura::Window> window( | 180 std::unique_ptr<aura::Window> window( |
190 CreateTestWindowInShellWithDelegate(&delegate, -1, illegal_bounds)); | 181 CreateTestWindowInShellWithDelegate(&delegate, -1, illegal_bounds)); |
191 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 182 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
192 | 183 |
193 // Trying to set the size to something bigger then the screen size should be | 184 // Trying to set the size to something bigger then the screen size should be |
194 // ignored. | 185 // ignored. |
195 window->SetBounds(illegal_bounds); | 186 window->SetBounds(illegal_bounds); |
196 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 187 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
197 | 188 |
198 // Maximizing the window should not allow it to go bigger than that either. | 189 // Maximizing the window should not allow it to go bigger than that either. |
199 WindowState* window_state = GetWindowState(window.get()); | 190 WindowState* window_state = GetWindowState(window.get()); |
200 window_state->Maximize(); | 191 window_state->Maximize(); |
201 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); | 192 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); |
202 } | 193 } |
203 | 194 |
204 // Test that setting the bounds of a snapped window keeps its snapped. | 195 // Test that setting the bounds of a snapped window keeps its snapped. |
205 TEST_P(WindowStateTest, SnapWindowSetBounds) { | 196 TEST_P(WindowStateTest, SnapWindowSetBounds) { |
206 if (!SupportsHostWindowResize()) | |
207 return; | |
208 | |
209 UpdateDisplay("0+0-900x600"); | 197 UpdateDisplay("0+0-900x600"); |
210 const gfx::Rect kWorkAreaBounds = | 198 const gfx::Rect kWorkAreaBounds = |
211 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 199 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
212 | 200 |
213 std::unique_ptr<aura::Window> window( | 201 std::unique_ptr<aura::Window> window( |
214 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); | 202 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); |
215 WindowState* window_state = GetWindowState(window.get()); | 203 WindowState* window_state = GetWindowState(window.get()); |
216 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); | 204 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); |
217 window_state->OnWMEvent(&snap_left); | 205 window_state->OnWMEvent(&snap_left); |
218 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); | 206 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 window_state->SetStateObject(std::unique_ptr<WindowState::State>( | 302 window_state->SetStateObject(std::unique_ptr<WindowState::State>( |
315 new AlwaysMaximizeTestState(window_state->GetStateType())))); | 303 new AlwaysMaximizeTestState(window_state->GetStateType())))); |
316 EXPECT_TRUE(window_state->IsMaximized()); | 304 EXPECT_TRUE(window_state->IsMaximized()); |
317 window_state->SetStateObject(std::move(old)); | 305 window_state->SetStateObject(std::move(old)); |
318 EXPECT_FALSE(window_state->IsMaximized()); | 306 EXPECT_FALSE(window_state->IsMaximized()); |
319 } | 307 } |
320 | 308 |
321 // Tests that a window that had same bounds as the work area shrinks after the | 309 // Tests that a window that had same bounds as the work area shrinks after the |
322 // window is maximized and then restored. | 310 // window is maximized and then restored. |
323 TEST_P(WindowStateTest, RestoredWindowBoundsShrink) { | 311 TEST_P(WindowStateTest, RestoredWindowBoundsShrink) { |
324 if (!SupportsHostWindowResize()) | |
325 return; | |
326 | |
327 UpdateDisplay("0+0-600x900"); | 312 UpdateDisplay("0+0-600x900"); |
328 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 313 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
329 WindowState* window_state = GetWindowState(window.get()); | 314 WindowState* window_state = GetWindowState(window.get()); |
330 EXPECT_FALSE(window_state->IsMaximized()); | 315 EXPECT_FALSE(window_state->IsMaximized()); |
331 gfx::Rect work_area = | 316 gfx::Rect work_area = |
332 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 317 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
333 | 318 |
334 window->SetBounds(work_area); | 319 window->SetBounds(work_area); |
335 window_state->Maximize(); | 320 window_state->Maximize(); |
336 EXPECT_TRUE(window_state->IsMaximized()); | 321 EXPECT_TRUE(window_state->IsMaximized()); |
337 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); | 322 EXPECT_EQ(work_area.ToString(), window->bounds().ToString()); |
338 | 323 |
339 window_state->Restore(); | 324 window_state->Restore(); |
340 EXPECT_FALSE(window_state->IsMaximized()); | 325 EXPECT_FALSE(window_state->IsMaximized()); |
341 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); | 326 EXPECT_NE(work_area.ToString(), window->bounds().ToString()); |
342 EXPECT_TRUE(work_area.Contains(window->bounds())); | 327 EXPECT_TRUE(work_area.Contains(window->bounds())); |
343 } | 328 } |
344 | 329 |
345 TEST_P(WindowStateTest, DoNotResizeMaximizedWindowInFullscreen) { | 330 TEST_P(WindowStateTest, DoNotResizeMaximizedWindowInFullscreen) { |
346 if (!SupportsHostWindowResize()) | |
347 return; | |
348 const int height_offset = GetMdMaximizedWindowHeightOffset(); | 331 const int height_offset = GetMdMaximizedWindowHeightOffset(); |
349 | 332 |
350 std::unique_ptr<aura::Window> maximized(CreateTestWindowInShellWithId(0)); | 333 std::unique_ptr<aura::Window> maximized(CreateTestWindowInShellWithId(0)); |
351 std::unique_ptr<aura::Window> fullscreen(CreateTestWindowInShellWithId(1)); | 334 std::unique_ptr<aura::Window> fullscreen(CreateTestWindowInShellWithId(1)); |
352 WindowState* maximized_state = GetWindowState(maximized.get()); | 335 WindowState* maximized_state = GetWindowState(maximized.get()); |
353 maximized_state->Maximize(); | 336 maximized_state->Maximize(); |
354 ASSERT_TRUE(maximized_state->IsMaximized()); | 337 ASSERT_TRUE(maximized_state->IsMaximized()); |
355 EXPECT_EQ(gfx::Rect(0, 0, 800, 553 + height_offset).ToString(), | 338 EXPECT_EQ(gfx::Rect(0, 0, 800, 553 + height_offset).ToString(), |
356 maximized->GetBoundsInScreen().ToString()); | 339 maximized->GetBoundsInScreen().ToString()); |
357 | 340 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 EXPECT_EQ(work_area, window->bounds()); | 389 EXPECT_EQ(work_area, window->bounds()); |
407 window->SetBounds(new_bounds); | 390 window->SetBounds(new_bounds); |
408 EXPECT_EQ(work_area, window->bounds()); | 391 EXPECT_EQ(work_area, window->bounds()); |
409 } | 392 } |
410 | 393 |
411 // TODO(skuhne): Add more unit test to verify the correctness for the restore | 394 // TODO(skuhne): Add more unit test to verify the correctness for the restore |
412 // operation. | 395 // operation. |
413 | 396 |
414 } // namespace wm | 397 } // namespace wm |
415 } // namespace ash | 398 } // namespace ash |
OLD | NEW |