This source file includes following definitions.
- OnMouseReleased
- OnGestureEvent
- pressed_
- OnMousePressed
- OnMouseEntered
- OnMouseExited
- EnteredCalls
- ExitedCalls
- pressed
- OnMousePressed
- SetUp
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- OnNativeWidgetActivationChanged
- active
- TEST_F
- GetModalType
- TEST_F
- TEST_F
- GetAndClearGotCaptureLost
- OnMouseCaptureLost
- SetUp
- TestCapture
- CreateNativeWidget
- TEST_F
- TEST_F
- GetAndClearGotMouseEvent
- OnMouseEvent
- TEST_F
#include "base/basictypes.h"
#include "base/bind.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/events/event_processor.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_surface.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
#include "ui/wm/public/activation_client.h"
#if !defined(OS_CHROMEOS)
#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
#endif
#if defined(OS_WIN)
#include "ui/views/win/hwnd_util.h"
#endif
namespace views {
namespace test {
namespace {
class ExitLoopOnRelease : public View {
public:
ExitLoopOnRelease() {}
virtual ~ExitLoopOnRelease() {}
private:
virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE {
GetWidget()->Close();
base::MessageLoop::current()->QuitNow();
}
DISALLOW_COPY_AND_ASSIGN(ExitLoopOnRelease);
};
class GestureCaptureView : public View {
public:
GestureCaptureView() {}
virtual ~GestureCaptureView() {}
private:
virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
if (event->type() == ui::ET_GESTURE_BEGIN) {
GetWidget()->SetCapture(this);
event->StopPropagation();
}
}
DISALLOW_COPY_AND_ASSIGN(GestureCaptureView);
};
class MouseView : public View {
public:
MouseView()
: View(),
entered_(0),
exited_(0),
pressed_(0) {
}
virtual ~MouseView() {}
virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
pressed_++;
return true;
}
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE {
entered_++;
}
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE {
exited_++;
}
int EnteredCalls() {
int i = entered_;
entered_ = 0;
return i;
}
int ExitedCalls() {
int i = exited_;
exited_ = 0;
return i;
}
int pressed() const { return pressed_; }
private:
int entered_;
int exited_;
int pressed_;
DISALLOW_COPY_AND_ASSIGN(MouseView);
};
class NestedLoopCaptureView : public View {
public:
explicit NestedLoopCaptureView(Widget* widget) : widget_(widget) {}
virtual ~NestedLoopCaptureView() {}
private:
virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
widget_->Show();
widget_->SetCapture(widget_->GetContentsView());
EXPECT_TRUE(widget_->HasCapture());
base::MessageLoopForUI* loop = base::MessageLoopForUI::current();
base::MessageLoop::ScopedNestableTaskAllower allow(loop);
base::RunLoop run_loop;
run_loop.Run();
return true;
}
Widget* widget_;
DISALLOW_COPY_AND_ASSIGN(NestedLoopCaptureView);
};
}
class WidgetTestInteractive : public WidgetTest {
public:
WidgetTestInteractive() {}
virtual ~WidgetTestInteractive() {}
virtual void SetUp() OVERRIDE {
gfx::GLSurface::InitializeOneOffForTests();
base::FilePath pak_dir;
PathService::Get(base::DIR_MODULE, &pak_dir);
base::FilePath pak_file;
pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak"));
ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
WidgetTest::SetUp();
}
};
#if defined(OS_WIN)
TEST_F(WidgetTestInteractive, DesktopNativeWidgetAuraActivationAndFocusTest) {
View* contents_view1 = new View;
contents_view1->SetFocusable(true);
Widget widget1;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
init_params.bounds = gfx::Rect(0, 0, 200, 200);
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.native_widget = new DesktopNativeWidgetAura(&widget1);
widget1.Init(init_params);
widget1.SetContentsView(contents_view1);
widget1.Show();
aura::Window* root_window1= widget1.GetNativeView()->GetRootWindow();
contents_view1->RequestFocus();
EXPECT_TRUE(root_window1 != NULL);
aura::client::ActivationClient* activation_client1 =
aura::client::GetActivationClient(root_window1);
EXPECT_TRUE(activation_client1 != NULL);
EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView());
View* contents_view2 = new View;
Widget widget2;
Widget::InitParams init_params2 =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
init_params2.bounds = gfx::Rect(0, 0, 200, 200);
init_params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params2.native_widget = new DesktopNativeWidgetAura(&widget2);
widget2.Init(init_params2);
widget2.SetContentsView(contents_view2);
widget2.Show();
aura::Window* root_window2 = widget2.GetNativeView()->GetRootWindow();
contents_view2->RequestFocus();
::SetActiveWindow(
root_window2->GetHost()->GetAcceleratedWidget());
aura::client::ActivationClient* activation_client2 =
aura::client::GetActivationClient(root_window2);
EXPECT_TRUE(activation_client2 != NULL);
EXPECT_EQ(activation_client2->GetActiveWindow(), widget2.GetNativeView());
EXPECT_EQ(activation_client1->GetActiveWindow(),
reinterpret_cast<aura::Window*>(NULL));
contents_view1->RequestFocus();
::SetActiveWindow(
root_window1->GetHost()->GetAcceleratedWidget());
EXPECT_EQ(activation_client2->GetActiveWindow(),
reinterpret_cast<aura::Window*>(NULL));
EXPECT_EQ(activation_client1->GetActiveWindow(), widget1.GetNativeView());
}
#endif
TEST_F(WidgetTestInteractive, CaptureAutoReset) {
Widget* toplevel = CreateTopLevelFramelessPlatformWidget();
View* container = new View;
toplevel->SetContentsView(container);
EXPECT_FALSE(toplevel->HasCapture());
toplevel->SetCapture(NULL);
EXPECT_TRUE(toplevel->HasCapture());
gfx::Point click_location(45, 15);
ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location,
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
toplevel->OnMouseEvent(&release);
EXPECT_FALSE(toplevel->HasCapture());
toplevel->set_auto_release_capture(false);
toplevel->SetCapture(NULL);
EXPECT_TRUE(toplevel->HasCapture());
toplevel->OnMouseEvent(&release);
EXPECT_TRUE(toplevel->HasCapture());
toplevel->ReleaseCapture();
EXPECT_FALSE(toplevel->HasCapture());
toplevel->Close();
RunPendingMessages();
}
TEST_F(WidgetTestInteractive, ResetCaptureOnGestureEnd) {
Widget* toplevel = CreateTopLevelFramelessPlatformWidget();
View* container = new View;
toplevel->SetContentsView(container);
View* gesture = new GestureCaptureView;
gesture->SetBounds(0, 0, 30, 30);
container->AddChildView(gesture);
MouseView* mouse = new MouseView;
mouse->SetBounds(30, 0, 30, 30);
container->AddChildView(mouse);
toplevel->SetSize(gfx::Size(100, 100));
toplevel->Show();
ui::GestureEvent begin(ui::ET_GESTURE_BEGIN,
15, 15, 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_BEGIN, 0, 0), 1);
ui::GestureEvent end(ui::ET_GESTURE_END,
15, 15, 0, base::TimeDelta(),
ui::GestureEventDetails(ui::ET_GESTURE_END, 0, 0), 1);
toplevel->OnGestureEvent(&begin);
gfx::Point click_location(45, 15);
ui::MouseEvent press(ui::ET_MOUSE_PRESSED, click_location, click_location,
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
ui::MouseEvent release(ui::ET_MOUSE_RELEASED, click_location, click_location,
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
EXPECT_TRUE(toplevel->HasCapture());
toplevel->OnMouseEvent(&press);
toplevel->OnMouseEvent(&release);
EXPECT_EQ(0, mouse->pressed());
EXPECT_FALSE(toplevel->HasCapture());
toplevel->OnGestureEvent(&end);
toplevel->OnMouseEvent(&press);
toplevel->OnMouseEvent(&release);
EXPECT_EQ(1, mouse->pressed());
toplevel->Close();
RunPendingMessages();
}
TEST_F(WidgetTestInteractive, DisableCaptureWidgetFromMousePress) {
Widget* first = CreateTopLevelFramelessPlatformWidget();
Widget* second = CreateTopLevelFramelessPlatformWidget();
View* container = new NestedLoopCaptureView(second);
first->SetContentsView(container);
second->SetContentsView(new ExitLoopOnRelease());
first->SetSize(gfx::Size(100, 100));
first->Show();
gfx::Point location(20, 20);
base::MessageLoop::current()->PostTask(FROM_HERE,
base::Bind(&Widget::OnMouseEvent,
base::Unretained(second),
base::Owned(new ui::MouseEvent(ui::ET_MOUSE_RELEASED,
location,
location,
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON))));
ui::MouseEvent press(ui::ET_MOUSE_PRESSED, location, location,
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
first->OnMouseEvent(&press);
EXPECT_FALSE(first->HasCapture());
first->Close();
RunPendingMessages();
}
TEST_F(WidgetTestInteractive, DISABLED_GrabUngrab) {
Widget* toplevel = CreateTopLevelPlatformWidget();
Widget* child1 = CreateChildNativeWidgetWithParent(toplevel);
Widget* child2 = CreateChildNativeWidgetWithParent(toplevel);
toplevel->SetBounds(gfx::Rect(0, 0, 500, 500));
child1->SetBounds(gfx::Rect(10, 10, 300, 300));
View* view = new MouseView();
view->SetBounds(0, 0, 300, 300);
child1->GetRootView()->AddChildView(view);
child2->SetBounds(gfx::Rect(200, 10, 200, 200));
view = new MouseView();
view->SetBounds(0, 0, 200, 200);
child2->GetRootView()->AddChildView(view);
toplevel->Show();
RunPendingMessages();
gfx::Point p1(45, 45);
ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, p1, p1,
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
toplevel->OnMouseEvent(&pressed);
EXPECT_TRUE(toplevel->HasCapture());
EXPECT_TRUE(child1->HasCapture());
EXPECT_FALSE(child2->HasCapture());
ui::MouseEvent released(ui::ET_MOUSE_RELEASED, p1, p1,
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
toplevel->OnMouseEvent(&released);
EXPECT_FALSE(toplevel->HasCapture());
EXPECT_FALSE(child1->HasCapture());
EXPECT_FALSE(child2->HasCapture());
RunPendingMessages();
gfx::Point p2(315, 45);
ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, p2, p2,
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
toplevel->OnMouseEvent(&pressed2);
EXPECT_TRUE(pressed2.handled());
EXPECT_TRUE(toplevel->HasCapture());
EXPECT_TRUE(child2->HasCapture());
EXPECT_FALSE(child1->HasCapture());
ui::MouseEvent released2(ui::ET_MOUSE_RELEASED, p2, p2,
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
toplevel->OnMouseEvent(&released2);
EXPECT_FALSE(toplevel->HasCapture());
EXPECT_FALSE(child1->HasCapture());
EXPECT_FALSE(child2->HasCapture());
toplevel->CloseNow();
}
TEST_F(WidgetTestInteractive, CheckResizeControllerEvents) {
Widget* toplevel = CreateTopLevelPlatformWidget();
toplevel->SetBounds(gfx::Rect(0, 0, 100, 100));
MouseView* view = new MouseView();
view->SetBounds(90, 90, 10, 10);
toplevel->GetRootView()->AddChildView(view);
toplevel->Show();
RunPendingMessages();
gfx::Point p1(200, 200);
ui::MouseEvent moved_out(ui::ET_MOUSE_MOVED, p1, p1, ui::EF_NONE,
ui::EF_NONE);
toplevel->OnMouseEvent(&moved_out);
EXPECT_EQ(0, view->EnteredCalls());
EXPECT_EQ(0, view->ExitedCalls());
gfx::Point p2(95, 95);
ui::MouseEvent moved_over(ui::ET_MOUSE_MOVED, p2, p2, ui::EF_NONE,
ui::EF_NONE);
toplevel->OnMouseEvent(&moved_over);
EXPECT_EQ(1, view->EnteredCalls());
EXPECT_EQ(0, view->ExitedCalls());
gfx::Point p3(102, 95);
ui::MouseEvent moved_resizer(ui::ET_MOUSE_MOVED, p3, p3, ui::EF_NONE,
ui::EF_NONE);
toplevel->OnMouseEvent(&moved_resizer);
EXPECT_EQ(0, view->EnteredCalls());
EXPECT_EQ(1, view->ExitedCalls());
toplevel->OnMouseEvent(&moved_over);
EXPECT_EQ(1, view->EnteredCalls());
EXPECT_EQ(0, view->ExitedCalls());
RunPendingMessages();
toplevel->CloseNow();
}
#if defined(OS_WIN)
class WidgetActivationTest : public Widget {
public:
WidgetActivationTest()
: active_(false) {}
virtual ~WidgetActivationTest() {}
virtual void OnNativeWidgetActivationChanged(bool active) OVERRIDE {
active_ = active;
}
bool active() const { return active_; }
private:
bool active_;
DISALLOW_COPY_AND_ASSIGN(WidgetActivationTest);
};
TEST_F(WidgetTestInteractive, WidgetNotActivatedOnFakeActivationMessages) {
WidgetActivationTest widget1;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS);
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.native_widget = new DesktopNativeWidgetAura(&widget1);
init_params.bounds = gfx::Rect(0, 0, 200, 200);
widget1.Init(init_params);
widget1.Show();
EXPECT_EQ(true, widget1.active());
WidgetActivationTest widget2;
init_params.native_widget = new DesktopNativeWidgetAura(&widget2);
widget2.Init(init_params);
widget2.Show();
EXPECT_EQ(true, widget2.active());
EXPECT_EQ(false, widget1.active());
HWND win32_native_window1 = HWNDForWidget(&widget1);
EXPECT_TRUE(::IsWindow(win32_native_window1));
::SendMessage(win32_native_window1, WM_NCACTIVATE, 1, 0);
EXPECT_EQ(false, widget1.active());
EXPECT_EQ(true, widget2.active());
::SetActiveWindow(win32_native_window1);
EXPECT_EQ(true, widget1.active());
EXPECT_EQ(false, widget2.active());
}
#endif
#if !defined(OS_CHROMEOS)
class ModalDialogDelegate : public DialogDelegateView {
public:
explicit ModalDialogDelegate(ui::ModalType type) : type_(type) {}
virtual ~ModalDialogDelegate() {}
virtual ui::ModalType GetModalType() const OVERRIDE {
return type_;
}
private:
ui::ModalType type_;
DISALLOW_COPY_AND_ASSIGN(ModalDialogDelegate);
};
TEST_F(WidgetTestInteractive, WindowModalWindowDestroyedActivationTest) {
Widget top_level_widget;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW);
init_params.show_state = ui::SHOW_STATE_NORMAL;
gfx::Rect initial_bounds(0, 0, 500, 500);
init_params.bounds = initial_bounds;
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.native_widget = new DesktopNativeWidgetAura(&top_level_widget);
top_level_widget.Init(init_params);
top_level_widget.Show();
aura::Window* top_level_window = top_level_widget.GetNativeWindow();
EXPECT_EQ(top_level_window, aura::client::GetFocusClient(
top_level_window)->GetFocusedWindow());
ModalDialogDelegate* dialog_delegate =
new ModalDialogDelegate(ui::MODAL_TYPE_WINDOW);
Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
dialog_delegate, NULL, top_level_widget.GetNativeWindow());
modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
modal_dialog_widget->Show();
aura::Window* dialog_window = modal_dialog_widget->GetNativeWindow();
EXPECT_EQ(dialog_window, aura::client::GetFocusClient(
top_level_window)->GetFocusedWindow());
modal_dialog_widget->CloseNow();
EXPECT_EQ(top_level_window, aura::client::GetFocusClient(
top_level_window)->GetFocusedWindow());
top_level_widget.CloseNow();
}
TEST_F(WidgetTestInteractive, SystemModalWindowReleasesCapture) {
Widget top_level_widget;
Widget::InitParams init_params =
CreateParams(Widget::InitParams::TYPE_WINDOW);
init_params.show_state = ui::SHOW_STATE_NORMAL;
gfx::Rect initial_bounds(0, 0, 500, 500);
init_params.bounds = initial_bounds;
init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
init_params.native_widget = new DesktopNativeWidgetAura(&top_level_widget);
top_level_widget.Init(init_params);
top_level_widget.Show();
aura::Window* top_level_window = top_level_widget.GetNativeWindow();
EXPECT_EQ(top_level_window, aura::client::GetFocusClient(
top_level_window)->GetFocusedWindow());
EXPECT_FALSE(top_level_window->HasCapture());
top_level_window->SetCapture();
EXPECT_TRUE(top_level_window->HasCapture());
ModalDialogDelegate* dialog_delegate =
new ModalDialogDelegate(ui::MODAL_TYPE_SYSTEM);
Widget* modal_dialog_widget = views::DialogDelegate::CreateDialogWidget(
dialog_delegate, NULL, top_level_widget.GetNativeWindow());
modal_dialog_widget->SetBounds(gfx::Rect(100, 100, 200, 200));
modal_dialog_widget->Show();
EXPECT_FALSE(top_level_window->HasCapture());
modal_dialog_widget->CloseNow();
top_level_widget.CloseNow();
}
#endif
namespace {
class CaptureLostTrackingWidget : public Widget {
public:
CaptureLostTrackingWidget() : got_capture_lost_(false) {}
virtual ~CaptureLostTrackingWidget() {}
bool GetAndClearGotCaptureLost() {
bool value = got_capture_lost_;
got_capture_lost_ = false;
return value;
}
virtual void OnMouseCaptureLost() OVERRIDE {
got_capture_lost_ = true;
Widget::OnMouseCaptureLost();
}
private:
bool got_capture_lost_;
DISALLOW_COPY_AND_ASSIGN(CaptureLostTrackingWidget);
};
}
class WidgetCaptureTest : public ViewsTestBase {
public:
WidgetCaptureTest() {
}
virtual ~WidgetCaptureTest() {
}
virtual void SetUp() OVERRIDE {
gfx::GLSurface::InitializeOneOffForTests();
base::FilePath pak_dir;
PathService::Get(base::DIR_MODULE, &pak_dir);
base::FilePath pak_file;
pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak"));
ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
ViewsTestBase::SetUp();
}
void TestCapture(bool use_desktop_native_widget) {
CaptureLostTrackingWidget widget1;
Widget::InitParams params1 =
CreateParams(views::Widget::InitParams::TYPE_WINDOW);
params1.native_widget = CreateNativeWidget(use_desktop_native_widget,
&widget1);
params1.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget1.Init(params1);
widget1.Show();
CaptureLostTrackingWidget widget2;
Widget::InitParams params2 =
CreateParams(views::Widget::InitParams::TYPE_WINDOW);
params2.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params2.native_widget = CreateNativeWidget(use_desktop_native_widget,
&widget2);
widget2.Init(params2);
widget2.Show();
widget2.SetCapture(widget2.GetRootView());
EXPECT_FALSE(widget1.HasCapture());
EXPECT_TRUE(widget2.HasCapture());
EXPECT_FALSE(widget1.GetAndClearGotCaptureLost());
EXPECT_FALSE(widget2.GetAndClearGotCaptureLost());
widget1.SetCapture(widget1.GetRootView());
EXPECT_TRUE(widget1.HasCapture());
EXPECT_FALSE(widget2.HasCapture());
EXPECT_FALSE(widget1.GetAndClearGotCaptureLost());
EXPECT_TRUE(widget2.GetAndClearGotCaptureLost());
widget1.ReleaseCapture();
EXPECT_FALSE(widget1.HasCapture());
EXPECT_FALSE(widget2.HasCapture());
EXPECT_TRUE(widget1.GetAndClearGotCaptureLost());
EXPECT_FALSE(widget2.GetAndClearGotCaptureLost());
}
private:
NativeWidget* CreateNativeWidget(bool create_desktop_native_widget,
Widget* widget) {
#if !defined(OS_CHROMEOS)
if (create_desktop_native_widget)
return new DesktopNativeWidgetAura(widget);
#endif
return NULL;
}
DISALLOW_COPY_AND_ASSIGN(WidgetCaptureTest);
};
TEST_F(WidgetCaptureTest, Capture) {
TestCapture(false);
}
#if !defined(OS_LINUX)
TEST_F(WidgetCaptureTest, CaptureDesktopNativeWidget) {
TestCapture(true);
}
#endif
#if !defined(OS_CHROMEOS)
namespace {
class MouseEventTrackingWidget : public Widget {
public:
MouseEventTrackingWidget() : got_mouse_event_(false) {}
virtual ~MouseEventTrackingWidget() {}
bool GetAndClearGotMouseEvent() {
bool value = got_mouse_event_;
got_mouse_event_ = false;
return value;
}
virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
got_mouse_event_ = true;
Widget::OnMouseEvent(event);
}
private:
bool got_mouse_event_;
DISALLOW_COPY_AND_ASSIGN(MouseEventTrackingWidget);
};
}
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
#define MAYBE_MouseEventDispatchedToRightWindow \
DISABLED_MouseEventDispatchedToRightWindow
#else
#define MAYBE_MouseEventDispatchedToRightWindow \
MouseEventDispatchedToRightWindow
#endif
TEST_F(WidgetCaptureTest, MAYBE_MouseEventDispatchedToRightWindow) {
MouseEventTrackingWidget widget1;
Widget::InitParams params1 =
CreateParams(views::Widget::InitParams::TYPE_WINDOW);
params1.native_widget = new DesktopNativeWidgetAura(&widget1);
params1.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
widget1.Init(params1);
widget1.Show();
MouseEventTrackingWidget widget2;
Widget::InitParams params2 =
CreateParams(views::Widget::InitParams::TYPE_WINDOW);
params2.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
params2.native_widget = new DesktopNativeWidgetAura(&widget2);
widget2.Init(params2);
widget2.Show();
widget2.SetCapture(widget2.GetRootView());
EXPECT_FALSE(widget1.HasCapture());
EXPECT_TRUE(widget2.HasCapture());
widget1.GetAndClearGotMouseEvent();
widget2.GetAndClearGotMouseEvent();
ui::MouseEvent mouse_event(ui::ET_MOUSE_EXITED, gfx::Point(), gfx::Point(),
ui::EF_NONE, ui::EF_NONE);
ui::EventDispatchDetails details = widget1.GetNativeWindow()->
GetHost()->event_processor()->OnEventFromSource(&mouse_event);
ASSERT_FALSE(details.dispatcher_destroyed);
EXPECT_TRUE(widget1.GetAndClearGotMouseEvent());
EXPECT_FALSE(widget2.GetAndClearGotMouseEvent());
}
#endif
}
}