Chromium Code Reviews| Index: ash/wm/dock/docked_window_resizer_unittest.cc |
| diff --git a/ash/wm/dock/docked_window_resizer_unittest.cc b/ash/wm/dock/docked_window_resizer_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f52c61a78fcf1d0c5776c36738b675af6a81cc0 |
| --- /dev/null |
| +++ b/ash/wm/dock/docked_window_resizer_unittest.cc |
| @@ -0,0 +1,562 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/wm/dock/docked_window_resizer.h" |
| + |
| +#include "ash/ash_switches.h" |
| +#include "ash/launcher/launcher.h" |
| +#include "ash/launcher/launcher_model.h" |
| +#include "ash/root_window_controller.h" |
| +#include "ash/shelf/shelf_layout_manager.h" |
| +#include "ash/shelf/shelf_types.h" |
| +#include "ash/shelf/shelf_widget.h" |
| +#include "ash/shell.h" |
| +#include "ash/shell_window_ids.h" |
| +#include "ash/test/ash_test_base.h" |
| +#include "ash/test/cursor_manager_test_api.h" |
| +#include "ash/test/shell_test_api.h" |
| +#include "ash/test/test_launcher_delegate.h" |
| +#include "ash/wm/dock/docked_window_layout_manager.h" |
| +#include "ash/wm/drag_window_resizer.h" |
| +#include "ash/wm/panels/panel_layout_manager.h" |
| +#include "ash/wm/window_properties.h" |
| +#include "base/command_line.h" |
| +#include "ui/aura/client/aura_constants.h" |
| +#include "ui/aura/root_window.h" |
| +#include "ui/base/hit_test.h" |
| +#include "ui/base/ui_base_types.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace ash { |
| +namespace internal { |
| + |
| +class DockWindowResizerTest |
| + : public test::AshTestBase, |
| + public testing::WithParamInterface<bool> { |
| + public: |
| + DockWindowResizerTest() : model_(NULL), test_panels_(GetParam()) {} |
| + virtual ~DockWindowResizerTest() {} |
| + |
| + virtual void SetUp() OVERRIDE { |
| + CommandLine::ForCurrentProcess()->AppendSwitch( |
| + ash::switches::kAshEnableStickyEdges); |
| + CommandLine::ForCurrentProcess()->AppendSwitch( |
| + ash::switches::kAshEnableDockedWindows); |
| + AshTestBase::SetUp(); |
| + UpdateDisplay("600x400"); |
| + test::ShellTestApi test_api(Shell::GetInstance()); |
| + model_ = test_api.launcher_model(); |
| + } |
| + |
| + virtual void TearDown() OVERRIDE { |
| + AshTestBase::TearDown(); |
| + } |
| + |
| + protected: |
| + aura::Window* CreateTestWindow(const gfx::Rect& bounds) { |
| + return (test_panels_) ? |
| + CreatePanel(bounds) : CreateTestWindowInShellWithBounds(bounds); |
| + } |
| + |
| + aura::Window* CreatePanel(const gfx::Rect& bounds) { |
| + aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
| + NULL, |
| + aura::client::WINDOW_TYPE_PANEL, |
| + 0, |
| + bounds); |
| + test::TestLauncherDelegate* launcher_delegate = |
| + test::TestLauncherDelegate::instance(); |
| + launcher_delegate->AddLauncherItem(window); |
| + PanelLayoutManager* manager = |
| + static_cast<PanelLayoutManager*>( |
| + Shell::GetContainer(window->GetRootWindow(), |
| + internal::kShellWindowId_PanelContainer)-> |
| + layout_manager()); |
| + manager->Relayout(); |
| + return window; |
| + } |
| + |
| + static WindowResizer* CreateSomeWindowResizer( |
| + aura::Window* window, |
| + const gfx::Point& point_in_parent, |
| + int window_component) { |
| + return static_cast<WindowResizer*>(CreateWindowResizer( |
| + window, point_in_parent, window_component).release()); |
| + } |
| + |
| + void DragStart(aura::Window* window) { |
| + initial_location_in_parent_ = window->bounds().origin(); |
| + resizer_.reset(CreateSomeWindowResizer(window, |
| + initial_location_in_parent_, |
| + HTCAPTION)); |
| + ASSERT_TRUE(resizer_.get()); |
| + } |
| + |
| + void DragStartAtOffsetFromwindowOrigin(aura::Window* window, |
| + int dx, |
| + int dy) { |
| + initial_location_in_parent_ = |
| + window->bounds().origin() + gfx::Vector2d(dx, dy); |
| + resizer_.reset(CreateSomeWindowResizer(window, |
| + initial_location_in_parent_, |
| + HTCAPTION)); |
| + ASSERT_TRUE(resizer_.get()); |
| + } |
| + |
| + void DragMove(int dx, int dy) { |
| + resizer_->Drag(initial_location_in_parent_ + gfx::Vector2d(dx, dy), 0); |
| + } |
| + |
| + void DragEnd() { |
| + resizer_->CompleteDrag(0); |
| + resizer_.reset(); |
| + } |
| + |
| + void DragRevert() { |
| + resizer_->RevertDrag(); |
| + resizer_.reset(); |
| + } |
| + |
| + int CorrectContainerIdDuringDrag() { |
| + return test_panels_ ? |
| + internal::kShellWindowId_PanelContainer : |
| + internal::kShellWindowId_WorkspaceContainer; |
| + } |
| + |
| + // Test dragging the window vertically (to detach if it is a panel) and then |
| + // horizontally to the edge with an added offset from the edge of |dx|. |
| + void DragRelativeToEdge(DockedEdge edge, |
| + aura::Window* window, |
| + int dx) { |
| + DragVerticallyAndRelativeToEdge(edge, window, dx, test_panels_ ? -100 : 20); |
| + } |
| + |
| + // Test dragging the panel slightly, then detaching, and then |
| + // dragging it vertically by |dy| and horizontally to the edge with an added |
| + // offset from the edge of |dx|. |
| + void DragVerticallyAndRelativeToEdge(DockedEdge edge, |
| + aura::Window* window, |
| + int dx, |
| + int dy) { |
| + aura::RootWindow* root_window = window->GetRootWindow(); |
| + EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| + DragStart(window); |
| + gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| + |
| + if (test_panels_) { |
| + EXPECT_TRUE(window->GetProperty(kPanelAttachedKey)); |
| + // Drag the panel slightly. The window should still be snapped to the |
| + // launcher. |
| + DragMove(0, 5); |
|
flackr
2013/06/11 17:59:31
FWIW, this is dragging in the opposite direction t
varkha
2013/06/12 04:52:13
Removed this initial drag so, Done.
|
| + EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); |
| + EXPECT_EQ(initial_bounds.y(), window->GetBoundsInScreen().y()); |
| + |
| + // Drag further out and the window should now move to the cursor. |
| + DragMove(0, dy); |
| + EXPECT_EQ(initial_bounds.x(), window->GetBoundsInScreen().x()); |
| + EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| + |
| + // The panel should be detached when the drag completes. |
| + DragEnd(); |
| + |
| + EXPECT_FALSE(window->GetProperty(kPanelAttachedKey)); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| + window->parent()->id()); |
| + EXPECT_EQ(root_window, window->GetRootWindow()); |
| + } |
| + |
| + // avoid snap by clicking away from the border |
| + DragStartAtOffsetFromwindowOrigin(window, 5, 5); |
| + |
| + // Drag the panel left or right to the edge (or almost to it). |
| + if (edge == DOCKED_EDGE_LEFT) |
| + dx += window->GetRootWindow()->bounds().x() - initial_bounds.x(); |
| + else if (edge == DOCKED_EDGE_RIGHT) |
| + dx += window->GetRootWindow()->bounds().right() - initial_bounds.right(); |
| + DragMove(dx, test_panels_ ? 0 : dy); |
| + // Release the mouse and the panel should be attached to the dock. |
| + DragEnd(); |
| + |
| + // x-coordinate can get adjusted by snapping or sticking. |
| + // y-coordinate should not change by possible docking. |
| + EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y()); |
| + } |
| + |
| + void DetachReattachTest(aura::Window* window, int dx, int dy) {} |
| + |
| + void TestWindowOrder(const std::vector<aura::Window*>& window_order) { |
| + Launcher* launcher = Launcher::ForPrimaryDisplay(); |
| + int panel_index = model_->FirstPanelIndex(); |
| + EXPECT_EQ((int)(panel_index + window_order.size()), model_->item_count()); |
| + for (std::vector<aura::Window*>::const_iterator iter = |
| + window_order.begin(); iter != window_order.end(); |
| + ++iter, ++panel_index) { |
| + LauncherID id = launcher->delegate()->GetIDByWindow(*iter); |
| + EXPECT_EQ(id, model_->items()[panel_index].id); |
| + } |
| + } |
| + |
| + bool test_panels() const { return test_panels_; } |
| + |
| + private: |
| + scoped_ptr<WindowResizer> resizer_; |
| + LauncherModel* model_; |
| + bool test_panels_; |
| + |
| + // Location at start of the drag in |window->parent()|'s coordinates. |
| + gfx::Point initial_location_in_parent_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DockWindowResizerTest); |
| +}; |
| + |
| +// Verifies a window can be dragged and detached and then attached to the dock. |
| +TEST_P(DockWindowResizerTest, AttachRightPrecise) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| + |
| + // The window should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| +} |
| + |
| +// Verifies a window can be dragged and detached and then attached to the dock |
| +// even if we overshoot the screen edge by a few pixels (sticky edge) |
| +TEST_P(DockWindowResizerTest, AttachRightOvershoot) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), +4); |
| + |
| + // The window should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| +} |
| + |
| +// Verifies a window can be dragged and detached and then if not quite reaching |
| +// the screen edge it does not get attached to the dock and stays in WS |
|
flackr
2013/06/11 17:59:31
s/WS/the workspace
varkha
2013/06/12 04:52:13
Done.
|
| +TEST_P(DockWindowResizerTest, AttachRightUndershoot) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), -1); |
| + |
| + // The window should not be attached to the dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_NONE); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right() - 1, |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| + window->parent()->id()); |
| +} |
| + |
| +// Verifies a window can be dragged and detached and then attached to the dock. |
|
flackr
2013/06/11 17:59:31
I think these comments are confusing, detaching th
varkha
2013/06/12 04:52:13
Done.
|
| +TEST_P(DockWindowResizerTest, AttachLeftPrecise) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0); |
| + |
| + // The window should be attached and snapped to the left dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_LEFT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| + window->GetBoundsInScreen().x()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| +} |
| + |
| +// Verifies a window can be dragged and detached and then attached to the dock |
| +// even if we overshoot the screen edge by a few pixels (sticky edge) |
| +TEST_P(DockWindowResizerTest, AttachLeftOvershoot) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), -4); |
| + |
| + // The window should be attached and snapped to the left dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_LEFT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| + window->GetBoundsInScreen().x()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| +} |
| + |
| +// Verifies a window can be dragged and detached and then if not quite reaching |
| +// the screen edge it does not get attached to the dock and stays in WS |
| +TEST_P(DockWindowResizerTest, AttachLeftUndershoot) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 1); |
| + |
| + // The window should not be attached to the dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_NONE); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().x() + 1, |
| + window->GetBoundsInScreen().x()); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| + window->parent()->id()); |
| +} |
| + |
| +// Dock on the right side, change shelf alignment, check that windows move to |
| +// the opposite side. |
| +TEST_P(DockWindowResizerTest, AttachRightChangeShelf) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| + |
| + // The window should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // set launcher shelf to be aligned on the right |
| + ash::Shell* shell = ash::Shell::GetInstance(); |
| + shell->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT, |
| + shell->GetPrimaryRootWindow()); |
| + // The window should have moved and get attached to the left dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_LEFT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().x(), |
| + window->GetBoundsInScreen().x()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // set launcher shelf to be aligned on the left |
| + shell->SetShelfAlignment(SHELF_ALIGNMENT_LEFT, |
| + shell->GetPrimaryRootWindow()); |
| + // The window should have moved and get attached to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // set launcher shelf to be aligned at the bottom |
| + shell->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM, |
| + shell->GetPrimaryRootWindow()); |
| + // The window should stay in the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| +} |
| + |
| +// Dock on the right side, try to undock, then drag more to really undock |
| +TEST_P(DockWindowResizerTest, AttachTryDetach) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| + |
| + // The window should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // Try to detach by dragging left a bit (should stay docked) |
| + DragStart(window.get()); |
| + DragMove(-10, -10); |
| + // Release the mouse and the window should be still attached to the dock. |
| + DragEnd(); |
| + |
| + // The window should be still attached to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // Try to detach by dragging left a bit more (should get undocked) |
| + DragStart(window.get()); |
| + DragMove(-32, -10); |
| + // Release the mouse and the window should be no longer attached to the dock. |
| + DragEnd(); |
| + |
| + // The window should be floating on a workspace again. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_NONE); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right() - 32, |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| + window->parent()->id()); |
| +} |
| + |
| +// Minimize a docked window, then restore it and check that it is still docked. |
| +TEST_P(DockWindowResizerTest, AttachMinimizeRestore) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| + |
| + // The window should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // Minimize the window, it should be hidden. |
| + window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED); |
| + RunAllPendingInMessageLoop(); |
| + EXPECT_FALSE(window->IsVisible()); |
| + // Restore the window; window should be visible. |
| + window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
| + RunAllPendingInMessageLoop(); |
| + EXPECT_TRUE(window->IsVisible()); |
| +} |
| + |
| +// Dock two windows, undock one, check that the other one is still docked. |
| +TEST_P(DockWindowResizerTest, AttachTwoWindows) { |
| + scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + if (test_panels()) { |
|
flackr
2013/06/11 17:59:31
I'm a little confused about what this is doing. It
varkha
2013/06/12 04:52:13
Done.
|
| + DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT, w1.get(), 0, -100); |
| + DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT, w2.get(), 0, -50); |
| + } else { |
| + DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT, w1.get(), 0, 20); |
| + DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT, w2.get(), 0, 50); |
| + } |
| + |
| + // Both windows should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(w1.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| + w1->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, w1->parent()->id()); |
| + |
| + EXPECT_TRUE(GetDockEdge(w2.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(w2->GetRootWindow()->bounds().right(), |
| + w2->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, w2->parent()->id()); |
| + |
| + // Detach by dragging left (should get undocked) |
| + DragStart(w2.get()); |
| + DragMove(-32, -10); |
| + // Release the mouse and the window should be no longer attached to the dock. |
| + DragEnd(); |
| + |
| + // The first window should be still docked. |
| + EXPECT_TRUE(GetDockEdge(w1.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| + w1->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, w1->parent()->id()); |
| + |
| + // The second window should be floating on a workspace again. |
| + EXPECT_TRUE(GetDockEdge(w2.get()) == DOCKED_EDGE_NONE); |
| + EXPECT_EQ(w2->GetRootWindow()->bounds().right() - 32, |
| + w2->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| + w2->parent()->id()); |
| +} |
| + |
| +// Dock one window, try to dock another window on the opposite side (should not |
| +// dock). |
| +TEST_P(DockWindowResizerTest, AttachOnTwoSides) { |
| + scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + if (test_panels()) { |
| + DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT, w1.get(), 0, -100); |
| + DragVerticallyAndRelativeToEdge(DOCKED_EDGE_LEFT, w2.get(), 0, -50); |
| + } else { |
| + DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT, w1.get(), 0, 20); |
| + DragVerticallyAndRelativeToEdge(DOCKED_EDGE_LEFT, w2.get(), 0, 50); |
| + } |
| + |
| + // The first window should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(w1.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(w1->GetRootWindow()->bounds().right(), |
| + w1->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, w1->parent()->id()); |
| + |
| + // The second window should be near the left edge but not snapped. |
| + EXPECT_TRUE(GetDockEdge(w2.get()) == DOCKED_EDGE_NONE); |
| + EXPECT_EQ(w2->GetRootWindow()->bounds().x(), w2->GetBoundsInScreen().x()); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, w2->parent()->id()); |
| +} |
| + |
| +// Reverting drag |
| +TEST_P(DockWindowResizerTest, RevertDragRestoresAttachment) { |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| + |
| + // The window should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // Drag the window out but revert the drag |
| + DragStart(window.get()); |
| + DragMove(-50, 0); |
| + DragRevert(); |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // Detach window. |
| + DragStart(window.get()); |
| + DragMove(-50, 0); |
| + DragEnd(); |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_NONE); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| + window->parent()->id()); |
| +} |
| + |
| +// Move a docked window to the second display |
| +TEST_P(DockWindowResizerTest, DragAcrossDisplays) { |
| + UpdateDisplay("800x800,800x800"); |
| + Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| + scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201))); |
| + gfx::Rect initial_bounds = window->GetBoundsInScreen(); |
| + EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| + |
| + DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0); |
| + // The window should be attached and snapped to the right dock. |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + |
| + // Undock and move to the right - enough to get it peeking at the other screen |
| + // but not enough to land in the other screen |
| + DragStart(window.get()); |
| + DragMove(50, 0); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + DragEnd(); |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_NONE); |
| + EXPECT_NE(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| + window->parent()->id()); |
| + EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| + |
| + // Move back left - should dock again. |
| + DragStart(window.get()); |
| + DragMove(-50, 0); |
| + EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| + DragEnd(); |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_RIGHT); |
| + EXPECT_EQ(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, |
| + window->parent()->id()); |
| + EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| + |
| + // Undock and move to the right - enough to get the mouse pointer past the |
| + // edge of the screen and into the second screen. The window should now be |
| + // in the second screen and not docked. |
| + DragStartAtOffsetFromwindowOrigin(window.get(), |
| + window->bounds().width()/2 + 10, |
| + 0); |
| + DragMove(window->bounds().width()/2 - 5, 0); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + DragEnd(); |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_NONE); |
| + EXPECT_NE(window->GetRootWindow()->bounds().right(), |
| + window->GetBoundsInScreen().right()); |
| + EXPECT_EQ(internal::kShellWindowId_WorkspaceContainer, |
| + window->parent()->id()); |
| + EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| + |
| + // Keep dragging it to the right until it docks. The window should now be |
| + // in the second screen. |
| + DragStartAtOffsetFromwindowOrigin(window.get(), |
| + window->bounds().width()/2 + 10, |
| + 0); |
| + DragMove(window->GetRootWindow()->GetBoundsInScreen().x() - |
| + window->GetBoundsInScreen().x(), |
| + 0); |
| + EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id()); |
| + DragEnd(); |
| + EXPECT_TRUE(GetDockEdge(window.get()) == DOCKED_EDGE_LEFT); |
| + EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(), |
| + window->GetBoundsInScreen().x()); |
| + EXPECT_EQ(internal::kShellWindowId_DockContainer, window->parent()->id()); |
| + EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| +} |
| + |
| +// Tests run twice - on both panels and normal windows |
| +INSTANTIATE_TEST_CASE_P(PanelsOrNormal, DockWindowResizerTest, testing::Bool()); |
|
flackr
2013/06/11 17:59:31
As before, perhaps use window type as parameter.
varkha
2013/06/12 04:52:13
Done.
|
| + |
| +} // namespace internal |
| +} // namespace ash |