OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/dock/docked_window_layout_manager.h" | 5 #include "ash/wm/dock/docked_window_layout_manager.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
9 #include "ash/launcher/launcher_model.h" | 9 #include "ash/launcher/launcher_model.h" |
10 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/screen_ash.h" |
11 #include "ash/shelf/shelf_layout_manager.h" | 12 #include "ash/shelf/shelf_layout_manager.h" |
12 #include "ash/shelf/shelf_types.h" | 13 #include "ash/shelf/shelf_types.h" |
13 #include "ash/shelf/shelf_widget.h" | 14 #include "ash/shelf/shelf_widget.h" |
14 #include "ash/shell.h" | 15 #include "ash/shell.h" |
15 #include "ash/shell_window_ids.h" | 16 #include "ash/shell_window_ids.h" |
16 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/launcher_view_test_api.h" | 18 #include "ash/test/launcher_view_test_api.h" |
18 #include "ash/test/shell_test_api.h" | 19 #include "ash/test/shell_test_api.h" |
19 #include "ash/test/test_launcher_delegate.h" | 20 #include "ash/test/test_launcher_delegate.h" |
20 #include "ash/wm/panels/panel_layout_manager.h" | 21 #include "ash/wm/panels/panel_layout_manager.h" |
(...skipping 16 matching lines...) Expand all Loading... |
37 public: | 38 public: |
38 DockedWindowLayoutManagerTest() : window_type_(GetParam()) {} | 39 DockedWindowLayoutManagerTest() : window_type_(GetParam()) {} |
39 virtual ~DockedWindowLayoutManagerTest() {} | 40 virtual ~DockedWindowLayoutManagerTest() {} |
40 | 41 |
41 virtual void SetUp() OVERRIDE { | 42 virtual void SetUp() OVERRIDE { |
42 CommandLine::ForCurrentProcess()->AppendSwitch( | 43 CommandLine::ForCurrentProcess()->AppendSwitch( |
43 ash::switches::kAshEnableStickyEdges); | 44 ash::switches::kAshEnableStickyEdges); |
44 CommandLine::ForCurrentProcess()->AppendSwitch( | 45 CommandLine::ForCurrentProcess()->AppendSwitch( |
45 ash::switches::kAshEnableDockedWindows); | 46 ash::switches::kAshEnableDockedWindows); |
46 AshTestBase::SetUp(); | 47 AshTestBase::SetUp(); |
47 UpdateDisplay("600x400"); | 48 UpdateDisplay("600x600"); |
48 ASSERT_TRUE(test::TestLauncherDelegate::instance()); | 49 ASSERT_TRUE(test::TestLauncherDelegate::instance()); |
49 | 50 |
50 launcher_view_test_.reset(new test::LauncherViewTestAPI( | 51 launcher_view_test_.reset(new test::LauncherViewTestAPI( |
51 Launcher::ForPrimaryDisplay()->GetLauncherViewForTest())); | 52 Launcher::ForPrimaryDisplay()->GetLauncherViewForTest())); |
52 launcher_view_test_->SetAnimationDuration(1); | 53 launcher_view_test_->SetAnimationDuration(1); |
53 } | 54 } |
54 | 55 |
55 protected: | 56 protected: |
56 enum DockedEdge { | 57 enum DockedEdge { |
57 DOCKED_EDGE_NONE, | 58 DOCKED_EDGE_NONE, |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 void DragRelativeToEdge(DockedEdge edge, | 148 void DragRelativeToEdge(DockedEdge edge, |
148 aura::Window* window, | 149 aura::Window* window, |
149 int dx) { | 150 int dx) { |
150 DragVerticallyAndRelativeToEdge( | 151 DragVerticallyAndRelativeToEdge( |
151 edge, | 152 edge, |
152 window, | 153 window, |
153 dx, | 154 dx, |
154 window_type_ == aura::client::WINDOW_TYPE_PANEL ? -100 : 20); | 155 window_type_ == aura::client::WINDOW_TYPE_PANEL ? -100 : 20); |
155 } | 156 } |
156 | 157 |
| 158 void DragToVerticalPositionAndToEdge(DockedEdge edge, |
| 159 aura::Window* window, |
| 160 int y) { |
| 161 DragToVerticalPositionRelativeToEdge(edge, window, 0, y); |
| 162 } |
| 163 |
| 164 void DragToVerticalPositionRelativeToEdge(DockedEdge edge, |
| 165 aura::Window* window, |
| 166 int dx, |
| 167 int y) { |
| 168 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| 169 DragVerticallyAndRelativeToEdge(edge, window, dx, y - initial_bounds.y()); |
| 170 } |
| 171 |
157 // Detach if our window is a panel, then drag it vertically by |dy| and | 172 // Detach if our window is a panel, then drag it vertically by |dy| and |
158 // horizontally to the edge with an added offset from the edge of |dx|. | 173 // horizontally to the edge with an added offset from the edge of |dx|. |
159 void DragVerticallyAndRelativeToEdge(DockedEdge edge, | 174 void DragVerticallyAndRelativeToEdge(DockedEdge edge, |
160 aura::Window* window, | 175 aura::Window* window, |
161 int dx, | 176 int dx, |
162 int dy) { | 177 int dy) { |
163 aura::RootWindow* root_window = window->GetRootWindow(); | 178 aura::RootWindow* root_window = window->GetRootWindow(); |
164 gfx::Rect initial_bounds = window->GetBoundsInScreen(); | 179 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
165 | 180 |
166 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) { | 181 if (window_type_ == aura::client::WINDOW_TYPE_PANEL) { |
(...skipping 10 matching lines...) Expand all Loading... |
177 // The panel should be detached when the drag completes. | 192 // The panel should be detached when the drag completes. |
178 DragEnd(); | 193 DragEnd(); |
179 | 194 |
180 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); | 195 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); |
181 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, | 196 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
182 window->parent()->id()); | 197 window->parent()->id()); |
183 EXPECT_EQ(root_window, window->GetRootWindow()); | 198 EXPECT_EQ(root_window, window->GetRootWindow()); |
184 } | 199 } |
185 | 200 |
186 // avoid snap by clicking away from the border | 201 // avoid snap by clicking away from the border |
187 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 5, 5)); | 202 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(window, 25, 5)); |
188 | 203 |
189 // Drag the window left or right to the edge (or almost to it). | 204 // Drag the window left or right to the edge (or almost to it). |
190 if (edge == DOCKED_EDGE_LEFT) | 205 if (edge == DOCKED_EDGE_LEFT) |
191 dx += window->GetRootWindow()->bounds().x() - initial_bounds.x(); | 206 dx += window->GetRootWindow()->bounds().x() - initial_bounds.x(); |
192 else if (edge == DOCKED_EDGE_RIGHT) | 207 else if (edge == DOCKED_EDGE_RIGHT) |
193 dx += window->GetRootWindow()->bounds().right() - initial_bounds.right(); | 208 dx += window->GetRootWindow()->bounds().right() - initial_bounds.right(); |
194 DragMove(dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? 0 : dy); | 209 DragMove(dx, window_type_ == aura::client::WINDOW_TYPE_PANEL ? 0 : dy); |
195 EXPECT_EQ(CorrectContainerIdDuringDrag(UNDOCKED), window->parent()->id()); | 210 EXPECT_EQ(CorrectContainerIdDuringDrag(UNDOCKED), window->parent()->id()); |
196 // Release the mouse and the panel should be attached to the dock. | 211 // Release the mouse and the panel should be attached to the dock. |
197 DragEnd(); | 212 DragEnd(); |
198 | 213 |
199 // x-coordinate can get adjusted by snapping or sticking. | 214 // x-coordinate can get adjusted by snapping or sticking. |
200 // y-coordinate should not change by possible docking. | 215 // y-coordinate could be changed by possible automatic layout if docked. |
201 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | 216 if (window->parent()->id() != internal::kShellWindowId_DockedContainer) |
| 217 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
202 } | 218 } |
203 | 219 |
204 private: | 220 private: |
205 scoped_ptr<WindowResizer> resizer_; | 221 scoped_ptr<WindowResizer> resizer_; |
206 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; | 222 scoped_ptr<test::LauncherViewTestAPI> launcher_view_test_; |
207 aura::client::WindowType window_type_; | 223 aura::client::WindowType window_type_; |
208 | 224 |
209 // Location at start of the drag in |window->parent()|'s coordinates. | 225 // Location at start of the drag in |window->parent()|'s coordinates. |
210 gfx::Point initial_location_in_parent_; | 226 gfx::Point initial_location_in_parent_; |
211 | 227 |
212 DISALLOW_COPY_AND_ASSIGN(DockedWindowLayoutManagerTest); | 228 DISALLOW_COPY_AND_ASSIGN(DockedWindowLayoutManagerTest); |
213 }; | 229 }; |
214 | 230 |
215 // Tests that a created window is successfully added to the dock | 231 // Tests that a created window is successfully added to the dock |
216 // layout manager. | 232 // layout manager. |
217 TEST_P(DockedWindowLayoutManagerTest, AddOneWindow) { | 233 TEST_P(DockedWindowLayoutManagerTest, AddOneWindow) { |
218 if (!SupportsHostWindowResize()) | 234 if (!SupportsHostWindowResize()) |
219 return; | 235 return; |
220 | 236 |
221 gfx::Rect bounds(0, 0, 201, 201); | 237 gfx::Rect bounds(0, 0, 201, 201); |
222 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); | 238 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); |
223 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 239 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
224 | 240 |
225 // The window should be attached and snapped to the right side of the screen. | 241 // The window should be attached and snapped to the right side of the screen. |
226 EXPECT_EQ(window->GetRootWindow()->bounds().right(), | 242 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
227 window->GetBoundsInScreen().right()); | 243 window->GetBoundsInScreen().right()); |
228 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 244 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); |
229 } | 245 } |
230 | 246 |
231 //TODO(varkha): Add more tests for fanning windows in the dock. | 247 // Adds two windows and tests that the gaps are evenly distributed. |
232 // See http://crbug.com/233334. | 248 TEST_P(DockedWindowLayoutManagerTest, AddTwoWindows) { |
| 249 if (!SupportsHostWindowResize()) |
| 250 return; |
| 251 |
| 252 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 253 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
| 254 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 255 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
| 256 |
| 257 // The windows should be attached and snapped to the right side of the screen. |
| 258 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 259 w1->GetBoundsInScreen().right()); |
| 260 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 261 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
| 262 w2->GetBoundsInScreen().right()); |
| 263 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 264 |
| 265 // Test that the gaps differ at most by a single pixel. |
| 266 int gap1 = w1->GetBoundsInScreen().y(); |
| 267 int gap2 = w2->GetBoundsInScreen().y() - w1->GetBoundsInScreen().bottom(); |
| 268 int gap3 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).bottom() - |
| 269 w2->GetBoundsInScreen().bottom(); |
| 270 EXPECT_LE(abs(gap1 - gap2), 1); |
| 271 EXPECT_LE(abs(gap2 - gap3), 1); |
| 272 EXPECT_LE(abs(gap3 - gap1), 1); |
| 273 } |
| 274 |
| 275 // Adds two non-overlapping windows and tests layout after a drag. |
| 276 TEST_P(DockedWindowLayoutManagerTest, TwoWindowsDragging) { |
| 277 if (!SupportsHostWindowResize()) |
| 278 return; |
| 279 |
| 280 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 281 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
| 282 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 283 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 300); |
| 284 |
| 285 // The windows should be attached and snapped to the right side of the screen. |
| 286 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 287 w1->GetBoundsInScreen().right()); |
| 288 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 289 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
| 290 w2->GetBoundsInScreen().right()); |
| 291 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 292 |
| 293 // Drag w2 above w1. |
| 294 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w2.get(), 0, 20)); |
| 295 DragMove(0, w1->bounds().y() - w2->bounds().y() - 20); |
| 296 DragEnd(); |
| 297 |
| 298 // Test the new windows order and that the gaps differ at most by a pixel. |
| 299 int gap1 = w2->GetBoundsInScreen().y(); |
| 300 int gap2 = w1->GetBoundsInScreen().y() - w2->GetBoundsInScreen().bottom(); |
| 301 int gap3 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w1.get()).bottom() - |
| 302 w1->GetBoundsInScreen().bottom(); |
| 303 EXPECT_LE(abs(gap1 - gap2), 1); |
| 304 EXPECT_LE(abs(gap2 - gap3), 1); |
| 305 EXPECT_LE(abs(gap3 - gap1), 1); |
| 306 } |
| 307 |
| 308 // Adds three overlapping windows and tests layout after a drag. |
| 309 TEST_P(DockedWindowLayoutManagerTest, ThreeWindowsDragging) { |
| 310 if (!SupportsHostWindowResize()) |
| 311 return; |
| 312 |
| 313 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 314 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 315 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 202))); |
| 316 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100); |
| 317 scoped_ptr<aura::Window> w3(CreateTestWindow(gfx::Rect(0, 0, 220, 204))); |
| 318 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w3.get(), 300); |
| 319 |
| 320 // All windows should be attached and snapped to the right side of the screen. |
| 321 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 322 w1->GetBoundsInScreen().right()); |
| 323 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 324 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
| 325 w2->GetBoundsInScreen().right()); |
| 326 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id()); |
| 327 EXPECT_EQ(w3->GetRootWindow()->bounds().right(), |
| 328 w3->GetBoundsInScreen().right()); |
| 329 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w3->parent()->id()); |
| 330 |
| 331 // Test that the top and bottom windows are clamped in work area and |
| 332 // that the overlaps between the windows differ at most by a pixel. |
| 333 int overlap1 = w1->GetBoundsInScreen().y(); |
| 334 int overlap2 = w1->GetBoundsInScreen().bottom() - w2->GetBoundsInScreen().y(); |
| 335 int overlap3 = w2->GetBoundsInScreen().bottom() - w3->GetBoundsInScreen().y(); |
| 336 int overlap4 = |
| 337 ScreenAsh::GetDisplayWorkAreaBoundsInParent(w3.get()).bottom() - |
| 338 w3->GetBoundsInScreen().bottom(); |
| 339 EXPECT_EQ(0, overlap1); |
| 340 EXPECT_LE(abs(overlap2 - overlap3), 1); |
| 341 EXPECT_EQ(0, overlap4); |
| 342 |
| 343 // Drag w1 below w2. |
| 344 ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromwindowOrigin(w1.get(), 0, 20)); |
| 345 DragMove(0, w2->bounds().y() - w1->bounds().y() + 20); |
| 346 |
| 347 // During the drag the windows get rearranged and the top and the bottom |
| 348 // should be clamped by the work area. |
| 349 EXPECT_EQ(0, w2->GetBoundsInScreen().y()); |
| 350 EXPECT_GT(w1->GetBoundsInScreen().y(), w2->GetBoundsInScreen().y()); |
| 351 EXPECT_EQ(ScreenAsh::GetDisplayWorkAreaBoundsInParent(w3.get()).bottom(), |
| 352 w3->GetBoundsInScreen().bottom()); |
| 353 DragEnd(); |
| 354 |
| 355 // Test the new windows order and that the overlaps differ at most by a pixel. |
| 356 overlap1 = w2->GetBoundsInScreen().y(); |
| 357 overlap2 = w2->GetBoundsInScreen().bottom() - w1->GetBoundsInScreen().y(); |
| 358 overlap3 = w1->GetBoundsInScreen().bottom() - w3->GetBoundsInScreen().y(); |
| 359 overlap4 = ScreenAsh::GetDisplayWorkAreaBoundsInParent(w3.get()).bottom() - |
| 360 w3->GetBoundsInScreen().bottom(); |
| 361 EXPECT_EQ(0, overlap1); |
| 362 EXPECT_LE(abs(overlap2 - overlap3), 1); |
| 363 EXPECT_EQ(0, overlap4); |
| 364 } |
233 | 365 |
234 // Tests run twice - on both panels and normal windows | 366 // Tests run twice - on both panels and normal windows |
235 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 367 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
236 DockedWindowLayoutManagerTest, | 368 DockedWindowLayoutManagerTest, |
237 testing::Values(aura::client::WINDOW_TYPE_NORMAL, | 369 testing::Values(aura::client::WINDOW_TYPE_NORMAL, |
238 aura::client::WINDOW_TYPE_PANEL)); | 370 aura::client::WINDOW_TYPE_PANEL)); |
239 } // namespace internal | 371 } // namespace internal |
240 } // namespace ash | 372 } // namespace ash |
OLD | NEW |