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