Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / components / html_viewer / input_events_unittest.cc
blobb5cdc50120afc6a2304fe99548e66ffec2f1611c
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "components/html_viewer/blink_input_events_type_converters.h"
7 #include "mojo/converters/input_events/input_events_type_converters.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/public/web/WebInputEvent.h"
10 #include "ui/events/event.h"
11 #include "ui/events/event_utils.h"
12 #include "ui/events/test/events_test_utils.h"
14 using ui::EventTimeForNow;
15 using blink::WebInputEvent;
16 using blink::WebMouseEvent;
17 using blink::WebMouseWheelEvent;
19 namespace mojo {
20 namespace {
22 TEST(InputEventLibTest, MouseEventConversion) {
23 scoped_ptr<ui::Event> mouseev(
24 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(1, 2),
25 gfx::Point(3, 4), EventTimeForNow(), 0, 0));
27 mojo::EventPtr mojo_event(Event::From(*mouseev));
29 EXPECT_EQ(EVENT_TYPE_POINTER_DOWN, mojo_event->action);
30 EXPECT_EQ(POINTER_KIND_MOUSE, mojo_event->pointer_data->kind);
32 scoped_ptr<blink::WebInputEvent> webevent =
33 mojo_event.To<scoped_ptr<blink::WebInputEvent>>();
35 ASSERT_TRUE(webevent);
36 EXPECT_EQ(WebInputEvent::MouseDown, webevent->type);
38 scoped_ptr<WebMouseEvent> web_mouse_event(
39 static_cast<WebMouseEvent*>(webevent.release()));
41 EXPECT_EQ(1, web_mouse_event->x);
42 EXPECT_EQ(2, web_mouse_event->y);
43 EXPECT_EQ(3, web_mouse_event->globalX);
44 EXPECT_EQ(4, web_mouse_event->globalY);
47 TEST(InputEventLibTest, MouseWheelEventConversionNonPrecise) {
48 scoped_ptr<ui::Event> original_wheel(new ui::MouseWheelEvent(
49 gfx::Vector2d(-1.0 * 53, -2.0 * 53), gfx::PointF(1.0, 2.0),
50 gfx::PointF(3.0, 4.0), EventTimeForNow(), 0, 0));
52 mojo::EventPtr mojo_event(mojo::Event::From(*original_wheel));
54 EXPECT_EQ(EVENT_TYPE_WHEEL, mojo_event->action);
56 // Exercise the blink converter.
57 scoped_ptr<blink::WebInputEvent> webevent =
58 mojo_event.To<scoped_ptr<blink::WebInputEvent>>();
60 ASSERT_TRUE(webevent);
61 EXPECT_EQ(WebInputEvent::MouseWheel, webevent->type);
63 scoped_ptr<WebMouseWheelEvent> web_wheel(
64 static_cast<WebMouseWheelEvent*>(webevent.release()));
66 EXPECT_EQ(1, web_wheel->x);
67 EXPECT_EQ(2, web_wheel->y);
68 EXPECT_EQ(3, web_wheel->globalX);
69 EXPECT_EQ(4, web_wheel->globalY);
71 EXPECT_EQ(-1.0 * ui::MouseWheelEvent::kWheelDelta, web_wheel->deltaX);
72 EXPECT_EQ(-2.0 * ui::MouseWheelEvent::kWheelDelta, web_wheel->deltaY);
74 EXPECT_EQ(-1.0, web_wheel->wheelTicksX);
75 EXPECT_EQ(-2.0, web_wheel->wheelTicksY);
77 EXPECT_FALSE(web_wheel->scrollByPage);
78 EXPECT_FALSE(web_wheel->hasPreciseScrollingDeltas);
79 EXPECT_TRUE(web_wheel->canScroll);
81 // Exercise the round-trip converter.
82 mojo::EventPtr mojo_other_event(mojo::Event::From(*original_wheel));
83 scoped_ptr<ui::Event> new_event =
84 mojo_other_event.To<scoped_ptr<ui::Event>>();
85 EXPECT_EQ(ui::ET_MOUSEWHEEL, new_event->type());
87 scoped_ptr<ui::MouseWheelEvent> ui_wheel(
88 static_cast<ui::MouseWheelEvent*>(new_event.release()));
90 EXPECT_EQ(-1 * ui::MouseWheelEvent::kWheelDelta, ui_wheel->x_offset());
91 EXPECT_EQ(-2 * ui::MouseWheelEvent::kWheelDelta, ui_wheel->y_offset());
94 } // namespace
95 } // namespace mojo