This source file includes following definitions.
- event_filter
- WarpMouseCursorIfNecessary
- WarpMouseCursorIfNecessaryWithDragRoot
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/display/mouse_cursor_event_filter.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/cursor_manager_test_api.h"
#include "ash/display/display_layout_store.h"
#include "ash/display/display_manager.h"
#include "ui/aura/env.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
namespace ash {
class MouseCursorEventFilterTest : public test::AshTestBase {
public:
MouseCursorEventFilterTest() {}
virtual ~MouseCursorEventFilterTest() {}
protected:
MouseCursorEventFilter* event_filter() {
return Shell::GetInstance()->mouse_cursor_filter();
}
bool WarpMouseCursorIfNecessary(aura::Window* target_root,
gfx::Point point_in_screen) {
bool is_warped = event_filter()->WarpMouseCursorIfNecessary(
target_root, point_in_screen);
event_filter()->reset_was_mouse_warped_for_test();
return is_warped;
}
bool WarpMouseCursorIfNecessaryWithDragRoot(
aura::Window* drag_source_root,
aura::Window* target_root,
gfx::Point point_in_screen) {
gfx::Point location = drag_source_root->bounds().CenterPoint();
ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, location,
location, 0, 0);
ui::Event::DispatcherApi(&pressed).set_target(drag_source_root);
event_filter()->OnMouseEvent(&pressed);
bool is_warped = event_filter()->WarpMouseCursorIfNecessary(
target_root, point_in_screen);
event_filter()->reset_was_mouse_warped_for_test();
ui::MouseEvent released(ui::ET_MOUSE_RELEASED, location,
location, 0, 0);
ui::Event::DispatcherApi(&released).set_target(drag_source_root);
event_filter()->OnMouseEvent(&released);
return is_warped;
}
private:
MouseCursorEventFilter* event_filter_;
DISALLOW_COPY_AND_ASSIGN(MouseCursorEventFilterTest);
};
TEST_F(MouseCursorEventFilterTest, WarpMouse) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,500x500");
ASSERT_EQ(
DisplayLayout::RIGHT,
Shell::GetInstance()->display_manager()->layout_store()->
default_display_layout().position);
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[0], gfx::Point(11, 11)));
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[1], gfx::Point(11, 11)));
EXPECT_TRUE(WarpMouseCursorIfNecessary(root_windows[0], gfx::Point(499, 11)));
EXPECT_EQ("501,11",
aura::Env::GetInstance()->last_mouse_location().ToString());
EXPECT_TRUE(WarpMouseCursorIfNecessary(root_windows[1], gfx::Point(500, 11)));
EXPECT_EQ("498,11",
aura::Env::GetInstance()->last_mouse_location().ToString());
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[0], gfx::Point(0, 11)));
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[0], gfx::Point(11, 0)));
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(11, 499)));
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(999, 11)));
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[1], gfx::Point(11, 0)));
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(11, 499)));
}
TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentSizeDisplays) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,600x600");
ASSERT_EQ(
DisplayLayout::RIGHT,
Shell::GetInstance()->display_manager()->
GetCurrentDisplayLayout().position);
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(623, 123));
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[1], gfx::Point(0, 500)));
EXPECT_EQ("623,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
EXPECT_TRUE(WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(500, 499)));
EXPECT_EQ("498,499",
aura::Env::GetInstance()->last_mouse_location().ToString());
}
TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentScaleDisplays) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,600x600*2");
ASSERT_EQ(
DisplayLayout::RIGHT,
Shell::GetInstance()->display_manager()->
GetCurrentDisplayLayout().position);
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(900, 123));
EXPECT_TRUE(WarpMouseCursorIfNecessaryWithDragRoot(
root_windows[1], root_windows[1], gfx::Point(498, 123)));
EXPECT_EQ("502,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
EXPECT_TRUE(WarpMouseCursorIfNecessaryWithDragRoot(
root_windows[1], root_windows[1], gfx::Point(500, 123)));
EXPECT_EQ("496,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
EXPECT_TRUE(WarpMouseCursorIfNecessaryWithDragRoot(
root_windows[1], root_windows[0], gfx::Point(500, 123)));
EXPECT_EQ("496,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
UpdateDisplay("500x500*2,600x600");
EXPECT_TRUE(WarpMouseCursorIfNecessaryWithDragRoot(
root_windows[0], root_windows[1], gfx::Point(250, 123)));
EXPECT_EQ("246,123",
aura::Env::GetInstance()->last_mouse_location().ToString());
}
TEST_F(MouseCursorEventFilterTest, DoNotWarpTwice) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,600x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(623, 123));
EXPECT_TRUE(event_filter()->WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(499, 11)));
EXPECT_EQ("501,11",
aura::Env::GetInstance()->last_mouse_location().ToString());
EXPECT_FALSE(event_filter()->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(500, 11)));
EXPECT_TRUE(event_filter()->WarpMouseCursorIfNecessary(root_windows[1],
gfx::Point(500, 11)));
EXPECT_EQ("498,11",
aura::Env::GetInstance()->last_mouse_location().ToString());
}
TEST_F(MouseCursorEventFilterTest, SetMouseWarpModeFlag) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("500x500,500x500");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(1, 1));
event_filter()->set_mouse_warp_mode(MouseCursorEventFilter::WARP_NONE);
EXPECT_FALSE(WarpMouseCursorIfNecessary(root_windows[0],
gfx::Point(499, 11)));
EXPECT_EQ("1,1",
aura::Env::GetInstance()->last_mouse_location().ToString());
event_filter()->set_mouse_warp_mode(MouseCursorEventFilter::WARP_ALWAYS);
EXPECT_TRUE(WarpMouseCursorIfNecessary(root_windows[0], gfx::Point(499, 11)));
EXPECT_EQ("501,11",
aura::Env::GetInstance()->last_mouse_location().ToString());
}
TEST_F(MouseCursorEventFilterTest, IndicatorBoundsTestOnRight) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("360x360,700x700");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
DisplayLayout layout(DisplayLayout::RIGHT, 0);
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("359,16 1x344", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("360,0 1x360", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("360,16 1x344", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("359,0 1x360", event_filter()->dst_indicator_bounds_.ToString());
layout.offset = 5;
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("359,16 1x344", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("360,5 1x355", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("360,21 1x339", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("359,5 1x355", event_filter()->dst_indicator_bounds_.ToString());
layout.offset = 200;
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("359,200 1x160", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("360,200 1x160", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("360,200 1x160", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("359,200 1x160", event_filter()->dst_indicator_bounds_.ToString());
layout.offset = -5;
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("359,16 1x344", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("360,0 1x360", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("360,11 1x349", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("359,0 1x360", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->HideSharedEdgeIndicator();
}
TEST_F(MouseCursorEventFilterTest, IndicatorBoundsTestOnLeft) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("360x360,700x700");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
DisplayLayout layout(DisplayLayout::LEFT, 0);
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("0,16 1x344", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("-1,0 1x360", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("-1,16 1x344", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("0,0 1x360", event_filter()->dst_indicator_bounds_.ToString());
layout.offset = 250;
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("0,250 1x110", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("-1,250 1x110", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("-1,250 1x110", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("0,250 1x110", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->HideSharedEdgeIndicator();
}
TEST_F(MouseCursorEventFilterTest, IndicatorBoundsTestOnTopBottom) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("360x360,700x700");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
DisplayLayout layout(DisplayLayout::TOP, 0);
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("0,0 360x1", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("0,-1 360x1", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("0,-1 360x1", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("0,0 360x1", event_filter()->dst_indicator_bounds_.ToString());
layout.offset = 250;
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("250,0 110x1", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("250,-1 110x1", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("250,-1 110x1", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("250,0 110x1", event_filter()->dst_indicator_bounds_.ToString());
layout.position = DisplayLayout::BOTTOM;
layout.offset = 0;
display_manager->SetLayoutForCurrentDisplays(layout);
event_filter()->ShowSharedEdgeIndicator(root_windows[0] );
EXPECT_EQ("0,359 360x1", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("0,360 360x1", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->ShowSharedEdgeIndicator(root_windows[1] );
EXPECT_EQ("0,360 360x1", event_filter()->src_indicator_bounds_.ToString());
EXPECT_EQ("0,359 360x1", event_filter()->dst_indicator_bounds_.ToString());
event_filter()->HideSharedEdgeIndicator();
}
TEST_F(MouseCursorEventFilterTest, CursorDeviceScaleFactor) {
if (!SupportsMultipleDisplays())
return;
UpdateDisplay("400x400,800x800*2");
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
display_manager->SetLayoutForCurrentDisplays(
DisplayLayout(DisplayLayout::RIGHT, 0));
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(2U, root_windows.size());
test::CursorManagerTestApi cursor_test_api(
Shell::GetInstance()->cursor_manager());
EXPECT_EQ(1.0f, cursor_test_api.GetDisplay().device_scale_factor());
WarpMouseCursorIfNecessary(root_windows[0], gfx::Point(399, 200));
EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor());
WarpMouseCursorIfNecessary(root_windows[1], gfx::Point(400, 200));
EXPECT_EQ(1.0f, cursor_test_api.GetDisplay().device_scale_factor());
}
}