Chromium Code Reviews| Index: ash/wm/workspace/workspace_window_resizer_unittest.cc |
| diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc |
| index 75b3085725995feba8c710cf8babf5f8780c53bd..a0a8561f51e7ad676b0b71758201827669367994 100644 |
| --- a/ash/wm/workspace/workspace_window_resizer_unittest.cc |
| +++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc |
| @@ -4,6 +4,7 @@ |
| #include "ash/wm/workspace/workspace_window_resizer.h" |
| +#include "ash/ash_switches.h" |
| #include "ash/display/display_controller.h" |
| #include "ash/root_window_controller.h" |
| #include "ash/screen_ash.h" |
| @@ -16,6 +17,7 @@ |
| #include "ash/wm/workspace/phantom_window_controller.h" |
| #include "ash/wm/workspace/snap_sizer.h" |
| #include "ash/wm/workspace_controller.h" |
| +#include "base/command_line.h" |
| #include "base/stringprintf.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "ui/aura/client/aura_constants.h" |
| @@ -162,6 +164,21 @@ class WorkspaceWindowResizerTest : public test::AshTestBase { |
| DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest); |
| }; |
| +class WorkspaceWindowResizerTestSticky : public WorkspaceWindowResizerTest { |
| + public: |
| + WorkspaceWindowResizerTestSticky() {} |
| + virtual ~WorkspaceWindowResizerTestSticky() {} |
|
varkha
2013/04/20 15:03:58
Should the test clean the command line flag after
stevenjb
2013/04/22 17:49:01
CommandLine is reset between tests, see TestClient
|
| + |
| + virtual void SetUp() OVERRIDE { |
| + CommandLine::ForCurrentProcess()->AppendSwitch( |
| + ash::switches::kAshEnableStickyEdges); |
| + WorkspaceWindowResizerTest::SetUp(); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTestSticky); |
| +}; |
| + |
| } // namespace |
| // Assertions around attached window resize dragging from the right with 2 |
| @@ -807,17 +824,17 @@ TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { |
| window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| ASSERT_TRUE(resizer.get()); |
| // Move to an x-coordinate of 15, which should not snap. |
| - resizer->Drag(CalculateDragPoint(*resizer, -81, 0), 0); |
| + resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); |
| // An x-coordinate of 7 should snap. |
| - resizer->Drag(CalculateDragPoint(*resizer, -89, 0), 0); |
| + resizer->Drag(CalculateDragPoint(*resizer, 7 - 96, 0), 0); |
| EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); |
| // Move to -15, should still snap to 0. |
| - resizer->Drag(CalculateDragPoint(*resizer, -111, 0), 0); |
| + resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0); |
| EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); |
| // At -32 should move past snap points. |
| - resizer->Drag(CalculateDragPoint(*resizer, -128, 0), 0); |
| + resizer->Drag(CalculateDragPoint(*resizer, -32 - 96, 0), 0); |
| EXPECT_EQ("-32,112 320x160", window_->bounds().ToString()); |
| - resizer->Drag(CalculateDragPoint(*resizer, -129, 0), 0); |
| + resizer->Drag(CalculateDragPoint(*resizer, -33 - 96, 0), 0); |
| EXPECT_EQ("-33,112 320x160", window_->bounds().ToString()); |
| // Right side should similarly snap. |
| @@ -909,6 +926,104 @@ TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) { |
| EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); |
| } |
| +// Verifies sticking to edges works. |
| +TEST_F(WorkspaceWindowResizerTestSticky, StickToEdge) { |
| + Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> |
| + SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| + window_->SetBounds(gfx::Rect(96, 112, 320, 160)); |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + // Move to an x-coordinate of 15, which should not stick. |
| + resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); |
| + // Move to -15, should still stick to 0. |
| + resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0); |
| + EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); |
| + // At -100 should move past edge. |
| + resizer->Drag(CalculateDragPoint(*resizer, -100 - 96, 0), 0); |
| + EXPECT_EQ("-100,112 320x160", window_->bounds().ToString()); |
| + resizer->Drag(CalculateDragPoint(*resizer, -101 - 96, 0), 0); |
| + EXPECT_EQ("-101,112 320x160", window_->bounds().ToString()); |
| + |
| + // Right side should similarly stick. |
| + resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0); |
| + EXPECT_EQ("465,112 320x160", window_->bounds().ToString()); |
| + resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0); |
| + EXPECT_EQ("480,112 320x160", window_->bounds().ToString()); |
| + resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 100, 0), 0); |
| + EXPECT_EQ("580,112 320x160", window_->bounds().ToString()); |
| + resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 101, 0), 0); |
| + EXPECT_EQ("581,112 320x160", window_->bounds().ToString()); |
| + |
| + // And the bottom should stick too. |
| + resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 + 15), 0); |
| + EXPECT_EQ("96,437 320x160", window_->bounds().ToString()); |
| + resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 100), 0); |
| + EXPECT_EQ("96,538 320x160", window_->bounds().ToString()); |
| + resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 101), 0); |
| + EXPECT_EQ("96,539 320x160", window_->bounds().ToString()); |
| + |
| + // No need to test dragging < 0 as we force that to 0. |
| +} |
| + |
| +// Verifies a resize sticks when dragging TOPLEFT. |
| +TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPLEFT) { |
| + window_->SetBounds(gfx::Rect(100, 200, 20, 30)); |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(), HTTOPLEFT, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, -15 -200), 0); |
| + EXPECT_EQ("0,0 120x230", window_->bounds().ToString()); |
| +} |
| + |
| +// Verifies a resize sticks when dragging TOPRIGHT. |
| +TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPRIGHT) { |
| + window_->SetBounds(gfx::Rect(100, 200, 20, 30)); |
| + gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
| + window_.get())); |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(), HTTOPRIGHT, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 + 20, |
| + -200 - 15), 0); |
| + EXPECT_EQ(100, window_->bounds().x()); |
| + EXPECT_EQ(work_area.y(), window_->bounds().y()); |
| + EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); |
| + EXPECT_EQ(230, window_->bounds().height()); |
| +} |
| + |
| +// Verifies a resize snap when dragging BOTTOMRIGHT. |
| +TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMRIGHT) { |
| + window_->SetBounds(gfx::Rect(100, 200, 20, 30)); |
| + gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
| + window_.get())); |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(), HTBOTTOMRIGHT, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 - 20 + 15, |
| + work_area.bottom() - 200 - 30 + 15), 0); |
| + EXPECT_EQ(100, window_->bounds().x()); |
| + EXPECT_EQ(200, window_->bounds().y()); |
| + EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); |
| + EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); |
| +} |
| + |
| +// Verifies a resize snap when dragging BOTTOMLEFT. |
| +TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMLEFT) { |
| + window_->SetBounds(gfx::Rect(100, 200, 20, 30)); |
| + gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( |
| + window_.get())); |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(), HTBOTTOMLEFT, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, |
| + work_area.bottom() - 200 - 30 + 15), 0); |
| + EXPECT_EQ(0, window_->bounds().x()); |
| + EXPECT_EQ(200, window_->bounds().y()); |
| + EXPECT_EQ(120, window_->bounds().width()); |
| + EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); |
| +} |
| + |
| TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) { |
| window_->SetBounds(gfx::Rect(96, 112, 320, 160)); |
| scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |