X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fash%2Fwm%2Fworkspace%2Fworkspace_window_resizer_unittest.cc;h=b511f8929866ab5ccd17bfcc740913464c0777a1;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=42eea1dbb84f06de99a02de0977ce2aaad898649;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/ash/wm/workspace/workspace_window_resizer_unittest.cc b/src/ash/wm/workspace/workspace_window_resizer_unittest.cc index 42eea1d..b511f89 100644 --- a/src/ash/wm/workspace/workspace_window_resizer_unittest.cc +++ b/src/ash/wm/workspace/workspace_window_resizer_unittest.cc @@ -26,6 +26,7 @@ #include "ui/aura/test/event_generator.h" #include "ui/aura/test/test_window_delegate.h" #include "ui/base/hit_test.h" +#include "ui/events/gestures/gesture_configuration.h" #include "ui/gfx/insets.h" #include "ui/gfx/screen.h" #include "ui/views/widget/widget.h" @@ -77,6 +78,8 @@ class WorkspaceWindowResizerTest : public test::AshTestBase { virtual void SetUp() OVERRIDE { AshTestBase::SetUp(); UpdateDisplay(base::StringPrintf("800x%d", kRootHeight)); + // Ignore the touch slop region. + ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0); aura::Window* root = Shell::GetPrimaryRootWindow(); gfx::Rect root_bounds(root->bounds()); @@ -189,14 +192,6 @@ class WorkspaceWindowResizerTest : public test::AshTestBase { touch_resize_window_.reset( CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0, bounds)); - gfx::Insets mouse_outer_insets(-ash::kResizeOutsideBoundsSize, - -ash::kResizeOutsideBoundsSize, - -ash::kResizeOutsideBoundsSize, - -ash::kResizeOutsideBoundsSize); - gfx::Insets touch_outer_insets = mouse_outer_insets.Scale( - ash::kResizeOutsideBoundsScaleForTouch); - touch_resize_window_->SetHitTestBoundsOverrideOuter(mouse_outer_insets, - touch_outer_insets); } TestWindowDelegate delegate_; @@ -691,6 +686,89 @@ TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) { } } +// Verifies that dragging a snapped window unsnaps it. +TEST_F(WorkspaceWindowResizerTest, DragSnapped) { + ash::wm::WindowState* window_state = ash::wm::GetWindowState(window_.get()); + + const gfx::Rect kInitialBounds(100, 100, 100, 100); + window_->SetBounds(kInitialBounds); + window_->Show(); + + internal::SnapSizer::SnapWindow(window_state, internal::SnapSizer::LEFT_EDGE); + EXPECT_EQ(wm::SHOW_TYPE_LEFT_SNAPPED, window_state->window_show_type()); + gfx::Rect snapped_bounds = window_->bounds(); + EXPECT_NE(snapped_bounds.ToString(), kInitialBounds.ToString()); + EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(), + kInitialBounds.ToString()); + + // Dragging a side snapped window should unsnap it. + scoped_ptr resizer(CreateResizerForTest( + window_.get(), gfx::Point(), HTCAPTION)); + resizer->Drag(CalculateDragPoint(*resizer, 10, 0), 0); + resizer->CompleteDrag(); + EXPECT_EQ(wm::SHOW_TYPE_NORMAL, window_state->window_show_type()); + EXPECT_EQ("10,0 100x100", window_->bounds().ToString()); + EXPECT_FALSE(window_state->HasRestoreBounds()); +} + +// Verifies the behavior of resizing a side snapped window. +TEST_F(WorkspaceWindowResizerTest, ResizeSnapped) { + ash::wm::WindowState* window_state = ash::wm::GetWindowState(window_.get()); + + const gfx::Rect kInitialBounds(100, 100, 100, 100); + window_->SetBounds(kInitialBounds); + window_->Show(); + + internal::SnapSizer::SnapWindow(window_state, internal::SnapSizer::LEFT_EDGE); + EXPECT_EQ(wm::SHOW_TYPE_LEFT_SNAPPED, window_state->window_show_type()); + gfx::Rect snapped_bounds = window_->bounds(); + EXPECT_NE(snapped_bounds.ToString(), kInitialBounds.ToString()); + EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(), + kInitialBounds.ToString()); + + { + // 1) Resizing a side snapped window to make it wider should not unsnap the + // window. + scoped_ptr resizer(CreateResizerForTest( + window_.get(), gfx::Point(), HTRIGHT)); + resizer->Drag(CalculateDragPoint(*resizer, 10, 0), 0); + resizer->CompleteDrag(); + EXPECT_EQ(wm::SHOW_TYPE_LEFT_SNAPPED, window_state->window_show_type()); + snapped_bounds.Inset(0, 0, -10, 0); + EXPECT_EQ(snapped_bounds.ToString(), window_->bounds().ToString()); + EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(), + kInitialBounds.ToString()); + } + + { + // 2) Resizing a side snapped window vertically and then undoing the change + // should not unsnap. + scoped_ptr resizer(CreateResizerForTest( + window_.get(), gfx::Point(), HTBOTTOM)); + resizer->Drag(CalculateDragPoint(*resizer, 0, -30), 0); + resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); + resizer->CompleteDrag(); + EXPECT_EQ(wm::SHOW_TYPE_LEFT_SNAPPED, window_state->window_show_type()); + EXPECT_EQ(snapped_bounds.ToString(), window_->bounds().ToString()); + EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(), + kInitialBounds.ToString()); + } + + { + // 3) Resizing a side snapped window vertically and then not undoing the + // change should unsnap. + scoped_ptr resizer(CreateResizerForTest( + window_.get(), gfx::Point(), HTBOTTOM)); + resizer->Drag(CalculateDragPoint(*resizer, 0, -10), 0); + resizer->CompleteDrag(); + EXPECT_EQ(wm::SHOW_TYPE_NORMAL, window_state->window_show_type()); + gfx::Rect expected_bounds(snapped_bounds); + expected_bounds.Inset(0, 0, 0, 10); + EXPECT_EQ(expected_bounds.ToString(), window_->bounds().ToString()); + EXPECT_FALSE(window_state->HasRestoreBounds()); + } +} + // Verifies windows are correctly restacked when reordering multiple windows. TEST_F(WorkspaceWindowResizerTest, RestackAttached) { window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); @@ -1120,6 +1198,54 @@ TEST_F(WorkspaceWindowResizerTestSticky, NoStickToEdgeWhenOutside) { EXPECT_EQ("-15,112 320x160", window_->bounds().ToString()); } +// Verifies window sticks to both window and work area. +TEST_F(WorkspaceWindowResizerTest, StickToBothEdgeAndWindow) { + window_->SetBounds(gfx::Rect(10, 10, 20, 50)); + window_->Show(); + window2_->SetBounds(gfx::Rect(150, 160, 25, 1000)); + window2_->Show(); + + scoped_ptr resizer(CreateResizerForTest( + window_.get(), gfx::Point(10, 10), HTCAPTION)); + ASSERT_TRUE(resizer.get()); + + // Move |window| one pixel to the left of |window2|. Should snap to right. + resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0); + gfx::Rect expected(130, 160, 20, 50); + EXPECT_EQ(expected.ToString(), window_->bounds().ToString()); + + gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent( + window_.get())); + + // The initial y position of |window_|. + int initial_y = 10; + // The drag position where the window is exactly attached to the bottom. + int attach_y = work_area.bottom() - window_->bounds().height() - initial_y; + + // Dragging 10px above should not attach to the bottom. + resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y - 10), 0); + expected.set_y(attach_y + initial_y - 10); + EXPECT_EQ(expected.ToString(), window_->bounds().ToString()); + + // Stick to the work area. + resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y - 1), 0); + expected.set_y(attach_y + initial_y); + EXPECT_EQ(expected.ToString(), window_->bounds().ToString()); + + resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y), 0); + expected.set_y(attach_y + initial_y); + EXPECT_EQ(expected.ToString(), window_->bounds().ToString()); + + resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 1), 0); + expected.set_y(attach_y + initial_y); + EXPECT_EQ(expected.ToString(), window_->bounds().ToString()); + + // Moving down further should move the window. + resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 18), 0); + expected.set_y(attach_y + initial_y + 18); + EXPECT_EQ(expected.ToString(), window_->bounds().ToString()); +} + // Verifies a resize sticks when dragging TOPLEFT. TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPLEFT) { window_->SetBounds(gfx::Rect(100, 200, 20, 30));