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

Unified Diff: blimp/common/input/input_event_conversions_unittest.cc

Issue 1426993008: Serialize a subset of WebInputEvents to protobufs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/common/input/input_event_conversions.cc ('k') | blimp/common/proto/input.proto » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/common/input/input_event_conversions_unittest.cc
diff --git a/blimp/common/input/input_event_conversions_unittest.cc b/blimp/common/input/input_event_conversions_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f676ea4337411175414412f75ed5ff2e478e9084
--- /dev/null
+++ b/blimp/common/input/input_event_conversions_unittest.cc
@@ -0,0 +1,186 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/common/input/input_event_conversions.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "blimp/common/proto/input.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "third_party/WebKit/public/platform/WebGestureDevice.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
+
+namespace blimp {
+namespace {
+
+const size_t kWebGestureEventCount = blink::WebGestureEvent::GestureTypeLast
+ - blink::WebGestureEvent::GestureTypeFirst + 1;
+
+void ValidateWebInputEventRoundTripping(const blink::WebInputEvent& event) {
+ InputMessage proto;
+ WebInputEventToProto(event, &proto);
+
+ scoped_ptr<blink::WebInputEvent> new_event =
+ ProtoToWebInputEvent(proto);
+
+ EXPECT_NE(nullptr, new_event);
+ EXPECT_EQ(event.size, new_event->size);
+ EXPECT_EQ(0, memcmp(&event, new_event.get(), event.size));
+}
+
+} // namespace
+
+TEST(InputEventConversionsTest, TestWebInputEventTypeSerialization) {
+ for (int type = blink::WebInputEvent::Type::TypeFirst;
+ type != blink::WebInputEvent::Type::TypeLast; type++) {
+ scoped_ptr<blink::WebInputEvent> event;
+ // As more input event types are serialized, add the methods to create those
+ // types of WebInputEvent objects here.
+ if (type >= blink::WebInputEvent::Type::GestureTypeFirst &&
+ type <= blink::WebInputEvent::Type::GestureTypeLast) {
+ event.reset(new blink::WebGestureEvent);
+ } else {
+ continue;
+ }
+ event->type = static_cast<blink::WebInputEvent::Type>(type);
+ ValidateWebInputEventRoundTripping(*event);
+ }
+}
+
+TEST(InputEventConversionsTest, TestWebGestureDeviceSerialization) {
+ blink::WebGestureEvent event;
+ event.type = blink::WebGestureEvent::Type::GestureTap;
+
+ for (int source = blink::WebGestureDevice::WebGestureDeviceUninitialized;
+ source != blink::WebGestureDevice::WebGestureDeviceTouchscreen;
+ source++) {
+ event.sourceDevice = static_cast<blink::WebGestureDevice>(source);
+ ValidateWebInputEventRoundTripping(event);
+ }
+}
+
+TEST(InputEventConversionsTest, TestWebGestureEvents) {
+ blink::WebGestureEvent events[kWebGestureEventCount];
+
+ // Set the custom parameters for each type of event.
+ {
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
+ events[0].type = blink::WebGestureEvent::Type::GestureScrollBegin;
+ events[0].data.scrollBegin.deltaXHint = 2.34f;
+ events[0].data.scrollBegin.deltaYHint = 3.45f;
+ events[0].data.scrollBegin.targetViewport = true;
+ }
+
+ {
+ events[1].type = blink::WebGestureEvent::Type::GestureScrollEnd;
+ }
+
+ {
+ events[2].type = blink::WebGestureEvent::Type::GestureScrollUpdate;
+ events[2].data.scrollUpdate.deltaX = 2.34f;
+ events[2].data.scrollUpdate.deltaY = 3.45f;
+ events[2].data.scrollUpdate.velocityX = 4.56f;
+ events[2].data.scrollUpdate.velocityY = 5.67f;
+ events[2].data.scrollUpdate.previousUpdateInSequencePrevented = true;
+ events[2].data.scrollUpdate.preventPropagation = true;
+ events[2].data.scrollUpdate.inertial = true;
+ }
+
+ {
+ events[3].type = blink::WebGestureEvent::Type::GestureFlingStart;
+ events[3].data.flingStart.velocityX = 2.34f;
+ events[3].data.flingStart.velocityY = 3.45f;
+ events[3].data.flingStart.targetViewport = true;
+ }
+
+ {
+ events[4].type = blink::WebGestureEvent::Type::GestureFlingCancel;
+ events[4].data.flingCancel.preventBoosting = true;
+ }
+
+ {
+ events[5].type = blink::WebGestureEvent::Type::GestureShowPress;
+ events[5].data.showPress.width = 2.34f;
+ events[5].data.showPress.height = 3.45f;
+ }
+
+ {
+ events[6].type = blink::WebGestureEvent::Type::GestureTap;
+ events[6].data.tap.tapCount = 3;
+ events[6].data.tap.width = 2.34f;
+ events[6].data.tap.height = 3.45f;
+ }
+
+ {
+ events[7].type = blink::WebGestureEvent::Type::GestureTapUnconfirmed;
+ events[7].data.tap.tapCount = 3;
+ events[7].data.tap.width = 2.34f;
+ events[7].data.tap.height = 3.45f;
+ }
+
+ {
+ events[8].type = blink::WebGestureEvent::Type::GestureTapDown;
+ events[8].data.tapDown.width = 2.34f;
+ events[8].data.tapDown.height = 3.45f;
+ }
+
+ {
+ events[9].type = blink::WebGestureEvent::Type::GestureTapCancel;
+ }
+
+ {
+ events[10].type = blink::WebGestureEvent::Type::GestureDoubleTap;
+ events[10].data.tap.tapCount = 3;
+ events[10].data.tap.width = 2.34f;
+ events[10].data.tap.height = 3.45f;
+ }
+
+ {
+ events[11].type = blink::WebGestureEvent::Type::GestureTwoFingerTap;
+ events[11].data.twoFingerTap.firstFingerWidth = 2.34f;
+ events[11].data.twoFingerTap.firstFingerHeight = 3.45f;
+ }
+
+ {
+ events[12].type = blink::WebGestureEvent::Type::GestureLongPress;
+ events[12].data.longPress.width = 2.34f;
+ events[12].data.longPress.height = 3.45f;
+ }
+
+ {
+ events[13].type = blink::WebGestureEvent::Type::GestureLongTap;
+ }
+
+ {
+ events[14].type = blink::WebGestureEvent::Type::GesturePinchBegin;
+ }
+
+ {
+ events[15].type = blink::WebGestureEvent::Type::GesturePinchEnd;
+ }
+
+ {
+ events[16].type = blink::WebGestureEvent::Type::GesturePinchUpdate;
+ events[16].data.pinchUpdate.zoomDisabled = true;
+ events[16].data.pinchUpdate.scale = 2.34f;
+ }
+
+ // Make sure no new events were added that weren't serialized.
+ 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.
+
+ for (size_t i = 0; i < kWebGestureEventCount; i++) {
+ // Set the common parameters.
+ events[i].timeStampSeconds = 1.23;
+ events[i].x = 2;
+ events[i].y = 3;
+ events[i].globalX = 4;
+ events[i].globalY = 5;
+ events[i].sourceDevice = blink::WebGestureDevice::WebGestureDeviceTouchpad;
+
+ // Validate that the event is the exact same after serialization and
+ // deserialization.
+ ValidateWebInputEventRoundTripping(events[i]);
+ }
+}
+
+} // namespace blimp
« no previous file with comments | « blimp/common/input/input_event_conversions.cc ('k') | blimp/common/proto/input.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698