| 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 "ash/wm/window_positioner.h" | 5 #include "ash/wm/window_positioner.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/shell.h" | |
| 10 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/test/test_shell_delegate.h" | 10 #include "ash/test/test_shell_delegate.h" |
| 12 #include "ash/wm/window_resizer.h" | 11 #include "ash/wm/window_resizer.h" |
| 13 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 14 #include "base/logging.h" | 13 #include "base/logging.h" |
| 15 #include "base/macros.h" | 14 #include "base/macros.h" |
| 16 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/host_desktop.h" | 16 #include "chrome/browser/ui/host_desktop.h" |
| 18 #include "chrome/test/base/test_browser_window_aura.h" | 17 #include "chrome/test/base/test_browser_window_aura.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 96 } |
| 98 | 97 |
| 99 int AlignToGridRoundDown(int location, int grid_size) { | 98 int AlignToGridRoundDown(int location, int grid_size) { |
| 100 if (grid_size <= 1 || location % grid_size == 0) | 99 if (grid_size <= 1 || location % grid_size == 0) |
| 101 return location; | 100 return location; |
| 102 return location / grid_size * grid_size; | 101 return location / grid_size * grid_size; |
| 103 } | 102 } |
| 104 | 103 |
| 105 TEST_F(WindowPositionerTest, cascading) { | 104 TEST_F(WindowPositionerTest, cascading) { |
| 106 const gfx::Rect work_area = | 105 const gfx::Rect work_area = |
| 107 Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 106 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 108 | 107 |
| 109 // First see that the window will cascade down when there is no space. | 108 // First see that the window will cascade down when there is no space. |
| 110 window()->SetBounds(work_area); | 109 window()->SetBounds(work_area); |
| 111 window()->Show(); | 110 window()->Show(); |
| 112 | 111 |
| 113 gfx::Rect popup_position(0, 0, 200, 200); | 112 gfx::Rect popup_position(0, 0, 200, 200); |
| 114 // Check that it gets cascaded. | 113 // Check that it gets cascaded. |
| 115 gfx::Rect cascade_1 = window_positioner()->GetPopupPosition(popup_position); | 114 gfx::Rect cascade_1 = window_positioner()->GetPopupPosition(popup_position); |
| 116 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_, | 115 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_, |
| 117 popup_position.width(), popup_position.height()), | 116 popup_position.width(), popup_position.height()), |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 gfx::Rect cascade_5 = | 157 gfx::Rect cascade_5 = |
| 159 window_positioner()->GetPopupPosition(popup_position_5); | 158 window_positioner()->GetPopupPosition(popup_position_5); |
| 160 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, | 159 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, |
| 161 work_area.y() + grid_size_, | 160 work_area.y() + grid_size_, |
| 162 popup_position_5.width(), popup_position_5.height()), | 161 popup_position_5.width(), popup_position_5.height()), |
| 163 cascade_5); | 162 cascade_5); |
| 164 } | 163 } |
| 165 | 164 |
| 166 TEST_F(WindowPositionerTest, filling) { | 165 TEST_F(WindowPositionerTest, filling) { |
| 167 const gfx::Rect work_area = | 166 const gfx::Rect work_area = |
| 168 Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 167 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 169 gfx::Rect popup_position(0, 0, 256, 128); | 168 gfx::Rect popup_position(0, 0, 256, 128); |
| 170 // Leave space on the left and the right and see if we fill top to bottom. | 169 // Leave space on the left and the right and see if we fill top to bottom. |
| 171 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), | 170 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), |
| 172 work_area.y(), | 171 work_area.y(), |
| 173 work_area.width() - 2 * popup_position.width(), | 172 work_area.width() - 2 * popup_position.width(), |
| 174 work_area.height())); | 173 work_area.height())); |
| 175 window()->Show(); | 174 window()->Show(); |
| 176 // Check that we are positioned in the top left corner. | 175 // Check that we are positioned in the top left corner. |
| 177 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); | 176 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); |
| 178 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 177 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 popup_position); | 212 popup_position); |
| 214 EXPECT_EQ(gfx::Rect(AlignToGridRoundDown(work_area.right() - | 213 EXPECT_EQ(gfx::Rect(AlignToGridRoundDown(work_area.right() - |
| 215 popup_position.width(), grid_size_), | 214 popup_position.width(), grid_size_), |
| 216 work_area.y(), | 215 work_area.y(), |
| 217 popup_position.width(), popup_position.height()), | 216 popup_position.width(), popup_position.height()), |
| 218 top_right); | 217 top_right); |
| 219 } | 218 } |
| 220 | 219 |
| 221 TEST_F(WindowPositionerTest, biggerThenBorder) { | 220 TEST_F(WindowPositionerTest, biggerThenBorder) { |
| 222 const gfx::Rect work_area = | 221 const gfx::Rect work_area = |
| 223 Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 222 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
| 224 | 223 |
| 225 gfx::Rect pop_position(0, 0, work_area.width(), work_area.height()); | 224 gfx::Rect pop_position(0, 0, work_area.width(), work_area.height()); |
| 226 | 225 |
| 227 // Check that the popup is placed full screen. | 226 // Check that the popup is placed full screen. |
| 228 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); | 227 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); |
| 229 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 228 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
| 230 pop_position.width(), pop_position.height()), | 229 pop_position.width(), pop_position.height()), |
| 231 full); | 230 full); |
| 232 } | 231 } |
| 233 | 232 |
| 234 } // namespace test | 233 } // namespace test |
| 235 } // namespace ash | 234 } // namespace ash |
| OLD | NEW |