Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: mojo/converters/input_events/tests/input_events_unittest.cc

Issue 1313353010: Overhaul Mandoline event transport code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
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"
13
14 using ui::EventTimeForNow;
15 using blink::WebInputEvent;
16 using blink::WebMouseEvent;
17 using blink::WebMouseWheelEvent;
18
19 namespace mojo {
20 namespace {
21
22 TEST(InputEventLibTest, MouseEventConversion) {
23 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, gfx::Point(1, 2),
24 gfx::Point(3, 4), EventTimeForNow(), 0, 0);
25
26 // this line can be better...
27 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
28
29 EXPECT_TRUE(mojo_event->action == mojo::EVENT_TYPE_POINTER_DOWN);
30 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.
31
32 scoped_ptr<blink::WebInputEvent> webevent =
33 mojo_event.To<scoped_ptr<blink::WebInputEvent>>();
34
35 EXPECT_TRUE(webevent != 0);
36 EXPECT_EQ(WebInputEvent::MouseDown, webevent->type);
37
38 scoped_ptr<WebMouseEvent> web_mouse_event(
39 static_cast<WebMouseEvent*>(webevent.release()));
40
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);
45 }
46
47 TEST(InputEventLibTest, MouseWheelEventConversionNonPrecise) {
48 ui::MouseWheelEvent original_wheel(
49 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.
50 gfx::PointF(3.0, 4.0), EventTimeForNow(), 0, 0);
51
52 // this line can be better...
53 mojo::EventPtr mojo_event(
54 mojo::Event::From(*(ui::Event::Clone(original_wheel))));
55
56 EXPECT_TRUE(mojo_event->action == mojo::EVENT_TYPE_POINTER_MOVE);
57 EXPECT_TRUE(mojo_event->pointer_data->kind = POINTER_KIND_WHEEL);
58
59 // Exercise the blink converter.
60 scoped_ptr<blink::WebInputEvent> webevent =
61 mojo_event.To<scoped_ptr<blink::WebInputEvent>>();
62
63 EXPECT_TRUE(webevent != 0);
64 EXPECT_EQ(WebInputEvent::MouseWheel, webevent->type);
65
66 scoped_ptr<WebMouseWheelEvent> web_wheel(
67 static_cast<WebMouseWheelEvent*>(webevent.release()));
68
69 EXPECT_EQ(1, web_wheel->x);
70 EXPECT_EQ(2, web_wheel->y);
71 EXPECT_EQ(3, web_wheel->globalX);
72 EXPECT_EQ(4, web_wheel->globalY);
73
74 EXPECT_EQ(-1.0 * 53, web_wheel->deltaX);
75 EXPECT_EQ(-2.0 * 53, web_wheel->deltaY);
76
77 EXPECT_EQ(-1.0, web_wheel->wheelTicksX);
78 EXPECT_EQ(-2.0, web_wheel->wheelTicksY);
79
80 EXPECT_FALSE(web_wheel->scrollByPage);
81 EXPECT_FALSE(web_wheel->hasPreciseScrollingDeltas);
82 EXPECT_TRUE(web_wheel->canScroll);
83
84 // Exercise the round-trip converter.
85 // this line can be better...
86 mojo::EventPtr mojo_other_event(
87 mojo::Event::From(*(ui::Event::Clone(original_wheel))));
88 scoped_ptr<ui::Event> new_event =
89 mojo_other_event.To<scoped_ptr<ui::Event>>();
90 EXPECT_EQ(ui::ET_MOUSEWHEEL, new_event->type());
91
92 scoped_ptr<ui::MouseWheelEvent> ui_wheel(
93 static_cast<ui::MouseWheelEvent*>(new_event.release()));
94
95 EXPECT_EQ(-53, ui_wheel->x_offset());
96 EXPECT_EQ(-106, ui_wheel->y_offset());
97 }
98
99 } // namespace
100 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698