Commit 58537966 authored by James Cook's avatar James Cook Committed by Commit Bot

aura: Don't synthesize mouse move or exit events during shutdown

This simplifies teardown, especially in ash on Chrome OS.

Also add tests for the code in crrev.com/c/1180070 which generally
skips event dispatch during shutdown.

Bug: 874156
Test: added to aura_unittests
Change-Id: I1356c3a1ab09f07d23dca1545d3159fcc4016e2d
Reviewed-on: https://chromium-review.googlesource.com/1181537Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585324}
parent a9e0bfb9
......@@ -861,7 +861,7 @@ ui::EventDispatchDetails WindowEventDispatcher::DispatchHeldEvents() {
}
void WindowEventDispatcher::PostSynthesizeMouseMove() {
if (synthesize_mouse_move_)
if (synthesize_mouse_move_ || in_shutdown_)
return;
synthesize_mouse_move_ = true;
base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask(
......@@ -873,6 +873,8 @@ void WindowEventDispatcher::PostSynthesizeMouseMove() {
void WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow(
Window* window) {
if (in_shutdown_)
return;
if (window->IsVisible() &&
window->ContainsPointInRoot(GetLastMouseLocationInRoot())) {
PostSynthesizeMouseMove();
......@@ -881,7 +883,7 @@ void WindowEventDispatcher::SynthesizeMouseMoveAfterChangeToWindow(
ui::EventDispatchDetails WindowEventDispatcher::SynthesizeMouseMoveEvent() {
DispatchDetails details;
if (!synthesize_mouse_move_)
if (!synthesize_mouse_move_ || in_shutdown_)
return details;
synthesize_mouse_move_ = false;
......
......@@ -64,6 +64,7 @@ class AURA_EXPORT WindowEventDispatcher : public ui::EventProcessor,
WindowEventDispatcher(WindowTreeHost* host, bool are_events_in_pixels);
~WindowEventDispatcher() override;
// Stops dispatching/synthesizing mouse events.
void Shutdown();
WindowTreeHost* host() { return host_; }
......
......@@ -940,6 +940,31 @@ TEST_P(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) {
recorder.mouse_locations()[0].ToString());
}
// Tests that a mouse-exit event is not synthesized during shutdown.
TEST_P(WindowEventDispatcherTest, NoMouseExitInShutdown) {
EventFilterRecorder recorder;
test::TestWindowDelegate delegate;
std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
&delegate, 1, gfx::Rect(10, 10, 50, 50), root_window()));
window->Show();
window->AddPreTargetHandler(&recorder);
// Simulate mouse move into the window.
const gfx::Point event_location = window->bounds().CenterPoint();
ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location,
ui::EventTimeForNow(), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse);
EXPECT_FALSE(recorder.events().empty());
recorder.Reset();
// Simulate shutdown.
host()->dispatcher()->Shutdown();
// Hiding the window does not generate a mouse-exit event.
window->Hide();
EXPECT_TRUE(recorder.events().empty());
}
// Verifies that a direct call to ProcessedTouchEvent() does not cause a crash.
TEST_P(WindowEventDispatcherTest, CallToProcessedTouchEvent) {
test::TestWindowDelegate delegate;
......@@ -1118,6 +1143,29 @@ TEST_P(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) {
root_window()->RemovePreTargetHandler(&recorder);
}
// Tests that a mouse-press event is not dispatched during shutdown.
TEST_P(WindowEventDispatcherTest, DoNotDispatchInShutdown) {
EventFilterRecorder recorder;
test::TestWindowDelegate delegate;
std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate(
&delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window()));
window->Show();
window->AddPreTargetHandler(&recorder);
// Simulate shutdown.
host()->dispatcher()->Shutdown();
// Attempt to dispatch a mouse press.
const gfx::Point center = window->bounds().CenterPoint();
ui::MouseEvent press(ui::ET_MOUSE_PRESSED, center, center,
ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
DispatchEventUsingWindowDispatcher(&press);
// Event was not dispatched.
EXPECT_TRUE(recorder.events().empty());
}
#if defined(OS_WIN) && defined(ARCH_CPU_X86)
#define MAYBE(x) DISABLED_##x
#else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment