OLD | NEW |
| (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 <memory> | |
6 #include <vector> | |
7 | |
8 #include "base/logging.h" | |
9 #include "blimp/common/proto/blimp_message.pb.h" | |
10 #include "blimp/common/proto/input.pb.h" | |
11 #include "blimp/net/blimp_message_processor.h" | |
12 #include "blimp/net/input_message_converter.h" | |
13 #include "blimp/net/input_message_generator.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 #include "third_party/WebKit/public/platform/WebGestureDevice.h" | |
16 #include "third_party/WebKit/public/platform/WebGestureEvent.h" | |
17 | |
18 namespace blimp { | |
19 namespace { | |
20 | |
21 void ValidateWebGestureEventRoundTripping(const blink::WebGestureEvent& event) { | |
22 InputMessageGenerator generator; | |
23 InputMessageConverter processor; | |
24 | |
25 std::unique_ptr<BlimpMessage> proto = generator.GenerateMessage(event); | |
26 EXPECT_NE(nullptr, proto.get()); | |
27 EXPECT_EQ(BlimpMessage::kInput, proto->feature_case()); | |
28 | |
29 std::unique_ptr<blink::WebGestureEvent> new_event = | |
30 processor.ProcessMessage(proto->input()); | |
31 EXPECT_NE(nullptr, new_event.get()); | |
32 | |
33 EXPECT_EQ(event.size(), new_event->size()); | |
34 EXPECT_EQ(0, memcmp(&event, new_event.get(), event.size())); | |
35 } | |
36 | |
37 blink::WebGestureEvent BuildBaseTestEvent(blink::WebInputEvent::Type type) { | |
38 blink::WebGestureEvent event(type, blink::WebInputEvent::NoModifiers, | |
39 blink::WebInputEvent::TimeStampForTesting); | |
40 event.x = 2; | |
41 event.y = 3; | |
42 event.globalX = 4; | |
43 event.globalY = 5; | |
44 event.sourceDevice = blink::WebGestureDevice::WebGestureDeviceTouchscreen; | |
45 return event; | |
46 } | |
47 | |
48 } // namespace | |
49 | |
50 TEST(InputMessageTest, TestGestureScrollBeginRoundTrip) { | |
51 blink::WebGestureEvent event = | |
52 BuildBaseTestEvent(blink::WebInputEvent::Type::GestureScrollBegin); | |
53 event.data.scrollBegin.deltaXHint = 2.34f; | |
54 event.data.scrollBegin.deltaYHint = 3.45f; | |
55 event.data.scrollBegin.targetViewport = true; | |
56 ValidateWebGestureEventRoundTripping(event); | |
57 } | |
58 | |
59 TEST(InputMessageTest, TestGestureScrollEndRoundTrip) { | |
60 blink::WebGestureEvent event = | |
61 BuildBaseTestEvent(blink::WebInputEvent::Type::GestureScrollEnd); | |
62 ValidateWebGestureEventRoundTripping(event); | |
63 } | |
64 | |
65 TEST(InputMessageTest, TestGestureScrollUpdateRoundTrip) { | |
66 blink::WebGestureEvent event = | |
67 BuildBaseTestEvent(blink::WebInputEvent::Type::GestureScrollUpdate); | |
68 event.data.scrollUpdate.deltaX = 2.34f; | |
69 event.data.scrollUpdate.deltaY = 3.45f; | |
70 event.data.scrollUpdate.velocityX = 4.56f; | |
71 event.data.scrollUpdate.velocityY = 5.67f; | |
72 event.data.scrollUpdate.previousUpdateInSequencePrevented = true; | |
73 event.data.scrollUpdate.preventPropagation = true; | |
74 event.data.scrollUpdate.inertialPhase = blink::WebGestureEvent::MomentumPhase; | |
75 ValidateWebGestureEventRoundTripping(event); | |
76 } | |
77 | |
78 TEST(InputMessageTest, TestGestureFlingStartRoundTrip) { | |
79 blink::WebGestureEvent event = | |
80 BuildBaseTestEvent(blink::WebInputEvent::Type::GestureFlingStart); | |
81 event.data.flingStart.velocityX = 2.34f; | |
82 event.data.flingStart.velocityY = 3.45f; | |
83 event.data.flingStart.targetViewport = true; | |
84 ValidateWebGestureEventRoundTripping(event); | |
85 } | |
86 | |
87 TEST(InputMessageTest, TestGestureFlingCancelRoundTrip) { | |
88 blink::WebGestureEvent event = | |
89 BuildBaseTestEvent(blink::WebInputEvent::Type::GestureFlingCancel); | |
90 event.data.flingCancel.preventBoosting = true; | |
91 ValidateWebGestureEventRoundTripping(event); | |
92 } | |
93 | |
94 TEST(InputMessageTest, TestGestureTapRoundTrip) { | |
95 blink::WebGestureEvent event = | |
96 BuildBaseTestEvent(blink::WebGestureEvent::Type::GestureTap); | |
97 event.data.tap.tapCount = 3; | |
98 event.data.tap.width = 2.34f; | |
99 event.data.tap.height = 3.45f; | |
100 ValidateWebGestureEventRoundTripping(event); | |
101 } | |
102 | |
103 TEST(InputMessageTest, TestGesturePinchBeginRoundTrip) { | |
104 blink::WebGestureEvent event = | |
105 BuildBaseTestEvent(blink::WebInputEvent::Type::GesturePinchBegin); | |
106 ValidateWebGestureEventRoundTripping(event); | |
107 } | |
108 | |
109 TEST(InputMessageTest, TestGesturePinchEndRoundTrip) { | |
110 blink::WebGestureEvent event = | |
111 BuildBaseTestEvent(blink::WebInputEvent::Type::GesturePinchEnd); | |
112 ValidateWebGestureEventRoundTripping(event); | |
113 } | |
114 | |
115 TEST(InputMessageTest, TestGesturePinchUpdateRoundTrip) { | |
116 blink::WebGestureEvent event = | |
117 BuildBaseTestEvent(blink::WebInputEvent::Type::GesturePinchUpdate); | |
118 event.data.pinchUpdate.zoomDisabled = true; | |
119 event.data.pinchUpdate.scale = 2.34f; | |
120 ValidateWebGestureEventRoundTripping(event); | |
121 } | |
122 | |
123 TEST(InputMessageTest, TestUnsupportedInputEventSerializationFails) { | |
124 // We currently do not support MouseWheel events. If that changes update | |
125 // this test. | |
126 blink::WebGestureEvent event(blink::WebInputEvent::Type::MouseWheel, | |
127 blink::WebInputEvent::NoModifiers, | |
128 blink::WebInputEvent::TimeStampForTesting); | |
129 InputMessageGenerator generator; | |
130 EXPECT_EQ(nullptr, generator.GenerateMessage(event).get()); | |
131 } | |
132 | |
133 TEST(InputMessageConverterTest, TestTextInputTypeToProtoConversion) { | |
134 for (size_t i = ui::TextInputType::TEXT_INPUT_TYPE_TEXT; | |
135 i < ui::TextInputType::TEXT_INPUT_TYPE_MAX; i++) { | |
136 ui::TextInputType type = static_cast<ui::TextInputType>(i); | |
137 EXPECT_EQ(type, InputMessageConverter::TextInputTypeFromProto( | |
138 InputMessageConverter::TextInputTypeToProto(type))); | |
139 } | |
140 } | |
141 | |
142 TEST(InputMessageTest, TestGestureTapDownRoundTrip) { | |
143 blink::WebGestureEvent event = | |
144 BuildBaseTestEvent(blink::WebGestureEvent::Type::GestureTapDown); | |
145 event.data.tapDown.width = 2.3f; | |
146 event.data.tapDown.height = 3.4f; | |
147 ValidateWebGestureEventRoundTripping(event); | |
148 } | |
149 | |
150 TEST(InputMessageTest, TestGestureTapCancelRoundTrip) { | |
151 blink::WebGestureEvent event = | |
152 BuildBaseTestEvent(blink::WebGestureEvent::Type::GestureTapCancel); | |
153 ValidateWebGestureEventRoundTripping(event); | |
154 } | |
155 | |
156 TEST(InputMessageTest, TestGestureTapUnconfirmedRoundTrip) { | |
157 blink::WebGestureEvent event = | |
158 BuildBaseTestEvent(blink::WebGestureEvent::Type::GestureTapUnconfirmed); | |
159 event.data.tap.tapCount = 2; | |
160 event.data.tap.width = 2.3f; | |
161 event.data.tap.height = 3.4f; | |
162 ValidateWebGestureEventRoundTripping(event); | |
163 } | |
164 | |
165 TEST(InputMessageTest, TestGestureShowPressRoundTrip) { | |
166 blink::WebGestureEvent event = | |
167 BuildBaseTestEvent(blink::WebGestureEvent::Type::GestureShowPress); | |
168 event.data.showPress.width = 2.3f; | |
169 event.data.showPress.height = 3.4f; | |
170 ValidateWebGestureEventRoundTripping(event); | |
171 } | |
172 | |
173 } // namespace blimp | |
OLD | NEW |