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

Side by Side Diff: ash/wm/window_state_unittest.cc

Issue 1924703002: Rename gfx::Display/Screen to display::Display/Screen in ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 | « ash/wm/window_positioner_unittest.cc ('k') | ash/wm/window_util.cc » ('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 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/common/window_state.h" 5 #include "ash/wm/common/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/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/wm/common/window_state.h" 11 #include "ash/wm/common/window_state.h"
12 #include "ash/wm/common/wm_event.h" 12 #include "ash/wm/common/wm_event.h"
13 #include "ash/wm/window_state_aura.h" 13 #include "ash/wm/window_state_aura.h"
14 #include "ui/aura/client/aura_constants.h" 14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/test/test_window_delegate.h" 15 #include "ui/aura/test/test_window_delegate.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/gfx/screen.h" 17 #include "ui/display/screen.h"
18 18
19 namespace ash { 19 namespace ash {
20 namespace wm { 20 namespace wm {
21 namespace { 21 namespace {
22 22
23 class AlwaysMaximizeTestState : public WindowState::State { 23 class AlwaysMaximizeTestState : public WindowState::State {
24 public: 24 public:
25 explicit AlwaysMaximizeTestState(WindowStateType initial_state_type) 25 explicit AlwaysMaximizeTestState(WindowStateType initial_state_type)
26 : state_type_(initial_state_type) {} 26 : state_type_(initial_state_type) {}
27 ~AlwaysMaximizeTestState() override {} 27 ~AlwaysMaximizeTestState() override {}
(...skipping 24 matching lines...) Expand all
52 typedef test::AshTestBase WindowStateTest; 52 typedef test::AshTestBase WindowStateTest;
53 53
54 // Test that a window gets properly snapped to the display's edges in a 54 // Test that a window gets properly snapped to the display's edges in a
55 // multi monitor environment. 55 // multi monitor environment.
56 TEST_F(WindowStateTest, SnapWindowBasic) { 56 TEST_F(WindowStateTest, SnapWindowBasic) {
57 if (!SupportsMultipleDisplays()) 57 if (!SupportsMultipleDisplays())
58 return; 58 return;
59 59
60 UpdateDisplay("0+0-500x400, 0+500-600x400"); 60 UpdateDisplay("0+0-500x400, 0+500-600x400");
61 const gfx::Rect kPrimaryDisplayWorkAreaBounds = 61 const gfx::Rect kPrimaryDisplayWorkAreaBounds =
62 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 62 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
63 const gfx::Rect kSecondaryDisplayWorkAreaBounds = 63 const gfx::Rect kSecondaryDisplayWorkAreaBounds =
64 ScreenUtil::GetSecondaryDisplay().work_area(); 64 ScreenUtil::GetSecondaryDisplay().work_area();
65 65
66 std::unique_ptr<aura::Window> window( 66 std::unique_ptr<aura::Window> window(
67 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); 67 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
68 WindowState* window_state = GetWindowState(window.get()); 68 WindowState* window_state = GetWindowState(window.get());
69 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); 69 const WMEvent snap_left(WM_EVENT_SNAP_LEFT);
70 window_state->OnWMEvent(&snap_left); 70 window_state->OnWMEvent(&snap_left);
71 gfx::Rect expected = gfx::Rect( 71 gfx::Rect expected = gfx::Rect(
72 kPrimaryDisplayWorkAreaBounds.x(), 72 kPrimaryDisplayWorkAreaBounds.x(),
(...skipping 26 matching lines...) Expand all
99 } 99 }
100 100
101 // Test how the minimum and maximum size specified by the aura::WindowDelegate 101 // Test how the minimum and maximum size specified by the aura::WindowDelegate
102 // affect snapping. 102 // affect snapping.
103 TEST_F(WindowStateTest, SnapWindowMinimumSize) { 103 TEST_F(WindowStateTest, SnapWindowMinimumSize) {
104 if (!SupportsHostWindowResize()) 104 if (!SupportsHostWindowResize())
105 return; 105 return;
106 106
107 UpdateDisplay("0+0-600x900"); 107 UpdateDisplay("0+0-600x900");
108 const gfx::Rect kWorkAreaBounds = 108 const gfx::Rect kWorkAreaBounds =
109 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 109 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
110 110
111 aura::test::TestWindowDelegate delegate; 111 aura::test::TestWindowDelegate delegate;
112 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 112 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
113 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); 113 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100)));
114 114
115 // It should be possible to snap a window with a minimum size. 115 // It should be possible to snap a window with a minimum size.
116 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); 116 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0));
117 WindowState* window_state = GetWindowState(window.get()); 117 WindowState* window_state = GetWindowState(window.get());
118 EXPECT_TRUE(window_state->CanSnap()); 118 EXPECT_TRUE(window_state->CanSnap());
119 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); 119 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 } 165 }
166 166
167 // Test that the minimum window size specified by aura::WindowDelegate does not 167 // Test that the minimum window size specified by aura::WindowDelegate does not
168 // exceed the screen size. 168 // exceed the screen size.
169 TEST_F(WindowStateTest, TestIgnoreTooBigMinimumSize) { 169 TEST_F(WindowStateTest, TestIgnoreTooBigMinimumSize) {
170 if (!SupportsHostWindowResize()) 170 if (!SupportsHostWindowResize())
171 return; 171 return;
172 172
173 UpdateDisplay("0+0-1024x768"); 173 UpdateDisplay("0+0-1024x768");
174 const gfx::Size work_area_size = 174 const gfx::Size work_area_size =
175 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area().size(); 175 display::Screen::GetScreen()->GetPrimaryDisplay().work_area().size();
176 const gfx::Size illegal_size(1280, 960); 176 const gfx::Size illegal_size(1280, 960);
177 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size); 177 const gfx::Rect illegal_bounds(gfx::Point(0, 0), illegal_size);
178 178
179 aura::test::TestWindowDelegate delegate; 179 aura::test::TestWindowDelegate delegate;
180 const gfx::Size minimum_size(illegal_size); 180 const gfx::Size minimum_size(illegal_size);
181 delegate.set_minimum_size(minimum_size); 181 delegate.set_minimum_size(minimum_size);
182 182
183 // The creation should force the window to respect the screen size. 183 // The creation should force the window to respect the screen size.
184 std::unique_ptr<aura::Window> window( 184 std::unique_ptr<aura::Window> window(
185 CreateTestWindowInShellWithDelegate(&delegate, -1, illegal_bounds)); 185 CreateTestWindowInShellWithDelegate(&delegate, -1, illegal_bounds));
(...skipping 10 matching lines...) Expand all
196 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString()); 196 EXPECT_EQ(work_area_size.ToString(), window->bounds().size().ToString());
197 } 197 }
198 198
199 // Test that setting the bounds of a snapped window keeps its snapped. 199 // Test that setting the bounds of a snapped window keeps its snapped.
200 TEST_F(WindowStateTest, SnapWindowSetBounds) { 200 TEST_F(WindowStateTest, SnapWindowSetBounds) {
201 if (!SupportsHostWindowResize()) 201 if (!SupportsHostWindowResize())
202 return; 202 return;
203 203
204 UpdateDisplay("0+0-900x600"); 204 UpdateDisplay("0+0-900x600");
205 const gfx::Rect kWorkAreaBounds = 205 const gfx::Rect kWorkAreaBounds =
206 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 206 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
207 207
208 std::unique_ptr<aura::Window> window( 208 std::unique_ptr<aura::Window> window(
209 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); 209 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
210 WindowState* window_state = GetWindowState(window.get()); 210 WindowState* window_state = GetWindowState(window.get());
211 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); 211 const WMEvent snap_left(WM_EVENT_SNAP_LEFT);
212 window_state->OnWMEvent(&snap_left); 212 window_state->OnWMEvent(&snap_left);
213 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); 213 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
214 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), 214 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(),
215 kWorkAreaBounds.y(), 215 kWorkAreaBounds.y(),
216 kWorkAreaBounds.width() / 2, 216 kWorkAreaBounds.width() / 2,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 window_state->set_window_position_managed(true); 272 window_state->set_window_position_managed(true);
273 window->Hide(); 273 window->Hide();
274 window->SetBounds(gfx::Rect(100, 100, 100, 100)); 274 window->SetBounds(gfx::Rect(100, 100, 100, 100));
275 window->Show(); 275 window->Show();
276 276
277 window_state->Maximize(); 277 window_state->Maximize();
278 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); 278 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT);
279 window_state->OnWMEvent(&snap_right); 279 window_state->OnWMEvent(&snap_right);
280 280
281 const gfx::Rect kWorkAreaBounds = 281 const gfx::Rect kWorkAreaBounds =
282 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 282 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
283 gfx::Rect expected_snapped_bounds( 283 gfx::Rect expected_snapped_bounds(
284 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, 284 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2,
285 kWorkAreaBounds.y(), 285 kWorkAreaBounds.y(),
286 kWorkAreaBounds.width() / 2, 286 kWorkAreaBounds.width() / 2,
287 kWorkAreaBounds.height()); 287 kWorkAreaBounds.height());
288 EXPECT_EQ(expected_snapped_bounds.ToString(), 288 EXPECT_EQ(expected_snapped_bounds.ToString(),
289 window->GetBoundsInScreen().ToString()); 289 window->GetBoundsInScreen().ToString());
290 290
291 // The window should still be auto managed despite being right maximized. 291 // The window should still be auto managed despite being right maximized.
292 EXPECT_TRUE(window_state->window_position_managed()); 292 EXPECT_TRUE(window_state->window_position_managed());
(...skipping 23 matching lines...) Expand all
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 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 322 std::unique_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 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 326 display::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
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
OLDNEW
« no previous file with comments | « ash/wm/window_positioner_unittest.cc ('k') | ash/wm/window_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698