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/common/window_positioner.h" | 5 #include "ash/wm/common/window_positioner.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
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" |
11 #include "ash/wm/aura/wm_globals_aura.h" | 11 #include "ash/wm/aura/wm_globals_aura.h" |
12 #include "ash/wm/common/window_resizer.h" | 12 #include "ash/wm/common/window_resizer.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/test/base/test_browser_window_aura.h" | 17 #include "chrome/test/base/test_browser_window_aura.h" |
18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
19 #include "content/public/test/render_view_test.h" | 19 #include "content/public/test/render_view_test.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
22 #include "ui/aura/test/test_windows.h" | 22 #include "ui/aura/test/test_windows.h" |
23 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
24 #include "ui/gfx/screen.h" | 24 #include "ui/display/screen.h" |
25 | 25 |
26 namespace ash { | 26 namespace ash { |
27 namespace test { | 27 namespace test { |
28 | 28 |
29 // A test class for preparing window positioner tests - it creates a testing | 29 // A test class for preparing window positioner tests - it creates a testing |
30 // base by adding a window and a popup which can be independently | 30 // base by adding a window and a popup which can be independently |
31 // positioned to see where the positioner will place the window. | 31 // positioned to see where the positioner will place the window. |
32 class WindowPositionerTest : public AshTestBase { | 32 class WindowPositionerTest : public AshTestBase { |
33 public: | 33 public: |
34 WindowPositionerTest(); | 34 WindowPositionerTest(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 94 } |
95 | 95 |
96 int AlignToGridRoundDown(int location, int grid_size) { | 96 int AlignToGridRoundDown(int location, int grid_size) { |
97 if (grid_size <= 1 || location % grid_size == 0) | 97 if (grid_size <= 1 || location % grid_size == 0) |
98 return location; | 98 return location; |
99 return location / grid_size * grid_size; | 99 return location / grid_size * grid_size; |
100 } | 100 } |
101 | 101 |
102 TEST_F(WindowPositionerTest, cascading) { | 102 TEST_F(WindowPositionerTest, cascading) { |
103 const gfx::Rect work_area = | 103 const gfx::Rect work_area = |
104 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 104 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
105 | 105 |
106 // First see that the window will cascade down when there is no space. | 106 // First see that the window will cascade down when there is no space. |
107 window()->SetBounds(work_area); | 107 window()->SetBounds(work_area); |
108 window()->Show(); | 108 window()->Show(); |
109 | 109 |
110 gfx::Rect popup_position(0, 0, 200, 200); | 110 gfx::Rect popup_position(0, 0, 200, 200); |
111 // Check that it gets cascaded. | 111 // Check that it gets cascaded. |
112 gfx::Rect cascade_1 = window_positioner()->GetPopupPosition(popup_position); | 112 gfx::Rect cascade_1 = window_positioner()->GetPopupPosition(popup_position); |
113 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_, | 113 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, work_area.y() + grid_size_, |
114 popup_position.width(), popup_position.height()), | 114 popup_position.width(), popup_position.height()), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 gfx::Rect cascade_5 = | 155 gfx::Rect cascade_5 = |
156 window_positioner()->GetPopupPosition(popup_position_5); | 156 window_positioner()->GetPopupPosition(popup_position_5); |
157 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, | 157 EXPECT_EQ(gfx::Rect(work_area.x() + grid_size_, |
158 work_area.y() + grid_size_, | 158 work_area.y() + grid_size_, |
159 popup_position_5.width(), popup_position_5.height()), | 159 popup_position_5.width(), popup_position_5.height()), |
160 cascade_5); | 160 cascade_5); |
161 } | 161 } |
162 | 162 |
163 TEST_F(WindowPositionerTest, filling) { | 163 TEST_F(WindowPositionerTest, filling) { |
164 const gfx::Rect work_area = | 164 const gfx::Rect work_area = |
165 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 165 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
166 gfx::Rect popup_position(0, 0, 256, 128); | 166 gfx::Rect popup_position(0, 0, 256, 128); |
167 // Leave space on the left and the right and see if we fill top to bottom. | 167 // Leave space on the left and the right and see if we fill top to bottom. |
168 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), | 168 window()->SetBounds(gfx::Rect(work_area.x() + popup_position.width(), |
169 work_area.y(), | 169 work_area.y(), |
170 work_area.width() - 2 * popup_position.width(), | 170 work_area.width() - 2 * popup_position.width(), |
171 work_area.height())); | 171 work_area.height())); |
172 window()->Show(); | 172 window()->Show(); |
173 // Check that we are positioned in the top left corner. | 173 // Check that we are positioned in the top left corner. |
174 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); | 174 gfx::Rect top_left = window_positioner()->GetPopupPosition(popup_position); |
175 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 175 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 popup_position); | 210 popup_position); |
211 EXPECT_EQ(gfx::Rect(AlignToGridRoundDown(work_area.right() - | 211 EXPECT_EQ(gfx::Rect(AlignToGridRoundDown(work_area.right() - |
212 popup_position.width(), grid_size_), | 212 popup_position.width(), grid_size_), |
213 work_area.y(), | 213 work_area.y(), |
214 popup_position.width(), popup_position.height()), | 214 popup_position.width(), popup_position.height()), |
215 top_right); | 215 top_right); |
216 } | 216 } |
217 | 217 |
218 TEST_F(WindowPositionerTest, biggerThenBorder) { | 218 TEST_F(WindowPositionerTest, biggerThenBorder) { |
219 const gfx::Rect work_area = | 219 const gfx::Rect work_area = |
220 gfx::Screen::GetScreen()->GetPrimaryDisplay().work_area(); | 220 display::Screen::GetScreen()->GetPrimaryDisplay().work_area(); |
221 | 221 |
222 gfx::Rect pop_position(0, 0, work_area.width(), work_area.height()); | 222 gfx::Rect pop_position(0, 0, work_area.width(), work_area.height()); |
223 | 223 |
224 // Check that the popup is placed full screen. | 224 // Check that the popup is placed full screen. |
225 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); | 225 gfx::Rect full = window_positioner()->GetPopupPosition(pop_position); |
226 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), | 226 EXPECT_EQ(gfx::Rect(work_area.x(), work_area.y(), |
227 pop_position.width(), pop_position.height()), | 227 pop_position.width(), pop_position.height()), |
228 full); | 228 full); |
229 } | 229 } |
230 | 230 |
231 } // namespace test | 231 } // namespace test |
232 } // namespace ash | 232 } // namespace ash |
OLD | NEW |