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