Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(414)

Side by Side Diff: ash/wm/workspace/workspace_window_resizer_unittest.cc

Issue 55363004: Enables docked windows by default (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Enables docked windows by default Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/ash_constants.h" 7 #include "ash/ash_constants.h"
8 #include "ash/ash_switches.h" 8 #include "ash/ash_switches.h"
9 #include "ash/display/display_manager.h" 9 #include "ash/display/display_manager.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 if (*i == window_ || *i == window2_ || *i == window3_) { 161 if (*i == window_ || *i == window2_ || *i == window3_) {
162 if (!result.empty()) 162 if (!result.empty())
163 result += " "; 163 result += " ";
164 result += base::IntToString((*i)->id()); 164 result += base::IntToString((*i)->id());
165 } 165 }
166 } 166 }
167 return result; 167 return result;
168 } 168 }
169 169
170 protected: 170 protected:
171 gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer, 171 gfx::Point CalculateDragPoint(const WindowResizer& resizer,
172 int delta_x, 172 int delta_x,
173 int delta_y) const { 173 int delta_y) const {
174 gfx::Point location = resizer.GetInitialLocation(); 174 gfx::Point location = resizer.GetInitialLocation();
175 location.set_x(location.x() + delta_x); 175 location.set_x(location.x() + delta_x);
176 location.set_y(location.y() + delta_y); 176 location.set_y(location.y() + delta_y);
177 return location; 177 return location;
178 } 178 }
179 179
180 std::vector<aura::Window*> empty_windows() const { 180 std::vector<aura::Window*> empty_windows() const {
181 return std::vector<aura::Window*>(); 181 return std::vector<aura::Window*>();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 virtual void SetUp() OVERRIDE { 230 virtual void SetUp() OVERRIDE {
231 CommandLine::ForCurrentProcess()->AppendSwitch( 231 CommandLine::ForCurrentProcess()->AppendSwitch(
232 ash::switches::kAshEnableStickyEdges); 232 ash::switches::kAshEnableStickyEdges);
233 WorkspaceWindowResizerTest::SetUp(); 233 WorkspaceWindowResizerTest::SetUp();
234 } 234 }
235 235
236 private: 236 private:
237 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTestSticky); 237 DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTestSticky);
238 }; 238 };
239 239
240 bool IsStickyEdgesEnabled() {
241 return (CommandLine::ForCurrentProcess()->HasSwitch(
242 switches::kAshEnableStickyEdges) || switches::UseDockedWindows());
243 }
244
240 } // namespace 245 } // namespace
241 246
242 // Assertions around attached window resize dragging from the right with 2 247 // Assertions around attached window resize dragging from the right with 2
243 // windows. 248 // windows.
244 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) { 249 TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
245 window_->SetBounds(gfx::Rect(0, 300, 400, 300)); 250 window_->SetBounds(gfx::Rect(0, 300, 400, 300));
246 window2_->SetBounds(gfx::Rect(400, 200, 100, 200)); 251 window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
247 252
248 std::vector<aura::Window*> windows; 253 std::vector<aura::Window*> windows;
249 windows.push_back(window2_.get()); 254 windows.push_back(window2_.get());
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 // 100 up again. 539 // 100 up again.
535 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0); 540 resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
536 EXPECT_EQ("0,0 200x100", window_->bounds().ToString()); 541 EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
537 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString()); 542 EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
538 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString()); 543 EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
539 } 544 }
540 545
541 546
542 // Assertions around dragging to the left/right edge of the screen. 547 // Assertions around dragging to the left/right edge of the screen.
543 TEST_F(WorkspaceWindowResizerTest, Edge) { 548 TEST_F(WorkspaceWindowResizerTest, Edge) {
544 int bottom = 549 // TODO(varkha): Insets are reset because of http://crbug.com/292238
545 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom(); 550 // Window is wide enough not to get docked right away.
546 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); 551 window_->SetBounds(gfx::Rect(20, 30, 400, 60));
547 wm::WindowState* window_state = wm::GetWindowState(window_.get()); 552 wm::WindowState* window_state = wm::GetWindowState(window_.get());
548 553
549 { 554 {
550 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 555 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
551 window_.get(), gfx::Point(), HTCAPTION, 556 window_.get(), gfx::Point(), HTCAPTION,
552 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 557 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
553 ASSERT_TRUE(resizer.get()); 558 ASSERT_TRUE(resizer.get());
554 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0); 559 resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0);
555 resizer->CompleteDrag(0); 560 resizer->CompleteDrag(0);
561 int bottom =
562 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom();
556 EXPECT_EQ("0,0 720x" + base::IntToString(bottom), 563 EXPECT_EQ("0,0 720x" + base::IntToString(bottom),
557 window_->bounds().ToString()); 564 window_->bounds().ToString());
558 ASSERT_TRUE(window_state->HasRestoreBounds()); 565 ASSERT_TRUE(window_state->HasRestoreBounds());
559 EXPECT_EQ("20,30 50x60", 566 EXPECT_EQ("20,30 400x60",
560 window_state->GetRestoreBoundsInScreen().ToString()); 567 window_state->GetRestoreBoundsInScreen().ToString());
561 } 568 }
562 // Try the same with the right side. 569 // Try the same with the right side.
563 { 570 {
564 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 571 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
565 window_.get(), gfx::Point(), HTCAPTION, 572 window_.get(), gfx::Point(), HTCAPTION,
566 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 573 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
567 ASSERT_TRUE(resizer.get()); 574 ASSERT_TRUE(resizer.get());
568 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); 575 resizer->Drag(CalculateDragPoint(*resizer, 799, 10), 0);
569 resizer->CompleteDrag(0); 576 resizer->CompleteDrag(0);
577 int bottom =
578 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom();
570 EXPECT_EQ("80,0 720x" + base::IntToString(bottom), 579 EXPECT_EQ("80,0 720x" + base::IntToString(bottom),
571 window_->bounds().ToString()); 580 window_->bounds().ToString());
572 ASSERT_TRUE(window_state->HasRestoreBounds()); 581 ASSERT_TRUE(window_state->HasRestoreBounds());
573 EXPECT_EQ("20,30 50x60", 582 EXPECT_EQ("20,30 400x60",
574 window_state->GetRestoreBoundsInScreen().ToString()); 583 window_state->GetRestoreBoundsInScreen().ToString());
575 } 584 }
576 585
577 // Test if the restore bounds is correct in multiple displays. 586 // Test if the restore bounds is correct in multiple displays.
578 window_state->ClearRestoreBounds(); 587 window_state->ClearRestoreBounds();
579 588
580 if (!SupportsMultipleDisplays()) 589 if (!SupportsMultipleDisplays())
581 return; 590 return;
582 591
583 UpdateDisplay("800x600,200x600"); 592 UpdateDisplay("800x600,500x600");
584 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 593 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
585 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 594 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
586 window_->SetBoundsInScreen(gfx::Rect(800, 10, 50, 60), 595 // Window is wide enough not to get docked right away.
596 window_->SetBoundsInScreen(gfx::Rect(800, 10, 400, 60),
587 ScreenAsh::GetSecondaryDisplay()); 597 ScreenAsh::GetSecondaryDisplay());
588 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 598 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
589 { 599 {
590 bottom = 600 EXPECT_EQ("800,10 400x60", window_->GetBoundsInScreen().ToString());
601
602 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
603 window_.get(), gfx::Point(), HTCAPTION,
604 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
605 ASSERT_TRUE(resizer.get());
606 resizer->Drag(CalculateDragPoint(*resizer, 499, 00), 0);
607 resizer->CompleteDrag(0);
608 // With the resolution of 500x600 we will hit in this case the 50% screen
609 // size setting.
610 // TODO(varkha): Insets are updated because of http://crbug.com/292238
611 int bottom =
591 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom(); 612 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom();
592 EXPECT_EQ("800,10 50x60", window_->GetBoundsInScreen().ToString()); 613 EXPECT_EQ("250,0 250x" + base::IntToString(bottom),
593
594 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
595 window_.get(), gfx::Point(), HTCAPTION,
596 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
597 ASSERT_TRUE(resizer.get());
598
599 resizer->Drag(CalculateDragPoint(*resizer, 199, 00), 0);
600 resizer->CompleteDrag(0);
601 // With the resolution of 200x600 we will hit in this case the 50% screen
602 // size setting.
603 EXPECT_EQ("100,0 100x" + base::IntToString(bottom),
604 window_->bounds().ToString()); 614 window_->bounds().ToString());
605 EXPECT_EQ("800,10 50x60", 615 EXPECT_EQ("800,10 400x60",
606 window_state->GetRestoreBoundsInScreen().ToString()); 616 window_state->GetRestoreBoundsInScreen().ToString());
607 } 617 }
608 } 618 }
609 619
610 // Check that non resizable windows will not get resized. 620 // Check that non resizable windows will not get resized.
611 TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) { 621 TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) {
612 window_->SetBounds(gfx::Rect(20, 30, 50, 60)); 622 window_->SetBounds(gfx::Rect(20, 30, 50, 60));
613 window_->SetProperty(aura::client::kCanResizeKey, false); 623 window_->SetProperty(aura::client::kCanResizeKey, false);
614 624
615 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 625 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
616 window_.get(), gfx::Point(), HTCAPTION, 626 window_.get(), gfx::Point(), HTCAPTION,
617 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 627 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
618 ASSERT_TRUE(resizer.get()); 628 ASSERT_TRUE(resizer.get());
619 resizer->Drag(CalculateDragPoint(*resizer, -20, 0), 0); 629 resizer->Drag(CalculateDragPoint(*resizer, -20, 0), 0);
620 resizer->CompleteDrag(0); 630 resizer->CompleteDrag(0);
621 EXPECT_EQ("0,30 50x60", window_->bounds().ToString()); 631 EXPECT_EQ("0,30 50x60", window_->bounds().ToString());
622 } 632 }
623 633
624 TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) { 634 TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) {
625 if (!SupportsMultipleDisplays()) 635 if (!SupportsMultipleDisplays())
626 return; 636 return;
627 637
628 UpdateDisplay("800x600,800x600"); 638 UpdateDisplay("800x600,800x600");
629 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 639 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
630 ASSERT_EQ(2U, root_windows.size()); 640 ASSERT_EQ(2U, root_windows.size());
631 641
632 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 642 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
633 Shell::GetScreen()->GetPrimaryDisplay()); 643 Shell::GetScreen()->GetPrimaryDisplay());
634 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 644 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
635 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 645 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
636 { 646 {
637 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 647 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
638 window_.get(), gfx::Point(), HTCAPTION, 648 window_.get(), gfx::Point(), HTCAPTION,
639 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 649 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
640 ASSERT_TRUE(resizer.get()); 650 ASSERT_TRUE(resizer.get());
641 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 651 WorkspaceWindowResizer* workspace_resizer =
652 WorkspaceWindowResizer::instance_;
653 EXPECT_FALSE(workspace_resizer->snap_phantom_window_controller_.get());
642 654
643 // The pointer is on the edge but not shared. The snap phantom window 655 // The pointer is on the edge but not shared. The snap phantom window
644 // controller should be non-NULL. 656 // controller should be non-NULL.
645 resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0); 657 resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0);
646 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get()); 658 EXPECT_TRUE(workspace_resizer->snap_phantom_window_controller_.get());
647 659
648 // Move the cursor across the edge. Now the snap phantom window controller 660 // Move the cursor across the edge. Now the snap phantom window controller
649 // should be canceled. 661 // should be canceled.
650 resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0); 662 resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0);
651 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 663 EXPECT_FALSE(workspace_resizer->snap_phantom_window_controller_.get());
652 } 664 }
653 } 665 }
654 666
655 // Verifies windows are correctly restacked when reordering multiple windows. 667 // Verifies windows are correctly restacked when reordering multiple windows.
656 TEST_F(WorkspaceWindowResizerTest, RestackAttached) { 668 TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
657 window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); 669 window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
658 window2_->SetBounds(gfx::Rect(200, 0, 100, 200)); 670 window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
659 window3_->SetBounds(gfx::Rect(300, 0, 100, 100)); 671 window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
660 672
661 { 673 {
(...skipping 26 matching lines...) Expand all
688 } 700 }
689 701
690 // Makes sure we don't allow dragging below the work area. 702 // Makes sure we don't allow dragging below the work area.
691 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { 703 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) {
692 Shell::GetInstance()->SetDisplayWorkAreaInsets( 704 Shell::GetInstance()->SetDisplayWorkAreaInsets(
693 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); 705 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
694 706
695 ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays()); 707 ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays());
696 708
697 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 709 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
698 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 710 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
699 window_.get(), gfx::Point(), HTCAPTION, 711 window_.get(), gfx::Point(), HTCAPTION,
700 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 712 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
701 ASSERT_TRUE(resizer.get()); 713 ASSERT_TRUE(resizer.get());
702 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); 714 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
703 int expected_y = 715 int expected_y =
704 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; 716 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
705 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", 717 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
706 window_->bounds().ToString()); 718 window_->bounds().ToString());
707 } 719 }
708 720
709 // Makes sure we don't allow dragging on the work area with multidisplay. 721 // Makes sure we don't allow dragging on the work area with multidisplay.
710 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) { 722 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) {
711 if (!SupportsMultipleDisplays()) 723 if (!SupportsMultipleDisplays())
712 return; 724 return;
713 725
714 UpdateDisplay("800x600,800x600"); 726 UpdateDisplay("800x600,800x600");
715 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 727 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
716 728
717 Shell::GetInstance()->SetDisplayWorkAreaInsets( 729 Shell::GetInstance()->SetDisplayWorkAreaInsets(
718 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); 730 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
719 731
720 // Positions the secondary display at the bottom the primary display. 732 // Positions the secondary display at the bottom the primary display.
721 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( 733 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
722 ash::DisplayLayout(ash::DisplayLayout::BOTTOM, 0)); 734 ash::DisplayLayout(ash::DisplayLayout::BOTTOM, 0));
723 735
724 { 736 {
725 window_->SetBounds(gfx::Rect(100, 200, 300, 20)); 737 window_->SetBounds(gfx::Rect(100, 200, 300, 20));
726 DCHECK_LT(window_->bounds().height(), 738 DCHECK_LT(window_->bounds().height(),
727 WorkspaceWindowResizer::kMinOnscreenHeight); 739 WorkspaceWindowResizer::kMinOnscreenHeight);
728 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 740 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
729 window_.get(), gfx::Point(), HTCAPTION, 741 window_.get(), gfx::Point(), HTCAPTION,
730 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 742 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
731 ASSERT_TRUE(resizer.get()); 743 ASSERT_TRUE(resizer.get());
732 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0); 744 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
733 int expected_y = kRootHeight - window_->bounds().height() - 10; 745 int expected_y = kRootHeight - window_->bounds().height() - 10;
734 // When the mouse cursor is in the primary display, the window cannot move 746 // When the mouse cursor is in the primary display, the window cannot move
735 // on non-work area but can get all the way towards the bottom, 747 // on non-work area but can get all the way towards the bottom,
736 // restricted only by the window height. 748 // restricted only by the window height.
737 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x20", 749 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x20",
738 window_->bounds().ToString()); 750 window_->bounds().ToString());
751 // Revert the drag in order to not remember the restore bounds.
752 resizer->RevertDrag();
739 } 753 }
740 754
755 Shell::GetInstance()->SetDisplayWorkAreaInsets(
756 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
741 { 757 {
742 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 758 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
743 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 759 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
744 window_.get(), gfx::Point(), HTCAPTION, 760 window_.get(), gfx::Point(), HTCAPTION,
745 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 761 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
746 ASSERT_TRUE(resizer.get()); 762 ASSERT_TRUE(resizer.get());
747 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0); 763 resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
748 int expected_y = 764 int expected_y =
749 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; 765 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
750 // When the mouse cursor is in the primary display, the window cannot move 766 // When the mouse cursor is in the primary display, the window cannot move
751 // on non-work area with kMinOnscreenHeight margin. 767 // on non-work area with kMinOnscreenHeight margin.
752 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", 768 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
753 window_->bounds().ToString()); 769 window_->bounds().ToString());
770 resizer->CompleteDrag(0);
754 } 771 }
755 772
756 { 773 {
757 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 774 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
758 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 775 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
759 window_.get(), gfx::Point(), HTCAPTION, 776 window_.get(), window_->bounds().origin(), HTCAPTION,
760 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 777 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
761 ASSERT_TRUE(resizer.get()); 778 ASSERT_TRUE(resizer.get());
762 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); 779 // Drag down avoiding getting stuck against the shelf on the bottom screen.
780 resizer->Drag(CalculateDragPoint(*resizer, 0, 500), 0);
763 // The window can move to the secondary display beyond non-work area of 781 // The window can move to the secondary display beyond non-work area of
764 // the primary display. 782 // the primary display.
765 EXPECT_EQ("100,800 300x400", window_->bounds().ToString()); 783 EXPECT_EQ("100,700 300x400", window_->bounds().ToString());
784 resizer->CompleteDrag(0);
766 } 785 }
767 } 786 }
768 787
769 // Makes sure we don't allow dragging off the top of the work area. 788 // Makes sure we don't allow dragging off the top of the work area.
770 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) { 789 TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) {
771 Shell::GetInstance()->SetDisplayWorkAreaInsets( 790 Shell::GetInstance()->SetDisplayWorkAreaInsets(
772 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0)); 791 Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0));
773 792
774 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 793 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
775 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 794 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
776 window_.get(), gfx::Point(), HTCAPTION, 795 window_.get(), gfx::Point(), HTCAPTION,
777 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 796 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
778 ASSERT_TRUE(resizer.get()); 797 ASSERT_TRUE(resizer.get());
779 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0); 798 resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0);
780 EXPECT_EQ("100,10 300x400", window_->bounds().ToString()); 799 EXPECT_EQ("100,10 300x400", window_->bounds().ToString());
781 } 800 }
782 801
783 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) { 802 TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) {
784 Shell::GetInstance()->SetDisplayWorkAreaInsets( 803 Shell::GetInstance()->SetDisplayWorkAreaInsets(
785 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 804 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
786 805
787 window_->SetBounds(gfx::Rect(100, 200, 300, 380)); 806 window_->SetBounds(gfx::Rect(100, 200, 300, 380));
788 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 807 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
789 window_.get(), gfx::Point(), HTTOP, 808 window_.get(), gfx::Point(), HTTOP,
790 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 809 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
791 ASSERT_TRUE(resizer.get()); 810 ASSERT_TRUE(resizer.get());
792 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0); 811 resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0);
793 EXPECT_EQ("100,200 300x380", window_->bounds().ToString()); 812 EXPECT_EQ("100,200 300x380", window_->bounds().ToString());
794 } 813 }
795 814
796 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideLeftWorkArea) { 815 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideLeftWorkArea) {
797 Shell::GetInstance()->SetDisplayWorkAreaInsets( 816 Shell::GetInstance()->SetDisplayWorkAreaInsets(
798 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 817 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
799 int left = ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).x(); 818 int left = ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_.get()).x();
800 int pixels_to_left_border = 50; 819 int pixels_to_left_border = 50;
801 int window_width = 300; 820 int window_width = 300;
802 int window_x = left - window_width + pixels_to_left_border; 821 int window_x = left - window_width + pixels_to_left_border;
803 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 822 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
804 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 823 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
805 window_.get(), gfx::Point(pixels_to_left_border, 0), HTRIGHT, 824 window_.get(), gfx::Point(pixels_to_left_border, 0), HTRIGHT,
806 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 825 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
807 ASSERT_TRUE(resizer.get()); 826 ASSERT_TRUE(resizer.get());
808 resizer->Drag(CalculateDragPoint(*resizer, -window_width, 0), 0); 827 resizer->Drag(CalculateDragPoint(*resizer, -window_width, 0), 0);
809 EXPECT_EQ(base::IntToString(window_x) + ",100 " + 828 EXPECT_EQ(base::IntToString(window_x) + ",100 " +
810 base::IntToString(kMinimumOnScreenArea - window_x) + 829 base::IntToString(kMinimumOnScreenArea - window_x) +
811 "x380", window_->bounds().ToString()); 830 "x380", window_->bounds().ToString());
812 } 831 }
813 832
814 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideRightWorkArea) { 833 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideRightWorkArea) {
815 Shell::GetInstance()->SetDisplayWorkAreaInsets( 834 Shell::GetInstance()->SetDisplayWorkAreaInsets(
816 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 835 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
817 int right = ScreenAsh::GetDisplayWorkAreaBoundsInParent( 836 int right = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
818 window_.get()).right(); 837 window_.get()).right();
819 int pixels_to_right_border = 50; 838 int pixels_to_right_border = 50;
820 int window_width = 300; 839 int window_width = 300;
821 int window_x = right - pixels_to_right_border; 840 int window_x = right - pixels_to_right_border;
822 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 841 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
823 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 842 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
824 window_.get(), gfx::Point(window_x, 0), HTLEFT, 843 window_.get(), gfx::Point(window_x, 0), HTLEFT,
825 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 844 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
826 ASSERT_TRUE(resizer.get()); 845 ASSERT_TRUE(resizer.get());
827 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); 846 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
828 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) + 847 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
829 ",100 " + 848 ",100 " +
830 base::IntToString(window_width - pixels_to_right_border + 849 base::IntToString(window_width - pixels_to_right_border +
831 kMinimumOnScreenArea) + 850 kMinimumOnScreenArea) +
832 "x380", window_->bounds().ToString()); 851 "x380", window_->bounds().ToString());
833 } 852 }
834 853
835 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideBottomWorkArea) { 854 TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideBottomWorkArea) {
836 Shell::GetInstance()->SetDisplayWorkAreaInsets( 855 Shell::GetInstance()->SetDisplayWorkAreaInsets(
837 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 856 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
838 int bottom = ScreenAsh::GetDisplayWorkAreaBoundsInParent( 857 int bottom = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
839 window_.get()).bottom(); 858 window_.get()).bottom();
840 int delta_to_bottom = 50; 859 int delta_to_bottom = 50;
841 int height = 380; 860 int height = 380;
842 window_->SetBounds(gfx::Rect(100, bottom - delta_to_bottom, 300, height)); 861 window_->SetBounds(gfx::Rect(100, bottom - delta_to_bottom, 300, height));
843 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 862 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
844 window_.get(), gfx::Point(0, bottom - delta_to_bottom), HTTOP, 863 window_.get(), gfx::Point(0, bottom - delta_to_bottom), HTTOP,
845 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 864 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
846 ASSERT_TRUE(resizer.get()); 865 ASSERT_TRUE(resizer.get());
847 resizer->Drag(CalculateDragPoint(*resizer, 0, bottom), 0); 866 resizer->Drag(CalculateDragPoint(*resizer, 0, bottom), 0);
848 EXPECT_EQ("100," + 867 EXPECT_EQ("100," +
849 base::IntToString(bottom - kMinimumOnScreenArea) + 868 base::IntToString(bottom - kMinimumOnScreenArea) +
850 " 300x" + 869 " 300x" +
851 base::IntToString(height - (delta_to_bottom - 870 base::IntToString(height - (delta_to_bottom -
852 kMinimumOnScreenArea)), 871 kMinimumOnScreenArea)),
853 window_->bounds().ToString()); 872 window_->bounds().ToString());
854 } 873 }
855 874
856 // Verifies that 'outside' check of the resizer take into account the extended 875 // Verifies that 'outside' check of the resizer take into account the extended
857 // desktop in case of repositions. 876 // desktop in case of repositions.
858 TEST_F(WorkspaceWindowResizerTest, DragWindowOutsideRightToSecondaryDisplay) { 877 TEST_F(WorkspaceWindowResizerTest, DragWindowOutsideRightToSecondaryDisplay) {
859 // Only primary display. Changes the window position to fit within the 878 // Only primary display. Changes the window position to fit within the
860 // display. 879 // display.
861 Shell::GetInstance()->SetDisplayWorkAreaInsets( 880 Shell::GetInstance()->SetDisplayWorkAreaInsets(
862 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 881 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
863 int right = ScreenAsh::GetDisplayWorkAreaBoundsInParent( 882 int right = ScreenAsh::GetDisplayWorkAreaBoundsInParent(
864 window_.get()).right(); 883 window_.get()).right();
865 int pixels_to_right_border = 50; 884 int pixels_to_right_border = 50;
866 int window_width = 300; 885 int window_width = 300;
867 int window_x = right - pixels_to_right_border; 886 int window_x = right - pixels_to_right_border;
868 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 887 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
869 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 888 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
870 window_.get(), gfx::Point(window_x, 0), HTCAPTION, 889 window_.get(), gfx::Point(window_x, 0), HTCAPTION,
871 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 890 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
872 ASSERT_TRUE(resizer.get()); 891 ASSERT_TRUE(resizer.get());
873 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); 892 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
874 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) + 893 EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
875 ",100 " + 894 ",100 " +
876 base::IntToString(window_width) + 895 base::IntToString(window_width) +
877 "x380", window_->bounds().ToString()); 896 "x380", window_->bounds().ToString());
878 897
879 if (!SupportsMultipleDisplays()) 898 if (!SupportsMultipleDisplays())
880 return; 899 return;
881 900
882 // With secondary display. Operation itself is same but doesn't change 901 // With secondary display. Operation itself is same but doesn't change
883 // the position because the window is still within the secondary display. 902 // the position because the window is still within the secondary display.
884 UpdateDisplay("1000x600,600x400"); 903 UpdateDisplay("1000x600,600x400");
885 Shell::GetInstance()->SetDisplayWorkAreaInsets( 904 Shell::GetInstance()->SetDisplayWorkAreaInsets(
886 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0)); 905 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
887 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380)); 906 window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
888 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0); 907 resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
889 EXPECT_EQ(base::IntToString(window_x + window_width) + 908 EXPECT_EQ(base::IntToString(window_x + window_width) +
890 ",100 " + 909 ",100 " +
891 base::IntToString(window_width) + 910 base::IntToString(window_width) +
892 "x380", window_->bounds().ToString()); 911 "x380", window_->bounds().ToString());
893 } 912 }
894 913
895 // Verifies snapping to edges works. 914 // Verifies snapping to edges works.
896 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) { 915 TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
916 if (IsStickyEdgesEnabled())
917 return;
897 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> 918 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
898 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 919 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
899 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 920 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
900 // Click 50px to the right so that the mouse pointer does not leave the 921 // Click 50px to the right so that the mouse pointer does not leave the
901 // workspace ensuring sticky behavior. 922 // workspace ensuring sticky behavior.
902 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 923 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
903 window_.get(), 924 window_.get(),
904 window_->bounds().origin() + gfx::Vector2d(50, 0), 925 window_->bounds().origin() + gfx::Vector2d(50, 0),
905 HTCAPTION, 926 HTCAPTION,
906 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 927 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 EXPECT_EQ("-32,470 320x160", window_->bounds().ToString()); 981 EXPECT_EQ("-32,470 320x160", window_->bounds().ToString());
961 resizer->Drag( 982 resizer->Drag(
962 CalculateDragPoint(*resizer, -33 - 96, 600 - 160 - 112 - 2 + 33), 0); 983 CalculateDragPoint(*resizer, -33 - 96, 600 - 160 - 112 - 2 + 33), 0);
963 EXPECT_EQ("-33,471 320x160", window_->bounds().ToString()); 984 EXPECT_EQ("-33,471 320x160", window_->bounds().ToString());
964 985
965 // No need to test dragging < 0 as we force that to 0. 986 // No need to test dragging < 0 as we force that to 0.
966 } 987 }
967 988
968 // Verifies a resize snap when dragging TOPLEFT. 989 // Verifies a resize snap when dragging TOPLEFT.
969 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPLEFT) { 990 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPLEFT) {
991 if (IsStickyEdgesEnabled())
992 return;
970 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 993 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
971 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 994 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
972 window_.get(), gfx::Point(), HTTOPLEFT, 995 window_.get(), gfx::Point(), HTTOPLEFT,
973 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 996 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
974 ASSERT_TRUE(resizer.get()); 997 ASSERT_TRUE(resizer.get());
975 resizer->Drag(CalculateDragPoint(*resizer, -98, -199), 0); 998 resizer->Drag(CalculateDragPoint(*resizer, -98, -199), 0);
976 EXPECT_EQ("0,0 120x230", window_->bounds().ToString()); 999 EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
977 } 1000 }
978 1001
979 // Verifies a resize snap when dragging TOPRIGHT. 1002 // Verifies a resize snap when dragging TOPRIGHT.
980 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPRIGHT) { 1003 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPRIGHT) {
1004 if (IsStickyEdgesEnabled())
1005 return;
981 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1006 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
982 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1007 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
983 window_.get())); 1008 window_.get()));
984 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1009 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
985 window_.get(), gfx::Point(), HTTOPRIGHT, 1010 window_.get(), gfx::Point(), HTTOPRIGHT,
986 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1011 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
987 ASSERT_TRUE(resizer.get()); 1012 ASSERT_TRUE(resizer.get());
988 resizer->Drag( 1013 resizer->Drag(
989 CalculateDragPoint(*resizer, work_area.right() - 120 - 1, -199), 0); 1014 CalculateDragPoint(*resizer, work_area.right() - 120 - 1, -199), 0);
990 EXPECT_EQ(100, window_->bounds().x()); 1015 EXPECT_EQ(100, window_->bounds().x());
991 EXPECT_EQ(work_area.y(), window_->bounds().y()); 1016 EXPECT_EQ(work_area.y(), window_->bounds().y());
992 EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); 1017 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
993 EXPECT_EQ(230, window_->bounds().height()); 1018 EXPECT_EQ(230, window_->bounds().height());
994 } 1019 }
995 1020
996 // Verifies a resize snap when dragging BOTTOMRIGHT. 1021 // Verifies a resize snap when dragging BOTTOMRIGHT.
997 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMRIGHT) { 1022 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMRIGHT) {
1023 if (IsStickyEdgesEnabled())
1024 return;
998 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1025 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
999 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1026 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
1000 window_.get())); 1027 window_.get()));
1001 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1028 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1002 window_.get(), gfx::Point(), HTBOTTOMRIGHT, 1029 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1003 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1030 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1004 ASSERT_TRUE(resizer.get()); 1031 ASSERT_TRUE(resizer.get());
1005 resizer->Drag( 1032 resizer->Drag(
1006 CalculateDragPoint(*resizer, work_area.right() - 120 - 1, 1033 CalculateDragPoint(*resizer, work_area.right() - 120 - 1,
1007 work_area.bottom() - 220 - 2), 0); 1034 work_area.bottom() - 220 - 2), 0);
1008 EXPECT_EQ(100, window_->bounds().x()); 1035 EXPECT_EQ(100, window_->bounds().x());
1009 EXPECT_EQ(200, window_->bounds().y()); 1036 EXPECT_EQ(200, window_->bounds().y());
1010 EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); 1037 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1011 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 1038 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1012 } 1039 }
1013 1040
1014 // Verifies a resize snap when dragging BOTTOMLEFT. 1041 // Verifies a resize snap when dragging BOTTOMLEFT.
1015 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) { 1042 TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) {
1043 if (IsStickyEdgesEnabled())
1044 return;
1016 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1045 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1017 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1046 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
1018 window_.get())); 1047 window_.get()));
1019 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1048 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
1020 window_.get(), gfx::Point(), HTBOTTOMLEFT, 1049 window_.get(), gfx::Point(), HTBOTTOMLEFT,
1021 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1050 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows()));
1022 ASSERT_TRUE(resizer.get()); 1051 ASSERT_TRUE(resizer.get());
1023 resizer->Drag( 1052 resizer->Drag(
1024 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0); 1053 CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0);
1025 EXPECT_EQ(0, window_->bounds().x()); 1054 EXPECT_EQ(0, window_->bounds().x());
1026 EXPECT_EQ(200, window_->bounds().y()); 1055 EXPECT_EQ(200, window_->bounds().y());
1027 EXPECT_EQ(120, window_->bounds().width()); 1056 EXPECT_EQ(120, window_->bounds().width());
1028 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 1057 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1029 } 1058 }
1030 1059
1031 // Verifies sticking to edges works. 1060 // Verifies sticking to edges works.
1032 TEST_F(WorkspaceWindowResizerTestSticky, StickToEdge) { 1061 TEST_F(WorkspaceWindowResizerTestSticky, StickToEdge) {
1033 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> 1062 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
1034 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1063 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1035 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1064 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1036 // Click 50px to the right so that the mouse pointer does not leave the 1065 // Click 50px to the right so that the mouse pointer does not leave the
1037 // workspace ensuring sticky behavior. 1066 // workspace ensuring sticky behavior.
1038 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1067 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1039 window_.get(), 1068 window_.get(),
1040 window_->bounds().origin() + gfx::Vector2d(50, 0), 1069 window_->bounds().origin() + gfx::Vector2d(50, 0),
1041 HTCAPTION, 1070 HTCAPTION,
1042 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1071 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1043 ASSERT_TRUE(resizer.get()); 1072 ASSERT_TRUE(resizer.get());
1044 // Move to an x-coordinate of 15, which should not stick. 1073 // Move to an x-coordinate of 15, which should not stick.
1045 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); 1074 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
1046 // Move to -15, should still stick to 0. 1075 // Move to -15, should still stick to 0.
1047 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0); 1076 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
1048 EXPECT_EQ("0,112 320x160", window_->bounds().ToString()); 1077 EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
1049 // At -100 should move past edge. 1078 // At -100 should move past edge.
1050 resizer->Drag(CalculateDragPoint(*resizer, -100 - 96, 0), 0); 1079 resizer->Drag(CalculateDragPoint(*resizer, -100 - 96, 0), 0);
1051 EXPECT_EQ("-100,112 320x160", window_->bounds().ToString()); 1080 EXPECT_EQ("-100,112 320x160", window_->bounds().ToString());
1052 resizer->Drag(CalculateDragPoint(*resizer, -101 - 96, 0), 0); 1081 resizer->Drag(CalculateDragPoint(*resizer, -101 - 96, 0), 0);
(...skipping 18 matching lines...) Expand all
1071 EXPECT_EQ("96,539 320x160", window_->bounds().ToString()); 1100 EXPECT_EQ("96,539 320x160", window_->bounds().ToString());
1072 1101
1073 // No need to test dragging < 0 as we force that to 0. 1102 // No need to test dragging < 0 as we force that to 0.
1074 } 1103 }
1075 1104
1076 // Verifies not sticking to edges when a mouse pointer is outside of work area. 1105 // Verifies not sticking to edges when a mouse pointer is outside of work area.
1077 TEST_F(WorkspaceWindowResizerTestSticky, NoStickToEdgeWhenOutside) { 1106 TEST_F(WorkspaceWindowResizerTestSticky, NoStickToEdgeWhenOutside) {
1078 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> 1107 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
1079 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1108 SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1080 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1109 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1081 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1110 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1082 window_.get(), gfx::Point(), HTCAPTION, 1111 window_.get(), gfx::Point(), HTCAPTION,
1083 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1112 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1084 ASSERT_TRUE(resizer.get()); 1113 ASSERT_TRUE(resizer.get());
1085 // Move to an x-coordinate of 15, which should not stick. 1114 // Move to an x-coordinate of 15, which should not stick.
1086 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0); 1115 resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
1087 // Move to -15, should still stick to 0. 1116 // Move to -15, should still stick to 0.
1088 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0); 1117 resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
1089 EXPECT_EQ("-15,112 320x160", window_->bounds().ToString()); 1118 EXPECT_EQ("-15,112 320x160", window_->bounds().ToString());
1090 } 1119 }
1091 1120
1092 // Verifies a resize sticks when dragging TOPLEFT. 1121 // Verifies a resize sticks when dragging TOPLEFT.
1093 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPLEFT) { 1122 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPLEFT) {
1094 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1123 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1095 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1124 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1096 window_.get(), gfx::Point(), HTTOPLEFT, 1125 window_.get(), gfx::Point(), HTTOPLEFT,
1097 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1126 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1098 ASSERT_TRUE(resizer.get()); 1127 ASSERT_TRUE(resizer.get());
1099 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, -15 -200), 0); 1128 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, -15 -200), 0);
1100 EXPECT_EQ("0,0 120x230", window_->bounds().ToString()); 1129 EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
1101 } 1130 }
1102 1131
1103 // Verifies a resize sticks when dragging TOPRIGHT. 1132 // Verifies a resize sticks when dragging TOPRIGHT.
1104 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPRIGHT) { 1133 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_TOPRIGHT) {
1105 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1134 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1106 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1135 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
1107 window_.get())); 1136 window_.get()));
1108 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1137 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1109 window_.get(), gfx::Point(), HTTOPRIGHT, 1138 window_.get(), gfx::Point(), HTTOPRIGHT,
1110 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1139 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1111 ASSERT_TRUE(resizer.get()); 1140 ASSERT_TRUE(resizer.get());
1112 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 + 20, 1141 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 + 20,
1113 -200 - 15), 0); 1142 -200 - 15), 0);
1114 EXPECT_EQ(100, window_->bounds().x()); 1143 EXPECT_EQ(100, window_->bounds().x());
1115 EXPECT_EQ(work_area.y(), window_->bounds().y()); 1144 EXPECT_EQ(work_area.y(), window_->bounds().y());
1116 EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); 1145 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1117 EXPECT_EQ(230, window_->bounds().height()); 1146 EXPECT_EQ(230, window_->bounds().height());
1118 } 1147 }
1119 1148
1120 // Verifies a resize snap when dragging BOTTOMRIGHT. 1149 // Verifies a resize snap when dragging BOTTOMRIGHT.
1121 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMRIGHT) { 1150 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMRIGHT) {
1122 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1151 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1123 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1152 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
1124 window_.get())); 1153 window_.get()));
1125 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1154 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1126 window_.get(), gfx::Point(), HTBOTTOMRIGHT, 1155 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1127 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1156 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1128 ASSERT_TRUE(resizer.get()); 1157 ASSERT_TRUE(resizer.get());
1129 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 - 20 + 15, 1158 resizer->Drag(CalculateDragPoint(*resizer, work_area.right() - 100 - 20 + 15,
1130 work_area.bottom() - 200 - 30 + 15), 0); 1159 work_area.bottom() - 200 - 30 + 15), 0);
1131 EXPECT_EQ(100, window_->bounds().x()); 1160 EXPECT_EQ(100, window_->bounds().x());
1132 EXPECT_EQ(200, window_->bounds().y()); 1161 EXPECT_EQ(200, window_->bounds().y());
1133 EXPECT_EQ(work_area.right() - 100, window_->bounds().width()); 1162 EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
1134 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 1163 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1135 } 1164 }
1136 1165
1137 // Verifies a resize snap when dragging BOTTOMLEFT. 1166 // Verifies a resize snap when dragging BOTTOMLEFT.
1138 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMLEFT) { 1167 TEST_F(WorkspaceWindowResizerTestSticky, StickToWorkArea_BOTTOMLEFT) {
1139 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1168 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1140 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent( 1169 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
1141 window_.get())); 1170 window_.get()));
1142 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1171 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1143 window_.get(), gfx::Point(), HTBOTTOMLEFT, 1172 window_.get(), gfx::Point(), HTBOTTOMLEFT,
1144 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1173 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1145 ASSERT_TRUE(resizer.get()); 1174 ASSERT_TRUE(resizer.get());
1146 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100, 1175 resizer->Drag(CalculateDragPoint(*resizer, -15 - 100,
1147 work_area.bottom() - 200 - 30 + 15), 0); 1176 work_area.bottom() - 200 - 30 + 15), 0);
1148 EXPECT_EQ(0, window_->bounds().x()); 1177 EXPECT_EQ(0, window_->bounds().x());
1149 EXPECT_EQ(200, window_->bounds().y()); 1178 EXPECT_EQ(200, window_->bounds().y());
1150 EXPECT_EQ(120, window_->bounds().width()); 1179 EXPECT_EQ(120, window_->bounds().width());
1151 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height()); 1180 EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
1152 } 1181 }
1153 1182
1154 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) { 1183 TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
1155 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1184 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1156 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1185 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1157 window_.get(), gfx::Point(), HTBOTTOMRIGHT, 1186 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1158 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1187 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1159 ASSERT_TRUE(resizer.get()); 1188 ASSERT_TRUE(resizer.get());
1160 // Resize the right bottom to add 10 in width, 12 in height. 1189 // Resize the right bottom to add 10 in width, 12 in height.
1161 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN); 1190 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
1162 // Both bottom and right sides to resize to exact size requested. 1191 // Both bottom and right sides to resize to exact size requested.
1163 EXPECT_EQ("96,112 330x172", window_->bounds().ToString()); 1192 EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
1164 } 1193 }
1165 1194
1166 TEST_F(WorkspaceWindowResizerTest, CtrlCompleteDragMoveToExactPosition) { 1195 TEST_F(WorkspaceWindowResizerTest, CtrlCompleteDragMoveToExactPosition) {
1167 window_->SetBounds(gfx::Rect(96, 112, 320, 160)); 1196 window_->SetBounds(gfx::Rect(96, 112, 320, 160));
1168 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1197 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1169 window_.get(), gfx::Point(), HTCAPTION, 1198 window_.get(), gfx::Point(), HTCAPTION,
1170 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1199 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1171 ASSERT_TRUE(resizer.get()); 1200 ASSERT_TRUE(resizer.get());
1172 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin, 1201 // Ctrl + drag the window to new poistion by adding (10, 12) to its origin,
1173 // the window should move to the exact position. 1202 // the window should move to the exact position.
1174 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0); 1203 resizer->Drag(CalculateDragPoint(*resizer, 10, 12), 0);
1175 resizer->CompleteDrag(ui::EF_CONTROL_DOWN); 1204 resizer->CompleteDrag(ui::EF_CONTROL_DOWN);
1176 EXPECT_EQ("106,124 320x160", window_->bounds().ToString()); 1205 EXPECT_EQ("106,124 320x160", window_->bounds().ToString());
1177 } 1206 }
1178 1207
1179 // Verifies that a dragged window will restore to its pre-maximized size. 1208 // Verifies that a dragged window will restore to its pre-maximized size.
1180 TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) { 1209 TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) {
1181 window_->SetBounds(gfx::Rect(0, 0, 1000, 1000)); 1210 window_->SetBounds(gfx::Rect(0, 0, 1000, 1000));
1182 wm::WindowState* window_state = wm::GetWindowState(window_.get()); 1211 wm::WindowState* window_state = wm::GetWindowState(window_.get());
1183 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160)); 1212 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
1184 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1213 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1185 window_.get(), gfx::Point(), HTCAPTION, 1214 window_.get(), gfx::Point(), HTCAPTION,
1186 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1215 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1187 ASSERT_TRUE(resizer.get()); 1216 ASSERT_TRUE(resizer.get());
1188 // Drag the window to new position by adding (10, 10) to original point, 1217 // Drag the window to new position by adding (10, 10) to original point,
1189 // the window should get restored. 1218 // the window should get restored.
1190 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); 1219 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
1191 resizer->CompleteDrag(0); 1220 resizer->CompleteDrag(0);
1192 EXPECT_EQ("10,10 320x160", window_->bounds().ToString()); 1221 EXPECT_EQ("10,10 320x160", window_->bounds().ToString());
1193 // The restore rectangle should get cleared as well. 1222 // The restore rectangle should get cleared as well.
1194 EXPECT_FALSE(window_state->HasRestoreBounds()); 1223 EXPECT_FALSE(window_state->HasRestoreBounds());
1195 } 1224 }
1196 1225
1197 // Verifies that a dragged window will restore to its pre-maximized size. 1226 // Verifies that a dragged window will restore to its pre-maximized size.
1198 TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) { 1227 TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) {
1199 const gfx::Rect initial_bounds(0, 0, 200, 400); 1228 const gfx::Rect initial_bounds(0, 0, 200, 400);
1200 window_->SetBounds(initial_bounds); 1229 window_->SetBounds(initial_bounds);
1201 1230
1202 wm::WindowState* window_state = wm::GetWindowState(window_.get()); 1231 wm::WindowState* window_state = wm::GetWindowState(window_.get());
1203 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160)); 1232 window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
1204 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1233 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1205 window_.get(), gfx::Point(), HTCAPTION, 1234 window_.get(), gfx::Point(), HTCAPTION,
1206 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1235 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1207 ASSERT_TRUE(resizer.get()); 1236 ASSERT_TRUE(resizer.get());
1208 // Drag the window to new poistion by adding (180, 16) to original point, 1237 // Drag the window to new poistion by adding (180, 16) to original point,
1209 // the window should get restored. 1238 // the window should get restored.
1210 resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0); 1239 resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0);
1211 resizer->RevertDrag(); 1240 resizer->RevertDrag();
1212 EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString()); 1241 EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString());
1213 EXPECT_EQ("96,112 320x160", 1242 EXPECT_EQ("96,112 320x160",
1214 window_state->GetRestoreBoundsInScreen().ToString()); 1243 window_state->GetRestoreBoundsInScreen().ToString());
1215 } 1244 }
1216 1245
1217 // Check that only usable sizes get returned by the resizer. 1246 // Check that only usable sizes get returned by the resizer.
1218 TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) { 1247 TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) {
1219 window_->SetBounds(gfx::Rect(10, 10, 20, 30)); 1248 window_->SetBounds(gfx::Rect(10, 10, 20, 30));
1220 window2_->SetBounds(gfx::Rect(150, 160, 25, 20)); 1249 window2_->SetBounds(gfx::Rect(150, 160, 25, 20));
1221 window2_->Show(); 1250 window2_->Show();
1222 1251
1223 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1252 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1224 window_.get(), gfx::Point(), HTCAPTION, 1253 window_.get(), gfx::Point(), HTCAPTION,
1225 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1254 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1226 ASSERT_TRUE(resizer.get()); 1255 ASSERT_TRUE(resizer.get());
1227 // Move |window| one pixel to the left of |window2|. Should snap to right and 1256 // Move |window| one pixel to the left of |window2|. Should snap to right and
1228 // top. 1257 // top.
1229 resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0); 1258 resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0);
1230 EXPECT_EQ("130,160 20x30", window_->bounds().ToString()); 1259 EXPECT_EQ("130,160 20x30", window_->bounds().ToString());
1231 1260
1232 // Move |window| one pixel to the right of |window2|. Should snap to left and 1261 // Move |window| one pixel to the right of |window2|. Should snap to left and
1233 // top. 1262 // top.
1234 resizer->Drag(CalculateDragPoint(*resizer, 164, 145), 0); 1263 resizer->Drag(CalculateDragPoint(*resizer, 164, 145), 0);
1235 EXPECT_EQ("175,160 20x30", window_->bounds().ToString()); 1264 EXPECT_EQ("175,160 20x30", window_->bounds().ToString());
1236 1265
1237 // Move |window| one pixel above |window2|. Should snap to top and left. 1266 // Move |window| one pixel above |window2|. Should snap to top and left.
1238 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0); 1267 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0);
1239 EXPECT_EQ("150,130 20x30", window_->bounds().ToString()); 1268 EXPECT_EQ("150,130 20x30", window_->bounds().ToString());
1240 1269
1241 // Move |window| one pixel above the bottom of |window2|. Should snap to 1270 // Move |window| one pixel above the bottom of |window2|. Should snap to
1242 // bottom and left. 1271 // bottom and left.
1243 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0); 1272 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0);
1244 EXPECT_EQ("150,180 20x30", window_->bounds().ToString()); 1273 EXPECT_EQ("150,180 20x30", window_->bounds().ToString());
1245 } 1274 }
1246 1275
1247 // The following variants verify magnetic snapping during resize when dragging a 1276 // The following variants verify magnetic snapping during resize when dragging a
1248 // particular edge. 1277 // particular edge.
1249 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOP) { 1278 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOP) {
1250 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1279 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1251 window2_->SetBounds(gfx::Rect(99, 179, 10, 20)); 1280 window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
1252 window2_->Show(); 1281 window2_->Show();
1253 1282
1254 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1283 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1255 window_.get(), gfx::Point(), HTTOP, 1284 window_.get(), gfx::Point(), HTTOP,
1256 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1285 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1257 ASSERT_TRUE(resizer.get()); 1286 ASSERT_TRUE(resizer.get());
1258 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1287 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1259 EXPECT_EQ("100,199 20x31", window_->bounds().ToString()); 1288 EXPECT_EQ("100,199 20x31", window_->bounds().ToString());
1260 } 1289 }
1261 1290
1262 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPLEFT) { 1291 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPLEFT) {
1263 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1292 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1264 window2_->SetBounds(gfx::Rect(99, 179, 10, 20)); 1293 window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
1265 window2_->Show(); 1294 window2_->Show();
1266 1295
1267 { 1296 {
1268 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1297 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1269 window_.get(), gfx::Point(), HTTOPLEFT, 1298 window_.get(), gfx::Point(), HTTOPLEFT,
1270 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1299 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1271 ASSERT_TRUE(resizer.get()); 1300 ASSERT_TRUE(resizer.get());
1272 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1301 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1273 EXPECT_EQ("99,199 21x31", window_->bounds().ToString()); 1302 EXPECT_EQ("99,199 21x31", window_->bounds().ToString());
1274 resizer->RevertDrag(); 1303 resizer->RevertDrag();
1275 } 1304 }
1276 1305
1277 { 1306 {
1278 window2_->SetBounds(gfx::Rect(88, 201, 10, 20)); 1307 window2_->SetBounds(gfx::Rect(88, 201, 10, 20));
1279 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1308 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1280 window_.get(), gfx::Point(), HTTOPLEFT, 1309 window_.get(), gfx::Point(), HTTOPLEFT,
1281 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1310 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1282 ASSERT_TRUE(resizer.get()); 1311 ASSERT_TRUE(resizer.get());
1283 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1312 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1284 EXPECT_EQ("98,201 22x29", window_->bounds().ToString()); 1313 EXPECT_EQ("98,201 22x29", window_->bounds().ToString());
1285 resizer->RevertDrag(); 1314 resizer->RevertDrag();
1286 } 1315 }
1287 } 1316 }
1288 1317
1289 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPRIGHT) { 1318 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPRIGHT) {
1290 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1319 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1291 window2_->Show(); 1320 window2_->Show();
1292 1321
1293 { 1322 {
1294 window2_->SetBounds(gfx::Rect(111, 179, 10, 20)); 1323 window2_->SetBounds(gfx::Rect(111, 179, 10, 20));
1295 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1324 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1296 window_.get(), gfx::Point(), HTTOPRIGHT, 1325 window_.get(), gfx::Point(), HTTOPRIGHT,
1297 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1326 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1298 ASSERT_TRUE(resizer.get()); 1327 ASSERT_TRUE(resizer.get());
1299 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1328 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1300 EXPECT_EQ("100,199 21x31", window_->bounds().ToString()); 1329 EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
1301 resizer->RevertDrag(); 1330 resizer->RevertDrag();
1302 } 1331 }
1303 1332
1304 { 1333 {
1305 window2_->SetBounds(gfx::Rect(121, 199, 10, 20)); 1334 window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
1306 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1335 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1307 window_.get(), gfx::Point(), HTTOPRIGHT, 1336 window_.get(), gfx::Point(), HTTOPRIGHT,
1308 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1337 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1309 ASSERT_TRUE(resizer.get()); 1338 ASSERT_TRUE(resizer.get());
1310 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1339 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1311 EXPECT_EQ("100,199 21x31", window_->bounds().ToString()); 1340 EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
1312 resizer->RevertDrag(); 1341 resizer->RevertDrag();
1313 } 1342 }
1314 } 1343 }
1315 1344
1316 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_RIGHT) { 1345 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_RIGHT) {
1317 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1346 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1318 window2_->SetBounds(gfx::Rect(121, 199, 10, 20)); 1347 window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
1319 window2_->Show(); 1348 window2_->Show();
1320 1349
1321 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1350 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1322 window_.get(), gfx::Point(), HTRIGHT, 1351 window_.get(), gfx::Point(), HTRIGHT,
1323 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1352 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1324 ASSERT_TRUE(resizer.get()); 1353 ASSERT_TRUE(resizer.get());
1325 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1354 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1326 EXPECT_EQ("100,200 21x30", window_->bounds().ToString()); 1355 EXPECT_EQ("100,200 21x30", window_->bounds().ToString());
1327 } 1356 }
1328 1357
1329 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMRIGHT) { 1358 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMRIGHT) {
1330 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1359 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1331 window2_->Show(); 1360 window2_->Show();
1332 1361
1333 { 1362 {
1334 window2_->SetBounds(gfx::Rect(122, 212, 10, 20)); 1363 window2_->SetBounds(gfx::Rect(122, 212, 10, 20));
1335 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1364 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1336 window_.get(), gfx::Point(), HTBOTTOMRIGHT, 1365 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1337 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1366 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1338 ASSERT_TRUE(resizer.get()); 1367 ASSERT_TRUE(resizer.get());
1339 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1368 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1340 EXPECT_EQ("100,200 22x32", window_->bounds().ToString()); 1369 EXPECT_EQ("100,200 22x32", window_->bounds().ToString());
1341 resizer->RevertDrag(); 1370 resizer->RevertDrag();
1342 } 1371 }
1343 1372
1344 { 1373 {
1345 window2_->SetBounds(gfx::Rect(111, 233, 10, 20)); 1374 window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
1346 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1375 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1347 window_.get(), gfx::Point(), HTBOTTOMRIGHT, 1376 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1348 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1377 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1349 ASSERT_TRUE(resizer.get()); 1378 ASSERT_TRUE(resizer.get());
1350 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1379 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1351 EXPECT_EQ("100,200 21x33", window_->bounds().ToString()); 1380 EXPECT_EQ("100,200 21x33", window_->bounds().ToString());
1352 resizer->RevertDrag(); 1381 resizer->RevertDrag();
1353 } 1382 }
1354 } 1383 }
1355 1384
1356 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOM) { 1385 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOM) {
1357 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1386 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1358 window2_->SetBounds(gfx::Rect(111, 233, 10, 20)); 1387 window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
1359 window2_->Show(); 1388 window2_->Show();
1360 1389
1361 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1390 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1362 window_.get(), gfx::Point(), HTBOTTOM, 1391 window_.get(), gfx::Point(), HTBOTTOM,
1363 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1392 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1364 ASSERT_TRUE(resizer.get()); 1393 ASSERT_TRUE(resizer.get());
1365 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1394 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1366 EXPECT_EQ("100,200 20x33", window_->bounds().ToString()); 1395 EXPECT_EQ("100,200 20x33", window_->bounds().ToString());
1367 } 1396 }
1368 1397
1369 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMLEFT) { 1398 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMLEFT) {
1370 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1399 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1371 window2_->Show(); 1400 window2_->Show();
1372 1401
1373 { 1402 {
1374 window2_->SetBounds(gfx::Rect(99, 231, 10, 20)); 1403 window2_->SetBounds(gfx::Rect(99, 231, 10, 20));
1375 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1404 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1376 window_.get(), gfx::Point(), HTBOTTOMLEFT, 1405 window_.get(), gfx::Point(), HTBOTTOMLEFT,
1377 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1406 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1378 ASSERT_TRUE(resizer.get()); 1407 ASSERT_TRUE(resizer.get());
1379 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1408 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1380 EXPECT_EQ("99,200 21x31", window_->bounds().ToString()); 1409 EXPECT_EQ("99,200 21x31", window_->bounds().ToString());
1381 resizer->RevertDrag(); 1410 resizer->RevertDrag();
1382 } 1411 }
1383 1412
1384 { 1413 {
1385 window2_->SetBounds(gfx::Rect(89, 209, 10, 20)); 1414 window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
1386 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1415 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1387 window_.get(), gfx::Point(), HTBOTTOMLEFT, 1416 window_.get(), gfx::Point(), HTBOTTOMLEFT,
1388 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1417 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1389 ASSERT_TRUE(resizer.get()); 1418 ASSERT_TRUE(resizer.get());
1390 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1419 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1391 EXPECT_EQ("99,200 21x29", window_->bounds().ToString()); 1420 EXPECT_EQ("99,200 21x29", window_->bounds().ToString());
1392 resizer->RevertDrag(); 1421 resizer->RevertDrag();
1393 } 1422 }
1394 } 1423 }
1395 1424
1396 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_LEFT) { 1425 TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_LEFT) {
1397 window2_->SetBounds(gfx::Rect(89, 209, 10, 20)); 1426 window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
1398 window_->SetBounds(gfx::Rect(100, 200, 20, 30)); 1427 window_->SetBounds(gfx::Rect(100, 200, 20, 30));
1399 window2_->Show(); 1428 window2_->Show();
1400 1429
1401 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1430 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1402 window_.get(), gfx::Point(), HTLEFT, 1431 window_.get(), gfx::Point(), HTLEFT,
1403 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1432 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1404 ASSERT_TRUE(resizer.get()); 1433 ASSERT_TRUE(resizer.get());
1405 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0); 1434 resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
1406 EXPECT_EQ("99,200 21x30", window_->bounds().ToString()); 1435 EXPECT_EQ("99,200 21x30", window_->bounds().ToString());
1407 } 1436 }
1408 1437
1409 // Test that the user user moved window flag is getting properly set. 1438 // Test that the user user moved window flag is getting properly set.
1410 TEST_F(WorkspaceWindowResizerTest, CheckUserWindowMangedFlags) { 1439 TEST_F(WorkspaceWindowResizerTest, CheckUserWindowManagedFlags) {
1411 window_->SetBounds(gfx::Rect( 0, 50, 400, 200)); 1440 window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
1412 1441
1413 std::vector<aura::Window*> no_attached_windows; 1442 std::vector<aura::Window*> no_attached_windows;
1414 // Check that an abort doesn't change anything. 1443 // Check that an abort doesn't change anything.
1415 { 1444 {
1416 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1445 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1417 window_.get(), gfx::Point(), HTCAPTION, 1446 window_.get(), gfx::Point(), HTCAPTION,
1418 aura::client::WINDOW_MOVE_SOURCE_MOUSE, no_attached_windows)); 1447 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1419 ASSERT_TRUE(resizer.get()); 1448 ASSERT_TRUE(resizer.get());
1420 // Move it 100 to the bottom. 1449 // Move it 100 to the bottom.
1421 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); 1450 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
1422 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); 1451 EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
1423 resizer->RevertDrag(); 1452 resizer->RevertDrag();
1424 1453
1425 EXPECT_FALSE(wm::GetWindowState(window_.get())->bounds_changed_by_user()); 1454 EXPECT_FALSE(wm::GetWindowState(window_.get())->bounds_changed_by_user());
1426 } 1455 }
1427 1456
1428 // Check that a completed move / size does change the user coordinates. 1457 // Check that a completed move / size does change the user coordinates.
1429 { 1458 {
1430 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1459 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1431 window_.get(), gfx::Point(), HTCAPTION, 1460 window_.get(), gfx::Point(), HTCAPTION,
1432 aura::client::WINDOW_MOVE_SOURCE_MOUSE, no_attached_windows)); 1461 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1433 ASSERT_TRUE(resizer.get()); 1462 ASSERT_TRUE(resizer.get());
1434 // Move it 100 to the bottom. 1463 // Move it 100 to the bottom.
1435 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0); 1464 resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
1436 EXPECT_EQ("0,150 400x200", window_->bounds().ToString()); 1465 EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
1437 resizer->CompleteDrag(0); 1466 resizer->CompleteDrag(0);
1438 EXPECT_TRUE(wm::GetWindowState(window_.get())->bounds_changed_by_user()); 1467 EXPECT_TRUE(wm::GetWindowState(window_.get())->bounds_changed_by_user());
1439 } 1468 }
1440 } 1469 }
1441 1470
1442 // Test that a window with a specified max size doesn't exceed it when dragged. 1471 // Test that a window with a specified max size doesn't exceed it when dragged.
1443 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) { 1472 TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) {
1444 window_->SetBounds(gfx::Rect(0, 0, 400, 300)); 1473 window_->SetBounds(gfx::Rect(0, 0, 400, 300));
1445 delegate_.set_max_size(gfx::Size(401, 301)); 1474 delegate_.set_max_size(gfx::Size(401, 301));
1446 1475
1447 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1476 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1448 window_.get(), gfx::Point(), HTBOTTOMRIGHT, 1477 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1449 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1478 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1450 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0); 1479 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
1451 EXPECT_EQ(401, window_->bounds().width()); 1480 EXPECT_EQ(401, window_->bounds().width());
1452 EXPECT_EQ(301, window_->bounds().height()); 1481 EXPECT_EQ(301, window_->bounds().height());
1453 } 1482 }
1454 1483
1455 // Test that a window with a specified max width doesn't restrict its height. 1484 // Test that a window with a specified max width doesn't restrict its height.
1456 TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) { 1485 TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) {
1457 window_->SetBounds(gfx::Rect(0, 0, 400, 300)); 1486 window_->SetBounds(gfx::Rect(0, 0, 400, 300));
1458 delegate_.set_max_size(gfx::Size(401, 0)); 1487 delegate_.set_max_size(gfx::Size(401, 0));
1459 1488
1460 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1489 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1461 window_.get(), gfx::Point(), HTBOTTOMRIGHT, 1490 window_.get(), gfx::Point(), HTBOTTOMRIGHT,
1462 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1491 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1463 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0); 1492 resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
1464 EXPECT_EQ(401, window_->bounds().width()); 1493 EXPECT_EQ(401, window_->bounds().width());
1465 EXPECT_EQ(302, window_->bounds().height()); 1494 EXPECT_EQ(302, window_->bounds().height());
1466 } 1495 }
1467 1496
1468 // Test that a window with a specified max size can't be snapped. 1497 // Test that a window with a specified max size can't be snapped.
1469 TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) { 1498 TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) {
1470 { 1499 {
1471 // With max size not set we get a phantom window controller for dragging off 1500 // With max size not set we get a phantom window controller for dragging off
1472 // the right hand side. 1501 // the right hand side.
1473 window_->SetBounds(gfx::Rect(0, 0, 300, 200)); 1502 // Make the window wider than maximum docked width.
1503 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1474 1504
1475 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1505 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1476 window_.get(), gfx::Point(), HTCAPTION, 1506 window_.get(), gfx::Point(), HTCAPTION,
1477 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1507 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1478 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 1508 WorkspaceWindowResizer* workspace_resizer =
1509 WorkspaceWindowResizer::instance_;
1510 EXPECT_FALSE(workspace_resizer->snap_phantom_window_controller_.get());
1479 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0); 1511 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1480 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get()); 1512 EXPECT_TRUE(workspace_resizer->snap_phantom_window_controller_.get());
1513 resizer->RevertDrag();
1481 } 1514 }
1482 { 1515 {
1483 // With max size defined, we get no phantom window. 1516 // With max size defined, we get no phantom window for snapping but we still
1484 window_->SetBounds(gfx::Rect(0, 0, 300, 200)); 1517 // get a phantom window (docking guide).
1485 delegate_.set_max_size(gfx::Size(300, 200)); 1518 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1519 delegate_.set_max_size(gfx::Size(410, 210));
1486 1520
1487 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1521 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1488 window_.get(), gfx::Point(), HTCAPTION, 1522 window_.get(), gfx::Point(), HTCAPTION,
1489 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1523 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1524 WorkspaceWindowResizer* workspace_resizer =
1525 WorkspaceWindowResizer::instance_;
1490 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0); 1526 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1491 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 1527 if (switches::UseDockedWindows())
1528 EXPECT_TRUE(workspace_resizer->snap_phantom_window_controller_.get());
1529 else
1530 EXPECT_FALSE(workspace_resizer->snap_phantom_window_controller_.get());
1531 resizer->RevertDrag();
1532 }
1533 {
1534 // With max size defined, we get no phantom window for snapping.
1535 window_->SetBounds(gfx::Rect(0, 0, 400, 200));
1536 delegate_.set_max_size(gfx::Size(410, 210));
1537 // With min size defined, we get no phantom window for docking.
1538 delegate_.set_min_size(gfx::Size(400, 200));
1539
1540 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1541 window_.get(), gfx::Point(), HTCAPTION,
1542 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1543 WorkspaceWindowResizer* workspace_resizer =
1544 WorkspaceWindowResizer::instance_;
1545 resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
1546 EXPECT_FALSE(workspace_resizer->snap_phantom_window_controller_.get());
1547 resizer->RevertDrag();
1492 } 1548 }
1493 } 1549 }
1494 1550
1495 TEST_F(WorkspaceWindowResizerTest, DontRewardRightmostWindowForOverflows) { 1551 TEST_F(WorkspaceWindowResizerTest, DontRewardRightmostWindowForOverflows) {
1496 UpdateDisplay("600x800"); 1552 UpdateDisplay("600x800");
1497 aura::Window* root = Shell::GetPrimaryRootWindow(); 1553 aura::Window* root = Shell::GetPrimaryRootWindow();
1498 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 1554 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
1499 1555
1500 // Four 100x100 windows flush against eachother, starting at 100,100. 1556 // Four 100x100 windows flush against eachother, starting at 100,100.
1501 window_->SetBounds(gfx::Rect( 100, 100, 100, 100)); 1557 window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 TEST_F(WorkspaceWindowResizerTest, PhantomWindowShow) { 1926 TEST_F(WorkspaceWindowResizerTest, PhantomWindowShow) {
1871 if (!SupportsMultipleDisplays()) 1927 if (!SupportsMultipleDisplays())
1872 return; 1928 return;
1873 1929
1874 UpdateDisplay("500x400,500x400"); 1930 UpdateDisplay("500x400,500x400");
1875 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 1931 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
1876 Shell::GetScreen()->GetPrimaryDisplay()); 1932 Shell::GetScreen()->GetPrimaryDisplay());
1877 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 1933 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
1878 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 1934 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
1879 1935
1880 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 1936 scoped_ptr<WindowResizer> resizer(CreateWindowResizer(
1881 window_.get(), gfx::Point(0,0), HTCAPTION, 1937 window_.get(), gfx::Point(), HTCAPTION,
1882 aura::client::WINDOW_MOVE_SOURCE_MOUSE, empty_windows())); 1938 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
1883 ASSERT_TRUE(resizer.get()); 1939 ASSERT_TRUE(resizer.get());
1884 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 1940 WorkspaceWindowResizer* workspace_resizer =
1941 WorkspaceWindowResizer::instance_;
1942 EXPECT_FALSE(workspace_resizer->snap_phantom_window_controller_.get());
1885 1943
1886 // The pointer is on the edge but not shared. The snap phantom window 1944 // The pointer is on the edge but not shared. The snap phantom window
1887 // controller should be non-NULL. 1945 // controller should be non-NULL.
1888 resizer->Drag(CalculateDragPoint(*resizer, -1, 0), 0); 1946 resizer->Drag(CalculateDragPoint(*resizer, -1, 0), 0);
1889 EXPECT_TRUE(resizer->snap_phantom_window_controller_.get()); 1947 EXPECT_TRUE(workspace_resizer->snap_phantom_window_controller_.get());
1890 PhantomWindowController* phantom_controller( 1948 PhantomWindowController* phantom_controller(
1891 resizer->snap_phantom_window_controller_.get()); 1949 workspace_resizer->snap_phantom_window_controller_.get());
1892 1950
1893 // phantom widget only in the left screen. 1951 // phantom widget only in the left screen.
1894 phantom_controller->Show(gfx::Rect(100, 100, 50, 60)); 1952 phantom_controller->Show(gfx::Rect(100, 100, 50, 60));
1895 EXPECT_TRUE(phantom_controller->phantom_widget_); 1953 EXPECT_TRUE(phantom_controller->phantom_widget_);
1896 EXPECT_FALSE(phantom_controller->phantom_widget_start_); 1954 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
1897 EXPECT_EQ( 1955 EXPECT_EQ(
1898 root_windows[0], 1956 root_windows[0],
1899 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow()); 1957 phantom_controller->phantom_widget_->GetNativeWindow()->GetRootWindow());
1900 1958
1901 // Move phantom widget into the right screen. Test that 2 widgets got created. 1959 // Move phantom widget into the right screen. Test that 2 widgets got created.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 RunAnimationTillComplete(phantom_controller->animation_.get()); 2028 RunAnimationTillComplete(phantom_controller->animation_.get());
1971 2029
1972 // Hide phantom controller. Both widgets should close. 2030 // Hide phantom controller. Both widgets should close.
1973 phantom_controller->Hide(); 2031 phantom_controller->Hide();
1974 EXPECT_FALSE(phantom_controller->phantom_widget_); 2032 EXPECT_FALSE(phantom_controller->phantom_widget_);
1975 EXPECT_FALSE(phantom_controller->phantom_widget_start_); 2033 EXPECT_FALSE(phantom_controller->phantom_widget_start_);
1976 } 2034 }
1977 2035
1978 } // namespace internal 2036 } // namespace internal
1979 } // namespace ash 2037 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698