Commit 15839197 authored by W. James MacLean's avatar W. James MacLean Committed by Commit Bot

Use EventRewriter to disable system mouse events in Aura SPPHTBTs.

It seems that spurious mousemove events on Win have been creeping into
tests in this suite (e.g. a test window pops up under where the system
thinks the mouse cursor is, and generates a mouse-enter). These events
appear to be at the root of flakes for at least one, and possibly more,
tests in this hierarchy.

This CL installs a ui::EventRewriter that discards all system mouse
events in an attempt to reduce flake in the tests.

Bug: 833380
Change-Id: I48adacad0fdf4126ea4198bfa72b336d0eb63389
Reviewed-on: https://chromium-review.googlesource.com/1194253
Commit-Queue: James MacLean <wjmaclean@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#587189}
parent c8326e39
......@@ -46,6 +46,7 @@
#include "content/public/browser/overscroll_configuration.h"
#include "content/test/mock_overscroll_controller_delegate_aura.h"
#include "ui/aura/window_tree_host.h"
#include "ui/events/event_rewriter.h"
#endif
#if defined(OS_MACOSX)
......@@ -648,6 +649,34 @@ class SetMouseCaptureInterceptor
DISALLOW_COPY_AND_ASSIGN(SetMouseCaptureInterceptor);
};
#if defined(USE_AURA)
// A class to allow intercepting and discarding of system-level mouse events
// that might otherwise cause unpredictable behaviour in tests.
class MouseEventRewriter : public ui::EventRewriter {
public:
MouseEventRewriter() = default;
~MouseEventRewriter() override {}
private:
ui::EventRewriteStatus RewriteEvent(
const ui::Event& event,
std::unique_ptr<ui::Event>* new_event) override {
if (event.IsMouseEvent())
return ui::EVENT_REWRITE_DISCARD;
return ui::EVENT_REWRITE_CONTINUE;
}
ui::EventRewriteStatus NextDispatchEvent(
const ui::Event& event,
std::unique_ptr<ui::Event>* new_event) override {
NOTREACHED();
return ui::EVENT_REWRITE_CONTINUE;
}
DISALLOW_COPY_AND_ASSIGN(MouseEventRewriter);
};
#endif
} // namespace
class SitePerProcessHitTestBrowserTest
......@@ -656,6 +685,19 @@ class SitePerProcessHitTestBrowserTest
public:
SitePerProcessHitTestBrowserTest() {}
#if defined(USE_AURA)
void PreRunTestOnMainThread() override {
SitePerProcessBrowserTest::PreRunTestOnMainThread();
// Disable system mouse events, which can interfere with tests.
shell()->window()->GetHost()->AddEventRewriter(&event_rewriter);
}
void PostRunTestOnMainThread() override {
shell()->window()->GetHost()->RemoveEventRewriter(&event_rewriter);
SitePerProcessBrowserTest::PostRunTestOnMainThread();
}
#endif
protected:
void SetUpCommandLine(base::CommandLine* command_line) override {
SitePerProcessBrowserTest::SetUpCommandLine(command_line);
......@@ -671,6 +713,9 @@ class SitePerProcessHitTestBrowserTest
}
base::test::ScopedFeatureList feature_list_;
#if defined(USE_AURA)
MouseEventRewriter event_rewriter;
#endif
};
//
......
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