| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 panel_.reset(NULL); | 187 panel_.reset(NULL); |
| 188 | 188 |
| 189 AshTestBase::TearDown(); | 189 AshTestBase::TearDown(); |
| 190 delete window_positioner_; | 190 delete window_positioner_; |
| 191 window_positioner_ = NULL; | 191 window_positioner_ = NULL; |
| 192 } | 192 } |
| 193 | 193 |
| 194 } // namespace | 194 } // namespace |
| 195 | 195 |
| 196 TEST_F(WindowPositionerTest, cascading) { | 196 TEST_F(WindowPositionerTest, cascading) { |
| 197 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); | 197 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); |
| 198 | 198 |
| 199 // First see that the window will cascade down when there is no space. | 199 // First see that the window will cascade down when there is no space. |
| 200 window()->SetBounds(work_area); | 200 window()->SetBounds(work_area); |
| 201 window()->Show(); | 201 window()->Show(); |
| 202 | 202 |
| 203 gfx::Rect popup_position(0, 0, 200, 200); | 203 gfx::Rect popup_position(0, 0, 200, 200); |
| 204 // Check that it gets cascaded. | 204 // Check that it gets cascaded. |
| 205 gfx::Rect cascade_1 = window_positioner()->GetPopupPosition(popup_position); | 205 gfx::Rect cascade_1 = window_positioner()->GetPopupPosition(popup_position); |
| 206 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_, | 206 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_, |
| 207 popup_position.width(), popup_position.height()), | 207 popup_position.width(), popup_position.height()), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 (2 * grid_size_ - work_area.y())); | 247 (2 * grid_size_ - work_area.y())); |
| 248 gfx::Rect cascade_5 = | 248 gfx::Rect cascade_5 = |
| 249 window_positioner()->GetPopupPosition(popup_position_5); | 249 window_positioner()->GetPopupPosition(popup_position_5); |
| 250 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, | 250 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, |
| 251 work_area.y() + grid_size_, | 251 work_area.y() + grid_size_, |
| 252 popup_position_5.width(), popup_position_5.height()), | 252 popup_position_5.width(), popup_position_5.height()), |
| 253 cascade_5); | 253 cascade_5); |
| 254 } | 254 } |
| 255 | 255 |
| 256 TEST_F(WindowPositionerTest, filling) { | 256 TEST_F(WindowPositionerTest, filling) { |
| 257 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); | 257 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); |
| 258 int grid = ash::Shell::GetInstance()->GetGridSize(); | 258 int grid = ash::Shell::GetInstance()->GetGridSize(); |
| 259 gfx::Rect popup_position(0, 0, 256, 128); | 259 gfx::Rect popup_position(0, 0, 256, 128); |
| 260 // Leave space on the left and the right and see if we fill top to bottom. | 260 // Leave space on the left and the right and see if we fill top to bottom. |
| 261 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), | 261 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), |
| 262 work_area.y(), | 262 work_area.y(), |
| 263 work_area.width() - 2 * popup_position.width(), | 263 work_area.width() - 2 * popup_position.width(), |
| 264 work_area.height())); | 264 work_area.height())); |
| 265 window()->Show(); | 265 window()->Show(); |
| 266 // Check that we are positioned in the top left corner. | 266 // Check that we are positioned in the top left corner. |
| 267 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); | 267 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 gfx::Rect top_right = window_positioner()->GetPopupPosition( | 302 gfx::Rect top_right = window_positioner()->GetPopupPosition( |
| 303 popup_position); | 303 popup_position); |
| 304 EXPECT_EQ(gfx::Rect(ash::WindowResizer::AlignToGridRoundDown( | 304 EXPECT_EQ(gfx::Rect(ash::WindowResizer::AlignToGridRoundDown( |
| 305 work_area.right() - popup_position.width(), grid), | 305 work_area.right() - popup_position.width(), grid), |
| 306 work_area.y(), | 306 work_area.y(), |
| 307 popup_position.width(), popup_position.height()), | 307 popup_position.width(), popup_position.height()), |
| 308 top_right); | 308 top_right); |
| 309 } | 309 } |
| 310 | 310 |
| 311 TEST_F(WindowPositionerTest, blockedByPanel) { | 311 TEST_F(WindowPositionerTest, blockedByPanel) { |
| 312 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); | 312 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); |
| 313 | 313 |
| 314 gfx::Rect pop_position(0, 0, 200, 200); | 314 gfx::Rect pop_position(0, 0, 200, 200); |
| 315 // Let the panel cover everything. | 315 // Let the panel cover everything. |
| 316 panel()->SetBounds(work_area); | 316 panel()->SetBounds(work_area); |
| 317 panel()->Show(); | 317 panel()->Show(); |
| 318 | 318 |
| 319 // Check that the popup does cascade due to the panel's existence. | 319 // Check that the popup does cascade due to the panel's existence. |
| 320 gfx::Rect top_right = window_positioner()->GetPopupPosition(pop_position); | 320 gfx::Rect top_right = window_positioner()->GetPopupPosition(pop_position); |
| 321 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_, | 321 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_, |
| 322 pop_position.width(), pop_position.height()), | 322 pop_position.width(), pop_position.height()), |
| 323 top_right); | 323 top_right); |
| 324 } | 324 } |
| 325 | 325 |
| 326 TEST_F(WindowPositionerTest, biggerThenBorder) { | 326 TEST_F(WindowPositionerTest, biggerThenBorder) { |
| 327 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); | 327 const gfx::Rect work_area = gfx::Screen::GetPrimaryMonitor().work_area(); |
| 328 | 328 |
| 329 gfx::Rect pop_position(0, 0, work_area.width(), work_area.height()); | 329 gfx::Rect pop_position(0, 0, work_area.width(), work_area.height()); |
| 330 | 330 |
| 331 // Check that the popup is placed full screen. | 331 // Check that the popup is placed full screen. |
| 332 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); | 332 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); |
| 333 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 333 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
| 334 pop_position.width(), pop_position.height()), | 334 pop_position.width(), pop_position.height()), |
| 335 full); | 335 full); |
| 336 } | 336 } |
| 337 | 337 |
| 338 } // namespace test | 338 } // namespace test |
| 339 } // namespace ash | 339 } // namespace ash |
| OLD | NEW |