| 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_resizer.h" | 5 #include "ash/wm/dock/docked_window_resizer.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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 namespace internal { | 36 namespace internal { |
| 37 | 37 |
| 38 class DockedWindowResizerTest | 38 class DockedWindowResizerTest |
| 39 : public test::AshTestBase, | 39 : public test::AshTestBase, |
| 40 public testing::WithParamInterface<aura::client::WindowType> { | 40 public testing::WithParamInterface<aura::client::WindowType> { |
| 41 public: | 41 public: |
| 42 DockedWindowResizerTest() : model_(NULL), window_type_(GetParam()) {} | 42 DockedWindowResizerTest() : model_(NULL), window_type_(GetParam()) {} |
| 43 virtual ~DockedWindowResizerTest() {} | 43 virtual ~DockedWindowResizerTest() {} |
| 44 | 44 |
| 45 virtual void SetUp() OVERRIDE { | 45 virtual void SetUp() OVERRIDE { |
| 46 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 47 ash::switches::kAshEnableStickyEdges); | |
| 48 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 49 ash::switches::kAshEnableDockedWindows); | |
| 50 AshTestBase::SetUp(); | 46 AshTestBase::SetUp(); |
| 51 UpdateDisplay("600x400"); | 47 UpdateDisplay("600x400"); |
| 52 test::ShellTestApi test_api(Shell::GetInstance()); | 48 test::ShellTestApi test_api(Shell::GetInstance()); |
| 53 model_ = test_api.launcher_model(); | 49 model_ = test_api.launcher_model(); |
| 54 } | 50 } |
| 55 | 51 |
| 56 virtual void TearDown() OVERRIDE { | 52 virtual void TearDown() OVERRIDE { |
| 57 AshTestBase::TearDown(); | 53 AshTestBase::TearDown(); |
| 58 } | 54 } |
| 59 | 55 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 if (window->parent()->id() != internal::kShellWindowId_DockedContainer && | 207 if (window->parent()->id() != internal::kShellWindowId_DockedContainer && |
| 212 !wm::GetWindowState(window)->HasRestoreBounds()) { | 208 !wm::GetWindowState(window)->HasRestoreBounds()) { |
| 213 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); | 209 EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| 214 } | 210 } |
| 215 } | 211 } |
| 216 | 212 |
| 217 bool test_panels() const { | 213 bool test_panels() const { |
| 218 return window_type_ == aura::client::WINDOW_TYPE_PANEL; | 214 return window_type_ == aura::client::WINDOW_TYPE_PANEL; |
| 219 } | 215 } |
| 220 | 216 |
| 217 const gfx::Point& initial_location_in_parent() const { |
| 218 return initial_location_in_parent_; |
| 219 } |
| 220 |
| 221 private: | 221 private: |
| 222 scoped_ptr<WindowResizer> resizer_; | 222 scoped_ptr<WindowResizer> resizer_; |
| 223 LauncherModel* model_; | 223 LauncherModel* model_; |
| 224 aura::client::WindowType window_type_; | 224 aura::client::WindowType window_type_; |
| 225 aura::test::TestWindowDelegate delegate_; | 225 aura::test::TestWindowDelegate delegate_; |
| 226 | 226 |
| 227 // Location at start of the drag in |window->parent()|'s coordinates. | 227 // Location at start of the drag in |window->parent()|'s coordinates. |
| 228 gfx::Point initial_location_in_parent_; | 228 gfx::Point initial_location_in_parent_; |
| 229 | 229 |
| 230 DISALLOW_COPY_AND_ASSIGN(DockedWindowResizerTest); | 230 DISALLOW_COPY_AND_ASSIGN(DockedWindowResizerTest); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); | 315 EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id()); |
| 316 } | 316 } |
| 317 | 317 |
| 318 // Verifies a window can be dragged and then if a pointer is not quite reaching | 318 // Verifies a window can be dragged and then if a pointer is not quite reaching |
| 319 // the screen edge the window does not get docked and stays in the desktop. | 319 // the screen edge the window does not get docked and stays in the desktop. |
| 320 TEST_P(DockedWindowResizerTest, AttachLeftUndershoot) { | 320 TEST_P(DockedWindowResizerTest, AttachLeftUndershoot) { |
| 321 if (!SupportsHostWindowResize()) | 321 if (!SupportsHostWindowResize()) |
| 322 return; | 322 return; |
| 323 | 323 |
| 324 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 324 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 325 gfx::Rect initial_bounds(window->bounds()); |
| 325 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 1); | 326 DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 1); |
| 326 | 327 |
| 327 // The window should be touching the screen edge but not docked. | 328 // The window should be crossing the screen edge but not docked. |
| 328 EXPECT_EQ(window->GetRootWindow()->bounds().x(), | 329 int expected_x = initial_bounds.x() - initial_location_in_parent().x() + 1; |
| 329 window->GetBoundsInScreen().x()); | 330 EXPECT_EQ(expected_x, window->GetBoundsInScreen().x()); |
| 330 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, | 331 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, |
| 331 window->parent()->id()); | 332 window->parent()->id()); |
| 332 } | 333 } |
| 333 | 334 |
| 334 // Dock on the right side, change shelf alignment, check that windows move to | 335 // Dock on the right side, change shelf alignment, check that windows move to |
| 335 // the opposite side. | 336 // the opposite side. |
| 336 TEST_P(DockedWindowResizerTest, AttachRightChangeShelf) { | 337 TEST_P(DockedWindowResizerTest, AttachRightChangeShelf) { |
| 337 if (!SupportsHostWindowResize()) | 338 if (!SupportsHostWindowResize()) |
| 338 return; | 339 return; |
| 339 | 340 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 | 544 |
| 544 // Dock one window, try to dock another window on the opposite side (should not | 545 // Dock one window, try to dock another window on the opposite side (should not |
| 545 // dock). | 546 // dock). |
| 546 TEST_P(DockedWindowResizerTest, AttachOnTwoSides) { | 547 TEST_P(DockedWindowResizerTest, AttachOnTwoSides) { |
| 547 if (!SupportsHostWindowResize()) | 548 if (!SupportsHostWindowResize()) |
| 548 return; | 549 return; |
| 549 | 550 |
| 550 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 551 scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 551 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 552 scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 552 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); | 553 DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20); |
| 554 gfx::Rect initial_bounds(w2->bounds()); |
| 553 DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w2.get(), 50); | 555 DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w2.get(), 50); |
| 554 | 556 |
| 555 // The first window should be attached and snapped to the right edge. | 557 // The first window should be attached and snapped to the right edge. |
| 556 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), | 558 EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| 557 w1->GetBoundsInScreen().right()); | 559 w1->GetBoundsInScreen().right()); |
| 558 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); | 560 EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id()); |
| 559 | 561 |
| 560 // The second window should be near the left edge but not snapped. | 562 // The second window should be near the left edge but not snapped. |
| 561 // Normal window will get side-maximized while panels will not. | 563 // Normal window will get side-maximized while panels will not. |
| 562 EXPECT_EQ(w2->GetRootWindow()->bounds().x(), w2->GetBoundsInScreen().x()); | 564 int expected_x = test_panels() ? |
| 565 (initial_bounds.x() - initial_location_in_parent().x()) : 0; |
| 566 EXPECT_EQ(expected_x, w2->GetBoundsInScreen().x()); |
| 563 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); | 567 EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id()); |
| 564 } | 568 } |
| 565 | 569 |
| 566 // Tests that reverting a drag restores docked state if a window was docked. | 570 // Tests that reverting a drag restores docked state if a window was docked. |
| 567 TEST_P(DockedWindowResizerTest, RevertDragRestoresAttachment) { | 571 TEST_P(DockedWindowResizerTest, RevertDragRestoresAttachment) { |
| 568 if (!SupportsHostWindowResize()) | 572 if (!SupportsHostWindowResize()) |
| 569 return; | 573 return; |
| 570 | 574 |
| 571 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); | 575 scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| 572 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); | 576 DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 child->GetBoundsInScreen().origin().ToString()); | 1171 child->GetBoundsInScreen().origin().ToString()); |
| 1168 } | 1172 } |
| 1169 | 1173 |
| 1170 // Tests run twice - on both panels and normal windows | 1174 // Tests run twice - on both panels and normal windows |
| 1171 INSTANTIATE_TEST_CASE_P(NormalOrPanel, | 1175 INSTANTIATE_TEST_CASE_P(NormalOrPanel, |
| 1172 DockedWindowResizerTest, | 1176 DockedWindowResizerTest, |
| 1173 testing::Values(aura::client::WINDOW_TYPE_NORMAL, | 1177 testing::Values(aura::client::WINDOW_TYPE_NORMAL, |
| 1174 aura::client::WINDOW_TYPE_PANEL)); | 1178 aura::client::WINDOW_TYPE_PANEL)); |
| 1175 } // namespace internal | 1179 } // namespace internal |
| 1176 } // namespace ash | 1180 } // namespace ash |
| OLD | NEW |