This source file includes following definitions.
- set_min_size
- set_max_size
- GetMinimumSize
- GetMaximumSize
- SetUp
- TearDown
- WindowOrderAsString
- CreateResizerForTest
- CreateWorkspaceResizerForTest
- snap_phantom_window_controller
- CalculateDragPoint
- empty_windows
- shelf_layout_manager
- InitTouchResizeWindow
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/wm/workspace/workspace_window_resizer.h"
#include "ash/ash_constants.h"
#include "ash/ash_switches.h"
#include "ash/display/display_manager.h"
#include "ash/root_window_controller.h"
#include "ash/screen_util.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/workspace/phantom_window_controller.h"
#include "ash/wm/workspace_controller.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "ui/aura/client/aura_constants.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/events/gestures/gesture_configuration.h"
#include "ui/gfx/insets.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace {
const int kRootHeight = 600;
class TestWindowDelegate : public aura::test::TestWindowDelegate {
public:
TestWindowDelegate() {
}
virtual ~TestWindowDelegate() {}
void set_min_size(const gfx::Size& size) {
min_size_ = size;
}
void set_max_size(const gfx::Size& size) {
max_size_ = size;
}
private:
virtual gfx::Size GetMinimumSize() const OVERRIDE {
return min_size_;
}
virtual gfx::Size GetMaximumSize() const OVERRIDE {
return max_size_;
}
gfx::Size min_size_;
gfx::Size max_size_;
DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
};
}
class WorkspaceWindowResizerTest : public test::AshTestBase {
public:
WorkspaceWindowResizerTest() : workspace_resizer_(NULL) {}
virtual ~WorkspaceWindowResizerTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
UpdateDisplay(base::StringPrintf("800x%d", kRootHeight));
ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
aura::Window* root = Shell::GetPrimaryRootWindow();
gfx::Rect root_bounds(root->bounds());
#if defined(OS_WIN)
EXPECT_EQ(kRootHeight, root_bounds.height());
#endif
EXPECT_EQ(800, root_bounds.width());
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_.reset(new aura::Window(&delegate_));
window_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
ParentWindowInPrimaryRootWindow(window_.get());
window_->set_id(1);
window2_.reset(new aura::Window(&delegate2_));
window2_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window2_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
ParentWindowInPrimaryRootWindow(window2_.get());
window2_->set_id(2);
window3_.reset(new aura::Window(&delegate3_));
window3_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window3_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
ParentWindowInPrimaryRootWindow(window3_.get());
window3_->set_id(3);
window4_.reset(new aura::Window(&delegate4_));
window4_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
window4_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
ParentWindowInPrimaryRootWindow(window4_.get());
window4_->set_id(4);
}
virtual void TearDown() OVERRIDE {
window_.reset();
window2_.reset();
window3_.reset();
window4_.reset();
touch_resize_window_.reset();
AshTestBase::TearDown();
}
std::string WindowOrderAsString(aura::Window* parent) const {
std::string result;
const aura::Window::Windows& windows = parent->children();
for (aura::Window::Windows::const_reverse_iterator i = windows.rbegin();
i != windows.rend(); ++i) {
if (*i == window_ || *i == window2_ || *i == window3_) {
if (!result.empty())
result += " ";
result += base::IntToString((*i)->id());
}
}
return result;
}
protected:
WindowResizer* CreateResizerForTest(
aura::Window* window,
const gfx::Point& point_in_parent,
int window_component) {
WindowResizer* resizer = CreateWindowResizer(
window,
point_in_parent,
window_component,
aura::client::WINDOW_MOVE_SOURCE_MOUSE).release();
workspace_resizer_ = WorkspaceWindowResizer::instance_;
return resizer;
}
WorkspaceWindowResizer* CreateWorkspaceResizerForTest(
aura::Window* window,
const gfx::Point& point_in_parent,
int window_component,
aura::client::WindowMoveSource source,
const std::vector<aura::Window*>& attached_windows) {
wm::WindowState* window_state = wm::GetWindowState(window);
window_state->CreateDragDetails(
window, point_in_parent, window_component, source);
return WorkspaceWindowResizer::Create(window_state, attached_windows);
}
PhantomWindowController* snap_phantom_window_controller() const {
return workspace_resizer_->snap_phantom_window_controller_.get();
}
gfx::Point CalculateDragPoint(const WindowResizer& resizer,
int delta_x,
int delta_y) const {
gfx::Point location = resizer.GetInitialLocation();
location.set_x(location.x() + delta_x);
location.set_y(location.y() + delta_y);
return location;
}
std::vector<aura::Window*> empty_windows() const {
return std::vector<aura::Window*>();
}
ShelfLayoutManager* shelf_layout_manager() {
return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
}
void InitTouchResizeWindow(const gfx::Rect& bounds, int window_component) {
touch_resize_delegate_.set_window_component(window_component);
touch_resize_window_.reset(
CreateTestWindowInShellWithDelegate(&touch_resize_delegate_, 0,
bounds));
}
TestWindowDelegate delegate_;
TestWindowDelegate delegate2_;
TestWindowDelegate delegate3_;
TestWindowDelegate delegate4_;
scoped_ptr<aura::Window> window_;
scoped_ptr<aura::Window> window2_;
scoped_ptr<aura::Window> window3_;
scoped_ptr<aura::Window> window4_;
TestWindowDelegate touch_resize_delegate_;
scoped_ptr<aura::Window> touch_resize_window_;
WorkspaceWindowResizer* workspace_resizer_;
private:
DISALLOW_COPY_AND_ASSIGN(WorkspaceWindowResizerTest);
};
TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_2) {
window_->SetBounds(gfx::Rect(0, 300, 400, 300));
window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
delegate2_.set_min_size(gfx::Size(20, 20));
resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
EXPECT_EQ("0,300 780x300", window_->bounds().ToString());
EXPECT_EQ("780,200 20x200", window2_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
resizer->RevertDrag();
EXPECT_EQ("0,300 400x300", window_->bounds().ToString());
EXPECT_EQ("400,200 100x200", window2_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_Compress) {
window_->SetBounds(gfx::Rect( 0, 300, 400, 300));
window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -100, 10), 0);
EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
delegate_.set_min_size(gfx::Size(20, 20));
resizer->Drag(CalculateDragPoint(*resizer, -800, 20), 0);
EXPECT_EQ("0,300 20x300", window_->bounds().ToString());
EXPECT_EQ("20,200 480x200", window2_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
EXPECT_EQ("0,300 500x300", window_->bounds().ToString());
EXPECT_EQ("500,200 100x200", window2_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, -100, 20), 0);
EXPECT_EQ("0,300 300x300", window_->bounds().ToString());
EXPECT_EQ("300,200 200x200", window2_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3) {
window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
window2_->SetBounds(gfx::Rect(300, 300, 150, 200));
window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
delegate2_.set_min_size(gfx::Size(52, 50));
delegate3_.set_min_size(gfx::Size(38, 50));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
EXPECT_EQ("400,300 150x200", window2_->bounds().ToString());
EXPECT_EQ("550,300 100x200", window3_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 300, -10), 0);
EXPECT_EQ("100,300 500x300", window_->bounds().ToString());
EXPECT_EQ("600,300 120x200", window2_->bounds().ToString());
EXPECT_EQ("720,300 80x200", window3_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 800, 50), 0);
EXPECT_EQ("100,300 610x300", window_->bounds().ToString());
EXPECT_EQ("710,300 52x200", window2_->bounds().ToString());
EXPECT_EQ("762,300 38x200", window3_->bounds().ToString());
resizer->RevertDrag();
EXPECT_EQ("100,300 200x300", window_->bounds().ToString());
EXPECT_EQ("300,300 150x200", window2_->bounds().ToString());
EXPECT_EQ("450,300 100x200", window3_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, AttachedResize_RIGHT_3_Compress) {
window_->SetBounds(gfx::Rect( 100, 300, 200, 300));
window2_->SetBounds(gfx::Rect(300, 300, 200, 200));
window3_->SetBounds(gfx::Rect(450, 300, 100, 200));
delegate2_.set_min_size(gfx::Size(52, 50));
delegate3_.set_min_size(gfx::Size(38, 50));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
EXPECT_EQ("100,300 300x300", window_->bounds().ToString());
EXPECT_EQ("400,300 200x200", window2_->bounds().ToString());
EXPECT_EQ("600,300 100x200", window3_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, -100, -10), 0);
EXPECT_EQ("100,300 100x300", window_->bounds().ToString());
EXPECT_EQ("200,300 266x200", window2_->bounds().ToString());
EXPECT_EQ("466,300 134x200", window3_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_Compress) {
window_->SetBounds(gfx::Rect( 0, 100, 400, 300));
window2_->SetBounds(gfx::Rect(400, 400, 100, 200));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 10, -100), 0);
EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
delegate_.set_min_size(gfx::Size(20, 20));
resizer->Drag(CalculateDragPoint(*resizer, 20, -800), 0);
EXPECT_EQ("0,100 400x20", window_->bounds().ToString());
EXPECT_EQ("400,120 100x480", window2_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
EXPECT_EQ("0,100 400x400", window_->bounds().ToString());
EXPECT_EQ("400,500 100x100", window2_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 20, -100), 0);
EXPECT_EQ("0,100 400x200", window_->bounds().ToString());
EXPECT_EQ("400,300 100x300", window2_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_2) {
window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
window2_->SetBounds(gfx::Rect(0, 250, 200, 100));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
delegate2_.set_min_size(gfx::Size(20, 20));
resizer->Drag(CalculateDragPoint(*resizer, 50, 820), 0);
EXPECT_EQ("0,50 400x530", window_->bounds().ToString());
EXPECT_EQ("0,580 200x20", window2_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
EXPECT_EQ("0,50 400x300", window_->bounds().ToString());
EXPECT_EQ("0,350 200x100", window2_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 800, 20), 0);
resizer->RevertDrag();
EXPECT_EQ("0,50 400x200", window_->bounds().ToString());
EXPECT_EQ("0,250 200x100", window2_->bounds().ToString());
}
#if defined(OS_WIN)
#define MAYBE_AttachedResize_BOTTOM_3 DISABLED_AttachedResize_BOTTOM_3
#else
#define MAYBE_AttachedResize_BOTTOM_3 AttachedResize_BOTTOM_3
#endif
TEST_F(WorkspaceWindowResizerTest, MAYBE_AttachedResize_BOTTOM_3) {
UpdateDisplay("600x800");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 300, 100, 300, 200));
window2_->SetBounds(gfx::Rect(300, 300, 200, 150));
window3_->SetBounds(gfx::Rect(300, 450, 200, 100));
delegate2_.set_min_size(gfx::Size(50, 52));
delegate3_.set_min_size(gfx::Size(50, 38));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -10, 100), 0);
EXPECT_EQ("300,100 300x300", window_->bounds().ToString());
EXPECT_EQ("300,400 200x150", window2_->bounds().ToString());
EXPECT_EQ("300,550 200x100", window3_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, -10, 296), 0);
EXPECT_EQ("300,100 300x496", window_->bounds().ToString());
EXPECT_EQ("300,596 200x123", window2_->bounds().ToString());
EXPECT_EQ("300,719 200x81", window3_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 50, 798), 0);
EXPECT_EQ("300,100 300x610", window_->bounds().ToString());
EXPECT_EQ("300,710 200x52", window2_->bounds().ToString());
EXPECT_EQ("300,762 200x38", window3_->bounds().ToString());
resizer->RevertDrag();
EXPECT_EQ("300,100 300x200", window_->bounds().ToString());
EXPECT_EQ("300,300 200x150", window2_->bounds().ToString());
EXPECT_EQ("300,450 200x100", window3_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, AttachedResize_BOTTOM_3_Compress) {
window_->SetBounds(gfx::Rect( 0, 0, 200, 200));
window2_->SetBounds(gfx::Rect(10, 200, 200, 200));
window3_->SetBounds(gfx::Rect(20, 400, 100, 100));
delegate2_.set_min_size(gfx::Size(52, 50));
delegate3_.set_min_size(gfx::Size(38, 50));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 10, 100), 0);
EXPECT_EQ("0,0 200x300", window_->bounds().ToString());
EXPECT_EQ("10,300 200x200", window2_->bounds().ToString());
EXPECT_EQ("20,500 100x100", window3_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, -10, -100), 0);
EXPECT_EQ("0,0 200x100", window_->bounds().ToString());
EXPECT_EQ("10,100 200x266", window2_->bounds().ToString());
EXPECT_EQ("20,366 100x134", window3_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, MouseMoveWithTouchDrag) {
window_->SetBounds(gfx::Rect(0, 300, 400, 300));
window2_->SetBounds(gfx::Rect(400, 200, 100, 200));
Shell* shell = Shell::GetInstance();
aura::test::EventGenerator generator(window_->GetRootWindow());
EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_TOUCH, windows));
ASSERT_TRUE(resizer.get());
EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
EXPECT_TRUE(shell->cursor_manager()->IsCursorVisible());
generator.PressTouch();
resizer->Drag(CalculateDragPoint(*resizer, 100, 10), 0);
EXPECT_FALSE(shell->cursor_manager()->IsCursorVisible());
EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
generator.MoveMouseBy(1, 1);
EXPECT_TRUE(shell->cursor_manager()->IsCursorVisible());
EXPECT_FALSE(shell->cursor_manager()->IsCursorLocked());
resizer->RevertDrag();
}
TEST_F(WorkspaceWindowResizerTest, Edge) {
if (!SupportsHostWindowResize())
return;
UpdateDisplay("800x700");
window_->SetBounds(gfx::Rect(20, 30, 400, 60));
wm::WindowState* window_state = wm::GetWindowState(window_.get());
{
gfx::Rect expected_bounds_in_parent(
wm::GetDefaultLeftSnappedWindowBoundsInParent(window_.get()));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 10), 0);
resizer->CompleteDrag();
EXPECT_EQ(expected_bounds_in_parent.ToString(),
window_->bounds().ToString());
ASSERT_TRUE(window_state->HasRestoreBounds());
EXPECT_EQ("20,30 400x60",
window_state->GetRestoreBoundsInScreen().ToString());
}
{
gfx::Rect expected_bounds_in_parent(
wm::GetDefaultRightSnappedWindowBoundsInParent(window_.get()));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
resizer->CompleteDrag();
EXPECT_EQ(expected_bounds_in_parent.ToString(),
window_->bounds().ToString());
ASSERT_TRUE(window_state->HasRestoreBounds());
EXPECT_EQ("20,30 400x60",
window_state->GetRestoreBoundsInScreen().ToString());
}
if (!SupportsMultipleDisplays())
return;
window_state->Restore();
UpdateDisplay("800x600,500x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
EXPECT_EQ(root_windows[0], window_->GetRootWindow());
window_->SetBoundsInScreen(gfx::Rect(800, 10, 400, 60),
ScreenUtil::GetSecondaryDisplay());
EXPECT_EQ(root_windows[1], window_->GetRootWindow());
{
EXPECT_EQ("800,10 400x60", window_->GetBoundsInScreen().ToString());
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 499, 0), 0);
int bottom =
ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_.get()).bottom();
resizer->CompleteDrag();
EXPECT_EQ("250,0 250x" + base::IntToString(bottom),
window_->bounds().ToString());
EXPECT_EQ("800,10 400x60",
window_state->GetRestoreBoundsInScreen().ToString());
}
}
TEST_F(WorkspaceWindowResizerTest, NonResizableWindows) {
window_->SetBounds(gfx::Rect(20, 30, 50, 60));
window_->SetProperty(aura::client::kCanResizeKey, false);
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -20, 0), 0);
resizer->CompleteDrag();
EXPECT_EQ("0,30 50x60", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x600,800x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(2U, root_windows.size());
window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60),
Shell::GetScreen()->GetPrimaryDisplay());
EXPECT_EQ(root_windows[0], window_->GetRootWindow());
EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
{
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
EXPECT_FALSE(snap_phantom_window_controller());
resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0);
EXPECT_TRUE(snap_phantom_window_controller());
resizer->Drag(CalculateDragPoint(*resizer, 800, 0), 0);
EXPECT_FALSE(snap_phantom_window_controller());
}
}
TEST_F(WorkspaceWindowResizerTest, DragSnapped) {
wm::WindowState* window_state = ash::wm::GetWindowState(window_.get());
const gfx::Rect kInitialBounds(100, 100, 100, 100);
window_->SetBounds(kInitialBounds);
window_->Show();
const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
window_state->OnWMEvent(&snap_event);
EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
gfx::Rect snapped_bounds = window_->bounds();
EXPECT_NE(snapped_bounds.ToString(), kInitialBounds.ToString());
EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
kInitialBounds.ToString());
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
resizer->Drag(CalculateDragPoint(*resizer, 10, 0), 0);
resizer->CompleteDrag();
EXPECT_EQ(wm::WINDOW_STATE_TYPE_NORMAL, window_state->GetStateType());
EXPECT_EQ("10,0 100x100", window_->bounds().ToString());
EXPECT_FALSE(window_state->HasRestoreBounds());
}
TEST_F(WorkspaceWindowResizerTest, ResizeSnapped) {
wm::WindowState* window_state = ash::wm::GetWindowState(window_.get());
const gfx::Rect kInitialBounds(100, 100, 100, 100);
window_->SetBounds(kInitialBounds);
window_->Show();
const wm::WMEvent snap_event(wm::WM_EVENT_SNAP_LEFT);
window_state->OnWMEvent(&snap_event);
EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
gfx::Rect snapped_bounds = window_->bounds();
EXPECT_NE(snapped_bounds.ToString(), kInitialBounds.ToString());
EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
kInitialBounds.ToString());
{
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTRIGHT));
resizer->Drag(CalculateDragPoint(*resizer, 10, 0), 0);
resizer->CompleteDrag();
EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
snapped_bounds.Inset(0, 0, -10, 0);
EXPECT_EQ(snapped_bounds.ToString(), window_->bounds().ToString());
EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
kInitialBounds.ToString());
}
{
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM));
resizer->Drag(CalculateDragPoint(*resizer, 0, -30), 0);
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
resizer->CompleteDrag();
EXPECT_EQ(wm::WINDOW_STATE_TYPE_LEFT_SNAPPED, window_state->GetStateType());
EXPECT_EQ(snapped_bounds.ToString(), window_->bounds().ToString());
EXPECT_EQ(window_state->GetRestoreBoundsInParent().ToString(),
kInitialBounds.ToString());
}
{
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM));
resizer->Drag(CalculateDragPoint(*resizer, 0, -10), 0);
resizer->CompleteDrag();
EXPECT_EQ(wm::WINDOW_STATE_TYPE_NORMAL, window_state->GetStateType());
gfx::Rect expected_bounds(snapped_bounds);
expected_bounds.Inset(0, 0, 0, 10);
EXPECT_EQ(expected_bounds.ToString(), window_->bounds().ToString());
EXPECT_FALSE(window_state->HasRestoreBounds());
}
}
TEST_F(WorkspaceWindowResizerTest, RestackAttached) {
window_->SetBounds(gfx::Rect( 0, 0, 200, 300));
window2_->SetBounds(gfx::Rect(200, 0, 100, 200));
window3_->SetBounds(gfx::Rect(300, 0, 100, 100));
{
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
EXPECT_EQ("2 1 3", WindowOrderAsString(window_->parent()));
}
{
std::vector<aura::Window*> windows;
windows.push_back(window3_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window2_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 100, -10), 0);
EXPECT_EQ("2 3 1", WindowOrderAsString(window_->parent()));
}
}
TEST_F(WorkspaceWindowResizerTest, DontDragOffBottom) {
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
ASSERT_EQ(1, Shell::GetScreen()->GetNumDisplays());
window_->SetBounds(gfx::Rect(100, 200, 300, 400));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 600), 0);
int expected_y =
kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, DontDragOffBottomWithMultiDisplay) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("800x600,800x600");
ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
ash::DisplayLayout(ash::DisplayLayout::BOTTOM, 0));
{
window_->SetBounds(gfx::Rect(100, 200, 300, 20));
DCHECK_LT(window_->bounds().height(),
WorkspaceWindowResizer::kMinOnscreenHeight);
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(10, 0), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
int expected_y = kRootHeight - window_->bounds().height() - 10;
EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x20",
window_->bounds().ToString());
resizer->RevertDrag();
}
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 10, 0));
{
window_->SetBounds(gfx::Rect(100, 200, 300, 400));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(10, 0), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 400), 0);
int expected_y =
kRootHeight - WorkspaceWindowResizer::kMinOnscreenHeight - 10;
EXPECT_EQ("100," + base::IntToString(expected_y) + " 300x400",
window_->bounds().ToString());
resizer->CompleteDrag();
}
{
window_->SetBounds(gfx::Rect(100, 200, 300, 400));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), window_->bounds().origin(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 500), 0);
EXPECT_EQ("100,700 300x400", window_->bounds().ToString());
resizer->CompleteDrag();
}
}
TEST_F(WorkspaceWindowResizerTest, DontDragOffTop) {
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(10, 0, 0, 0));
window_->SetBounds(gfx::Rect(100, 200, 300, 400));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, -600), 0);
EXPECT_EQ("100,10 300x400", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, ResizeBottomOutsideWorkArea) {
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
window_->SetBounds(gfx::Rect(100, 200, 300, 380));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTTOP));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 8, 0), 0);
EXPECT_EQ("100,200 300x380", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideLeftWorkArea) {
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
int left = ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_.get()).x();
int pixels_to_left_border = 50;
int window_width = 300;
int window_x = left - window_width + pixels_to_left_border;
window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(pixels_to_left_border, 0), HTRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -window_width, 0), 0);
EXPECT_EQ(base::IntToString(window_x) + ",100 " +
base::IntToString(kMinimumOnScreenArea - window_x) +
"x380", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideRightWorkArea) {
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
int right = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
window_.get()).right();
int pixels_to_right_border = 50;
int window_width = 300;
int window_x = right - pixels_to_right_border;
window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(window_x, 0), HTLEFT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
",100 " +
base::IntToString(window_width - pixels_to_right_border +
kMinimumOnScreenArea) +
"x380", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, ResizeWindowOutsideBottomWorkArea) {
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
int bottom = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
window_.get()).bottom();
int delta_to_bottom = 50;
int height = 380;
window_->SetBounds(gfx::Rect(100, bottom - delta_to_bottom, 300, height));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(0, bottom - delta_to_bottom), HTTOP));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, bottom), 0);
EXPECT_EQ("100," +
base::IntToString(bottom - kMinimumOnScreenArea) +
" 300x" +
base::IntToString(height - (delta_to_bottom -
kMinimumOnScreenArea)),
window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, DragWindowOutsideRightToSecondaryDisplay) {
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
int right = ScreenUtil::GetDisplayWorkAreaBoundsInParent(
window_.get()).right();
int pixels_to_right_border = 50;
int window_width = 300;
int window_x = right - pixels_to_right_border;
window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(window_x, 0), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
EXPECT_EQ(base::IntToString(right - kMinimumOnScreenArea) +
",100 " +
base::IntToString(window_width) +
"x380", window_->bounds().ToString());
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("1000x600,600x400");
Shell::GetInstance()->SetDisplayWorkAreaInsets(
Shell::GetPrimaryRootWindow(), gfx::Insets(0, 0, 50, 0));
window_->SetBounds(gfx::Rect(window_x, 100, window_width, 380));
resizer->Drag(CalculateDragPoint(*resizer, window_width, 0), 0);
EXPECT_EQ(base::IntToString(window_x + window_width) +
",100 " +
base::IntToString(window_width) +
"x380", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, SnapToEdge) {
Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
window_->SetBounds(gfx::Rect(96, 112, 320, 160));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(),
window_->bounds().origin() + gfx::Vector2d(50, 0),
HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 15 - 96, 0), 0);
resizer->Drag(CalculateDragPoint(*resizer, 7 - 96, 0), 0);
EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, -15 - 96, 0), 0);
EXPECT_EQ("0,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, -32 - 96, 0), 0);
EXPECT_EQ("-32,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, -33 - 96, 0), 0);
EXPECT_EQ("-33,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 15, 0), 0);
EXPECT_EQ("465,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 - 7, 0), 0);
EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 15, 0), 0);
EXPECT_EQ("480,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 32, 0), 0);
EXPECT_EQ("512,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 800 - 320 - 96 + 33, 0), 0);
EXPECT_EQ("513,112 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 - 7), 0);
EXPECT_EQ("96,437 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 3 + 15), 0);
EXPECT_EQ("96,437 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 32), 0);
EXPECT_EQ("96,470 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 0, 600 - 160 - 112 - 2 + 33), 0);
EXPECT_EQ("96,471 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 20), 0);
EXPECT_EQ("96,20 320x160", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 0, -112 + 7), 0);
EXPECT_EQ("96,0 320x160", window_->bounds().ToString());
resizer->Drag(
CalculateDragPoint(*resizer, 7 - 96, 600 - 160 - 112 - 3 - 7), 0);
EXPECT_EQ("0,437 320x160", window_->bounds().ToString());
resizer->Drag(
CalculateDragPoint(*resizer, -15 - 96, 600 - 160 - 112 - 3 + 15), 0);
EXPECT_EQ("0,437 320x160", window_->bounds().ToString());
resizer->Drag(
CalculateDragPoint(*resizer, -32 - 96, 600 - 160 - 112 - 2 + 32), 0);
EXPECT_EQ("-32,470 320x160", window_->bounds().ToString());
resizer->Drag(
CalculateDragPoint(*resizer, -33 - 96, 600 - 160 - 112 - 2 + 33), 0);
EXPECT_EQ("-33,471 320x160", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPLEFT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTTOPLEFT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -98, -199), 0);
EXPECT_EQ("0,0 120x230", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_TOPRIGHT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
window_.get()));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTTOPRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(
CalculateDragPoint(*resizer, work_area.right() - 120 - 1, -199), 0);
EXPECT_EQ(100, window_->bounds().x());
EXPECT_EQ(work_area.y(), window_->bounds().y());
EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
EXPECT_EQ(230, window_->bounds().height());
}
TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMRIGHT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
window_.get()));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(
CalculateDragPoint(*resizer, work_area.right() - 120 - 1,
work_area.bottom() - 220 - 2), 0);
EXPECT_EQ(100, window_->bounds().x());
EXPECT_EQ(200, window_->bounds().y());
EXPECT_EQ(work_area.right() - 100, window_->bounds().width());
EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
}
TEST_F(WorkspaceWindowResizerTest, SnapToWorkArea_BOTTOMLEFT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
window_.get()));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMLEFT));
ASSERT_TRUE(resizer.get());
resizer->Drag(
CalculateDragPoint(*resizer, -98, work_area.bottom() - 220 - 2), 0);
EXPECT_EQ(0, window_->bounds().x());
EXPECT_EQ(200, window_->bounds().y());
EXPECT_EQ(120, window_->bounds().width());
EXPECT_EQ(work_area.bottom() - 200, window_->bounds().height());
}
TEST_F(WorkspaceWindowResizerTest, StickToBothEdgeAndWindow) {
window_->SetBounds(gfx::Rect(10, 10, 20, 50));
window_->Show();
window2_->SetBounds(gfx::Rect(150, 160, 25, 1000));
window2_->Show();
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(10, 10), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0);
gfx::Rect expected(130, 160, 20, 50);
EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
gfx::Rect work_area(ScreenUtil::GetDisplayWorkAreaBoundsInParent(
window_.get()));
int initial_y = 10;
int attach_y = work_area.bottom() - window_->bounds().height() - initial_y;
resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y - 10), 0);
expected.set_y(attach_y + initial_y - 10);
EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y - 1), 0);
expected.set_y(attach_y + initial_y);
EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y), 0);
expected.set_y(attach_y + initial_y);
EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 1), 0);
expected.set_y(attach_y + initial_y);
EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 119, attach_y + 18), 0);
expected.set_y(attach_y + initial_y + 18);
EXPECT_EQ(expected.ToString(), window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, CtrlDragResizeToExactPosition) {
window_->SetBounds(gfx::Rect(96, 112, 320, 160));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 10, 12), ui::EF_CONTROL_DOWN);
EXPECT_EQ("96,112 330x172", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, RestoreToPreMaximizeCoordinates) {
window_->SetBounds(gfx::Rect(0, 0, 1000, 1000));
wm::WindowState* window_state = wm::GetWindowState(window_.get());
window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
resizer->CompleteDrag();
EXPECT_EQ("10,10 320x160", window_->bounds().ToString());
EXPECT_FALSE(window_state->HasRestoreBounds());
}
TEST_F(WorkspaceWindowResizerTest, RevertResizeOperation) {
const gfx::Rect initial_bounds(0, 0, 200, 400);
window_->SetBounds(initial_bounds);
wm::WindowState* window_state = wm::GetWindowState(window_.get());
window_state->SetRestoreBoundsInScreen(gfx::Rect(96, 112, 320, 160));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 180, 16), 0);
resizer->RevertDrag();
EXPECT_EQ(initial_bounds.ToString(), window_->bounds().ToString());
EXPECT_EQ("96,112 320x160",
window_state->GetRestoreBoundsInScreen().ToString());
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyAttach) {
window_->SetBounds(gfx::Rect(10, 10, 20, 30));
window2_->SetBounds(gfx::Rect(150, 160, 25, 20));
window2_->Show();
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 119, 145), 0);
EXPECT_EQ("130,160 20x30", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 164, 145), 0);
EXPECT_EQ("175,160 20x30", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 142, 119), 0);
EXPECT_EQ("150,130 20x30", window_->bounds().ToString());
resizer->Drag(CalculateDragPoint(*resizer, 142, 169), 0);
EXPECT_EQ("150,180 20x30", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOP) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
window2_->Show();
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTTOP));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("100,199 20x31", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPLEFT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
window2_->SetBounds(gfx::Rect(99, 179, 10, 20));
window2_->Show();
{
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTTOPLEFT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("99,199 21x31", window_->bounds().ToString());
resizer->RevertDrag();
}
{
window2_->SetBounds(gfx::Rect(88, 201, 10, 20));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTTOPLEFT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("98,201 22x29", window_->bounds().ToString());
resizer->RevertDrag();
}
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_TOPRIGHT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
window2_->Show();
{
window2_->SetBounds(gfx::Rect(111, 179, 10, 20));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTTOPRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
resizer->RevertDrag();
}
{
window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTTOPRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("100,199 21x31", window_->bounds().ToString());
resizer->RevertDrag();
}
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_RIGHT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
window2_->SetBounds(gfx::Rect(121, 199, 10, 20));
window2_->Show();
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("100,200 21x30", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMRIGHT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
window2_->Show();
{
window2_->SetBounds(gfx::Rect(122, 212, 10, 20));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("100,200 22x32", window_->bounds().ToString());
resizer->RevertDrag();
}
{
window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMRIGHT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("100,200 21x33", window_->bounds().ToString());
resizer->RevertDrag();
}
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOM) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
window2_->SetBounds(gfx::Rect(111, 233, 10, 20));
window2_->Show();
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("100,200 20x33", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_BOTTOMLEFT) {
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
window2_->Show();
{
window2_->SetBounds(gfx::Rect(99, 231, 10, 20));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMLEFT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("99,200 21x31", window_->bounds().ToString());
resizer->RevertDrag();
}
{
window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMLEFT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("99,200 21x29", window_->bounds().ToString());
resizer->RevertDrag();
}
}
TEST_F(WorkspaceWindowResizerTest, MagneticallyResize_LEFT) {
window2_->SetBounds(gfx::Rect(89, 209, 10, 20));
window_->SetBounds(gfx::Rect(100, 200, 20, 30));
window2_->Show();
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTLEFT));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 0), 0);
EXPECT_EQ("99,200 21x30", window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, CheckUserWindowManagedFlags) {
window_->SetBounds(gfx::Rect( 0, 50, 400, 200));
std::vector<aura::Window*> no_attached_windows;
{
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
resizer->RevertDrag();
EXPECT_FALSE(wm::GetWindowState(window_.get())->bounds_changed_by_user());
}
{
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 100), 0);
EXPECT_EQ("0,150 400x200", window_->bounds().ToString());
resizer->CompleteDrag();
EXPECT_TRUE(wm::GetWindowState(window_.get())->bounds_changed_by_user());
}
}
TEST_F(WorkspaceWindowResizerTest, TestMaxSizeEnforced) {
window_->SetBounds(gfx::Rect(0, 0, 400, 300));
delegate_.set_max_size(gfx::Size(401, 301));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMRIGHT));
resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
EXPECT_EQ(401, window_->bounds().width());
EXPECT_EQ(301, window_->bounds().height());
}
TEST_F(WorkspaceWindowResizerTest, TestPartialMaxSizeEnforced) {
window_->SetBounds(gfx::Rect(0, 0, 400, 300));
delegate_.set_max_size(gfx::Size(401, 0));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTBOTTOMRIGHT));
resizer->Drag(CalculateDragPoint(*resizer, 2, 2), 0);
EXPECT_EQ(401, window_->bounds().width());
EXPECT_EQ(302, window_->bounds().height());
}
TEST_F(WorkspaceWindowResizerTest, PhantomSnapMaxSize) {
{
window_->SetBounds(gfx::Rect(0, 0, 400, 200));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
EXPECT_FALSE(snap_phantom_window_controller());
resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
EXPECT_TRUE(snap_phantom_window_controller());
resizer->RevertDrag();
}
{
window_->SetBounds(gfx::Rect(0, 0, 400, 200));
delegate_.set_max_size(gfx::Size(400, 200));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
if (switches::UseDockedWindows())
EXPECT_TRUE(snap_phantom_window_controller());
else
EXPECT_FALSE(snap_phantom_window_controller());
resizer->RevertDrag();
}
{
window_->SetBounds(gfx::Rect(0, 0, 400, 200));
delegate_.set_max_size(gfx::Size(400, 200));
delegate_.set_min_size(gfx::Size(400, 200));
scoped_ptr<WindowResizer> resizer(CreateResizerForTest(
window_.get(), gfx::Point(), HTCAPTION));
resizer->Drag(CalculateDragPoint(*resizer, 801, 0), 0);
EXPECT_FALSE(snap_phantom_window_controller());
resizer->RevertDrag();
}
}
TEST_F(WorkspaceWindowResizerTest, DontRewardRightmostWindowForOverflows) {
UpdateDisplay("600x800");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
window4_->SetBounds(gfx::Rect(400, 100, 100, 100));
delegate2_.set_max_size(gfx::Size(101, 0));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
windows.push_back(window4_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0);
EXPECT_EQ("100,100 49x100", window_->bounds().ToString());
EXPECT_EQ("149,100 101x100", window2_->bounds().ToString());
EXPECT_EQ("250,100 125x100", window3_->bounds().ToString());
EXPECT_EQ("375,100 125x100", window4_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, DontExceedMaxWidth) {
UpdateDisplay("600x800");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
window4_->SetBounds(gfx::Rect(400, 100, 100, 100));
delegate2_.set_max_size(gfx::Size(101, 0));
delegate3_.set_max_size(gfx::Size(101, 0));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
windows.push_back(window4_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0);
EXPECT_EQ("100,100 48x100", window_->bounds().ToString());
EXPECT_EQ("148,100 101x100", window2_->bounds().ToString());
EXPECT_EQ("249,100 101x100", window3_->bounds().ToString());
EXPECT_EQ("350,100 150x100", window4_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, DontExceedMaxHeight) {
UpdateDisplay("600x800");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
window2_->SetBounds(gfx::Rect(100, 200, 100, 100));
window3_->SetBounds(gfx::Rect(100, 300, 100, 100));
window4_->SetBounds(gfx::Rect(100, 400, 100, 100));
delegate2_.set_max_size(gfx::Size(0, 101));
delegate3_.set_max_size(gfx::Size(0, 101));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
windows.push_back(window4_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, -52), 0);
EXPECT_EQ("100,100 100x48", window_->bounds().ToString());
EXPECT_EQ("100,148 100x101", window2_->bounds().ToString());
EXPECT_EQ("100,249 100x101", window3_->bounds().ToString());
EXPECT_EQ("100,350 100x150", window4_->bounds().ToString());
}
#if defined(OS_WIN)
#define MAYBE_DontExceedMinHeight DISABLED_DontExceedMinHeight
#else
#define MAYBE_DontExceedMinHeight DontExceedMinHeight
#endif
TEST_F(WorkspaceWindowResizerTest, MAYBE_DontExceedMinHeight) {
UpdateDisplay("600x500");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
window2_->SetBounds(gfx::Rect(100, 200, 100, 100));
window3_->SetBounds(gfx::Rect(100, 300, 100, 100));
window4_->SetBounds(gfx::Rect(100, 400, 100, 100));
delegate2_.set_min_size(gfx::Size(0, 99));
delegate3_.set_min_size(gfx::Size(0, 99));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
windows.push_back(window4_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTBOTTOM,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 52), 0);
EXPECT_EQ("100,100 100x152", window_->bounds().ToString());
EXPECT_EQ("100,252 100x99", window2_->bounds().ToString());
EXPECT_EQ("100,351 100x99", window3_->bounds().ToString());
EXPECT_EQ("100,450 100x50", window4_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, DontExpandRightmostPastMaxWidth) {
UpdateDisplay("600x800");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
delegate3_.set_max_size(gfx::Size(101, 0));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
windows.push_back(window4_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -51, 0), 0);
EXPECT_EQ("100,100 49x100", window_->bounds().ToString());
EXPECT_EQ("149,100 150x100", window2_->bounds().ToString());
EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, MoveAttachedWhenGrownToMaxSize) {
UpdateDisplay("600x800");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
delegate2_.set_max_size(gfx::Size(101, 0));
delegate3_.set_max_size(gfx::Size(101, 0));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
windows.push_back(window4_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -52, 0), 0);
EXPECT_EQ("100,100 48x100", window_->bounds().ToString());
EXPECT_EQ("148,100 101x100", window2_->bounds().ToString());
EXPECT_EQ("249,100 101x100", window3_->bounds().ToString());
}
#if defined(OS_WIN)
#define MAYBE_MainWindowHonoursMaxWidth DISABLED_MainWindowHonoursMaxWidth
#else
#define MAYBE_MainWindowHonoursMaxWidth MainWindowHonoursMaxWidth
#endif
TEST_F(WorkspaceWindowResizerTest, MAYBE_MainWindowHonoursMaxWidth) {
UpdateDisplay("400x800");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
delegate_.set_max_size(gfx::Size(102, 0));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
windows.push_back(window4_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, 50, 0), 0);
EXPECT_EQ("100,100 102x100", window_->bounds().ToString());
EXPECT_EQ("202,100 99x100", window2_->bounds().ToString());
EXPECT_EQ("301,100 99x100", window3_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, MainWindowHonoursMinWidth) {
UpdateDisplay("400x800");
aura::Window* root = Shell::GetPrimaryRootWindow();
Shell::GetInstance()->SetDisplayWorkAreaInsets(root, gfx::Insets());
window_->SetBounds(gfx::Rect( 100, 100, 100, 100));
window2_->SetBounds(gfx::Rect(200, 100, 100, 100));
window3_->SetBounds(gfx::Rect(300, 100, 100, 100));
delegate_.set_min_size(gfx::Size(98, 0));
std::vector<aura::Window*> windows;
windows.push_back(window2_.get());
windows.push_back(window3_.get());
scoped_ptr<WorkspaceWindowResizer> resizer(CreateWorkspaceResizerForTest(
window_.get(), gfx::Point(), HTRIGHT,
aura::client::WINDOW_MOVE_SOURCE_MOUSE, windows));
ASSERT_TRUE(resizer.get());
resizer->Drag(CalculateDragPoint(*resizer, -50, 0), 0);
EXPECT_EQ("100,100 98x100", window_->bounds().ToString());
EXPECT_EQ("198,100 101x100", window2_->bounds().ToString());
EXPECT_EQ("299,100 101x100", window3_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_RIGHT) {
shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTRIGHT);
EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
touch_resize_window_.get());
generator.GestureScrollSequence(gfx::Point(715, kRootHeight / 2),
gfx::Point(725, kRootHeight / 2),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 100, 625, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
generator.GestureScrollSequence(gfx::Point(725, kRootHeight / 2),
gfx::Point(760, kRootHeight / 2),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 100, 660, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
generator.GestureScrollSequence(gfx::Point(760, kRootHeight / 2),
gfx::Point(775, kRootHeight / 2),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 100, 700, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_LEFT) {
shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTLEFT);
EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
touch_resize_window_.get());
generator.GestureScrollSequence(gfx::Point(85, kRootHeight / 2),
gfx::Point(75, kRootHeight / 2),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(75, 100, 625, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
generator.GestureScrollSequence(gfx::Point(75, kRootHeight / 2),
gfx::Point(40, kRootHeight / 2),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(40, 100, 660, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
generator.GestureScrollSequence(gfx::Point(40, kRootHeight / 2),
gfx::Point(25, kRootHeight / 2),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(0, 100, 700, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_TOP) {
shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTTOP);
EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
touch_resize_window_.get());
generator.GestureScrollSequence(gfx::Point(400, 85),
gfx::Point(400, 75),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 75, 600, kRootHeight - 175).ToString(),
touch_resize_window_->bounds().ToString());
generator.GestureScrollSequence(gfx::Point(400, 75),
gfx::Point(400, 40),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 40, 600, kRootHeight - 140).ToString(),
touch_resize_window_->bounds().ToString());
generator.GestureScrollSequence(gfx::Point(400, 40),
gfx::Point(400, 25),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 0, 600, kRootHeight - 100).ToString(),
touch_resize_window_->bounds().ToString());
}
TEST_F(WorkspaceWindowResizerTest, TouchResizeToEdge_BOTTOM) {
shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
InitTouchResizeWindow(gfx::Rect(100, 100, 600, kRootHeight - 200), HTBOTTOM);
EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 200).ToString(),
touch_resize_window_->bounds().ToString());
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
touch_resize_window_.get());
generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 85),
gfx::Point(400, kRootHeight - 75),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 175).ToString(),
touch_resize_window_->bounds().ToString());
generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 75),
gfx::Point(400, kRootHeight - 40),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 140).ToString(),
touch_resize_window_->bounds().ToString());
generator.GestureScrollSequence(gfx::Point(400, kRootHeight - 40),
gfx::Point(400, kRootHeight - 25),
base::TimeDelta::FromMilliseconds(10),
5);
EXPECT_EQ(gfx::Rect(100, 100, 600, kRootHeight - 100).ToString(),
touch_resize_window_->bounds().ToString());
}
}