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

Side by Side Diff: ash/wm/workspace/snap_sizer_unittest.cc

Issue 24108003: [Cleanup] Rename WindowSettings to WindowState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/workspace/snap_sizer.h" 5 #include "ash/wm/workspace/snap_sizer.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "ash/wm/property_util.h" 11 #include "ash/wm/window_state.h"
12 #include "ash/wm/window_settings.h"
13 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
14 #include "base/command_line.h" 13 #include "base/command_line.h"
15 #include "ui/aura/root_window.h" 14 #include "ui/aura/root_window.h"
16 #include "ui/aura/test/test_window_delegate.h" 15 #include "ui/aura/test/test_window_delegate.h"
17 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
18 #include "ui/gfx/screen.h" 17 #include "ui/gfx/screen.h"
19 18
20 namespace ash { 19 namespace ash {
21 20
22 typedef test::AshTestBase SnapSizerTest; 21 typedef test::AshTestBase SnapSizerTest;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 UpdateDisplay("0+0-600x800"); 79 UpdateDisplay("0+0-600x800");
81 const gfx::Rect kWorkAreaBounds = 80 const gfx::Rect kWorkAreaBounds =
82 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); 81 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
83 82
84 aura::test::TestWindowDelegate delegate; 83 aura::test::TestWindowDelegate delegate;
85 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate( 84 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
86 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100))); 85 &delegate, -1, gfx::Rect(0, 100, kWorkAreaBounds.width() - 1, 100)));
87 86
88 // It should be possible to snap a window with a minimum size. 87 // It should be possible to snap a window with a minimum size.
89 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0)); 88 delegate.set_minimum_size(gfx::Size(kWorkAreaBounds.width() - 1, 0));
90 EXPECT_TRUE(ash::wm::CanSnapWindow(window.get())); 89 wm::WindowState* window_state = wm::GetWindowState(window.get());
90 EXPECT_TRUE(window_state->CanSnap());
91 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); 91 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE);
92 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x() + 1, 92 gfx::Rect expected = gfx::Rect(kWorkAreaBounds.x() + 1,
93 kWorkAreaBounds.y(), 93 kWorkAreaBounds.y(),
94 kWorkAreaBounds.width() - 1, 94 kWorkAreaBounds.width() - 1,
95 kWorkAreaBounds.height()); 95 kWorkAreaBounds.height());
96 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 96 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
97 97
98 // It should not be possible to snap a window with a maximum size. 98 // It should not be possible to snap a window with a maximum size.
99 delegate.set_minimum_size(gfx::Size()); 99 delegate.set_minimum_size(gfx::Size());
100 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX)); 100 delegate.set_maximum_size(gfx::Size(kWorkAreaBounds.width() - 1, INT_MAX));
101 EXPECT_FALSE(ash::wm::CanSnapWindow(window.get())); 101 EXPECT_FALSE(window_state->CanSnap());
102 } 102 }
103 103
104 // Test that repeadedly calling SnapSizer::SnapWindow() steps through the ideal 104 // Test that repeadedly calling SnapSizer::SnapWindow() steps through the ideal
105 // widths in descending order as well as 90% and 50% of the work area's width. 105 // widths in descending order as well as 90% and 50% of the work area's width.
106 TEST_F(SnapSizerTest, StepThroughSizes) { 106 TEST_F(SnapSizerTest, StepThroughSizes) {
107 if (!SupportsHostWindowResize()) 107 if (!SupportsHostWindowResize())
108 return; 108 return;
109 109
110 UpdateDisplay("0+0-1024x800"); 110 UpdateDisplay("0+0-1024x800");
111 const gfx::Rect kWorkAreaBounds = 111 const gfx::Rect kWorkAreaBounds =
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 SnapSizer::OTHER_INPUT); 224 SnapSizer::OTHER_INPUT);
225 sizer.SelectDefaultSizeAndDisableResize(); 225 sizer.SelectDefaultSizeAndDisableResize();
226 sizer.SnapWindowToTargetBounds(); 226 sizer.SnapWindowToTargetBounds();
227 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString()); 227 EXPECT_EQ(expected.ToString(), window->GetBoundsInScreen().ToString());
228 } 228 }
229 229
230 // Test that snapping left/right preserves the restore bounds. 230 // Test that snapping left/right preserves the restore bounds.
231 TEST_F(SnapSizerTest, RestoreBounds) { 231 TEST_F(SnapSizerTest, RestoreBounds) {
232 scoped_ptr<aura::Window> window( 232 scoped_ptr<aura::Window> window(
233 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100))); 233 CreateTestWindowInShellWithBounds(gfx::Rect(100, 100, 100, 100)));
234 EXPECT_TRUE(wm::IsWindowNormal(window.get())); 234 wm::WindowState* window_state = wm::GetWindowState(window.get());
235
236 EXPECT_TRUE(window_state->IsNormalShowState());
235 237
236 // 1) Start with restored window with restore bounds set. 238 // 1) Start with restored window with restore bounds set.
237 gfx::Rect restore_bounds = window->GetBoundsInScreen(); 239 gfx::Rect restore_bounds = window->GetBoundsInScreen();
238 restore_bounds.set_width(restore_bounds.width() + 1); 240 restore_bounds.set_width(restore_bounds.width() + 1);
239 SetRestoreBoundsInScreen(window.get(), restore_bounds); 241 window_state->SetRestoreBoundsInScreen(restore_bounds);
240 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); 242 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE);
241 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); 243 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE);
242 EXPECT_NE(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); 244 EXPECT_NE(restore_bounds.ToString(), window->GetBoundsInScreen().ToString());
243 EXPECT_EQ(restore_bounds.ToString(), 245 EXPECT_EQ(restore_bounds.ToString(),
244 GetRestoreBoundsInScreen(window.get())->ToString()); 246 window_state->GetRestoreBoundsInScreen().ToString());
245 wm::RestoreWindow(window.get()); 247 window_state->Restore();
246 EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); 248 EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString());
247 249
248 // 2) Start with restored bounds set as a result of maximizing the window. 250 // 2) Start with restored bounds set as a result of maximizing the window.
249 wm::MaximizeWindow(window.get()); 251 window_state->Maximize();
250 gfx::Rect maximized_bounds = window->GetBoundsInScreen(); 252 gfx::Rect maximized_bounds = window->GetBoundsInScreen();
251 EXPECT_NE(maximized_bounds.ToString(), restore_bounds.ToString()); 253 EXPECT_NE(maximized_bounds.ToString(), restore_bounds.ToString());
252 EXPECT_EQ(restore_bounds.ToString(), 254 EXPECT_EQ(restore_bounds.ToString(),
253 GetRestoreBoundsInScreen(window.get())->ToString()); 255 window_state->GetRestoreBoundsInScreen().ToString());
254 256
255 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE); 257 SnapSizer::SnapWindow(window.get(), SnapSizer::LEFT_EDGE);
256 EXPECT_NE(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); 258 EXPECT_NE(restore_bounds.ToString(), window->GetBoundsInScreen().ToString());
257 EXPECT_NE(maximized_bounds.ToString(), 259 EXPECT_NE(maximized_bounds.ToString(),
258 window->GetBoundsInScreen().ToString()); 260 window->GetBoundsInScreen().ToString());
259 EXPECT_EQ(restore_bounds.ToString(), 261 EXPECT_EQ(restore_bounds.ToString(),
260 GetRestoreBoundsInScreen(window.get())->ToString()); 262 window_state->GetRestoreBoundsInScreen().ToString());
261 263
262 wm::RestoreWindow(window.get()); 264 window_state->Restore();
263 EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString()); 265 EXPECT_EQ(restore_bounds.ToString(), window->GetBoundsInScreen().ToString());
264 } 266 }
265 267
266 // Test that maximizing an auto managed window, then snapping it puts the window 268 // Test that maximizing an auto managed window, then snapping it puts the window
267 // at the snapped bounds and not at the auto-managed (centered) bounds. 269 // at the snapped bounds and not at the auto-managed (centered) bounds.
268 TEST_F(SnapSizerTest, AutoManaged) { 270 TEST_F(SnapSizerTest, AutoManaged) {
269 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); 271 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0));
270 wm::GetWindowSettings(window.get())->set_window_position_managed(true); 272 wm::WindowState* window_state = wm::GetWindowState(window.get());
273 window_state->set_window_position_managed(true);
271 window->Hide(); 274 window->Hide();
272 window->SetBounds(gfx::Rect(100, 100, 100, 100)); 275 window->SetBounds(gfx::Rect(100, 100, 100, 100));
273 window->Show(); 276 window->Show();
274 277
275 wm::MaximizeWindow(window.get()); 278 window_state->Maximize();
276 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE); 279 SnapSizer::SnapWindow(window.get(), SnapSizer::RIGHT_EDGE);
277 280
278 const gfx::Rect kWorkAreaBounds = 281 const gfx::Rect kWorkAreaBounds =
279 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(); 282 ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
280 gfx::Rect expected_snapped_bounds( 283 gfx::Rect expected_snapped_bounds(
281 kWorkAreaBounds.right() - window->bounds().width(), 284 kWorkAreaBounds.right() - window->bounds().width(),
282 kWorkAreaBounds.y(), 285 kWorkAreaBounds.y(),
283 window->bounds().width(), // No expectation for the width. 286 window->bounds().width(), // No expectation for the width.
284 kWorkAreaBounds.height()); 287 kWorkAreaBounds.height());
285 EXPECT_EQ(expected_snapped_bounds.ToString(), 288 EXPECT_EQ(expected_snapped_bounds.ToString(),
286 window->GetBoundsInScreen().ToString()); 289 window->GetBoundsInScreen().ToString());
287 290
288 // The window should still be auto managed despite being right maximized. 291 // The window should still be auto managed despite being right maximized.
289 EXPECT_TRUE(wm::GetWindowSettings(window.get())->window_position_managed()); 292 EXPECT_TRUE(wm::GetWindowState(window.get())->window_position_managed());
290 } 293 }
291 294
292 } // namespace ash 295 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698