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

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

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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_properties.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/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 const gfx::Rect kPrimaryDisplayWorkAreaBounds = 69 const gfx::Rect kPrimaryDisplayWorkAreaBounds =
70 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 70 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
71 const gfx::Rect kSecondaryDisplayWorkAreaBounds = 71 const gfx::Rect kSecondaryDisplayWorkAreaBounds =
72 ScreenUtil::GetSecondaryDisplay().work_area(); 72 ScreenUtil::GetSecondaryDisplay().work_area();
73 73
74 std::unique_ptr<aura::Window> window( 74 std::unique_ptr<aura::Window> window(
75 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); 75 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
76 WindowState* window_state = GetWindowState(window.get()); 76 WindowState* window_state = GetWindowState(window.get());
77 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); 77 const WMEvent snap_left(WM_EVENT_SNAP_LEFT);
78 window_state->OnWMEvent(&snap_left); 78 window_state->OnWMEvent(&snap_left);
79 gfx::Rect expected = gfx::Rect( 79 gfx::Rect expected = gfx::Rect(kPrimaryDisplayWorkAreaBounds.x(),
80 kPrimaryDisplayWorkAreaBounds.x(), 80 kPrimaryDisplayWorkAreaBounds.y(),
81 kPrimaryDisplayWorkAreaBounds.y(), 81 kPrimaryDisplayWorkAreaBounds.width() / 2,
82 kPrimaryDisplayWorkAreaBounds.width() / 2, 82 kPrimaryDisplayWorkAreaBounds.height());
83 kPrimaryDisplayWorkAreaBounds.height());
84 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 83 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
85 84
86 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); 85 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT);
87 window_state->OnWMEvent(&snap_right); 86 window_state->OnWMEvent(&snap_right);
88 expected.set_x(kPrimaryDisplayWorkAreaBounds.right() - expected.width()); 87 expected.set_x(kPrimaryDisplayWorkAreaBounds.right() - expected.width());
89 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 88 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
90 89
91 // Move the window to the secondary display. 90 // Move the window to the secondary display.
92 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100), 91 window->SetBoundsInScreen(gfx::Rect(600, 0, 100, 100),
93 ScreenUtil::GetSecondaryDisplay()); 92 ScreenUtil::GetSecondaryDisplay());
94 93
95 window_state->OnWMEvent(&snap_right); 94 window_state->OnWMEvent(&snap_right);
96 expected = gfx::Rect( 95 expected = gfx::Rect(kSecondaryDisplayWorkAreaBounds.x() +
97 kSecondaryDisplayWorkAreaBounds.x() + 96 kSecondaryDisplayWorkAreaBounds.width() / 2,
98 kSecondaryDisplayWorkAreaBounds.width() / 2, 97 kSecondaryDisplayWorkAreaBounds.y(),
99 kSecondaryDisplayWorkAreaBounds.y(), 98 kSecondaryDisplayWorkAreaBounds.width() / 2,
100 kSecondaryDisplayWorkAreaBounds.width() / 2, 99 kSecondaryDisplayWorkAreaBounds.height());
101 kSecondaryDisplayWorkAreaBounds.height());
102 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 100 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
103 101
104 window_state->OnWMEvent(&snap_left); 102 window_state->OnWMEvent(&snap_left);
105 expected.set_x(kSecondaryDisplayWorkAreaBounds.x()); 103 expected.set_x(kSecondaryDisplayWorkAreaBounds.x());
106 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 104 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
107 } 105 }
108 106
109 // 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
110 // affect snapping. 108 // affect snapping.
111 TEST_P(WindowStateTest, SnapWindowMinimumSize) { 109 TEST_P(WindowStateTest, SnapWindowMinimumSize) {
112 if (!SupportsHostWindowResize()) 110 if (!SupportsHostWindowResize())
113 return; 111 return;
114 112
115 UpdateDisplay("0+0-600x900"); 113 UpdateDisplay("0+0-600x900");
116 const gfx::Rect kWorkAreaBounds = 114 const gfx::Rect kWorkAreaBounds =
117 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 115 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
118 116
119 aura::test::TestWindowDelegate delegate; 117 aura::test::TestWindowDelegate delegate;
120 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 118 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
121 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); 119 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100)));
122 120
123 // It should be possible to snap a window with a minimum size. 121 // It should be possible to snap a window with a minimum size.
124 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); 122 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0));
125 WindowState* window_state = GetWindowState(window.get()); 123 WindowState* window_state = GetWindowState(window.get());
126 EXPECT_TRUE(window_state->CanSnap()); 124 EXPECT_TRUE(window_state->CanSnap());
127 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); 125 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT);
128 window_state->OnWMEvent(&snap_right); 126 window_state->OnWMEvent(&snap_right);
129 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x() + 1, 127 gfx::Rect expected =
130 kWorkAreaBounds.y(), 128 gfx::Rect(kWorkAreaBounds.x() + 1, kWorkAreaBounds.y(),
131 kWorkAreaBounds.width() - 1, 129 kWorkAreaBounds.width() - 1, kWorkAreaBounds.height());
132 kWorkAreaBounds.height());
133 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 130 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
134 131
135 // It should not be possible to snap a window with a maximum size, or if it 132 // It should not be possible to snap a window with a maximum size, or if it
136 // cannot be maximized. 133 // cannot be maximized.
137 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); 134 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0));
138 EXPECT_FALSE(window_state->CanSnap()); 135 EXPECT_FALSE(window_state->CanSnap());
139 delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1)); 136 delegate.set_maximum_size(gfx::Size(0, kWorkAreaBounds.height() - 1));
140 EXPECT_FALSE(window_state->CanSnap()); 137 EXPECT_FALSE(window_state->CanSnap());
141 delegate.set_maximum_size(gfx::Size()); 138 delegate.set_maximum_size(gfx::Size());
142 window->SetProperty(aura::client::kCanMaximizeKey, false); 139 window->SetProperty(aura::client::kCanMaximizeKey, false);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 UpdateDisplay("0+0-900x600"); 209 UpdateDisplay("0+0-900x600");
213 const gfx::Rect kWorkAreaBounds = 210 const gfx::Rect kWorkAreaBounds =
214 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 211 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
215 212
216 std::unique_ptr<aura::Window> window( 213 std::unique_ptr<aura::Window> window(
217 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); 214 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
218 WindowState* window_state = GetWindowState(window.get()); 215 WindowState* window_state = GetWindowState(window.get());
219 const WMEvent snap_left(WM_EVENT_SNAP_LEFT); 216 const WMEvent snap_left(WM_EVENT_SNAP_LEFT);
220 window_state->OnWMEvent(&snap_left); 217 window_state->OnWMEvent(&snap_left);
221 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); 218 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
222 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x(), 219 gfx::Rect expected =
223 kWorkAreaBounds.y(), 220 gfx::Rect(kWorkAreaBounds.x(), kWorkAreaBounds.y(),
224 kWorkAreaBounds.width() / 2, 221 kWorkAreaBounds.width() / 2, kWorkAreaBounds.height());
225 kWorkAreaBounds.height());
226 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 222 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
227 223
228 // Snapped windows can have any width. 224 // Snapped windows can have any width.
229 expected.set_width(500); 225 expected.set_width(500);
230 window->SetBounds(gfx::Rect(10, 10, 500, 300)); 226 window->SetBounds(gfx::Rect(10, 10, 500, 300));
231 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 227 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
232 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType()); 228 EXPECT_EQ(WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
233 } 229 }
234 230
235 // Test that snapping left/right preserves the restore bounds. 231 // Test that snapping left/right preserves the restore bounds.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 window->SetBounds(gfx::Rect(100, 100, 100, 100)); 278 window->SetBounds(gfx::Rect(100, 100, 100, 100));
283 window->Show(); 279 window->Show();
284 280
285 window_state->Maximize(); 281 window_state->Maximize();
286 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT); 282 const WMEvent snap_right(WM_EVENT_SNAP_RIGHT);
287 window_state->OnWMEvent(&snap_right); 283 window_state->OnWMEvent(&snap_right);
288 284
289 const gfx::Rect kWorkAreaBounds = 285 const gfx::Rect kWorkAreaBounds =
290 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); 286 display::Screen::GetScreen()->GetPrimaryDisplay().work_area();
291 gfx::Rect expected_snapped_bounds( 287 gfx::Rect expected_snapped_bounds(
292 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, 288 kWorkAreaBounds.x() + kWorkAreaBounds.width() / 2, kWorkAreaBounds.y(),
293 kWorkAreaBounds.y(), 289 kWorkAreaBounds.width() / 2, kWorkAreaBounds.height());
294 kWorkAreaBounds.width() / 2,
295 kWorkAreaBounds.height());
296 EXPECT_EQ(expected_snapped_bounds.ToString(), 290 EXPECT_EQ(expected_snapped_bounds.ToString(),
297 window->GetBoundsInScreen().ToString()); 291 window->GetBoundsInScreen().ToString());
298 292
299 // The window should still be auto managed despite being right maximized. 293 // The window should still be auto managed despite being right maximized.
300 EXPECT_TRUE(window_state->window_position_managed()); 294 EXPECT_TRUE(window_state->window_position_managed());
301 } 295 }
302 296
303 // Test that the replacement of a State object works as expected. 297 // Test that the replacement of a State object works as expected.
304 TEST_P(WindowStateTest, SimpleStateSwap) { 298 TEST_P(WindowStateTest, SimpleStateSwap) {
305 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 299 std::unique_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 // Exiting fullscreen will update the maximized window to the work area. 373 // Exiting fullscreen will update the maximized window to the work area.
380 EXPECT_EQ(gfx::Rect(0, 0, 900, 653 + height_offset).ToString(), 374 EXPECT_EQ(gfx::Rect(0, 0, 900, 653 + height_offset).ToString(),
381 maximized->GetBoundsInScreen().ToString()); 375 maximized->GetBoundsInScreen().ToString());
382 } 376 }
383 377
384 // TODO(skuhne): Add more unit test to verify the correctness for the restore 378 // TODO(skuhne): Add more unit test to verify the correctness for the restore
385 // operation. 379 // operation.
386 380
387 } // namespace wm 381 } // namespace wm
388 } // namespace ash 382 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_properties.cc ('k') | ash/wm/window_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698