Chromium Code Reviews| Index: ash/wm/workspace/workspace_window_resizer_unittest.cc |
| diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc |
| index b9f09a15f40499985e48764ccc4e866521defe1e..7906de216bfe6f9db448a98e7808730174062542 100644 |
| --- a/ash/wm/workspace/workspace_window_resizer_unittest.cc |
| +++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc |
| @@ -4,8 +4,10 @@ |
| #include "ash/wm/workspace/workspace_window_resizer.h" |
| +#include "ash/display/display_controller.h" |
| #include "ash/screen_ash.h" |
| #include "ash/shell.h" |
| +#include "ash/shell_window_ids.h" |
| #include "ash/test/ash_test_base.h" |
| #include "ash/wm/property_util.h" |
| #include "ash/wm/workspace_controller.h" |
| @@ -14,6 +16,7 @@ |
| #include "ui/aura/test/test_window_delegate.h" |
| #include "ui/base/hit_test.h" |
| #include "ui/gfx/insets.h" |
| +#include "ui/gfx/screen.h" |
| namespace ash { |
| namespace internal { |
| @@ -49,26 +52,30 @@ class WorkspaceWindowResizerTest : public test::AshTestBase { |
| virtual ~WorkspaceWindowResizerTest() {} |
| virtual void SetUp() OVERRIDE { |
| + DisplayController::SetExtendedDesktopEnabled(true); |
| AshTestBase::SetUp(); |
| aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
| root->SetHostSize(gfx::Size(800, kRootHeight)); |
| + aura::Window* default_container = |
| + Shell::GetContainer(root, kShellWindowId_DefaultContainer); |
| + |
| gfx::Rect root_bounds(root->bounds()); |
| EXPECT_EQ(kRootHeight, root_bounds.height()); |
| Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets()); |
| window_.reset(new aura::Window(&delegate_)); |
| window_->Init(ui::LAYER_NOT_DRAWN); |
| - window_->SetParent(root); |
| + window_->SetParent(default_container); |
| window_->set_id(1); |
| window2_.reset(new aura::Window(&delegate2_)); |
| window2_->Init(ui::LAYER_NOT_DRAWN); |
| - window2_->SetParent(root); |
| + window2_->SetParent(default_container); |
| window2_->set_id(2); |
| window3_.reset(new aura::Window(&delegate3_)); |
| window3_->Init(ui::LAYER_NOT_DRAWN); |
| - window3_->SetParent(root); |
| + window3_->SetParent(default_container); |
| window3_->set_id(3); |
| } |
| @@ -77,6 +84,7 @@ class WorkspaceWindowResizerTest : public test::AshTestBase { |
| window2_.reset(); |
| window3_.reset(); |
| AshTestBase::TearDown(); |
| + DisplayController::SetExtendedDesktopEnabled(false); |
| } |
| // Returns a string identifying the z-order of each of the known windows. |
| @@ -84,8 +92,9 @@ class WorkspaceWindowResizerTest : public test::AshTestBase { |
| // from topmost to bottomost windows. |
| std::string WindowOrderAsString() const { |
| std::string result; |
| - const aura::Window::Windows& windows = |
| - Shell::GetPrimaryRootWindow()->children(); |
| + aura::Window* default_container = Shell::GetContainer( |
| + Shell::GetPrimaryRootWindow(), kShellWindowId_DefaultContainer); |
| + const aura::Window::Windows& windows = default_container->children(); |
| for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin(); |
| i != windows.rend(); ++i) { |
| if (*i == window_.get() || *i == window2_.get() || *i == window3_.get()) { |
| @@ -102,6 +111,7 @@ class WorkspaceWindowResizerTest : public test::AshTestBase { |
| Shell::TestApi shell_test(Shell::GetInstance()); |
| shell_test.workspace_controller()->SetGridSize(grid_size); |
| } |
| + |
| gfx::Point CalculateDragPoint(const WorkspaceWindowResizer& resizer, |
| int delta_x, |
| int delta_y) const { |
| @@ -454,6 +464,97 @@ TEST_F(WorkspaceWindowResizerTest, Edge) { |
| EXPECT_EQ("20,30 50x60", GetRestoreBoundsInScreen(window_.get())->ToString()); |
| } |
| +// Verifies a window can be moved from the primary display to another. |
| +TEST_F(WorkspaceWindowResizerTest, WindowDragWithMultiMonitors) { |
| + // The secondary display is logically on the right, but on the system (e.g. X) |
| + // layer, it's below the primary one. See UpdateDisplay() in ash_test_base.cc. |
| + UpdateDisplay("800x600,800x600"); |
| + Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| + ASSERT_EQ(2U, root_windows.size()); |
| + |
| + window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| + gfx::Screen::GetPrimaryDisplay()); |
| + EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| + { |
| + SetGridSize(0); |
| + // Grab (0, 0) of the window. |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + // Drag the pointer to the right. Once it reaches the right edge of the |
| + // primary display, it warps to the secondary. Since the secondary root |
| + // window's native origin held by aura::RootWindowHost is (0, 600), and a |
| + // mouse drag event has a location in the primary root window's coordinates, |
| + // (0, 610) below means (0, 10) in the second root window's coordinates. |
| + resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); |
| + resizer->CompleteDrag(0); |
| + // The whole window is on the secondary display now. The parent should be |
| + // changed. |
| + EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
| + EXPECT_EQ("0,10 50x60", window_->bounds().ToString()); |
| + } |
| + |
| + window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| + gfx::Screen::GetPrimaryDisplay()); |
| + EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| + { |
| + SetGridSize(0); |
|
sky
2012/08/09 00:47:38
Why do you need SetGridSize so many times?
Yusuke Sato
2012/08/09 00:58:00
Thanks, removed.
|
| + // Grab (0, 0) of the window and move the pointer to (790, 10). |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + resizer->Drag(CalculateDragPoint(*resizer, 790, 10), 0); |
| + resizer->CompleteDrag(0); |
| + // Since the pointer is still on the primary root window, the parent should |
| + // not be changed. |
| + EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| + EXPECT_EQ("790,10 50x60", window_->bounds().ToString()); |
| + } |
| + |
| + window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| + gfx::Screen::GetPrimaryDisplay()); |
| + EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| + { |
| + SetGridSize(0); |
| + // Grab the top-right edge of the window and move the pointer to (0, 10) |
| + // in the secondary root window's coordinates. |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(49, 0), HTCAPTION, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + resizer->Drag(CalculateDragPoint(*resizer, -49, 610), 0); |
| + resizer->CompleteDrag(0); |
| + // Since the pointer is on the secondary, the parent should not be changed |
| + // even though only small fraction of the window is within the secondary |
| + // root window's bounds. |
| + EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
| + EXPECT_EQ("-49,10 50x60", window_->bounds().ToString()); |
| + } |
| +} |
| + |
| +// Verifies a window can be moved from the secondary display to primary. |
| +TEST_F(WorkspaceWindowResizerTest, WindowDragWithMultiMonitorsRightToLeft) { |
| + UpdateDisplay("800x600,800x600"); |
| + Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| + ASSERT_EQ(2U, root_windows.size()); |
| + |
| + window_->SetBoundsInScreen( |
| + gfx::Rect(800, 00, 50, 60), |
| + gfx::Screen::GetDisplayNearestWindow(root_windows[1])); |
| + EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
| + { |
| + SetGridSize(0); |
| + // Grab (0, 0) of the window. |
| + scoped_ptr<WorkspaceWindowResizer> resizer(WorkspaceWindowResizer::Create( |
| + window_.get(), gfx::Point(), HTCAPTION, empty_windows())); |
| + ASSERT_TRUE(resizer.get()); |
| + // Move the mouse near the right edge, (798, 0), of the primary display. |
| + resizer->Drag(CalculateDragPoint(*resizer, 798, -600), 0); |
| + resizer->CompleteDrag(0); |
| + EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| + EXPECT_EQ("798,0 50x60", window_->bounds().ToString()); |
| + } |
| +} |
| + |
| // Verifies windows are correctly restacked when reordering multiple windows. |
| TEST_F(WorkspaceWindowResizerTest, RestackAttached) { |
| window_->SetBounds(gfx::Rect( 0, 0, 200, 300)); |