Commit 252b10b3 authored by Elliot Glaysher's avatar Elliot Glaysher Committed by Commit Bot

Don't slice ui::MouseWheelEvents in tests.

This fixes an ubisan error in ws::EventDispatcher where the creation of a
ui::MouseWheelEvent object was copied into a ui::MouseEvent object, and then
near immediately casted back to a ui::MouseWheelEvent, which it no longer was
because the object was sliced.

Bug: 752271
Change-Id: I9e49369c0ff599b99c1b68ab3785bdd051998568
Reviewed-on: https://chromium-review.googlesource.com/601179Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Elliot Glaysher <erg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491872}
parent f42ff9b5
......@@ -25,6 +25,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/event.h"
using base::MakeUnique;
namespace ui {
namespace ws {
namespace test {
......@@ -197,7 +199,7 @@ class TestEventDispatcherDelegate : public EventDispatcherDelegate {
// ServerWindow and points identify the second event. If only one event is
// generated set the second window to null.
struct MouseEventTest {
ui::MouseEvent input_event;
std::unique_ptr<ui::MouseEvent> input_event;
ServerWindow* expected_target_window1;
gfx::Point expected_root_location1;
gfx::Point expected_location1;
......@@ -320,7 +322,7 @@ void EventDispatcherTest::RunMouseEventTests(
const MouseEventTest& test = tests[i];
ASSERT_FALSE(dispatcher_delegate->has_queued_events())
<< " unexpected queued events before running " << i;
DispatchEvent(dispatcher, ui::PointerEvent(test.input_event), 0,
DispatchEvent(dispatcher, ui::PointerEvent(*test.input_event), 0,
EventDispatcher::AcceleratorMatchPhase::ANY);
std::unique_ptr<DispatchedEventDetails> details =
......@@ -648,32 +650,36 @@ TEST_P(EventDispatcherTest, Capture) {
MouseEventTest tests[] = {
// Send a mouse down event over child.
{ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
gfx::Point(20, 25), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
gfx::Point(20, 25), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr,
gfx::Point(), gfx::Point()},
// Capture should be activated. Let's send a mouse move outside the bounds
// of the child.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
gfx::Point(), gfx::Point()},
// Release the mouse and verify that the mouse up event goes to the child.
{ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
gfx::Point(), gfx::Point()},
// A mouse move at (50, 50) should now go to the root window. As the
// move crosses between |child| and |root| |child| gets an exit, and
// |root| the move.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40), root,
gfx::Point(50, 50), gfx::Point(50, 50)},
......@@ -690,33 +696,36 @@ TEST_P(EventDispatcherTest, CaptureMultipleMouseButtons) {
MouseEventTest tests[] = {
// Send a mouse down event over child with a left mouse button
{ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
gfx::Point(20, 25), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
gfx::Point(20, 25), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
child.get(), gfx::Point(20, 25), gfx::Point(10, 15), nullptr,
gfx::Point(), gfx::Point()},
// Capture should be activated. Let's send a mouse move outside the bounds
// of the child and press the right mouse button too.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 0),
{MakeUnique<ui::MouseEvent>(
ui::ET_MOUSE_MOVED, gfx::Point(50, 50), gfx::Point(50, 50),
base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 0),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
gfx::Point(), gfx::Point()},
// Release the left mouse button and verify that the mouse up event goes
// to the child.
{ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
ui::EF_RIGHT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(
ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), gfx::Point(50, 50),
base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
ui::EF_RIGHT_MOUSE_BUTTON),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
gfx::Point(), gfx::Point()},
// A mouse move at (50, 50) should still go to the child.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, 0),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, 0),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40), nullptr,
gfx::Point(), gfx::Point()},
......@@ -1072,15 +1081,16 @@ TEST_P(EventDispatcherTest, WheelWhileDown) {
MouseEventTest tests[] = {
// Send a mouse down event over child1.
{ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15),
gfx::Point(15, 15), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_PRESSED, gfx::Point(15, 15),
gfx::Point(15, 15), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
child1.get(), gfx::Point(15, 15), gfx::Point(5, 5), nullptr,
gfx::Point(), gfx::Point()},
// Send mouse wheel over child2, should go to child1 as it has capture.
{ui::MouseWheelEvent(gfx::Vector2d(1, 0), gfx::Point(53, 54),
gfx::Point(53, 54), base::TimeTicks(), ui::EF_NONE,
ui::EF_NONE),
{MakeUnique<ui::MouseWheelEvent>(gfx::Vector2d(1, 0), gfx::Point(53, 54),
gfx::Point(53, 54), base::TimeTicks(),
ui::EF_NONE, ui::EF_NONE),
child1.get(), gfx::Point(53, 54), gfx::Point(43, 44), nullptr,
gfx::Point(), gfx::Point()},
};
......@@ -1207,27 +1217,30 @@ TEST_P(EventDispatcherTest, ExplicitCaptureOverridesImplicitCapture) {
// Run some implicit capture tests.
MouseEventTest tests[] = {
// Send a mouse down event over child with a left mouse button
{ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
gfx::Point(20, 25), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_PRESSED, gfx::Point(20, 25),
gfx::Point(20, 25), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
child.get(), gfx::Point(20, 25), gfx::Point(10, 15)},
// Capture should be activated. Let's send a mouse move outside the bounds
// of the child and press the right mouse button too.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 0),
{MakeUnique<ui::MouseEvent>(
ui::ET_MOUSE_MOVED, gfx::Point(50, 50), gfx::Point(50, 50),
base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 0),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40)},
// Release the left mouse button and verify that the mouse up event goes
// to the child.
{ui::MouseEvent(ui::ET_MOUSE_RELEASED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
ui::EF_RIGHT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(
ui::ET_MOUSE_RELEASED, gfx::Point(50, 50), gfx::Point(50, 50),
base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
ui::EF_RIGHT_MOUSE_BUTTON),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40)},
// A mouse move at (50, 50) should still go to the child.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, 0),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(50, 50),
gfx::Point(50, 50), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, 0),
child.get(), gfx::Point(50, 50), gfx::Point(40, 40)},
};
......@@ -1954,14 +1967,14 @@ TEST_P(EventDispatcherTest, MoveMouseFromNoTargetToValidTarget) {
MouseEventTest tests[] = {
// Send a mouse down over the root, but not the child. No event should
// be generated.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5),
base::TimeTicks(), 0, 0),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(5, 5),
gfx::Point(5, 5), base::TimeTicks(), 0, 0),
nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
gfx::Point()},
// Move into child.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12),
gfx::Point(12, 12), base::TimeTicks(), 0, 0),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(12, 12),
gfx::Point(12, 12), base::TimeTicks(), 0, 0),
child.get(), gfx::Point(12, 12), gfx::Point(2, 2), nullptr, gfx::Point(),
gfx::Point()}};
RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
......@@ -1979,22 +1992,23 @@ TEST_P(EventDispatcherTest, NoTargetToTargetWithMouseDown) {
MouseEventTest tests[] = {
// Mouse over the root, but not the child. No event should be generated.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(5, 5), gfx::Point(5, 5),
base::TimeTicks(), 0, 0),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(5, 5),
gfx::Point(5, 5), base::TimeTicks(), 0, 0),
nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
gfx::Point()},
// Press in same location, still no target.
{ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(5, 5), gfx::Point(5, 5),
base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_PRESSED, gfx::Point(5, 5),
gfx::Point(5, 5), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
gfx::Point()},
// Move into child, still no target.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(12, 12),
gfx::Point(12, 12), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, 0),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(12, 12),
gfx::Point(12, 12), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, 0),
nullptr, gfx::Point(), gfx::Point(), nullptr, gfx::Point(),
gfx::Point()}};
RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
......@@ -2014,15 +2028,16 @@ TEST_P(EventDispatcherTest, DontSendExitToSameClientWhenCaptureChanges) {
MouseEventTest tests[] = {
// Mouse over |c2|.
{ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(16, 16),
gfx::Point(16, 16), base::TimeTicks(), 0, 0),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_MOVED, gfx::Point(16, 16),
gfx::Point(16, 16), base::TimeTicks(), 0, 0),
c2.get(), gfx::Point(16, 16), gfx::Point(1, 1), nullptr, gfx::Point(),
gfx::Point()},
// Press in same location.
{ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(16, 16),
gfx::Point(16, 16), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON),
{MakeUnique<ui::MouseEvent>(ui::ET_MOUSE_PRESSED, gfx::Point(16, 16),
gfx::Point(16, 16), base::TimeTicks(),
ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON),
c2.get(), gfx::Point(16, 16), gfx::Point(1, 1), nullptr, gfx::Point(),
gfx::Point()}};
RunMouseEventTests(event_dispatcher(), test_event_dispatcher_delegate(),
......
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