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