This source file includes following definitions.
- window_type_
- SetUp
- TearDown
- ideal_width
- min_dock_gap
- max_width
- docked_width
- docked_alignment
- CreateTestWindow
- CreateModalWindow
- CreateSomeWindowResizer
- DragStart
- DragStartAtOffsetFromWindowOrigin
- ResizeStartAtOffsetFromWindowOrigin
- DragMove
- DragEnd
- DragRevert
- CorrectContainerIdDuringDrag
- DragRelativeToEdge
- DragToVerticalPositionAndToEdge
- DragToVerticalPositionRelativeToEdge
- DragVerticallyAndRelativeToEdge
- test_panels
- delegate
- initial_location_in_parent
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
- TEST_P
#include "ash/wm/dock/docked_window_resizer.h"
#include "ash/ash_switches.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_model.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_shelf_delegate.h"
#include "ash/wm/coordinate_conversion.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_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "base/command_line.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/window_util.h"
namespace ash {
class DockedWindowResizerTest
: public test::AshTestBase,
public testing::WithParamInterface<ui::wm::WindowType> {
public:
DockedWindowResizerTest() : model_(NULL), window_type_(GetParam()) {}
virtual ~DockedWindowResizerTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
UpdateDisplay("600x400");
test::ShellTestApi test_api(Shell::GetInstance());
model_ = test_api.shelf_model();
}
virtual void TearDown() OVERRIDE {
AshTestBase::TearDown();
}
protected:
enum DockedEdge {
DOCKED_EDGE_NONE,
DOCKED_EDGE_LEFT,
DOCKED_EDGE_RIGHT,
};
int ideal_width() const { return DockedWindowLayoutManager::kIdealWidth; }
int min_dock_gap() const { return DockedWindowLayoutManager::kMinDockGap; }
int max_width() const { return DockedWindowLayoutManager::kMaxDockWidth; }
int docked_width(const DockedWindowLayoutManager* layout_manager) const {
return layout_manager->docked_width_;
}
int docked_alignment(const DockedWindowLayoutManager* layout_manager) const {
return layout_manager->alignment_;
}
aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
aura::Window* window = CreateTestWindowInShellWithDelegateAndType(
&delegate_,
window_type_,
0,
bounds);
if (window_type_ == ui::wm::WINDOW_TYPE_PANEL) {
test::TestShelfDelegate* shelf_delegate =
test::TestShelfDelegate::instance();
shelf_delegate->AddShelfItem(window);
PanelLayoutManager* manager = static_cast<PanelLayoutManager*>(
Shell::GetContainer(window->GetRootWindow(),
kShellWindowId_PanelContainer)->layout_manager());
manager->Relayout();
}
return window;
}
aura::Window* CreateModalWindow(const gfx::Rect& bounds) {
aura::Window* window = new aura::Window(&delegate_);
window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window->Init(aura::WINDOW_LAYER_TEXTURED);
window->Show();
if (bounds.IsEmpty()) {
ParentWindowInPrimaryRootWindow(window);
} else {
gfx::Display display =
Shell::GetScreen()->GetDisplayMatching(bounds);
aura::Window* root = ash::Shell::GetInstance()->display_controller()->
GetRootWindowForDisplayId(display.id());
gfx::Point origin = bounds.origin();
wm::ConvertPointFromScreen(root, &origin);
window->SetBounds(gfx::Rect(origin, bounds.size()));
aura::client::ParentWindowWithContext(window, root, bounds);
}
return window;
}
static WindowResizer* CreateSomeWindowResizer(
aura::Window* window,
const gfx::Point& point_in_parent,
int window_component) {
return CreateWindowResizer(
window,
point_in_parent,
window_component,
aura::client::WINDOW_MOVE_SOURCE_MOUSE).release();
}
void DragStart(aura::Window* window) {
DragStartAtOffsetFromWindowOrigin(window, 0, 0);
}
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 ResizeStartAtOffsetFromWindowOrigin(aura::Window* window,
int dx, int dy,
int window_component) {
initial_location_in_parent_ =
window->bounds().origin() + gfx::Vector2d(dx, dy);
resizer_.reset(CreateSomeWindowResizer(window,
initial_location_in_parent_,
window_component));
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();
resizer_.reset();
}
void DragRevert() {
resizer_->RevertDrag();
resizer_.reset();
}
int CorrectContainerIdDuringDrag() {
if (window_type_ == ui::wm::WINDOW_TYPE_PANEL)
return kShellWindowId_PanelContainer;
return kShellWindowId_DockedContainer;
}
void DragRelativeToEdge(DockedEdge edge,
aura::Window* window,
int dx) {
DragVerticallyAndRelativeToEdge(
edge,
window,
dx,
window_type_ == ui::wm::WINDOW_TYPE_PANEL ? -100 : 20,
25,
5);
}
void DragToVerticalPositionAndToEdge(DockedEdge edge,
aura::Window* window,
int y) {
DragToVerticalPositionRelativeToEdge(edge, window, 0, y);
}
void DragToVerticalPositionRelativeToEdge(DockedEdge edge,
aura::Window* window,
int dx,
int y) {
gfx::Rect initial_bounds = window->GetBoundsInScreen();
DragVerticallyAndRelativeToEdge(edge,
window,
dx, y - initial_bounds.y(),
25, 5);
}
void DragVerticallyAndRelativeToEdge(DockedEdge edge,
aura::Window* window,
int dx, int dy,
int grab_x, int grab_y) {
gfx::Rect initial_bounds = window->GetBoundsInScreen();
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(window,
grab_x, grab_y));
gfx::Rect work_area =
Shell::GetScreen()->GetDisplayNearestWindow(window).work_area();
gfx::Point initial_location_in_screen = initial_location_in_parent_;
wm::ConvertPointToScreen(window->parent(), &initial_location_in_screen);
if (edge == DOCKED_EDGE_LEFT)
dx += work_area.x() - initial_location_in_screen.x();
else if (edge == DOCKED_EDGE_RIGHT)
dx += work_area.right() - 1 - initial_location_in_screen.x();
DragMove(dx, dy);
EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
DragEnd();
if (window->parent()->id() != kShellWindowId_DockedContainer &&
!wm::GetWindowState(window)->HasRestoreBounds()) {
EXPECT_EQ(initial_bounds.y() + dy, window->GetBoundsInScreen().y());
}
}
bool test_panels() const { return window_type_ == ui::wm::WINDOW_TYPE_PANEL; }
aura::test::TestWindowDelegate* delegate() {
return &delegate_;
}
const gfx::Point& initial_location_in_parent() const {
return initial_location_in_parent_;
}
private:
scoped_ptr<WindowResizer> resizer_;
ShelfModel* model_;
ui::wm::WindowType window_type_;
aura::test::TestWindowDelegate delegate_;
gfx::Point initial_location_in_parent_;
DISALLOW_COPY_AND_ASSIGN(DockedWindowResizerTest);
};
TEST_P(DockedWindowResizerTest, AttachRightPrecise) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachRightOvershoot) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), +4);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachRightUndershoot) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
const int kGrabOffsetX = 70;
const int kUndershootBy = 1;
DragVerticallyAndRelativeToEdge(DOCKED_EDGE_RIGHT,
window.get(),
-kUndershootBy, test_panels() ? -100 : 20,
kGrabOffsetX, 5);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right() +
window->bounds().width() - kGrabOffsetX - kUndershootBy - 1,
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachLeftPrecise) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
window->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachLeftOvershoot) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), -4);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
window->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachLeftUndershoot) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
gfx::Rect initial_bounds(window->bounds());
DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 1);
int expected_x = initial_bounds.x() - initial_location_in_parent().x() + 1;
EXPECT_EQ(expected_x, window->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachRightChangeShelf) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
ash::Shell* shell = ash::Shell::GetInstance();
shell->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT,
shell->GetPrimaryRootWindow());
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
window->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
shell->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
shell->GetPrimaryRootWindow());
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
shell->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM,
shell->GetPrimaryRootWindow());
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachTryDetach) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(
gfx::Rect(0, 0, ideal_width() + 10, 201)));
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(ideal_width(), window->GetBoundsInScreen().width());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
window.get(), 10, 0));
DragMove(-4, -10);
DragEnd();
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
const int left_edge = window->bounds().x();
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
window.get(), 10, 0));
DragMove(-32, -10);
DragEnd();
EXPECT_EQ(left_edge - 32, window->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachTryDetachDragRightEdgeOfHeader) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(
gfx::Rect(0, 0, ideal_width() + 10, 201)));
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(ideal_width(), window->GetBoundsInScreen().width());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
window.get(), ideal_width() - 10, 0));
DragMove(-4, -10);
DragEnd();
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
const int left_edge = window->bounds().x();
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
window.get(), ideal_width() - 10, 0));
DragMove(-32, -10);
DragEnd();
EXPECT_EQ(left_edge - 32, window->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachMinimizeRestore) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->Minimize();
RunAllPendingInMessageLoop();
EXPECT_FALSE(window->IsVisible());
EXPECT_TRUE(window_state->IsMinimized());
window_state->Restore();
RunAllPendingInMessageLoop();
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window_state->IsNormalStateType());
}
TEST_P(DockedWindowResizerTest, AttachMaximize) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
wm::WindowState* window_state = wm::GetWindowState(window.get());
window_state->Maximize();
RunAllPendingInMessageLoop();
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(window_state->IsMaximized());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachTwoWindows) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("600x600");
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 50);
wm::WindowState* window_state1 = wm::GetWindowState(w1.get());
EXPECT_FALSE(window_state1->IsMinimized());
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
w2->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
const int left_edge = w2->bounds().x();
ASSERT_NO_FATAL_FAILURE(DragStart(w2.get()));
DragMove(-32, -100);
DragEnd();
EXPECT_FALSE(window_state1->IsMinimized());
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(left_edge - 32, w2->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
}
TEST_P(DockedWindowResizerTest, AttachOneAutoHideShelf) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegateAndType(
NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20)));
wm::GetWindowState(w2.get())->Maximize();
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
EXPECT_TRUE(wm::GetWindowState(w2.get())->IsMaximized());
gfx::Rect work_area =
Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area();
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y());
EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom());
ash::Shell* shell = ash::Shell::GetInstance();
shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS,
shell->GetPrimaryRootWindow());
work_area =
Shell::GetScreen()->GetDisplayNearestWindow(w1.get()).work_area();
EXPECT_EQ(work_area.CenterPoint().y(), w1->bounds().CenterPoint().y());
EXPECT_EQ(work_area.bottom(), manager->docked_bounds().bottom());
}
TEST_P(DockedWindowResizerTest, AttachOnTwoSides) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
gfx::Rect initial_bounds(w2->bounds());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w2.get(), 50);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
int expected_x = test_panels() ?
(initial_bounds.x() - initial_location_in_parent().x()) : 0;
EXPECT_EQ(expected_x, w2->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
}
TEST_P(DockedWindowResizerTest, RevertDragRestoresAttachment) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
DragMove(-50, 0);
DragRevert();
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
DragMove(-50, 0);
DragEnd();
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
}
TEST_P(DockedWindowResizerTest, RevertDockedDragRevertsAttachment) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
aura::Window* dock_container = Shell::GetContainer(
window->GetRootWindow(),
kShellWindowId_DockedContainer);
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(dock_container->layout_manager());
int previous_container_id = window->parent()->id();
ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
DragMove(-50 - window->bounds().x(), 50 - window->bounds().y());
EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
DragRevert();
EXPECT_EQ(previous_container_id, window->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
window.get(),
window->bounds().width()/2 + 10,
0));
DragMove(-50 - window->bounds().x(), 50 - window->bounds().y());
DragEnd();
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
EXPECT_LT(window->bounds().x(), 0);
EXPECT_GT(window->bounds().right(), 0);
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
window.get(),
window->bounds().width()/2 + 10,
0));
DragMove(-10, 10);
DragRevert();
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
}
TEST_P(DockedWindowResizerTest, DragAcrossDisplays) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x800,800x800");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
EXPECT_EQ(2, static_cast<int>(root_windows.size()));
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);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
DragMove(100, 0);
EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
DragEnd();
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
EXPECT_EQ(root_windows[0], window->GetRootWindow());
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
window.get(),
window->bounds().width()/2 + 10,
0));
DragMove(window->bounds().width()/2 - 5, 0);
EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
DragEnd();
EXPECT_NE(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(root_windows[1], window->GetRootWindow());
ASSERT_NO_FATAL_FAILURE(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_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
window->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(root_windows[1], window->GetRootWindow());
}
TEST_P(DockedWindowResizerTest, AttachTwoWindowsDetachOne) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("600x600");
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
w2->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()),
docked_width(manager));
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 60, 0));
DragMove(-40, -40);
DragEnd();
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
w2->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
const int left_edge = w2->bounds().x();
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
w2.get(),
w2->bounds().width()/2 + 10,
0));
const int drag_x = -(w2->bounds().width()/2 + 20);
DragMove(drag_x, -100);
DragEnd();
EXPECT_EQ(left_edge + drag_x, w2->bounds().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
}
TEST_P(DockedWindowResizerTest, AttachWindowMaximizeOther) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 25, 5));
DragMove(w2->GetRootWindow()->bounds().width()
-w2->bounds().width()
-(w2->bounds().width()/2 + 20)
-w2->bounds().x(),
50 - w2->bounds().y());
DragEnd();
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right() -
(w2->bounds().width()/2 + 20),
w2->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
docked_width(manager) - min_dock_gap(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
const gfx::Rect restored_bounds = w2->bounds();
wm::WindowState* w2_state = wm::GetWindowState(w2.get());
w2_state->Maximize();
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
docked_width(manager) - min_dock_gap(),
w2->bounds().width());
ASSERT_NO_FATAL_FAILURE(DragStart(w1.get()));
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
DragMove(-35, 10);
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
DragEnd();
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
EXPECT_EQ(kShellWindowId_DefaultContainer, w1->parent()->id());
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
EXPECT_EQ(0, docked_width(manager));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
w2->bounds().width());
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w1.get(), 10, 0));
DragMove(-w1->bounds().x() - 10, 0);
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
docked_width(manager) - min_dock_gap(),
w2->bounds().width());
w2_state->Restore();
EXPECT_EQ(restored_bounds, w2->bounds());
}
TEST_P(DockedWindowResizerTest, AttachOneTestSticky) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().x(),
w1->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().x(),
w1->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_LEFT,
w2.get(),
20 + 25 -
min_dock_gap(),
50);
EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().x() +
(w1->bounds().right() + 20),
w2->GetBoundsInScreen().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 10, 0));
DragMove(1 + docked_width(manager) - w2->bounds().x(), 0);
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
int start_x = w2->bounds().x();
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 100, 5));
DragMove(-2, 0);
EXPECT_EQ(start_x, w2->bounds().x());
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(start_x, w2->bounds().x());
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
ASSERT_NO_FATAL_FAILURE(DragStart(w2.get()));
DragMove(-100, 0);
EXPECT_NE(start_x, w2->bounds().x());
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_LEFT, docked_alignment(manager));
EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()),
docked_width(manager));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
docked_width(manager) - min_dock_gap(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
}
TEST_P(DockedWindowResizerTest, ResizeOneOfTwoWindows) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("1000x600");
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
w2->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(std::max(w1->bounds().width(), w2->bounds().width()),
docked_width(manager));
int previous_width = w1->bounds().width();
const int kResizeSpan1 = 30;
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
0, 20,
HTLEFT));
DragMove(-kResizeSpan1, 0);
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
docked_width(manager) - min_dock_gap(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
previous_width = w1->bounds().width();
const int kResizeSpan2 = 250;
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
0, 20,
HTLEFT));
DragMove(-kResizeSpan2, 0);
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(max_width(), w1->bounds().width());
EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
docked_width(manager) - min_dock_gap(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
previous_width = w1->bounds().width();
const int kResizeSpan3 = 100;
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
0, 20,
HTLEFT));
DragMove(kResizeSpan3, 0);
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(previous_width - kResizeSpan3, w1->bounds().width());
EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w2.get()).width() -
docked_width(manager) - min_dock_gap(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w2.get()).width());
previous_width = w1->bounds().width();
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
0, 20,
HTLEFT));
DragMove(-kResizeSpan3, 0);
DragEnd();
EXPECT_EQ(previous_width + kResizeSpan3, w1->bounds().width());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(max_width(), docked_width(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
ASSERT_NO_FATAL_FAILURE(DragStart(w1.get()));
DragMove(-(400 - 210), -100);
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DefaultContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(ideal_width(), docked_width(manager));
EXPECT_EQ(w2->bounds().width(), docked_width(manager));
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w1.get()).width() -
docked_width(manager) - min_dock_gap(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).width());
}
TEST_P(DockedWindowResizerTest, ResizingKeepsWidth) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("1000x600");
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
int previous_width = w1->bounds().width();
const int kResizeSpan1 = 30;
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
0, 20,
HTLEFT));
DragMove(-kResizeSpan1, 0);
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_LEFT, w1.get(), 100, 20);
EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
EXPECT_EQ(201, w1->bounds().height());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(ideal_width(), w1->bounds().width());
DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_LEFT, w1.get(), 100, 20);
EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
EXPECT_EQ(201, w1->bounds().height());
}
TEST_P(DockedWindowResizerTest, ResizingKeepsDockedState) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("1000x600");
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
int previous_width = w1->bounds().width();
const int kResizeSpan1 = 30;
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(
w1.get(), 0, 20, HTLEFT));
DragMove(-kResizeSpan1, 0);
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
previous_width = w1->bounds().width();
const int kResizeSpan2 = 15;
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(
w1.get(), w1->bounds().width(), 20, HTRIGHT));
DragMove(-kResizeSpan2, 0);
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
DragEnd();
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(previous_width - kResizeSpan2, w1->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
}
TEST_P(DockedWindowResizerTest, ResizeTwoWindows) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("1000x600");
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> w2(CreateTestWindow(gfx::Rect(0, 0, 210, 201)));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(ideal_width(), docked_width(manager));
int previous_width = w1->bounds().width();
const int kResizeSpan1 = 30;
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
0, 20,
HTLEFT));
DragMove(-kResizeSpan1, 0);
DragEnd();
EXPECT_EQ(previous_width + kResizeSpan1, w1->bounds().width());
EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
previous_width = w2->bounds().width();
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w2.get(),
0, 20,
HTLEFT));
DragMove(-kResizeSpan1, 0);
DragEnd();
EXPECT_EQ(previous_width + kResizeSpan1, w2->bounds().width());
EXPECT_EQ(w2->bounds().width(), w1->bounds().width());
EXPECT_EQ(w2->bounds().width(), docked_width(manager));
DragToVerticalPositionRelativeToEdge(DOCKED_EDGE_RIGHT, w2.get(), -400, 100);
EXPECT_EQ(kShellWindowId_DefaultContainer, w2->parent()->id());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
EXPECT_EQ(kShellWindowId_DockedContainer, w2->parent()->id());
EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
ASSERT_NO_FATAL_FAILURE(ResizeStartAtOffsetFromWindowOrigin(w1.get(),
0, 20,
HTLEFT));
DragMove(-kResizeSpan1, 0);
DragEnd();
EXPECT_EQ(w1->bounds().width(), w2->bounds().width());
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
}
TEST_P(DockedWindowResizerTest, DragToShelf) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
EXPECT_EQ(ScreenUtil::GetDisplayBoundsInParent(w1.get()).width(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).width());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
ASSERT_NO_FATAL_FAILURE(DragStart(w1.get()));
DragMove(-40, 0);
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
DragEnd();
EXPECT_EQ(DOCKED_ALIGNMENT_NONE, docked_alignment(manager));
ShelfWidget* shelf = Shelf::ForPrimaryDisplay()->shelf_widget();
const int shelf_y = shelf->GetWindowBoundsInScreen().y();
const int kDistanceFromShelf = 10;
ASSERT_NO_FATAL_FAILURE(DragStart(w1.get()));
DragMove(0, -kDistanceFromShelf + shelf_y - w1->bounds().bottom());
DragEnd();
if (test_panels()) {
EXPECT_EQ(shelf_y, w1->bounds().bottom());
EXPECT_TRUE(wm::GetWindowState(w1.get())->panel_attached());
} else {
EXPECT_EQ(shelf_y - kDistanceFromShelf, w1->bounds().bottom());
}
}
TEST_P(DockedWindowResizerTest, DragWindowWithTransientChild) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
scoped_ptr<aura::Window> child(CreateTestWindowInShellWithDelegateAndType(
NULL, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect(20, 20, 150, 20)));
::wm::AddTransientChild(window.get(), child.get());
if (window->parent() != child->parent())
window->parent()->AddChild(child.get());
EXPECT_EQ(window.get(), ::wm::GetTransientParent(child.get()));
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20);
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
EXPECT_EQ(kShellWindowId_DockedContainer, child->parent()->id());
ASSERT_NO_FATAL_FAILURE(DragStart(child.get()));
DragMove(500, 20);
DragEnd();
EXPECT_EQ(gfx::Point(20 + 500, 20 + 20).ToString(),
child->GetBoundsInScreen().origin().ToString());
ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
DragMove(-32, -10);
DragEnd();
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(kShellWindowId_DefaultContainer, child->parent()->id());
EXPECT_EQ(gfx::Point(20 + 500, 20 + 20).ToString(),
child->GetBoundsInScreen().origin().ToString());
}
TEST_P(DockedWindowResizerTest, DragWindowWithModalTransientChild) {
if (!SupportsHostWindowResize())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
gfx::Rect bounds(window->bounds());
ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
gfx::Vector2d move_vector(40, test_panels() ? -60 : 60);
DragMove(move_vector.x(), move_vector.y());
EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
scoped_ptr<aura::Window> child(CreateModalWindow(gfx::Rect(20, 20, 150, 20)));
::wm::AddTransientChild(window.get(), child.get());
EXPECT_EQ(window.get(), ::wm::GetTransientParent(child.get()));
EXPECT_EQ(kShellWindowId_SystemModalContainer, child->parent()->id());
DragEnd();
bounds.Offset(move_vector);
EXPECT_EQ(bounds.ToString(), window->GetBoundsInScreen().ToString());
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(kShellWindowId_SystemModalContainer, child->parent()->id());
EXPECT_EQ(gfx::Point(20, 20).ToString(),
child->GetBoundsInScreen().origin().ToString());
EXPECT_EQ(window.get(), ::wm::GetTransientParent(child.get()));
}
TEST_P(DockedWindowResizerTest, SideSnapDocked) {
if (!SupportsHostWindowResize() || test_panels())
return;
scoped_ptr<aura::Window> w1(CreateTestWindow(gfx::Rect(0, 0, 201, 201)));
wm::WindowState* window_state = wm::GetWindowState(w1.get());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_TRUE(window_state->IsDocked());
EXPECT_FALSE(window_state->IsSnapped());
const wm::WMEvent snap_right(wm::WM_EVENT_SNAP_RIGHT);
window_state->OnWMEvent(&snap_right);
gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()));
EXPECT_EQ(0, docked_width(manager));
EXPECT_EQ(work_area.height(), w1->bounds().height());
EXPECT_EQ(work_area.right(), w1->bounds().right());
EXPECT_EQ(kShellWindowId_DefaultContainer, w1->parent()->id());
EXPECT_FALSE(window_state->IsDocked());
EXPECT_TRUE(window_state->IsSnapped());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
EXPECT_TRUE(window_state->IsDocked());
EXPECT_FALSE(window_state->IsSnapped());
const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT);
window_state->OnWMEvent(&snap_left);
EXPECT_EQ(work_area.ToString(),
ScreenUtil::GetDisplayWorkAreaBoundsInParent(w1.get()).ToString());
EXPECT_EQ(0, docked_width(manager));
EXPECT_EQ(work_area.height(), w1->bounds().height());
EXPECT_EQ(work_area.x(), w1->bounds().x());
EXPECT_EQ(kShellWindowId_DefaultContainer, w1->parent()->id());
EXPECT_FALSE(window_state->IsDocked());
EXPECT_TRUE(window_state->IsSnapped());
}
TEST_P(DockedWindowResizerTest, MaximizedDuringDrag) {
if (!SupportsHostWindowResize() || test_panels())
return;
scoped_ptr<aura::Window> window(CreateTestWindow(
gfx::Rect(0, 0, ideal_width(), 201)));
wm::WindowState* window_state = wm::GetWindowState(window.get());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20);
EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(kShellWindowId_DockedContainer, window->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(
window->parent()->layout_manager());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_EQ(window->bounds().width(), docked_width(manager));
EXPECT_TRUE(window_state->IsDocked());
delegate()->set_window_component(HTCAPTION);
aura::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(window->GetBoundsInScreen().origin());
generator.PressLeftButton();
generator.MoveMouseBy(10, 10);
window_state->Maximize();
generator.ReleaseLeftButton();
EXPECT_EQ(kShellWindowId_DefaultContainer, window->parent()->id());
EXPECT_EQ(0, docked_width(manager));
EXPECT_EQ(
ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
window->bounds().ToString());
EXPECT_TRUE(window_state->IsMaximized());
}
INSTANTIATE_TEST_CASE_P(NormalOrPanel,
DockedWindowResizerTest,
testing::Values(ui::wm::WINDOW_TYPE_NORMAL,
ui::wm::WINDOW_TYPE_PANEL));
}