| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/wm/dock/dock_window_resizer.h" |
| 6 |
| 7 #include "ash/ash_switches.h" |
| 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/launcher/launcher_model.h" |
| 10 #include "ash/root_window_controller.h" |
| 11 #include "ash/shelf/shelf_layout_manager.h" |
| 12 #include "ash/shelf/shelf_types.h" |
| 13 #include "ash/shelf/shelf_widget.h" |
| 14 #include "ash/shell.h" |
| 15 #include "ash/shell_window_ids.h" |
| 16 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/test/cursor_manager_test_api.h" |
| 18 #include "ash/test/shell_test_api.h" |
| 19 #include "ash/test/test_launcher_delegate.h" |
| 20 #include "ash/wm/dock/dock_layout_manager.h" |
| 21 #include "ash/wm/drag_window_resizer.h" |
| 22 #include "ash/wm/panels/panel_layout_manager.h" |
| 23 #include "ash/wm/window_properties.h" |
| 24 #include "base/command_line.h" |
| 25 #include "ui/aura/client/aura_constants.h" |
| 26 #include "ui/aura/root_window.h" |
| 27 #include "ui/base/hit_test.h" |
| 28 #include "ui/base/ui_base_types.h" |
| 29 #include "ui/views/widget/widget.h" |
| 30 |
| 31 namespace ash { |
| 32 namespace internal { |
| 33 |
| 34 class DockWindowResizerTest |
| 35 : public test::AshTestBase, |
| 36 public testing::WithParamInterface<bool> { |
| 37 public: |
| 38 DockWindowResizerTest() : model_(NULL), test_panels_(GetParam()) {} |
| 39 virtual ~DockWindowResizerTest() {} |
| 40 |
| 41 virtual void SetUp() OVERRIDE { |
| 42 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 43 ash::switches::kAshEnableStickyEdges); |
| 44 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 45 ash::switches::kAshEnableDockedWindows); |
| 46 AshTestBase::SetUp(); |
| 47 UpdateDisplay("600x400"); |
| 48 test::ShellTestApi test_api(Shell::GetInstance()); |
| 49 model_ = test_api.launcher_model(); |
| 50 } |
| 51 |
| 52 virtual void TearDown() OVERRIDE { |
| 53 AshTestBase::TearDown(); |
| 54 } |
| 55 |
| 56 protected: |
| 57 aura::Window* CreateTestWindow(const gfx::Rect& bounds) { |
| 58 return (test_panels_) ? |
| 59 CreatePanel(bounds) : CreateTestWindowInShellWithBounds(bounds); |
| 60 } |
| 61 |
| 62 aura::Window* CreatePanel(const gfx::Rect& bounds) { |
| 63 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
| 64 NULL, |
| 65 aura::client::WINDOW_TYPE_PANEL, |
| 66 0, |
| 67 bounds); |
| 68 test::TestLauncherDelegate* launcher_delegate = |
| 69 test::TestLauncherDelegate::instance(); |
| 70 launcher_delegate->AddLauncherItem(window); |
| 71 PanelLayoutManager* manager = |
| 72 static_cast<PanelLayoutManager*>( |
| 73 Shell::GetContainer(window->GetRootWindow(), |
| 74 internal::kShellWindowId_PanelContainer)-> |
| 75 layout_manager()); |
| 76 manager->Relayout(); |
| 77 return window; |
| 78 } |
| 79 |
| 80 static WindowResizer* CreateSomeWindowResizer( |
| 81 aura::Window* window, |
| 82 const gfx::Point& point_in_parent, |
| 83 int window_component) { |
| 84 return static_cast<WindowResizer*>(CreateWindowResizer( |
| 85 window, point_in_parent, window_component).release()); |
| 86 } |
| 87 |
| 88 void DragStart(aura::Window* window) { |
| 89 initial_location_in_parent_ = window->bounds().origin(); |
| 90 resizer_.reset(CreateSomeWindowResizer(window, |
| 91 initial_location_in_parent_, |
| 92 HTCAPTION)); |
| 93 ASSERT_TRUE(resizer_.get()); |
| 94 } |
| 95 |
| 96 void DragStartAtOffsetFromwindowOrigin(aura::Window* window, |
| 97 int dx, |
| 98 int dy) { |
| 99 initial_location_in_parent_ = |
| 100 window->bounds().origin() + gfx::Vector2d(dx, dy); |
| 101 resizer_.reset(CreateSomeWindowResizer(window, |
| 102 initial_location_in_parent_, |
| 103 HTCAPTION)); |
| 104 ASSERT_TRUE(resizer_.get()); |
| 105 } |
| 106 |
| 107 void DragMove(int dx, int dy) { |
| 108 resizer_->Drag(initial_location_in_parent_ + gfx::Vector2d(dx, dy), 0); |
| 109 } |
| 110 |
| 111 void DragEnd() { |
| 112 resizer_->CompleteDrag(0); |
| 113 resizer_.reset(); |
| 114 } |
| 115 |
| 116 void DragRevert() { |
| 117 resizer_->RevertDrag(); |
| 118 resizer_.reset(); |
| 119 } |
| 120 |
| 121 int CorrectContainerIdDuringDrag() { |
| 122 return test_panels_ ? |
| 123 internal::kShellWindowId_PanelContainer : |
| 124 internal::kShellWindowId_WorkspaceContainer; |
| 125 } |
| 126 |
| 127 // Test dragging the window vertically (to detach if it is a panel) and then |
| 128 // horizontally to the edge with an added offset from the edge of |dx|. |
| 129 void DragRelativeToEdge(DockEdge edge, |
| 130 aura::Window* window, |
| 131 int dx) { |
| 132 DragVerticallyAndRelativeToEdge(edge, window, dx, test_panels_ ? -100 : 20); |
| 133 } |
| 134 |
| 135 // Test dragging the panel slightly, then detaching, and then |
| 136 // dragging it vertically by |dy| and horizontally to the edge with an added |
| 137 // offset from the edge of |dx|. |
| 138 void DragVerticallyAndRelativeToEdge(DockEdge edge, |
| 139 aura::Window* window, |
| 140 int dx, |
| 141 int dy) { |
| 142 aura::RootWindow* root_window = window->GetRootWindow(); |
| 143 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 144 DragStart(window); |
| 145 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| 146 |
| 147 if (test_panels_) { |
| 148 EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); |
| 149 // Drag the panel slightly. The window should still be snapped to the |
| 150 // launcher. |
| 151 DragMove(0, 5); |
| 152 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); |
| 153 EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y()); |
| 154 |
| 155 // Drag further out and the window should now move to the cursor. |
| 156 DragMove(0, dy); |
| 157 EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); |
| 158 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| 159 |
| 160 // The panel should be detached when the drag completes. |
| 161 DragEnd(); |
| 162 |
| 163 EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); |
| 164 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| 165 window->parent()->id()); |
| 166 EXPECT_EQ(root_window, window->GetRootWindow()); |
| 167 } |
| 168 |
| 169 // avoid snap by clicking away from the border |
| 170 DragStartAtOffsetFromwindowOrigin(window, 5, 5); |
| 171 |
| 172 // Drag the panel left or right to the edge (or almost to it). |
| 173 if (edge == DOCK_EDGE_LEFT) |
| 174 dx += window->GetRootWindow()->bounds().x() - initial_bounds.x(); |
| 175 else if (edge == DOCK_EDGE_RIGHT) |
| 176 dx += window->GetRootWindow()->bounds().right() - initial_bounds.right(); |
| 177 DragMove(dx, test_panels_ ? 0 : dy); |
| 178 // Release the mouse and the panel should be attached to the dock. |
| 179 DragEnd(); |
| 180 |
| 181 // x-coordinate can get adjusted by snapping or sticking. |
| 182 // y-coordinate should not change by possible docking. |
| 183 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| 184 } |
| 185 |
| 186 void DetachReattachTest(aura::Window* window, int dx, int dy) {} |
| 187 |
| 188 void TestWindowOrder(const std::vector<aura::Window*>& window_order) { |
| 189 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
| 190 int panel_index = model_->FirstPanelIndex(); |
| 191 EXPECT_EQ((int)(panel_index + window_order.size()), model_->item_count()); |
| 192 for (std::vector<aura::Window*>::const_iterator iter = |
| 193 window_order.begin(); iter != window_order.end(); |
| 194 ++iter, ++panel_index) { |
| 195 LauncherID id = launcher->delegate()->GetIDByWindow(*iter); |
| 196 EXPECT_EQ(id, model_->items()[panel_index].id); |
| 197 } |
| 198 } |
| 199 |
| 200 bool test_panels() const { return test_panels_; } |
| 201 |
| 202 private: |
| 203 scoped_ptr<WindowResizer> resizer_; |
| 204 LauncherModel* model_; |
| 205 bool test_panels_; |
| 206 |
| 207 // Location at start of the drag in |window->parent()|'s coordinates. |
| 208 gfx::Point initial_location_in_parent_; |
| 209 |
| 210 DISALLOW_COPY_AND_ASSIGN(DockWindowResizerTest); |
| 211 }; |
| 212 |
| 213 // Verifies a window can be dragged and detached and then attached to the dock. |
| 214 TEST_P(DockWindowResizerTest, AttachRightPrecise) { |
| 215 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 216 DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), 0); |
| 217 |
| 218 // The window should be attached and snapped to the right dock. |
| 219 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 220 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 221 window->GetBoundsInScreen().right()); |
| 222 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 223 } |
| 224 |
| 225 // Verifies a window can be dragged and detached and then attached to the dock |
| 226 // even if we overshoot the screen edge by a few pixels (sticky edge) |
| 227 TEST_P(DockWindowResizerTest, AttachRightOvershoot) { |
| 228 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 229 DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), +4); |
| 230 |
| 231 // The window should be attached and snapped to the right dock. |
| 232 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 233 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 234 window->GetBoundsInScreen().right()); |
| 235 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 236 } |
| 237 |
| 238 // Verifies a window can be dragged and detached and then if not quite reaching |
| 239 // the screen edge it does not get attached to the dock and stays in WS |
| 240 TEST_P(DockWindowResizerTest, AttachRightUndershoot) { |
| 241 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 242 DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), -1); |
| 243 |
| 244 // The window should not be attached to the dock. |
| 245 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_NONE); |
| 246 EXPECT_EQ(window->GetRootWindow()->bounds().right() - 1, |
| 247 window->GetBoundsInScreen().right()); |
| 248 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| 249 window->parent()->id()); |
| 250 } |
| 251 |
| 252 // Verifies a window can be dragged and detached and then attached to the dock. |
| 253 TEST_P(DockWindowResizerTest, AttachLeftPrecise) { |
| 254 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 255 DragRelativeToEdge(DOCK_EDGE_LEFT, window.get(), 0); |
| 256 |
| 257 // The window should be attached and snapped to the left dock. |
| 258 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_LEFT); |
| 259 EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| 260 window->GetBoundsInScreen().x()); |
| 261 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 262 } |
| 263 |
| 264 // Verifies a window can be dragged and detached and then attached to the dock |
| 265 // even if we overshoot the screen edge by a few pixels (sticky edge) |
| 266 TEST_P(DockWindowResizerTest, AttachLeftOvershoot) { |
| 267 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 268 DragRelativeToEdge(DOCK_EDGE_LEFT, window.get(), -4); |
| 269 |
| 270 // The window should be attached and snapped to the left dock. |
| 271 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_LEFT); |
| 272 EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| 273 window->GetBoundsInScreen().x()); |
| 274 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 275 } |
| 276 |
| 277 // Verifies a window can be dragged and detached and then if not quite reaching |
| 278 // the screen edge it does not get attached to the dock and stays in WS |
| 279 TEST_P(DockWindowResizerTest, AttachLeftUndershoot) { |
| 280 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 281 DragRelativeToEdge(DOCK_EDGE_LEFT, window.get(), 1); |
| 282 |
| 283 // The window should not be attached to the dock. |
| 284 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_NONE); |
| 285 EXPECT_EQ(window->GetRootWindow()->bounds().x() + 1, |
| 286 window->GetBoundsInScreen().x()); |
| 287 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| 288 window->parent()->id()); |
| 289 } |
| 290 |
| 291 // Dock on the right side, change shelf alignment, check that windows move to |
| 292 // the opposite side. |
| 293 TEST_P(DockWindowResizerTest, AttachRightChangeShelf) { |
| 294 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 295 DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), 0); |
| 296 |
| 297 // The window should be attached and snapped to the right dock. |
| 298 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 299 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 300 window->GetBoundsInScreen().right()); |
| 301 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 302 |
| 303 // set launcher shelf to be aligned on the right |
| 304 ash::Shell* shell = ash::Shell::GetInstance(); |
| 305 shell->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT, |
| 306 shell->GetPrimaryRootWindow()); |
| 307 // The window should have moved and get attached to the left dock. |
| 308 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_LEFT); |
| 309 EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| 310 window->GetBoundsInScreen().x()); |
| 311 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 312 |
| 313 // set launcher shelf to be aligned on the left |
| 314 shell->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, |
| 315 shell->GetPrimaryRootWindow()); |
| 316 // The window should have moved and get attached to the right dock. |
| 317 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 318 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 319 window->GetBoundsInScreen().right()); |
| 320 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 321 |
| 322 // set launcher shelf to be aligned at the bottom |
| 323 shell->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM, |
| 324 shell->GetPrimaryRootWindow()); |
| 325 // The window should stay in the right dock. |
| 326 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 327 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 328 window->GetBoundsInScreen().right()); |
| 329 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 330 } |
| 331 |
| 332 // Dock on the right side, try to undock, then drag more to really undock |
| 333 TEST_P(DockWindowResizerTest, AttachTryDetach) { |
| 334 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 335 DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), 0); |
| 336 |
| 337 // The window should be attached and snapped to the right dock. |
| 338 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 339 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 340 window->GetBoundsInScreen().right()); |
| 341 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 342 |
| 343 // Try to detach by dragging left a bit (should stay docked) |
| 344 DragStart(window.get()); |
| 345 DragMove(-10, -10); |
| 346 // Release the mouse and the window should be still attached to the dock. |
| 347 DragEnd(); |
| 348 |
| 349 // The window should be still attached to the right dock. |
| 350 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 351 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 352 window->GetBoundsInScreen().right()); |
| 353 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 354 |
| 355 // Try to detach by dragging left a bit more (should get undocked) |
| 356 DragStart(window.get()); |
| 357 DragMove(-32, -10); |
| 358 // Release the mouse and the window should be no longer attached to the dock. |
| 359 DragEnd(); |
| 360 |
| 361 // The window should be floating on a workspace again. |
| 362 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_NONE); |
| 363 EXPECT_EQ(window->GetRootWindow()->bounds().right() - 32, |
| 364 window->GetBoundsInScreen().right()); |
| 365 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| 366 window->parent()->id()); |
| 367 } |
| 368 |
| 369 // Minimize a docked window, then restore it and check that it is still docked. |
| 370 TEST_P(DockWindowResizerTest, AttachMinimizeRestore) { |
| 371 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 372 DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), 0); |
| 373 |
| 374 // The window should be attached and snapped to the right dock. |
| 375 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 376 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 377 window->GetBoundsInScreen().right()); |
| 378 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 379 |
| 380 // Minimize the window, it should be hidden. |
| 381 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| 382 RunAllPendingInMessageLoop(); |
| 383 EXPECT_FALSE(window->IsVisible()); |
| 384 // Restore the window; window should be visible. |
| 385 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| 386 RunAllPendingInMessageLoop(); |
| 387 EXPECT_TRUE(window->IsVisible()); |
| 388 } |
| 389 |
| 390 // Dock two windows, undock one, check that the other one is still docked. |
| 391 TEST_P(DockWindowResizerTest, AttachTwoWindows) { |
| 392 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 393 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 394 if (test_panels()) { |
| 395 DragVerticallyAndRelativeToEdge(DOCK_EDGE_RIGHT, w1.get(), 0, -100); |
| 396 DragVerticallyAndRelativeToEdge(DOCK_EDGE_RIGHT, w2.get(), 0, -50); |
| 397 } else { |
| 398 DragVerticallyAndRelativeToEdge(DOCK_EDGE_RIGHT, w1.get(), 0, 20); |
| 399 DragVerticallyAndRelativeToEdge(DOCK_EDGE_RIGHT, w2.get(), 0, 50); |
| 400 } |
| 401 |
| 402 // Both windows should be attached and snapped to the right dock. |
| 403 EXPECT_TRUE(GetDockEdge(w1.get()) == DOCK_EDGE_RIGHT); |
| 404 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 405 w1->GetBoundsInScreen().right()); |
| 406 EXPECT_EQ(internal::kShellWindowId_DockContainer, w1->parent()->id()); |
| 407 |
| 408 EXPECT_TRUE(GetDockEdge(w2.get()) == DOCK_EDGE_RIGHT); |
| 409 EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
| 410 w2->GetBoundsInScreen().right()); |
| 411 EXPECT_EQ(internal::kShellWindowId_DockContainer, w2->parent()->id()); |
| 412 |
| 413 // Detach by dragging left (should get undocked) |
| 414 DragStart(w2.get()); |
| 415 DragMove(-32, -10); |
| 416 // Release the mouse and the window should be no longer attached to the dock. |
| 417 DragEnd(); |
| 418 |
| 419 // The first window should be still docked. |
| 420 EXPECT_TRUE(GetDockEdge(w1.get()) == DOCK_EDGE_RIGHT); |
| 421 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 422 w1->GetBoundsInScreen().right()); |
| 423 EXPECT_EQ(internal::kShellWindowId_DockContainer, w1->parent()->id()); |
| 424 |
| 425 // The second window should be floating on a workspace again. |
| 426 EXPECT_TRUE(GetDockEdge(w2.get()) == DOCK_EDGE_NONE); |
| 427 EXPECT_EQ(w2->GetRootWindow()->bounds().right() - 32, |
| 428 w2->GetBoundsInScreen().right()); |
| 429 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| 430 w2->parent()->id()); |
| 431 } |
| 432 |
| 433 // Dock one window, try to dock another window on the opposite side (should not |
| 434 // dock). |
| 435 TEST_P(DockWindowResizerTest, AttachOnTwoSides) { |
| 436 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 437 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 438 if (test_panels()) { |
| 439 DragVerticallyAndRelativeToEdge(DOCK_EDGE_RIGHT, w1.get(), 0, -100); |
| 440 DragVerticallyAndRelativeToEdge(DOCK_EDGE_LEFT, w2.get(), 0, -50); |
| 441 } else { |
| 442 DragVerticallyAndRelativeToEdge(DOCK_EDGE_RIGHT, w1.get(), 0, 20); |
| 443 DragVerticallyAndRelativeToEdge(DOCK_EDGE_LEFT, w2.get(), 0, 50); |
| 444 } |
| 445 |
| 446 // The first window should be attached and snapped to the right dock. |
| 447 EXPECT_TRUE(GetDockEdge(w1.get()) == DOCK_EDGE_RIGHT); |
| 448 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 449 w1->GetBoundsInScreen().right()); |
| 450 EXPECT_EQ(internal::kShellWindowId_DockContainer, w1->parent()->id()); |
| 451 |
| 452 // The second window should be near the left edge but not snapped. |
| 453 EXPECT_TRUE(GetDockEdge(w2.get()) == DOCK_EDGE_NONE); |
| 454 EXPECT_EQ(w2->GetRootWindow()->bounds().x(), w2->GetBoundsInScreen().x()); |
| 455 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, w2->parent()->id()); |
| 456 } |
| 457 |
| 458 // Reverting drag |
| 459 TEST_P(DockWindowResizerTest, RevertDragRestoresAttachment) { |
| 460 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 461 DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), 0); |
| 462 |
| 463 // The window should be attached and snapped to the right dock. |
| 464 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 465 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 466 window->GetBoundsInScreen().right()); |
| 467 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 468 |
| 469 // Drag the window out but revert the drag |
| 470 DragStart(window.get()); |
| 471 DragMove(-50, 0); |
| 472 DragRevert(); |
| 473 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 474 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 475 |
| 476 // Detach window. |
| 477 DragStart(window.get()); |
| 478 DragMove(-50, 0); |
| 479 DragEnd(); |
| 480 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_NONE); |
| 481 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| 482 window->parent()->id()); |
| 483 } |
| 484 |
| 485 // Move a docked window to the second display |
| 486 TEST_P(DockWindowResizerTest, DragAcrossDisplays) { |
| 487 UpdateDisplay("800x800,800x800"); |
| 488 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 489 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 490 gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| 491 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 492 |
| 493 DragRelativeToEdge(DOCK_EDGE_RIGHT, window.get(), 0); |
| 494 // The window should be attached and snapped to the right dock. |
| 495 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 496 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 497 window->GetBoundsInScreen().right()); |
| 498 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 499 |
| 500 // Undock and move to the right - enough to get it peeking at the other screen |
| 501 // but not enough to land in the other screen |
| 502 DragStart(window.get()); |
| 503 DragMove(50, 0); |
| 504 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 505 DragEnd(); |
| 506 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_NONE); |
| 507 EXPECT_NE(window->GetRootWindow()->bounds().right(), |
| 508 window->GetBoundsInScreen().right()); |
| 509 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| 510 window->parent()->id()); |
| 511 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 512 |
| 513 // Move back left - should dock again. |
| 514 DragStart(window.get()); |
| 515 DragMove(-50, 0); |
| 516 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 517 DragEnd(); |
| 518 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_RIGHT); |
| 519 EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| 520 window->GetBoundsInScreen().right()); |
| 521 EXPECT_EQ(internal::kShellWindowId_DockContainer, |
| 522 window->parent()->id()); |
| 523 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 524 |
| 525 // Undock and move to the right - enough to get the mouse pointer past the |
| 526 // edge of the screen and into the second screen. The window should now be |
| 527 // in the second screen and not docked. |
| 528 DragStartAtOffsetFromwindowOrigin(window.get(), |
| 529 window->bounds().width()/2 + 10, |
| 530 0); |
| 531 DragMove(window->bounds().width()/2 - 5, 0); |
| 532 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 533 DragEnd(); |
| 534 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_NONE); |
| 535 EXPECT_NE(window->GetRootWindow()->bounds().right(), |
| 536 window->GetBoundsInScreen().right()); |
| 537 EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| 538 window->parent()->id()); |
| 539 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 540 |
| 541 // Keep dragging it to the right until it docks. The window should now be |
| 542 // in the second screen. |
| 543 DragStartAtOffsetFromwindowOrigin(window.get(), |
| 544 window->bounds().width()/2 + 10, |
| 545 0); |
| 546 DragMove(window->GetRootWindow()->GetBoundsInScreen().x() - |
| 547 window->GetBoundsInScreen().x(), |
| 548 0); |
| 549 EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| 550 DragEnd(); |
| 551 EXPECT_TRUE(GetDockEdge(window.get()) == DOCK_EDGE_LEFT); |
| 552 EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(), |
| 553 window->GetBoundsInScreen().x()); |
| 554 EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| 555 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 556 } |
| 557 |
| 558 // Tests run twice - on both panels and normal windows |
| 559 INSTANTIATE_TEST_CASE_P(PanelsOrNormal, DockWindowResizerTest, testing::Bool()); |
| 560 |
| 561 } // namespace internal |
| 562 } // namespace ash |
| OLD | NEW |