Chromium Code Reviews| 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 "blimp/common/input/input_event_conversions.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "blimp/common/proto/input.pb.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 #include "third_party/WebKit/public/platform/WebGestureDevice.h" | |
| 12 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 13 | |
| 14 namespace blimp { | |
| 15 namespace { | |
| 16 | |
| 17 const size_t kWebGestureEventCount = blink::WebGestureEvent::GestureTypeLast | |
| 18 - blink::WebGestureEvent::GestureTypeFirst + 1; | |
| 19 | |
| 20 void ValidateWebInputEventRoundTripping(const blink::WebInputEvent& event) { | |
| 21 InputMessage proto; | |
| 22 WebInputEventToProto(event, &proto); | |
| 23 | |
| 24 scoped_ptr<blink::WebInputEvent> new_event = | |
| 25 ProtoToWebInputEvent(proto); | |
| 26 | |
| 27 EXPECT_NE(nullptr, new_event); | |
| 28 EXPECT_EQ(event.size, new_event->size); | |
| 29 EXPECT_EQ(0, memcmp(&event, new_event.get(), event.size)); | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 TEST(InputEventConversionsTest, TestWebInputEventTypeSerialization) { | |
| 35 for (int type = blink::WebInputEvent::Type::TypeFirst; | |
| 36 type != blink::WebInputEvent::Type::TypeLast; type++) { | |
| 37 scoped_ptr<blink::WebInputEvent> event; | |
| 38 // As more input event types are serialized, add the methods to create those | |
| 39 // types of WebInputEvent objects here. | |
| 40 if (type >= blink::WebInputEvent::Type::GestureTypeFirst && | |
| 41 type <= blink::WebInputEvent::Type::GestureTypeLast) { | |
| 42 event.reset(new blink::WebGestureEvent); | |
| 43 } else { | |
| 44 continue; | |
| 45 } | |
| 46 event->type = static_cast<blink::WebInputEvent::Type>(type); | |
| 47 ValidateWebInputEventRoundTripping(*event); | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 TEST(InputEventConversionsTest, TestWebGestureDeviceSerialization) { | |
| 52 blink::WebGestureEvent event; | |
| 53 event.type = blink::WebGestureEvent::Type::GestureTap; | |
| 54 | |
| 55 for (int source = blink::WebGestureDevice::WebGestureDeviceUninitialized; | |
| 56 source != blink::WebGestureDevice::WebGestureDeviceTouchscreen; | |
| 57 source++) { | |
| 58 event.sourceDevice = static_cast<blink::WebGestureDevice>(source); | |
| 59 ValidateWebInputEventRoundTripping(event); | |
| 60 } | |
| 61 } | |
| 62 | |
| 63 TEST(InputEventConversionsTest, TestWebGestureEvents) { | |
| 64 blink::WebGestureEvent events[kWebGestureEventCount]; | |
| 65 | |
| 66 // Set the custom parameters for each type of event. | |
| 67 { | |
|
Kevin M
2015/11/12 21:20:05
Curly braces aren't needed since you aren't reusin
David Trainor- moved to gerrit
2015/11/12 22:14:14
Gah good point! Because I changed this to a vecto
David Trainor- moved to gerrit
2015/11/12 22:14:14
Gah good point! If I end up pushing these to a ve
| |
| 68 events[0].type = blink::WebGestureEvent::Type::GestureScrollBegin; | |
| 69 events[0].data.scrollBegin.deltaXHint = 2.34f; | |
| 70 events[0].data.scrollBegin.deltaYHint = 3.45f; | |
| 71 events[0].data.scrollBegin.targetViewport = true; | |
| 72 } | |
| 73 | |
| 74 { | |
| 75 events[1].type = blink::WebGestureEvent::Type::GestureScrollEnd; | |
| 76 } | |
| 77 | |
| 78 { | |
| 79 events[2].type = blink::WebGestureEvent::Type::GestureScrollUpdate; | |
| 80 events[2].data.scrollUpdate.deltaX = 2.34f; | |
| 81 events[2].data.scrollUpdate.deltaY = 3.45f; | |
| 82 events[2].data.scrollUpdate.velocityX = 4.56f; | |
| 83 events[2].data.scrollUpdate.velocityY = 5.67f; | |
| 84 events[2].data.scrollUpdate.previousUpdateInSequencePrevented = true; | |
| 85 events[2].data.scrollUpdate.preventPropagation = true; | |
| 86 events[2].data.scrollUpdate.inertial = true; | |
| 87 } | |
| 88 | |
| 89 { | |
| 90 events[3].type = blink::WebGestureEvent::Type::GestureFlingStart; | |
| 91 events[3].data.flingStart.velocityX = 2.34f; | |
| 92 events[3].data.flingStart.velocityY = 3.45f; | |
| 93 events[3].data.flingStart.targetViewport = true; | |
| 94 } | |
| 95 | |
| 96 { | |
| 97 events[4].type = blink::WebGestureEvent::Type::GestureFlingCancel; | |
| 98 events[4].data.flingCancel.preventBoosting = true; | |
| 99 } | |
| 100 | |
| 101 { | |
| 102 events[5].type = blink::WebGestureEvent::Type::GestureShowPress; | |
| 103 events[5].data.showPress.width = 2.34f; | |
| 104 events[5].data.showPress.height = 3.45f; | |
| 105 } | |
| 106 | |
| 107 { | |
| 108 events[6].type = blink::WebGestureEvent::Type::GestureTap; | |
| 109 events[6].data.tap.tapCount = 3; | |
| 110 events[6].data.tap.width = 2.34f; | |
| 111 events[6].data.tap.height = 3.45f; | |
| 112 } | |
| 113 | |
| 114 { | |
| 115 events[7].type = blink::WebGestureEvent::Type::GestureTapUnconfirmed; | |
| 116 events[7].data.tap.tapCount = 3; | |
| 117 events[7].data.tap.width = 2.34f; | |
| 118 events[7].data.tap.height = 3.45f; | |
| 119 } | |
| 120 | |
| 121 { | |
| 122 events[8].type = blink::WebGestureEvent::Type::GestureTapDown; | |
| 123 events[8].data.tapDown.width = 2.34f; | |
| 124 events[8].data.tapDown.height = 3.45f; | |
| 125 } | |
| 126 | |
| 127 { | |
| 128 events[9].type = blink::WebGestureEvent::Type::GestureTapCancel; | |
| 129 } | |
| 130 | |
| 131 { | |
| 132 events[10].type = blink::WebGestureEvent::Type::GestureDoubleTap; | |
| 133 events[10].data.tap.tapCount = 3; | |
| 134 events[10].data.tap.width = 2.34f; | |
| 135 events[10].data.tap.height = 3.45f; | |
| 136 } | |
| 137 | |
| 138 { | |
| 139 events[11].type = blink::WebGestureEvent::Type::GestureTwoFingerTap; | |
| 140 events[11].data.twoFingerTap.firstFingerWidth = 2.34f; | |
| 141 events[11].data.twoFingerTap.firstFingerHeight = 3.45f; | |
| 142 } | |
| 143 | |
| 144 { | |
| 145 events[12].type = blink::WebGestureEvent::Type::GestureLongPress; | |
| 146 events[12].data.longPress.width = 2.34f; | |
| 147 events[12].data.longPress.height = 3.45f; | |
| 148 } | |
| 149 | |
| 150 { | |
| 151 events[13].type = blink::WebGestureEvent::Type::GestureLongTap; | |
| 152 } | |
| 153 | |
| 154 { | |
| 155 events[14].type = blink::WebGestureEvent::Type::GesturePinchBegin; | |
| 156 } | |
| 157 | |
| 158 { | |
| 159 events[15].type = blink::WebGestureEvent::Type::GesturePinchEnd; | |
| 160 } | |
| 161 | |
| 162 { | |
| 163 events[16].type = blink::WebGestureEvent::Type::GesturePinchUpdate; | |
| 164 events[16].data.pinchUpdate.zoomDisabled = true; | |
| 165 events[16].data.pinchUpdate.scale = 2.34f; | |
| 166 } | |
| 167 | |
| 168 // Make sure no new events were added that weren't serialized. | |
| 169 EXPECT_EQ(17U, kWebGestureEventCount); | |
|
Kevin M
2015/11/12 21:20:05
If you want to be extra safe, what about accumulat
David Trainor- moved to gerrit
2015/11/12 22:14:14
Done.
| |
| 170 | |
| 171 for (size_t i = 0; i < kWebGestureEventCount; i++) { | |
| 172 // Set the common parameters. | |
| 173 events[i].timeStampSeconds = 1.23; | |
| 174 events[i].x = 2; | |
| 175 events[i].y = 3; | |
| 176 events[i].globalX = 4; | |
| 177 events[i].globalY = 5; | |
| 178 events[i].sourceDevice = blink::WebGestureDevice::WebGestureDeviceTouchpad; | |
| 179 | |
| 180 // Validate that the event is the exact same after serialization and | |
| 181 // deserialization. | |
| 182 ValidateWebInputEventRoundTripping(events[i]); | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 } // namespace blimp | |
| OLD | NEW |