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

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

Issue 10961021: Return primary display if out of bounds point or NULL ponter is passed to gfx::Screen::GeDisplayNea (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a few other tests that were using native coordinate. it shoud use screen coordinate now. Created 8 years, 3 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
« no previous file with comments | « ash/display/multi_display_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/workspace/workspace_window_resizer.h" 5 #include "ash/wm/workspace/workspace_window_resizer.h"
6 6
7 #include "ash/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"
11 #include "ash/shell_window_ids.h" 11 #include "ash/shell_window_ids.h"
12 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
13 #include "ash/wm/property_util.h" 13 #include "ash/wm/property_util.h"
14 #include "ash/wm/shelf_layout_manager.h" 14 #include "ash/wm/shelf_layout_manager.h"
15 #include "ash/wm/workspace_controller.h" 15 #include "ash/wm/workspace_controller.h"
16 #include "ash/wm/workspace/snap_sizer.h" 16 #include "ash/wm/workspace/snap_sizer.h"
17 #include "ash/wm/workspace/phantom_window_controller.h" 17 #include "ash/wm/workspace/phantom_window_controller.h"
18 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
19 #include "base/stringprintf.h"
19 #include "ui/aura/root_window.h" 20 #include "ui/aura/root_window.h"
20 #include "ui/aura/test/test_window_delegate.h" 21 #include "ui/aura/test/test_window_delegate.h"
21 #include "ui/base/hit_test.h" 22 #include "ui/base/hit_test.h"
22 #include "ui/gfx/insets.h" 23 #include "ui/gfx/insets.h"
23 #include "ui/gfx/screen.h" 24 #include "ui/gfx/screen.h"
24 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
25 26
26 namespace ash { 27 namespace ash {
27 namespace internal { 28 namespace internal {
28 namespace { 29 namespace {
(...skipping 22 matching lines...) Expand all
51 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); 52 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
52 }; 53 };
53 54
54 class WorkspaceWindowResizerTest : public test::AshTestBase { 55 class WorkspaceWindowResizerTest : public test::AshTestBase {
55 public: 56 public:
56 WorkspaceWindowResizerTest() : window_(NULL) {} 57 WorkspaceWindowResizerTest() : window_(NULL) {}
57 virtual ~WorkspaceWindowResizerTest() {} 58 virtual ~WorkspaceWindowResizerTest() {}
58 59
59 virtual void SetUp() OVERRIDE { 60 virtual void SetUp() OVERRIDE {
60 AshTestBase::SetUp(); 61 AshTestBase::SetUp();
62 UpdateDisplay(StringPrintf("800x%d", kRootHeight));
63
61 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); 64 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
62 root->SetHostSize(gfx::Size(800, kRootHeight));
63
64 gfx::Rect root_bounds(root->bounds()); 65 gfx::Rect root_bounds(root->bounds());
65 EXPECT_EQ(kRootHeight, root_bounds.height()); 66 EXPECT_EQ(kRootHeight, root_bounds.height());
67 EXPECT_EQ(800, root_bounds.width());
66 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); 68 Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
67 window_.reset(new aura::Window(&delegate_)); 69 window_.reset(new aura::Window(&delegate_));
68 window_->SetType(aura::client::WINDOW_TYPE_NORMAL); 70 window_->SetType(aura::client::WINDOW_TYPE_NORMAL);
69 window_->Init(ui::LAYER_NOT_DRAWN); 71 window_->Init(ui::LAYER_NOT_DRAWN);
70 window_->SetParent(NULL); 72 window_->SetParent(NULL);
71 window_->set_id(1); 73 window_->set_id(1);
72 74
73 window2_.reset(new aura::Window(&delegate2_)); 75 window2_.reset(new aura::Window(&delegate2_));
74 window2_->SetType(aura::client::WINDOW_TYPE_NORMAL); 76 window2_->SetType(aura::client::WINDOW_TYPE_NORMAL);
75 window2_->Init(ui::LAYER_NOT_DRAWN); 77 window2_->Init(ui::LAYER_NOT_DRAWN);
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 486
485 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 487 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
486 gfx::Screen::GetPrimaryDisplay()); 488 gfx::Screen::GetPrimaryDisplay());
487 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 489 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
488 { 490 {
489 // Grab (0, 0) of the window. 491 // Grab (0, 0) of the window.
490 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 492 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
491 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 493 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
492 ASSERT_TRUE(resizer.get()); 494 ASSERT_TRUE(resizer.get());
493 // 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
494 // primary display, it warps to the secondary. Since the secondary root 496 // primary display, it warps to the secondary.
495 // window's native origin held by aura::RootWindowHost is (0, 600), and a 497 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
496 // mouse drag event has a location in the primary root window's coordinates,
497 // (810, 0) right means (10, 0) in the second root window's coordinates.
498 resizer->Drag(CalculateDragPoint(*resizer, 810, 0), 0);
499 resizer->CompleteDrag(0); 498 resizer->CompleteDrag(0);
500 // 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
501 // changed. 500 // changed.
502 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 501 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
503 EXPECT_EQ("10,0 50x60", window_->bounds().ToString()); 502 EXPECT_EQ("0,10 50x60", window_->bounds().ToString());
504 } 503 }
505 504
506 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 505 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
507 gfx::Screen::GetPrimaryDisplay()); 506 gfx::Screen::GetPrimaryDisplay());
508 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 507 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
509 { 508 {
510 // 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).
511 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 510 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
512 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 511 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
513 ASSERT_TRUE(resizer.get()); 512 ASSERT_TRUE(resizer.get());
514 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0); 513 resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0);
515 resizer->CompleteDrag(0); 514 resizer->CompleteDrag(0);
516 // 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
517 // not be changed. 516 // not be changed.
518 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 517 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
519 EXPECT_EQ("790,10 50x60", window_->bounds().ToString()); 518 EXPECT_EQ("790,10 50x60", window_->bounds().ToString());
520 } 519 }
521 520
522 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), 521 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
523 gfx::Screen::GetPrimaryDisplay()); 522 gfx::Screen::GetPrimaryDisplay());
524 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 523 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
525 { 524 {
526 // 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)
527 // in the secondary root window's coordinates. 526 // in the secondary root window's coordinates.
528 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 527 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
529 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows())); 528 window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows()));
530 ASSERT_TRUE(resizer.get()); 529 ASSERT_TRUE(resizer.get());
531 resizer->Drag(CalculateDragPoint(*resizer, -49 + 800, 0), 530 resizer->Drag(CalculateDragPoint(*resizer, 751, 10), ui::EF_CONTROL_DOWN);
532 ui::EF_CONTROL_DOWN);
533 resizer->CompleteDrag(0); 531 resizer->CompleteDrag(0);
534 // Since the pointer is on the secondary, the parent should not be changed 532 // Since the pointer is on the secondary, the parent should be changed
535 // 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
536 // root window's bounds. 534 // root window's bounds.
537 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 535 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
538 EXPECT_EQ("-49,0 50x60", window_->bounds().ToString()); 536 EXPECT_EQ("-49,10 50x60", window_->bounds().ToString());
539 } 537 }
540 } 538 }
541 539
542 // 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.
543 TEST_F(WorkspaceWindowResizerTest, 541 TEST_F(WorkspaceWindowResizerTest,
544 MAYBE_WindowDragWithMultiDisplaysRightToLeft) { 542 MAYBE_WindowDragWithMultiDisplaysRightToLeft) {
545 UpdateDisplay("800x600,800x600"); 543 UpdateDisplay("800x600,800x600");
546 Shell::GetInstance()->shelf()->LayoutShelf(); 544 Shell::GetInstance()->shelf()->LayoutShelf();
547 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 545 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
548 ASSERT_EQ(2U, root_windows.size()); 546 ASSERT_EQ(2U, root_windows.size());
549 547
550 window_->SetBoundsInScreen( 548 window_->SetBoundsInScreen(
551 gfx::Rect(800, 00, 50, 60), 549 gfx::Rect(800, 00, 50, 60),
552 gfx::Screen::GetDisplayNearestWindow(root_windows[1])); 550 gfx::Screen::GetDisplayNearestWindow(root_windows[1]));
553 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 551 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
554 { 552 {
555 // Grab (0, 0) of the window. 553 // Grab (0, 0) of the window.
556 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( 554 scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create(
557 window_.get(), gfx::Point(), HTCAPTION, empty_windows())); 555 window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
558 ASSERT_TRUE(resizer.get()); 556 ASSERT_TRUE(resizer.get());
559 // 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.
560 resizer->Drag(CalculateDragPoint(*resizer, -2, 0), 558 resizer->Drag(CalculateDragPoint(*resizer, -2, 0), ui::EF_CONTROL_DOWN);
561 ui::EF_CONTROL_DOWN);
562 resizer->CompleteDrag(0); 559 resizer->CompleteDrag(0);
563 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); 560 EXPECT_EQ(root_windows[0], window_->GetRootWindow());
564 EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); 561 EXPECT_EQ("798,0 50x60", window_->bounds().ToString());
565 } 562 }
566 } 563 }
567 564
568 // Verifies the style of the drag phantom window is correct. 565 // Verifies the style of the drag phantom window is correct.
569 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) { 566 TEST_F(WorkspaceWindowResizerTest, MAYBE_PhantomStyle) {
570 UpdateDisplay("800x600,800x600"); 567 UpdateDisplay("800x600,800x600");
571 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 568 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
(...skipping 28 matching lines...) Expand all
600 controller->phantom_widget_->GetNativeWindow()->layer()->children(); 597 controller->phantom_widget_->GetNativeWindow()->layer()->children();
601 EXPECT_FALSE(layers.empty()); 598 EXPECT_FALSE(layers.empty());
602 EXPECT_EQ(resizer->layer_, layers.back()); 599 EXPECT_EQ(resizer->layer_, layers.back());
603 600
604 // |window_| should be opaque since the pointer is still on the primary 601 // |window_| should be opaque since the pointer is still on the primary
605 // root window. The phantom should be semi-transparent. 602 // root window. The phantom should be semi-transparent.
606 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); 603 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
607 EXPECT_GT(1.0f, controller->GetOpacity()); 604 EXPECT_GT(1.0f, controller->GetOpacity());
608 605
609 // Enter the pointer to the secondary display. 606 // Enter the pointer to the secondary display.
610 resizer->Drag(CalculateDragPoint(*resizer, 810, 0), 0); 607 resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
611 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get()); 608 EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
612 controller = resizer->drag_phantom_window_controller_.get(); 609 controller = resizer->drag_phantom_window_controller_.get();
613 ASSERT_TRUE(controller); 610 ASSERT_TRUE(controller);
614 EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style()); 611 EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style());
615 // |window_| should be transparent, and the phantom should be opaque. 612 // |window_| should be transparent, and the phantom should be opaque.
616 EXPECT_GT(1.0f, window_->layer()->opacity()); 613 EXPECT_GT(1.0f, window_->layer()->opacity());
617 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity()); 614 EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity());
618 615
619 resizer->CompleteDrag(0); 616 resizer->CompleteDrag(0);
620 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); 617 EXPECT_EQ(root_windows[1], window_->GetRootWindow());
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0); 1002 resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0);
1006 EXPECT_EQ("152,130 20x30", window_->bounds().ToString()); 1003 EXPECT_EQ("152,130 20x30", window_->bounds().ToString());
1007 1004
1008 // Move |window| one pixel above the bottom of |window2|. 1005 // Move |window| one pixel above the bottom of |window2|.
1009 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0); 1006 resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0);
1010 EXPECT_EQ("152,180 20x30", window_->bounds().ToString()); 1007 EXPECT_EQ("152,180 20x30", window_->bounds().ToString());
1011 } 1008 }
1012 1009
1013 } // namespace internal 1010 } // namespace internal
1014 } // namespace ash 1011 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/multi_display_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698