This source file includes following definitions.
- CanResize
- CanMaximize
- CreateNonClientFrameView
- SetUp
- ResizeShadowHitTest
- HasResizeShadow
- GetCurrentCursorType
- ProcessBottomRightResizeGesture
- window
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/ash_constants.h"
#include "ash/frame/custom_frame_view_ash.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/cursor_manager_test_api.h"
#include "ash/wm/resize_shadow.h"
#include "ash/wm/resize_shadow_controller.h"
#include "ash/wm/window_state.h"
#include "base/bind.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
namespace test {
namespace {
class TestWidgetDelegate : public views::WidgetDelegateView {
public:
TestWidgetDelegate() {}
virtual ~TestWidgetDelegate() {}
virtual bool CanResize() const OVERRIDE {
return true;
}
virtual bool CanMaximize() const OVERRIDE {
return true;
}
virtual views::NonClientFrameView* CreateNonClientFrameView(
views::Widget* widget) OVERRIDE {
return new ash::CustomFrameViewAsh(widget);
}
private:
DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
};
}
class ResizeShadowAndCursorTest : public AshTestBase {
public:
ResizeShadowAndCursorTest() {}
virtual ~ResizeShadowAndCursorTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
views::Widget* widget(views::Widget::CreateWindowWithContextAndBounds(
new TestWidgetDelegate(), CurrentContext(), gfx::Rect(0, 0, 200, 100)));
widget->Show();
window_ = widget->GetNativeView();
aura::Window* child = CreateTestWindowInShell(
SK_ColorWHITE, 0, gfx::Rect(0, 10, 200, 90));
window_->AddChild(child);
}
int ResizeShadowHitTest() const {
ash::ResizeShadow* resize_shadow = ash::Shell::GetInstance()
->resize_shadow_controller()
->GetShadowForWindowForTest(window_);
return resize_shadow ? resize_shadow->GetLastHitTestForTest() : HTNOWHERE;
}
bool HasResizeShadow() const {
return ResizeShadowHitTest() != HTNOWHERE;
}
int GetCurrentCursorType() const {
CursorManagerTestApi test_api(ash::Shell::GetInstance()->cursor_manager());
return test_api.GetCurrentCursor().native_type();
}
void ProcessBottomRightResizeGesture(ui::EventType type,
const gfx::Vector2dF& delta) {
if (type == ui::ET_GESTURE_SCROLL_END) {
EXPECT_FALSE(HasResizeShadow());
} else {
EXPECT_EQ(HTBOTTOMRIGHT, ResizeShadowHitTest());
}
}
aura::Window* window() {
return window_;
}
private:
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(ResizeShadowAndCursorTest);
};
TEST_F(ResizeShadowAndCursorTest, MouseHover) {
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType());
generator.MoveMouseTo(50, 50);
EXPECT_FALSE(HasResizeShadow());
EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType());
generator.MoveMouseTo(gfx::Point(50, 0));
EXPECT_EQ(HTTOP, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorNorthResize, GetCurrentCursorType());
generator.MoveMouseTo(50, 50);
EXPECT_FALSE(HasResizeShadow());
EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType());
generator.MoveMouseTo(200, 100);
EXPECT_EQ(HTBOTTOMRIGHT, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorSouthEastResize, GetCurrentCursorType());
generator.MoveMouseTo(50, 100);
EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorSouthResize, GetCurrentCursorType());
generator.MoveMouseTo(50, 100 + ash::kResizeOutsideBoundsSize - 1);
EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorSouthResize, GetCurrentCursorType());
generator.MoveMouseTo(50, 100 + ash::kResizeOutsideBoundsSize + 10);
EXPECT_FALSE(HasResizeShadow());
EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType());
generator.MoveMouseTo(50, 100 - ash::kResizeInsideBoundsSize);
EXPECT_EQ(HTBOTTOM, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorSouthResize, GetCurrentCursorType());
generator.MoveMouseTo(50, 100 - ash::kResizeInsideBoundsSize - 10);
EXPECT_FALSE(HasResizeShadow());
EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType());
}
TEST_F(ResizeShadowAndCursorTest, MouseDrag) {
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType());
gfx::Size initial_size(window()->bounds().size());
generator.MoveMouseTo(200, 50);
generator.PressLeftButton();
EXPECT_EQ(HTRIGHT, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType());
generator.MoveMouseTo(210, 50);
EXPECT_EQ(HTRIGHT, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType());
generator.ReleaseLeftButton();
EXPECT_EQ(HTRIGHT, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType());
gfx::Size new_size(window()->bounds().size());
EXPECT_NE(new_size.ToString(), initial_size.ToString());
}
TEST_F(ResizeShadowAndCursorTest, Touch) {
ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType());
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
int start_x = 200 + ash::kResizeOutsideBoundsSize - 1;
int start_y = 100 + ash::kResizeOutsideBoundsSize - 1;
generator.GestureScrollSequenceWithCallback(
gfx::Point(start_x, start_y),
gfx::Point(start_x + 50, start_y + 50),
base::TimeDelta::FromMilliseconds(200),
3,
base::Bind(&ResizeShadowAndCursorTest::ProcessBottomRightResizeGesture,
base::Unretained(this)));
}
TEST_F(ResizeShadowAndCursorTest, MaximizeRestore) {
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
ASSERT_TRUE(ash::wm::GetWindowState(window())->IsNormalStateType());
generator.MoveMouseTo(200, 50);
EXPECT_EQ(HTRIGHT, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType());
generator.MoveMouseTo(200 - ash::kResizeInsideBoundsSize, 50);
EXPECT_EQ(HTRIGHT, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType());
ash::wm::GetWindowState(window())->Maximize();
gfx::Rect bounds(window()->GetBoundsInRootWindow());
gfx::Point right_center(bounds.right() - 1,
(bounds.y() + bounds.bottom()) / 2);
generator.MoveMouseTo(right_center);
EXPECT_FALSE(HasResizeShadow());
EXPECT_EQ(ui::kCursorNull, GetCurrentCursorType());
ash::wm::GetWindowState(window())->Restore();
generator.MoveMouseTo(200, 50);
EXPECT_EQ(HTRIGHT, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType());
generator.MoveMouseTo(200 - ash::kResizeInsideBoundsSize, 50);
EXPECT_EQ(HTRIGHT, ResizeShadowHitTest());
EXPECT_EQ(ui::kCursorEastResize, GetCurrentCursorType());
}
}
}