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

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

Issue 11030017: Add context to gfx::Screen calls in support of simultaneous desktop+ash (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix new addition Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/display/display_controller.h" 7 #include "ash/display/display_controller.h"
8 #include "ash/display/mouse_cursor_event_filter.h" 8 #include "ash/display/mouse_cursor_event_filter.h"
9 #include "ash/screen_ash.h" 9 #include "ash/screen_ash.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 // Verifies a window can be moved from the primary display to another. 478 // Verifies a window can be moved from the primary display to another.
479 TEST_F(WorkspaceWindowResizerTest, MAYBE_WindowDragWithMultiDisplays) { 479 TEST_F(WorkspaceWindowResizerTest, MAYBE_WindowDragWithMultiDisplays) {
480 // The secondary display is logically on the right, but on the system (e.g. X) 480 // The secondary display is logically on the right, but on the system (e.g. X)
481 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. 481 // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc.
482 UpdateDisplay("800x600,800x600"); 482 UpdateDisplay("800x600,800x600");
483 Shell::GetInstance()->shelf()->LayoutShelf(); 483 Shell::GetInstance()->shelf()->LayoutShelf();
484 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 484 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
485 ASSERT_EQ(2U, root_windows.size()); 485 ASSERT_EQ(2U, root_windows.size());
486 486
487 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 487 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
488 gfx::Screen::GetPrimaryDisplay()); 488 Shell::GetScreen()->GetPrimaryDisplay());
489 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 489 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
490 { 490 {
491 // Grab (0, 0) of the window. 491 // Grab (0, 0) of the window.
492 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 492 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
493 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 493 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
494 ASSERT_TRUE(resizer.get()); 494 ASSERT_TRUE(resizer.get());
495 // Drag the pointer to the right. Once it reaches the right edge of the 495 // Drag the pointer to the right. Once it reaches the right edge of the
496 // primary display, it warps to the secondary. 496 // primary display, it warps to the secondary.
497 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0); 497 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
498 resizer->CompleteDrag(0); 498 resizer->CompleteDrag(0);
499 // The whole window is on the secondary display now. The parent should be 499 // The whole window is on the secondary display now. The parent should be
500 // changed. 500 // changed.
501 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 501 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
502 EXPECT_EQ("0,10 50x60", window_->bounds().ToString()); 502 EXPECT_EQ("0,10 50x60", window_->bounds().ToString());
503 } 503 }
504 504
505 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 505 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
506 gfx::Screen::GetPrimaryDisplay()); 506 Shell::GetScreen()->GetPrimaryDisplay());
507 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 507 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
508 { 508 {
509 // Grab (0, 0) of the window and move the pointer to (790, 10). 509 // Grab (0, 0) of the window and move the pointer to (790, 10).
510 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 510 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
511 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 511 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
512 ASSERT_TRUE(resizer.get()); 512 ASSERT_TRUE(resizer.get());
513 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0); 513 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0);
514 resizer->CompleteDrag(0); 514 resizer->CompleteDrag(0);
515 // Since the pointer is still on the primary root window, the parent should 515 // Since the pointer is still on the primary root window, the parent should
516 // not be changed. 516 // not be changed.
517 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 517 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
518 EXPECT_EQ("790,10 50x60", window_->bounds().ToString()); 518 EXPECT_EQ("790,10 50x60", window_->bounds().ToString());
519 } 519 }
520 520
521 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 521 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
522 gfx::Screen::GetPrimaryDisplay()); 522 Shell::GetScreen()->GetPrimaryDisplay());
523 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 523 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
524 { 524 {
525 // Grab the top-right edge of the window and move the pointer to (0, 10) 525 // Grab the top-right edge of the window and move the pointer to (0, 10)
526 // in the secondary root window's coordinates. 526 // in the secondary root window's coordinates.
527 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 527 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
528 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows())); 528 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows()));
529 ASSERT_TRUE(resizer.get()); 529 ASSERT_TRUE(resizer.get());
530 resizer->Drag(CalculateDragPoint(*resizer, 751, 10), ui::EF_CONTROL_DOWN); 530 resizer->Drag(CalculateDragPoint(*resizer, 751, 10), ui::EF_CONTROL_DOWN);
531 resizer->CompleteDrag(0); 531 resizer->CompleteDrag(0);
532 // Since the pointer is on the secondary, the parent should be changed 532 // Since the pointer is on the secondary, the parent should be changed
533 // even though only small fraction of the window is within the secondary 533 // even though only small fraction of the window is within the secondary
534 // root window's bounds. 534 // root window's bounds.
535 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 535 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
536 EXPECT_EQ("-49,10 50x60", window_->bounds().ToString()); 536 EXPECT_EQ("-49,10 50x60", window_->bounds().ToString());
537 } 537 }
538 } 538 }
539 539
540 // Verifies a window can be moved from the secondary display to primary. 540 // Verifies a window can be moved from the secondary display to primary.
541 TEST_F(WorkspaceWindowResizerTest, 541 TEST_F(WorkspaceWindowResizerTest,
542 MAYBE_WindowDragWithMultiDisplaysRightToLeft) { 542 MAYBE_WindowDragWithMultiDisplaysRightToLeft) {
543 UpdateDisplay("800x600,800x600"); 543 UpdateDisplay("800x600,800x600");
544 Shell::GetInstance()->shelf()->LayoutShelf(); 544 Shell::GetInstance()->shelf()->LayoutShelf();
545 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 545 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
546 ASSERT_EQ(2U, root_windows.size()); 546 ASSERT_EQ(2U, root_windows.size());
547 547
548 window_->SetBoundsInScreen( 548 window_->SetBoundsInScreen(
549 gfx::Rect(800, 00, 50, 60), 549 gfx::Rect(800, 00, 50, 60),
550 gfx::Screen::GetDisplayNearestWindow(root_windows[1])); 550 Shell::GetScreen()->GetDisplayNearestWindow(root_windows[1]));
551 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 551 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
552 { 552 {
553 // Grab (0, 0) of the window. 553 // Grab (0, 0) of the window.
554 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 554 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
555 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 555 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
556 ASSERT_TRUE(resizer.get()); 556 ASSERT_TRUE(resizer.get());
557 // Move the mouse near the right edge, (798, 0), of the primary display. 557 // Move the mouse near the right edge, (798, 0), of the primary display.
558 resizer->Drag(CalculateDragPoint(*resizer, -2, 0), ui::EF_CONTROL_DOWN); 558 resizer->Drag(CalculateDragPoint(*resizer, -2, 0), ui::EF_CONTROL_DOWN);
559 resizer->CompleteDrag(0); 559 resizer->CompleteDrag(0);
560 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 560 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
561 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); 561 EXPECT_EQ("798,0 50x60", window_->bounds().ToString());
562 } 562 }
563 } 563 }
564 564
565 // Verifies the style of the drag phantom window is correct. 565 // Verifies the style of the drag phantom window is correct.
566 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) { 566 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) {
567 UpdateDisplay("800x600,800x600"); 567 UpdateDisplay("800x600,800x600");
568 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 568 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
569 ASSERT_EQ(2U, root_windows.size()); 569 ASSERT_EQ(2U, root_windows.size());
570 570
571 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 571 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
572 gfx::Screen::GetPrimaryDisplay()); 572 Shell::GetScreen()->GetPrimaryDisplay());
573 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 573 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
574 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 574 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
575 { 575 {
576 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 576 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
577 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 577 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
578 ASSERT_TRUE(resizer.get()); 578 ASSERT_TRUE(resizer.get());
579 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 579 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
580 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); 580 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
581 581
582 // The pointer is inside the primary root. Both phantoms should be NULL. 582 // The pointer is inside the primary root. Both phantoms should be NULL.
(...skipping 30 matching lines...) Expand all
613 EXPECT_GT(1.0f, window_->layer()->opacity()); 613 EXPECT_GT(1.0f, window_->layer()->opacity());
614 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity()); 614 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity());
615 615
616 resizer->CompleteDrag(0); 616 resizer->CompleteDrag(0);
617 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 617 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
618 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 618 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
619 } 619 }
620 620
621 // Do the same test with RevertDrag(). 621 // Do the same test with RevertDrag().
622 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 622 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
623 gfx::Screen::GetPrimaryDisplay()); 623 Shell::GetScreen()->GetPrimaryDisplay());
624 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 624 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
625 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 625 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
626 { 626 {
627 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 627 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
628 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 628 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
629 ASSERT_TRUE(resizer.get()); 629 ASSERT_TRUE(resizer.get());
630 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 630 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
631 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); 631 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
632 632
633 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); 633 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0);
634 resizer->RevertDrag(); 634 resizer->RevertDrag();
635 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 635 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
636 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 636 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
637 } 637 }
638 } 638 }
639 639
640 // Verifies the style of the drag phantom window is correct. 640 // Verifies the style of the drag phantom window is correct.
641 TEST_F(WorkspaceWindowResizerTest, MAYBE_CancelSnapPhantom) { 641 TEST_F(WorkspaceWindowResizerTest, MAYBE_CancelSnapPhantom) {
642 UpdateDisplay("800x600,800x600"); 642 UpdateDisplay("800x600,800x600");
643 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 643 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
644 ASSERT_EQ(2U, root_windows.size()); 644 ASSERT_EQ(2U, root_windows.size());
645 645
646 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 646 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
647 gfx::Screen::GetPrimaryDisplay()); 647 Shell::GetScreen()->GetPrimaryDisplay());
648 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 648 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
649 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 649 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
650 { 650 {
651 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 651 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
652 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 652 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
653 ASSERT_TRUE(resizer.get()); 653 ASSERT_TRUE(resizer.get());
654 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 654 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
655 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get()); 655 EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
656 EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_); 656 EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_);
657 657
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 // 2 should be topmost since it's initially the highest in the stack. 761 // 2 should be topmost since it's initially the highest in the stack.
762 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent())); 762 EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent()));
763 } 763 }
764 } 764 }
765 765
766 // Makes sure we don't allow dragging below the work area. 766 // Makes sure we don't allow dragging below the work area.
767 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) { 767 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) {
768 Shell::GetInstance()->SetDisplayWorkAreaInsets( 768 Shell::GetInstance()->SetDisplayWorkAreaInsets(
769 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); 769 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
770 770
771 ASSERT_EQ(1, gfx::Screen::GetNumDisplays()); 771 ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays());
772 772
773 window_->SetBounds(gfx::Rect(100, 200, 300, 400)); 773 window_->SetBounds(gfx::Rect(100, 200, 300, 400));
774 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 774 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
775 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 775 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
776 ASSERT_TRUE(resizer.get()); 776 ASSERT_TRUE(resizer.get());
777 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0); 777 resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
778 int expected_y = 778 int expected_y =
779 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10; 779 kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
780 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400", 780 EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
781 window_->bounds().ToString()); 781 window_->bounds().ToString());
782 } 782 }
783 783
784 // Makes sure we don't allow dragging on the work area with multidisplay. 784 // Makes sure we don't allow dragging on the work area with multidisplay.
785 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) { 785 TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) {
786 UpdateDisplay("800x600,800x600"); 786 UpdateDisplay("800x600,800x600");
787 ASSERT_EQ(2, gfx::Screen::GetNumDisplays()); 787 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
788 788
789 Shell::GetInstance()->SetDisplayWorkAreaInsets( 789 Shell::GetInstance()->SetDisplayWorkAreaInsets(
790 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0)); 790 Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
791 791
792 // Positions the secondary display at the bottom the primary display. 792 // Positions the secondary display at the bottom the primary display.
793 ash::DisplayLayout display_layout(ash::DisplayLayout::BOTTOM, 0); 793 ash::DisplayLayout display_layout(ash::DisplayLayout::BOTTOM, 0);
794 Shell::GetInstance()->display_controller()->SetDefaultDisplayLayout( 794 Shell::GetInstance()->display_controller()->SetDefaultDisplayLayout(
795 display_layout); 795 display_layout);
796 796
797 { 797 {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0); 1002 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0);
1003 EXPECT_EQ("152,130 20x30", window_->bounds().ToString()); 1003 EXPECT_EQ("152,130 20x30", window_->bounds().ToString());
1004 1004
1005 // Move |window| one pixel above the bottom of |window2|. 1005 // Move |window| one pixel above the bottom of |window2|.
1006 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0); 1006 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0);
1007 EXPECT_EQ("152,180 20x30", window_->bounds().ToString()); 1007 EXPECT_EQ("152,180 20x30", window_->bounds().ToString());
1008 } 1008 }
1009 1009
1010 } // namespace internal 1010 } // namespace internal
1011 } // namespace ash 1011 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/workspace_window_resizer.cc ('k') | chrome/browser/chromeos/display/primary_display_switch_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698