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

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

Powered by Google App Engine
This is Rietveld 408576698