Chromium Code Reviews| Index: mojo/converters/input_events/tests/input_events_unittest.cc |
| diff --git a/mojo/converters/input_events/tests/input_events_unittest.cc b/mojo/converters/input_events/tests/input_events_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..01dc111f467ae325b243fcfdf2a7129e99e32ce4 |
| --- /dev/null |
| +++ b/mojo/converters/input_events/tests/input_events_unittest.cc |
| @@ -0,0 +1,100 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "components/html_viewer/blink_input_events_type_converters.h" |
| +#include "mojo/converters/input_events/input_events_type_converters.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/WebKit/public/web/WebInputEvent.h" |
| +#include "ui/events/event.h" |
| +#include "ui/events/event_utils.h" |
| +#include "ui/events/test/events_test_utils.h" |
| + |
| +using ui::EventTimeForNow; |
| +using blink::WebInputEvent; |
| +using blink::WebMouseEvent; |
| +using blink::WebMouseWheelEvent; |
| + |
| +namespace mojo { |
| +namespace { |
| + |
| +TEST(InputEventLibTest, MouseEventConversion) { |
| + ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, gfx::Point(1, 2), |
| + gfx::Point(3, 4), EventTimeForNow(), 0, 0); |
| + |
| + // this line can be better... |
| + mojo::EventPtr mojo_event(mojo::Event::From(*(ui::Event::Clone(mouseev)))); |
|
sadrul
2015/09/09 04:19:04
I don't think there's a reason to use Event::Clone
rjkroege
2015/09/09 19:45:38
no. The template specialization in the converters
sadrul
2015/09/10 17:39:15
That's ... weird? Does ui::MouseEvent not auto-dow
rjkroege
2015/09/12 01:29:02
Nope. not in a template instantiation. It is possi
|
| + |
| + EXPECT_TRUE(mojo_event->action == mojo::EVENT_TYPE_POINTER_DOWN); |
| + EXPECT_TRUE(mojo_event->pointer_data->kind = POINTER_KIND_MOUSE); |
|
sadrul
2015/09/09 04:19:04
EXPECT_EQ
rjkroege
2015/09/09 19:45:38
Done.
|
| + |
| + scoped_ptr<blink::WebInputEvent> webevent = |
| + mojo_event.To<scoped_ptr<blink::WebInputEvent>>(); |
| + |
| + EXPECT_TRUE(webevent != 0); |
| + EXPECT_EQ(WebInputEvent::MouseDown, webevent->type); |
| + |
| + scoped_ptr<WebMouseEvent> web_mouse_event( |
| + static_cast<WebMouseEvent*>(webevent.release())); |
| + |
| + EXPECT_EQ(1, web_mouse_event->x); |
| + EXPECT_EQ(2, web_mouse_event->y); |
| + EXPECT_EQ(3, web_mouse_event->globalX); |
| + EXPECT_EQ(4, web_mouse_event->globalY); |
| +} |
| + |
| +TEST(InputEventLibTest, MouseWheelEventConversionNonPrecise) { |
| + ui::MouseWheelEvent original_wheel( |
| + gfx::Vector2d(-1.0 * 53, -2.0 * 53), gfx::PointF(1.0, 2.0), |
|
sadrul
2015/09/09 04:19:04
Instead of hardcoding 53 everywhere, can we use ui
rjkroege
2015/09/09 19:45:38
Done.
|
| + gfx::PointF(3.0, 4.0), EventTimeForNow(), 0, 0); |
| + |
| + // this line can be better... |
| + mojo::EventPtr mojo_event( |
| + mojo::Event::From(*(ui::Event::Clone(original_wheel)))); |
| + |
| + EXPECT_TRUE(mojo_event->action == mojo::EVENT_TYPE_POINTER_MOVE); |
| + EXPECT_TRUE(mojo_event->pointer_data->kind = POINTER_KIND_WHEEL); |
| + |
| + // Exercise the blink converter. |
| + scoped_ptr<blink::WebInputEvent> webevent = |
| + mojo_event.To<scoped_ptr<blink::WebInputEvent>>(); |
| + |
| + EXPECT_TRUE(webevent != 0); |
| + EXPECT_EQ(WebInputEvent::MouseWheel, webevent->type); |
| + |
| + scoped_ptr<WebMouseWheelEvent> web_wheel( |
| + static_cast<WebMouseWheelEvent*>(webevent.release())); |
| + |
| + EXPECT_EQ(1, web_wheel->x); |
| + EXPECT_EQ(2, web_wheel->y); |
| + EXPECT_EQ(3, web_wheel->globalX); |
| + EXPECT_EQ(4, web_wheel->globalY); |
| + |
| + EXPECT_EQ(-1.0 * 53, web_wheel->deltaX); |
| + EXPECT_EQ(-2.0 * 53, web_wheel->deltaY); |
| + |
| + EXPECT_EQ(-1.0, web_wheel->wheelTicksX); |
| + EXPECT_EQ(-2.0, web_wheel->wheelTicksY); |
| + |
| + EXPECT_FALSE(web_wheel->scrollByPage); |
| + EXPECT_FALSE(web_wheel->hasPreciseScrollingDeltas); |
| + EXPECT_TRUE(web_wheel->canScroll); |
| + |
| + // Exercise the round-trip converter. |
| + // this line can be better... |
| + mojo::EventPtr mojo_other_event( |
| + mojo::Event::From(*(ui::Event::Clone(original_wheel)))); |
| + scoped_ptr<ui::Event> new_event = |
| + mojo_other_event.To<scoped_ptr<ui::Event>>(); |
| + EXPECT_EQ(ui::ET_MOUSEWHEEL, new_event->type()); |
| + |
| + scoped_ptr<ui::MouseWheelEvent> ui_wheel( |
| + static_cast<ui::MouseWheelEvent*>(new_event.release())); |
| + |
| + EXPECT_EQ(-53, ui_wheel->x_offset()); |
| + EXPECT_EQ(-106, ui_wheel->y_offset()); |
| +} |
| + |
| +} // namespace |
| +} // namespace mojo |