Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / html_viewer / input_events_unittest.cc
blob8c4e8c3777c6d92b33826079a236ea38327e2c95
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 // TODO(rjkroege): Fix on windows per http://crbug.com/533588.
48 #if defined(OS_WIN)
49 #define MAYBE_MouseWheelEventConversionNonPrecise \
50 DISABLED_MouseWheelEventConversionNonPrecise
51 #else
52 #define MAYBE_MouseWheelEventConversionNonPrecise \
53 MouseWheelEventConversionNonPrecise
54 #endif
56 TEST(InputEventLibTest, MAYBE_MouseWheelEventConversionNonPrecise) {
57 scoped_ptr<ui::Event> original_wheel(new ui::MouseWheelEvent(
58 gfx::Vector2d(-1.0 * 53, -2.0 * 53), gfx::PointF(1.0, 2.0),
59 gfx::PointF(3.0, 4.0), EventTimeForNow(), 0, 0));
61 mojo::EventPtr mojo_event(mojo::Event::From(*original_wheel));
63 EXPECT_EQ(EVENT_TYPE_WHEEL, mojo_event->action);
65 // Exercise the blink converter.
66 scoped_ptr<blink::WebInputEvent> webevent =
67 mojo_event.To<scoped_ptr<blink::WebInputEvent>>();
69 ASSERT_TRUE(webevent);
70 EXPECT_EQ(WebInputEvent::MouseWheel, webevent->type);
72 scoped_ptr<WebMouseWheelEvent> web_wheel(
73 static_cast<WebMouseWheelEvent*>(webevent.release()));
75 EXPECT_EQ(1, web_wheel->x);
76 EXPECT_EQ(2, web_wheel->y);
77 EXPECT_EQ(3, web_wheel->globalX);
78 EXPECT_EQ(4, web_wheel->globalY);
80 EXPECT_EQ(-1.0 * ui::MouseWheelEvent::kWheelDelta, web_wheel->deltaX);
81 EXPECT_EQ(-2.0 * ui::MouseWheelEvent::kWheelDelta, web_wheel->deltaY);
83 EXPECT_EQ(-1.0, web_wheel->wheelTicksX);
84 EXPECT_EQ(-2.0, web_wheel->wheelTicksY);
86 EXPECT_FALSE(web_wheel->scrollByPage);
87 EXPECT_FALSE(web_wheel->hasPreciseScrollingDeltas);
88 EXPECT_TRUE(web_wheel->canScroll);
90 // Exercise the round-trip converter.
91 mojo::EventPtr mojo_other_event(mojo::Event::From(*original_wheel));
92 scoped_ptr<ui::Event> new_event =
93 mojo_other_event.To<scoped_ptr<ui::Event>>();
94 EXPECT_EQ(ui::ET_MOUSEWHEEL, new_event->type());
96 scoped_ptr<ui::MouseWheelEvent> ui_wheel(
97 static_cast<ui::MouseWheelEvent*>(new_event.release()));
99 EXPECT_EQ(-1 * ui::MouseWheelEvent::kWheelDelta, ui_wheel->x_offset());
100 EXPECT_EQ(-2 * ui::MouseWheelEvent::kWheelDelta, ui_wheel->y_offset());
103 } // namespace
104 } // namespace mojo