This source file includes following definitions.
- did_visibility_change_
- reset
- is_cursor_visible
- did_visibility_change
- OnCursorVisibilityChanged
- getTime
- mouse_result_
- set_key_event_handling_result
- set_mouse_event_handling_result
- OnKeyEvent
- OnMouseEvent
- CanFocus
- set_hittest_code
- GetNonClientComponent
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/shell_test_api.h"
#include "ash/test/test_activation_delegate.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/cursor_client_observer.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/env.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/hit_test.h"
#include "ui/events/event.h"
#include "ui/events/event_processor.h"
#include "ui/events/event_utils.h"
#include "ui/events/test/test_event_handler.h"
#include "ui/gfx/screen.h"
#include "ui/wm/core/compound_event_filter.h"
#include "ui/wm/core/input_method_event_filter.h"
#include "ui/wm/public/activation_client.h"
#include "ui/wm/public/activation_delegate.h"
namespace {
class TestingCursorClientObserver : public aura::client::CursorClientObserver {
public:
TestingCursorClientObserver()
: cursor_visibility_(false),
did_visibility_change_(false) {}
void reset() { cursor_visibility_ = did_visibility_change_ = false; }
bool is_cursor_visible() const { return cursor_visibility_; }
bool did_visibility_change() const { return did_visibility_change_; }
virtual void OnCursorVisibilityChanged(bool is_visible) OVERRIDE {
cursor_visibility_ = is_visible;
did_visibility_change_ = true;
}
private:
bool cursor_visibility_;
bool did_visibility_change_;
DISALLOW_COPY_AND_ASSIGN(TestingCursorClientObserver);
};
base::TimeDelta getTime() {
return ui::EventTimeForNow();
}
class CustomEventHandler : public ui::test::TestEventHandler {
public:
CustomEventHandler()
: key_result_(ui::ER_UNHANDLED),
mouse_result_(ui::ER_UNHANDLED) {
}
virtual ~CustomEventHandler() {}
void set_key_event_handling_result(ui::EventResult result) {
key_result_ = result;
}
void set_mouse_event_handling_result(ui::EventResult result) {
mouse_result_ = result;
}
virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE {
ui::test::TestEventHandler::OnKeyEvent(event);
if (key_result_ & ui::ER_HANDLED)
event->SetHandled();
if (key_result_ & ui::ER_CONSUMED)
event->StopPropagation();
}
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
ui::test::TestEventHandler::OnMouseEvent(event);
if (mouse_result_ & ui::ER_HANDLED)
event->SetHandled();
if (mouse_result_ & ui::ER_CONSUMED)
event->StopPropagation();
}
private:
ui::EventResult key_result_;
ui::EventResult mouse_result_;
DISALLOW_COPY_AND_ASSIGN(CustomEventHandler);
};
}
namespace ash {
typedef test::AshTestBase WindowManagerTest;
class NonFocusableDelegate : public aura::test::TestWindowDelegate {
public:
NonFocusableDelegate() {}
private:
virtual bool CanFocus() OVERRIDE {
return false;
}
DISALLOW_COPY_AND_ASSIGN(NonFocusableDelegate);
};
class HitTestWindowDelegate : public aura::test::TestWindowDelegate {
public:
HitTestWindowDelegate()
: hittest_code_(HTNOWHERE) {
}
virtual ~HitTestWindowDelegate() {}
void set_hittest_code(int hittest_code) { hittest_code_ = hittest_code; }
private:
virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE {
return hittest_code_;
}
int hittest_code_;
DISALLOW_COPY_AND_ASSIGN(HitTestWindowDelegate);
};
TEST_F(WindowManagerTest, Focus) {
test::ShellTestApi shell_test(Shell::GetInstance());
Shell::GetInstance()->RemovePreTargetHandler(
shell_test.input_method_event_filter());
aura::Window* root_window = Shell::GetPrimaryRootWindow();
root_window->SetBounds(gfx::Rect(0, 0, 510, 510));
scoped_ptr<aura::Window> w1(CreateTestWindowInShell(
SK_ColorWHITE, -1, gfx::Rect(10, 10, 500, 500)));
scoped_ptr<aura::Window> w11(aura::test::CreateTestWindow(
SK_ColorGREEN, -11, gfx::Rect(5, 5, 100, 100), w1.get()));
scoped_ptr<aura::Window> w111(aura::test::CreateTestWindow(
SK_ColorCYAN, -111, gfx::Rect(5, 5, 75, 75), w11.get()));
scoped_ptr<aura::Window> w1111(aura::test::CreateTestWindow(
SK_ColorRED, -1111, gfx::Rect(5, 5, 50, 50), w111.get()));
scoped_ptr<aura::Window> w12(aura::test::CreateTestWindow(
SK_ColorMAGENTA, -12, gfx::Rect(10, 420, 25, 25), w1.get()));
aura::test::ColorTestWindowDelegate* w121delegate =
new aura::test::ColorTestWindowDelegate(SK_ColorYELLOW);
scoped_ptr<aura::Window> w121(aura::test::CreateTestWindowWithDelegate(
w121delegate, -121, gfx::Rect(5, 5, 5, 5), w12.get()));
aura::test::ColorTestWindowDelegate* w122delegate =
new aura::test::ColorTestWindowDelegate(SK_ColorRED);
scoped_ptr<aura::Window> w122(aura::test::CreateTestWindowWithDelegate(
w122delegate, -122, gfx::Rect(10, 5, 5, 5), w12.get()));
aura::test::ColorTestWindowDelegate* w123delegate =
new aura::test::ColorTestWindowDelegate(SK_ColorRED);
scoped_ptr<aura::Window> w123(aura::test::CreateTestWindowWithDelegate(
w123delegate, -123, gfx::Rect(15, 5, 5, 5), w12.get()));
scoped_ptr<aura::Window> w13(aura::test::CreateTestWindow(
SK_ColorGRAY, -13, gfx::Rect(5, 470, 50, 50), w1.get()));
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
w121.get());
generator.ClickLeftButton();
aura::client::FocusClient* focus_client =
aura::client::GetFocusClient(w121.get());
EXPECT_EQ(w121.get(), focus_client->GetFocusedWindow());
ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor();
ui::KeyEvent keyev(ui::ET_KEY_PRESSED, ui::VKEY_E, 0, false);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&keyev);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::VKEY_E, w121delegate->last_key_code());
gfx::Point click_point = w122->bounds().CenterPoint();
aura::Window::ConvertPointToTarget(w122->parent(), root_window, &click_point);
ui::TouchEvent touchev(ui::ET_TOUCH_PRESSED, click_point, 0, getTime());
details = dispatcher->OnEventFromSource(&touchev);
ASSERT_FALSE(details.dispatcher_destroyed);
focus_client = aura::client::GetFocusClient(w122.get());
EXPECT_EQ(w122.get(), focus_client->GetFocusedWindow());
details = dispatcher->OnEventFromSource(&keyev);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::VKEY_E, w122delegate->last_key_code());
w122->Hide();
EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
aura::client::GetFocusClient(w122.get()));
EXPECT_EQ(w12.get(),
aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
w122->Show();
w122->Focus();
EXPECT_EQ(w122.get(),
aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
w12->RemoveChild(w122.get());
EXPECT_EQ(NULL, aura::client::GetFocusClient(w122.get()));
EXPECT_EQ(w12.get(),
aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
test::TestActivationDelegate activation_delegate(false);
w123->Focus();
EXPECT_EQ(w123.get(),
aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
w123->Hide();
EXPECT_EQ(aura::client::GetFocusClient(w12.get()),
aura::client::GetFocusClient(w123.get()));
EXPECT_EQ(NULL, aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
details = dispatcher->OnEventFromSource(&keyev);
EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed);
aura::client::SetActivationDelegate(w1.get(), NULL);
w123->Show();
w123->Focus();
EXPECT_EQ(w123.get(),
aura::client::GetFocusClient(w12.get())->GetFocusedWindow());
aura::client::SetActivationDelegate(w1.get(), &activation_delegate);
w12->RemoveChild(w123.get());
EXPECT_EQ(NULL, aura::client::GetFocusClient(w123.get()));
details = dispatcher->OnEventFromSource(&keyev);
EXPECT_FALSE(keyev.handled() || details.dispatcher_destroyed);
}
TEST_F(WindowManagerTest, ActivateOnMouse) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
test::TestActivationDelegate d1;
aura::test::TestWindowDelegate wd;
scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
&wd, -1, gfx::Rect(10, 10, 50, 50)));
d1.SetWindow(w1.get());
test::TestActivationDelegate d2;
scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
&wd, -2, gfx::Rect(70, 70, 50, 50)));
d2.SetWindow(w2.get());
aura::client::FocusClient* focus_client =
aura::client::GetFocusClient(w1.get());
d1.Clear();
d2.Clear();
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(1, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
d1.Clear();
{
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
w2.get());
generator.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(0, d1.activated_count());
EXPECT_EQ(1, d1.lost_active_count());
EXPECT_EQ(1, d2.activated_count());
EXPECT_EQ(0, d2.lost_active_count());
d1.Clear();
d2.Clear();
}
{
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
w1.get());
d1.set_activate(false);
generator.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(0, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
EXPECT_EQ(0, d2.activated_count());
EXPECT_EQ(0, d2.lost_active_count());
d1.Clear();
d2.Clear();
}
d1.set_activate(true);
w2.reset();
EXPECT_EQ(0, d2.activated_count());
EXPECT_EQ(1, d2.lost_active_count());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(1, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
{
scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate(
&wd, -11, gfx::Rect(10, 10, 10, 10), w1.get()));
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
w11.get());
generator.ClickLeftButton();
EXPECT_EQ(w11.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(w1.get(), wm::GetActiveWindow());
gfx::Point left_top = w1->bounds().origin();
aura::Window::ConvertPointToTarget(w1->parent(), root_window, &left_top);
left_top.Offset(1, 1);
generator.MoveMouseTo(left_top);
generator.ClickLeftButton();
EXPECT_EQ(w11.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(w1.get(), wm::GetActiveWindow());
}
{
NonFocusableDelegate nfd;
scoped_ptr<aura::Window> w11(CreateTestWindowWithDelegate(
&nfd, -1, gfx::Rect(10, 10, 10, 10), w1.get()));
scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
&wd, -1, gfx::Rect(70, 70, 50, 50)));
aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
w2.get());
generator.ClickLeftButton();
EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
EXPECT_FALSE(w11->CanFocus());
generator.MoveMouseToCenterOf(w11.get());
generator.ClickLeftButton();
EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
}
}
TEST_F(WindowManagerTest, PanelActivation) {
aura::test::TestWindowDelegate wd;
scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
&wd, -1, gfx::Rect(10, 10, 50, 50)));
aura::test::TestWindowDelegate pd;
scoped_ptr<aura::Window> p1(CreateTestWindowInShellWithDelegateAndType(
&pd, ui::wm::WINDOW_TYPE_PANEL, -1, gfx::Rect(10, 10, 50, 50)));
aura::client::FocusClient* focus_client =
aura::client::GetFocusClient(w1.get());
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
wm::ActivateWindow(p1.get());
EXPECT_TRUE(wm::IsActiveWindow(p1.get()));
EXPECT_EQ(p1.get(), focus_client->GetFocusedWindow());
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
{
NonFocusableDelegate nfd;
scoped_ptr<aura::Window> w3(CreateTestWindowInShellWithDelegate(
&nfd, -1, gfx::Rect(70, 70, 50, 50)));
aura::test::EventGenerator generator3(Shell::GetPrimaryRootWindow(),
w3.get());
wm::ActivateWindow(p1.get());
EXPECT_TRUE(wm::IsActiveWindow(p1.get()));
generator3.ClickLeftButton();
EXPECT_TRUE(wm::IsActiveWindow(p1.get()));
}
}
TEST_F(WindowManagerTest, ActivateOnTouch) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
test::TestActivationDelegate d1;
aura::test::TestWindowDelegate wd;
scoped_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
&wd, -1, gfx::Rect(10, 10, 50, 50)));
d1.SetWindow(w1.get());
test::TestActivationDelegate d2;
scoped_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
&wd, -2, gfx::Rect(70, 70, 50, 50)));
d2.SetWindow(w2.get());
aura::client::FocusClient* focus_client =
aura::client::GetFocusClient(w1.get());
d1.Clear();
d2.Clear();
wm::ActivateWindow(w1.get());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(1, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
d1.Clear();
gfx::Point press_point = w2->bounds().CenterPoint();
aura::Window::ConvertPointToTarget(w2->parent(), root_window, &press_point);
ui::TouchEvent touchev1(ui::ET_TOUCH_PRESSED, press_point, 0, getTime());
ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor();
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&touchev1);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(0, d1.activated_count());
EXPECT_EQ(1, d1.lost_active_count());
EXPECT_EQ(1, d2.activated_count());
EXPECT_EQ(0, d2.lost_active_count());
d1.Clear();
d2.Clear();
press_point = w1->bounds().CenterPoint();
aura::Window::ConvertPointToTarget(w1->parent(), root_window, &press_point);
d1.set_activate(false);
ui::TouchEvent touchev2(ui::ET_TOUCH_PRESSED, press_point, 1, getTime());
details = dispatcher->OnEventFromSource(&touchev2);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_TRUE(wm::IsActiveWindow(w2.get()));
EXPECT_EQ(w2.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(0, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
EXPECT_EQ(0, d2.activated_count());
EXPECT_EQ(0, d2.lost_active_count());
d1.Clear();
d2.Clear();
d1.set_activate(true);
w2.reset();
EXPECT_EQ(0, d2.activated_count());
EXPECT_EQ(1, d2.lost_active_count());
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_EQ(w1.get(), focus_client->GetFocusedWindow());
EXPECT_EQ(1, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
}
TEST_F(WindowManagerTest, MouseEventCursors) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
const int kWindowLeft = 123;
const int kWindowTop = 45;
HitTestWindowDelegate window_delegate;
scoped_ptr<aura::Window> window(CreateTestWindowInShellWithDelegate(
&window_delegate,
-1,
gfx::Rect(kWindowLeft, kWindowTop, 640, 480)));
gfx::Point point1(kWindowLeft, kWindowTop);
aura::Window::ConvertPointToTarget(window->parent(), root_window, &point1);
gfx::Point point2(kWindowLeft + 1, kWindowTop + 1);
aura::Window::ConvertPointToTarget(window->parent(), root_window, &point2);
aura::WindowTreeHost* host = root_window->GetHost();
ui::EventProcessor* dispatcher = host->event_processor();
EXPECT_EQ(ui::kCursorPointer, host->last_cursor().native_type());
{
window_delegate.set_hittest_code(HTBOTTOM);
ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorSouthResize, host->last_cursor().native_type());
}
{
window_delegate.set_hittest_code(HTBOTTOMLEFT);
ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorSouthWestResize, host->last_cursor().native_type());
}
{
window_delegate.set_hittest_code(HTBOTTOMRIGHT);
ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorSouthEastResize, host->last_cursor().native_type());
}
{
window_delegate.set_hittest_code(HTLEFT);
ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorWestResize, host->last_cursor().native_type());
}
{
window_delegate.set_hittest_code(HTRIGHT);
ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorEastResize, host->last_cursor().native_type());
}
{
window_delegate.set_hittest_code(HTTOP);
ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorNorthResize, host->last_cursor().native_type());
}
{
window_delegate.set_hittest_code(HTTOPLEFT);
ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorNorthWestResize, host->last_cursor().native_type());
}
{
window_delegate.set_hittest_code(HTTOPRIGHT);
ui::MouseEvent move2(ui::ET_MOUSE_MOVED, point2, point2, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move2);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorNorthEastResize, host->last_cursor().native_type());
}
{
window_delegate.set_hittest_code(HTCLIENT);
ui::MouseEvent move1(ui::ET_MOUSE_MOVED, point1, point1, 0, 0);
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move1);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(ui::kCursorNull, host->last_cursor().native_type());
}
}
#if defined(OS_WIN)
#define MAYBE_TransformActivate DISABLED_TransformActivate
#else
#define MAYBE_TransformActivate TransformActivate
#endif
TEST_F(WindowManagerTest, MAYBE_TransformActivate) {
aura::Window* root_window = Shell::GetPrimaryRootWindow();
gfx::Size size = root_window->bounds().size();
EXPECT_EQ(gfx::Rect(size).ToString(),
Shell::GetScreen()->GetDisplayNearestPoint(
gfx::Point()).bounds().ToString());
gfx::Transform transform;
transform.Translate(size.width(), 0);
transform.Rotate(90.0f);
root_window->GetHost()->SetTransform(transform);
test::TestActivationDelegate d1;
aura::test::TestWindowDelegate wd;
scoped_ptr<aura::Window> w1(
CreateTestWindowInShellWithDelegate(&wd, 1, gfx::Rect(0, 15, 50, 50)));
d1.SetWindow(w1.get());
w1->Show();
gfx::Point miss_point(5, 5);
transform.TransformPoint(&miss_point);
ui::MouseEvent mouseev1(ui::ET_MOUSE_PRESSED,
miss_point,
miss_point,
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor();
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&mouseev1);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(NULL, aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
ui::MouseEvent mouseup(ui::ET_MOUSE_RELEASED,
miss_point,
miss_point,
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
details = dispatcher->OnEventFromSource(&mouseup);
ASSERT_FALSE(details.dispatcher_destroyed);
gfx::Point hit_point(5, 15);
transform.TransformPoint(&hit_point);
ui::MouseEvent mouseev2(ui::ET_MOUSE_PRESSED,
hit_point,
hit_point,
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
details = dispatcher->OnEventFromSource(&mouseev2);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_TRUE(wm::IsActiveWindow(w1.get()));
EXPECT_EQ(w1.get(),
aura::client::GetFocusClient(w1.get())->GetFocusedWindow());
}
TEST_F(WindowManagerTest, AdditionalFilters) {
test::ShellTestApi shell_test(Shell::GetInstance());
Shell::GetInstance()->RemovePreTargetHandler(
shell_test.input_method_event_filter());
aura::Window* root_window = Shell::GetPrimaryRootWindow();
scoped_ptr<aura::Window> w1(CreateTestWindowInShell(
SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100)));
wm::ActivateWindow(w1.get());
scoped_ptr<CustomEventHandler> f1(new CustomEventHandler);
scoped_ptr<CustomEventHandler> f2(new CustomEventHandler);
::wm::CompoundEventFilter* env_filter =
Shell::GetInstance()->env_filter();
env_filter->AddHandler(f1.get());
env_filter->AddHandler(f2.get());
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false);
ui::EventProcessor* dispatcher = root_window->GetHost()->event_processor();
ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&key_event);
ASSERT_FALSE(details.dispatcher_destroyed);
ui::MouseEvent mouse_pressed(
ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
details = dispatcher->OnEventFromSource(&mouse_pressed);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(1, f1->num_key_events());
EXPECT_EQ(1, f1->num_mouse_events());
EXPECT_EQ(1, f2->num_key_events());
EXPECT_EQ(1, f2->num_mouse_events());
f1->Reset();
f2->Reset();
f1->set_key_event_handling_result(ui::ER_CONSUMED);
f1->set_mouse_event_handling_result(ui::ER_CONSUMED);
details = dispatcher->OnEventFromSource(&key_event);
ASSERT_FALSE(details.dispatcher_destroyed);
ui::MouseEvent mouse_released(
ui::ET_MOUSE_RELEASED, gfx::Point(0, 0), gfx::Point(0, 0), 0, 0);
details = dispatcher->OnEventFromSource(&mouse_released);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(1, f1->num_key_events());
EXPECT_EQ(1, f1->num_mouse_events());
EXPECT_EQ(0, f2->num_key_events());
EXPECT_EQ(0, f2->num_mouse_events());
f1->Reset();
f2->Reset();
env_filter->RemoveHandler(f1.get());
details = dispatcher->OnEventFromSource(&key_event);
ASSERT_FALSE(details.dispatcher_destroyed);
details = dispatcher->OnEventFromSource(&mouse_pressed);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_EQ(0, f1->num_key_events());
EXPECT_EQ(0, f1->num_mouse_events());
EXPECT_EQ(1, f2->num_key_events());
EXPECT_EQ(1, f2->num_mouse_events());
env_filter->RemoveHandler(f2.get());
}
#if defined(OS_CHROMEOS) || defined(OS_WIN)
TEST_F(WindowManagerTest, UpdateCursorVisibility) {
aura::test::EventGenerator& generator = GetEventGenerator();
::wm::CursorManager* cursor_manager =
ash::Shell::GetInstance()->cursor_manager();
generator.MoveMouseTo(gfx::Point(0, 0));
EXPECT_TRUE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
generator.PressTouch();
EXPECT_FALSE(cursor_manager->IsCursorVisible());
EXPECT_FALSE(cursor_manager->IsMouseEventsEnabled());
generator.MoveMouseTo(gfx::Point(0, 0));
EXPECT_TRUE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
generator.ReleaseTouch();
EXPECT_TRUE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
}
#endif
#if defined(OS_CHROMEOS)
TEST_F(WindowManagerTest, UpdateCursorVisibilityOnKeyEvent) {
aura::test::EventGenerator& generator = GetEventGenerator();
::wm::CursorManager* cursor_manager =
ash::Shell::GetInstance()->cursor_manager();
generator.PressKey(ui::VKEY_A, ui::EF_NONE);
EXPECT_FALSE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
generator.MoveMouseTo(gfx::Point(0, 0));
EXPECT_TRUE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
generator.ReleaseKey(ui::VKEY_A, ui::EF_NONE);
EXPECT_FALSE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
generator.MoveMouseTo(gfx::Point(0, 0));
EXPECT_TRUE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsMouseEventsEnabled());
}
TEST_F(WindowManagerTest, TestCursorClientObserver) {
aura::test::EventGenerator& generator = GetEventGenerator();
::wm::CursorManager* cursor_manager =
ash::Shell::GetInstance()->cursor_manager();
scoped_ptr<aura::Window> w1(CreateTestWindowInShell(
SK_ColorWHITE, -1, gfx::Rect(0, 0, 100, 100)));
wm::ActivateWindow(w1.get());
TestingCursorClientObserver observer_a;
TestingCursorClientObserver observer_b;
cursor_manager->AddObserver(&observer_a);
cursor_manager->AddObserver(&observer_b);
observer_a.reset();
observer_b.reset();
EXPECT_FALSE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_b.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
EXPECT_FALSE(observer_b.is_cursor_visible());
generator.PressKey(ui::VKEY_A, ui::EF_NONE);
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_TRUE(observer_b.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
EXPECT_FALSE(observer_b.is_cursor_visible());
observer_a.reset();
observer_b.reset();
generator.MoveMouseTo(50, 50);
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_TRUE(observer_b.did_visibility_change());
EXPECT_TRUE(observer_a.is_cursor_visible());
EXPECT_TRUE(observer_b.is_cursor_visible());
cursor_manager->RemoveObserver(&observer_b);
observer_a.reset();
observer_b.reset();
generator.GestureTapAt(gfx::Point(25, 25));
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_b.did_visibility_change());
EXPECT_FALSE(observer_a.is_cursor_visible());
observer_a.reset();
observer_b.reset();
generator.MoveMouseTo(50, 50);
EXPECT_TRUE(observer_a.did_visibility_change());
EXPECT_FALSE(observer_b.did_visibility_change());
EXPECT_TRUE(observer_a.is_cursor_visible());
}
#endif
}