OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/views/ash/window_positioner.h" | 5 #include "chrome/browser/ui/views/ash/window_positioner.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
10 #include "ash/test/test_shell_delegate.h" | 10 #include "ash/test/test_shell_delegate.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
22 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/test_windows.h" | 23 #include "ui/aura/test/test_windows.h" |
24 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
25 | 25 |
26 namespace ash { | 26 namespace ash { |
27 namespace test { | 27 namespace test { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
| 31 // A function which aligns a size to a step within the grid. |
| 32 int align(int size, int alignment_factor) { |
| 33 if (alignment_factor > 1) { |
| 34 return size - size % alignment_factor; |
| 35 } |
| 36 return size; |
| 37 } |
| 38 |
31 // A browser window proxy which is able to associate an aura native window with | 39 // A browser window proxy which is able to associate an aura native window with |
32 // it. | 40 // it. |
33 class TestBrowserWindowAura : public TestBrowserWindow { | 41 class TestBrowserWindowAura : public TestBrowserWindow { |
34 public: | 42 public: |
35 TestBrowserWindowAura(Browser* browser, aura::Window *native_window); | 43 TestBrowserWindowAura(Browser* browser, aura::Window *native_window); |
36 virtual ~TestBrowserWindowAura(); | 44 virtual ~TestBrowserWindowAura(); |
37 | 45 |
38 virtual gfx::NativeWindow GetNativeHandle() OVERRIDE { | 46 virtual gfx::NativeWindow GetNativeHandle() OVERRIDE { |
39 return native_window_; | 47 return native_window_; |
40 } | 48 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 : window_positioner_(NULL) { | 113 : window_positioner_(NULL) { |
106 // Create a message loop. | 114 // Create a message loop. |
107 MessageLoopForUI* ui_loop = message_loop(); | 115 MessageLoopForUI* ui_loop = message_loop(); |
108 ui_thread_.reset( | 116 ui_thread_.reset( |
109 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); | 117 new content::TestBrowserThread(content::BrowserThread::UI, ui_loop)); |
110 | 118 |
111 // Create a browser profile. | 119 // Create a browser profile. |
112 profile_.reset(new TestingProfile()); | 120 profile_.reset(new TestingProfile()); |
113 } | 121 } |
114 | 122 |
115 WindowPositionerTest::~WindowPositionerTest() {} | 123 WindowPositionerTest::~WindowPositionerTest() { |
| 124 profile_.reset(NULL); |
| 125 ui_thread_.reset(NULL); |
| 126 } |
116 | 127 |
117 void WindowPositionerTest::SetUp() { | 128 void WindowPositionerTest::SetUp() { |
118 AshTestBase::SetUp(); | 129 AshTestBase::SetUp(); |
119 // Create some default dummy windows. | 130 // Create some default dummy windows. |
120 aura::Window* default_container = | 131 aura::Window* default_container = |
121 ash::Shell::GetInstance()->GetContainer( | 132 ash::Shell::GetInstance()->GetContainer( |
122 ash::internal::kShellWindowId_DefaultContainer); | 133 ash::internal::kShellWindowId_DefaultContainer); |
123 window_.reset(aura::test::CreateTestWindowWithId(0, default_container)); | 134 window_.reset(aura::test::CreateTestWindowWithId(0, default_container)); |
124 window_->SetBounds(gfx::Rect(16, 32, 640, 320)); | 135 window_->SetBounds(gfx::Rect(16, 32, 640, 320)); |
125 popup_.reset(aura::test::CreateTestWindowWithId(1, default_container)); | 136 popup_.reset(aura::test::CreateTestWindowWithId(1, default_container)); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 gfx::Rect cascade_5 = | 255 gfx::Rect cascade_5 = |
245 window_positioner()->GetPopupPosition(popup_position_5); | 256 window_positioner()->GetPopupPosition(popup_position_5); |
246 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, | 257 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, |
247 work_area.y() + grid_size_, | 258 work_area.y() + grid_size_, |
248 popup_position_5.width(), popup_position_5.height()), | 259 popup_position_5.width(), popup_position_5.height()), |
249 cascade_5); | 260 cascade_5); |
250 } | 261 } |
251 | 262 |
252 TEST_F(WindowPositionerTest, filling) { | 263 TEST_F(WindowPositionerTest, filling) { |
253 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); | 264 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); |
254 | 265 int grid = ash::Shell::GetInstance()->GetGridSize(); |
255 gfx::Rect popup_position(0, 0, 256, 128); | 266 gfx::Rect popup_position(0, 0, 256, 128); |
256 // Leave space on the left and the right and see if we fill top to bottom. | 267 // Leave space on the left and the right and see if we fill top to bottom. |
257 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), | 268 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), |
258 work_area.y(), | 269 work_area.y(), |
259 work_area.width() - 2 * popup_position.width(), | 270 work_area.width() - 2 * popup_position.width(), |
260 work_area.height())); | 271 work_area.height())); |
261 window()->Show(); | 272 window()->Show(); |
262 // Check that we are positioned in the top left corner. | 273 // Check that we are positioned in the top left corner. |
263 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); | 274 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); |
264 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 275 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
265 popup_position.width(), popup_position.height()), | 276 popup_position.width(), popup_position.height()), |
266 top_left); | 277 top_left); |
267 | 278 |
268 // Now block the found location. | 279 // Now block the found location. |
269 popup()->SetBounds(top_left); | 280 popup()->SetBounds(top_left); |
270 popup()->Show(); | 281 popup()->Show(); |
271 gfx::Rect mid_left = window_positioner()->GetPopupPosition(popup_position); | 282 gfx::Rect mid_left = window_positioner()->GetPopupPosition(popup_position); |
272 EXPECT_EQ(gfx::Rect(work_area.x(), | 283 EXPECT_EQ(gfx::Rect(work_area.x(), |
273 work_area.y() + top_left.height(), | 284 align(work_area.y() + top_left.height(), grid), |
274 popup_position.width(), popup_position.height()), | 285 popup_position.width(), popup_position.height()), |
275 mid_left); | 286 mid_left); |
276 | 287 |
277 // Block now everything so that we can only put the popup on the bottom | 288 // Block now everything so that we can only put the popup on the bottom |
278 // of the left side. | 289 // of the left side. |
| 290 // Note: We need to keep one "grid spacing free" if the window does not |
| 291 // fit into the grid (which is true for 200 height).` |
279 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(), | 292 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(), |
280 popup_position.width(), | 293 popup_position.width(), |
281 work_area.height() - popup_position.height())); | 294 work_area.height() - popup_position.height() - |
| 295 grid + 1)); |
282 gfx::Rect bottom_left = window_positioner()->GetPopupPosition( | 296 gfx::Rect bottom_left = window_positioner()->GetPopupPosition( |
283 popup_position); | 297 popup_position); |
284 EXPECT_EQ(gfx::Rect(work_area.x(), | 298 EXPECT_EQ(gfx::Rect(work_area.x(), |
285 work_area.y() + work_area.height() - | 299 work_area.bottom() - popup_position.height(), |
286 popup_position.height(), | |
287 popup_position.width(), popup_position.height()), | 300 popup_position.width(), popup_position.height()), |
288 bottom_left); | 301 bottom_left); |
289 | 302 |
290 // Block now enough to force the right side. | 303 // Block now enough to force the right side. |
291 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(), | 304 popup()->SetBounds(gfx::Rect(work_area.x(), work_area.y(), |
292 popup_position.width(), | 305 popup_position.width(), |
293 work_area.height() - popup_position.height() + | 306 work_area.height() - popup_position.height() + |
294 1)); | 307 1)); |
295 gfx::Rect top_right = window_positioner()->GetPopupPosition( | 308 gfx::Rect top_right = window_positioner()->GetPopupPosition( |
296 popup_position); | 309 popup_position); |
297 EXPECT_EQ(gfx::Rect(work_area.x() + work_area.width() - | 310 EXPECT_EQ(gfx::Rect(align(work_area.right() - |
298 popup_position.width(), | 311 popup_position.width(), grid), |
299 work_area.y(), | 312 work_area.y(), |
300 popup_position.width(), popup_position.height()), | 313 popup_position.width(), popup_position.height()), |
301 top_right); | 314 top_right); |
302 } | 315 } |
303 | 316 |
304 TEST_F(WindowPositionerTest, blockedByPanel) { | 317 TEST_F(WindowPositionerTest, blockedByPanel) { |
305 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); | 318 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); |
306 | 319 |
307 gfx::Rect pop_position(0, 0, 200, 200); | 320 gfx::Rect pop_position(0, 0, 200, 200); |
308 // Let the panel cover everything. | 321 // Let the panel cover everything. |
(...skipping 14 matching lines...) Expand all Loading... |
323 | 336 |
324 // Check that the popup is placed full screen. | 337 // Check that the popup is placed full screen. |
325 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); | 338 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); |
326 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 339 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
327 pop_position.width(), pop_position.height()), | 340 pop_position.width(), pop_position.height()), |
328 full); | 341 full); |
329 } | 342 } |
330 | 343 |
331 } // namespace test | 344 } // namespace test |
332 } // namespace ash | 345 } // namespace ash |
OLD | NEW |