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

Unified Diff: remoting/protocol/touch_input_filter_unittest.cc

Issue 799233004: Add touch events to the protocol, the stub layer, and to the client plugin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mac builds Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: remoting/protocol/touch_input_filter_unittest.cc
diff --git a/remoting/protocol/touch_input_filter_unittest.cc b/remoting/protocol/touch_input_filter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f840009547734170c84b52ee7c395a375ca092d3
--- /dev/null
+++ b/remoting/protocol/touch_input_filter_unittest.cc
@@ -0,0 +1,286 @@
+// Copyright (c) 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 "remoting/protocol/touch_input_filter.h"
+
+#include <cmath>
+
+#include "base/logging.h"
+#include "remoting/protocol/protocol_mock_objects.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+namespace protocol {
+
+using ::testing::_;
+
+namespace {
Wez 2015/01/21 03:08:38 nit: Blank line between namespace { and } lines, a
Rintaro Kuroiwa 2015/01/28 01:12:30 Done.
+const float kDefaultRadius = 30.0f;
+
+// If it's within 1 pixel diff, it should be acceptable.
Wez 2015/01/21 03:08:38 What is "it" in this comment? :)
Rintaro Kuroiwa 2015/01/28 01:12:30 Done.
+const float kEpsilon = 1.0f;
+
+MATCHER_P(TouchPointCoordinateEqual,
+ expected_event,
+ "Expect point coordinates equal.") {
+ EXPECT_EQ(expected_event.touch_points().size(), arg.touch_points().size());
+ if (arg.touch_points().size() != expected_event.touch_points().size())
+ return false;
+
+ for (int i = 0; i < expected_event.touch_points().size(); ++i) {
+ const TouchEvent::Point& arg_point = arg.touch_points(i);
+ const TouchEvent::Point& expected_point = expected_event.touch_points(i);
+ EXPECT_NEAR(expected_point.x(), arg_point.x(), kEpsilon);
+ if (std::abs(expected_point.x() - arg_point.x()) >= kEpsilon)
+ return false;
+
+ EXPECT_NEAR(expected_point.y(), arg_point.y(), kEpsilon);
+ if (std::abs(expected_point.y() - arg_point.y()) >= kEpsilon)
+ return false;
+ }
+ return true;
+}
+
+struct Coordinate {
+ float x;
+ float y;
+};
+} // namespace
+
+class TouchInputFilterTest : public ::testing::Test {
+ protected:
+ TouchInputFilterTest() : touch_input_filter_(&mock_stub_) {}
+
+ void AddInputCoordinate(const Coordinate& coordinate) {
+ coordinates_.push_back(coordinate);
+ }
+
+ void AddDefaultTestCoordinate() {
+ coordinates_.push_back({1.0f, 1.0f});
+ }
+
+ void InjectTestTouchEvent() {
+ CHECK(!coordinates_.empty());
+ TouchEvent e;
+ uint32_t id = 1;
+ for (const Coordinate& coordinate : coordinates_) {
+ TouchEvent::Point* point = e.add_touch_points();
+ point->set_event_type(TouchEvent::Point::TOUCH_POINT_MOVE);
+ point->set_id(id++);
+ point->set_x(coordinate.x);
+ point->set_y(coordinate.y);
+ point->set_radius_x(kDefaultRadius);
+ point->set_radius_y(kDefaultRadius);
+ }
+
+ touch_input_filter_.InjectTouchEvent(e);
+ }
+
+ void SetInputDimensions(int width, int height) {
+ touch_input_filter_.set_input_size(webrtc::DesktopSize(width, height));
+ }
+
+ void SetOutputDimensions(int width, int height) {
+ touch_input_filter_.set_output_size(webrtc::DesktopSize(width, height));
+ }
+
+ MockInputStub mock_stub_;
+ TouchInputFilter touch_input_filter_;
+
+private:
+ std::vector<Coordinate> coordinates_;
+};
+
+// TouchInputFilter require both input and output dimensions.
+// These test verify that no events are forwarded to the next InputStub if
+// either dimensions are not set.
+TEST_F(TouchInputFilterTest, BothDimensionsZero) {
+ AddDefaultTestCoordinate();
+ EXPECT_CALL(mock_stub_, InjectTouchEvent(_)).Times(0);
+ InjectTestTouchEvent();
+}
+
+TEST_F(TouchInputFilterTest, SetOnlyInputDimensions) {
+ SetInputDimensions(50, 60);
+ AddDefaultTestCoordinate();
+ EXPECT_CALL(mock_stub_, InjectTouchEvent(_)).Times(0);
+ InjectTestTouchEvent();
+}
+
+TEST_F(TouchInputFilterTest, SetOnlyOutputDimensions) {
+ SetOutputDimensions(50, 60);
+ AddDefaultTestCoordinate();
+ EXPECT_CALL(mock_stub_, InjectTouchEvent(_)).Times(0);
+ InjectTestTouchEvent();
+}
+
+// The x,y coordinate fall in the desktop size.
+TEST_F(TouchInputFilterTest, NoClampingNoScaling) {
+ SetInputDimensions(50, 60);
+ SetOutputDimensions(50, 60);
+
+ AddInputCoordinate({10.0f, 15.0f});
+ TouchEvent expected_out;
+ TouchEvent::Point* point = expected_out.add_touch_points();
+ point->set_x(10.0f);
+ point->set_y(15.0f);
+
+ EXPECT_CALL(mock_stub_,
+ InjectTouchEvent(TouchPointCoordinateEqual(expected_out)));
+ InjectTestTouchEvent();
+}
+
+// Make sure clamping works.
+TEST_F(TouchInputFilterTest, ClampingNoScaling) {
+ SetInputDimensions(50, 60);
+ SetOutputDimensions(50, 60);
+
+ // Note that this could happen if touch started in the chromoting window but
+ // the finger moved off the windows.
+ AddInputCoordinate({-1.0f, 1.0f});
+ TouchEvent expected_out;
+ TouchEvent::Point* point = expected_out.add_touch_points();
+ point->set_x(0.0f);
+ point->set_y(1.0f);
+
+ EXPECT_CALL(mock_stub_,
+ InjectTouchEvent(TouchPointCoordinateEqual(expected_out)));
+ InjectTestTouchEvent();
+}
+
+TEST_F(TouchInputFilterTest, ClampingMultiplePointsNoScaling) {
+ SetInputDimensions(50, 60);
+ SetOutputDimensions(50, 60);
+
+ AddInputCoordinate({-1.0f, 1.0f});
+ TouchEvent expected_out;
+ TouchEvent::Point* point = expected_out.add_touch_points();
+ point->set_x(0.0f);
+ point->set_y(1.0f);
+
+ AddInputCoordinate({-2.0f, 1.0f});
+ point = expected_out.add_touch_points();
+ point->set_x(0.0f);
+ point->set_y(1.0f);
+
+ AddInputCoordinate({-3.0f, -1.0f});
+ point = expected_out.add_touch_points();
+ point->set_x(0.0f);
+ point->set_y(0.0f);
+
+ AddInputCoordinate({100.0f, 100.0f});
+ point = expected_out.add_touch_points();
+ // 1 less than max width and height.
+ point->set_x(49.0f);
+ point->set_y(59.0f);
+
+ EXPECT_CALL(mock_stub_,
+ InjectTouchEvent(TouchPointCoordinateEqual(expected_out)));
+ InjectTestTouchEvent();
+}
+
+// Verify up scaling works. All coordinates should fall inside the output
+// dimensions, after scaling, i.e. no clamping testing.
+TEST_F(TouchInputFilterTest, UpScalingNoClamp) {
+ const int kInputDimension = 20;
+ const int kScalingFactor = 2;
+ SetInputDimensions(kInputDimension, kInputDimension);
+ SetOutputDimensions(kInputDimension * kScalingFactor,
+ kInputDimension * kScalingFactor);
+
+ AddInputCoordinate({1.0f, 1.0f});
+ TouchEvent expected_out;
+ TouchEvent::Point* point = expected_out.add_touch_points();
+ point->set_x(1.0f * kScalingFactor);
+ point->set_y(1.0f * kScalingFactor);
+
+ AddInputCoordinate({5.0f, 3.0f});
+ point = expected_out.add_touch_points();
+ point->set_x(5.0f * kScalingFactor);
+ point->set_y(3.0f * kScalingFactor);
+ EXPECT_CALL(mock_stub_,
+ InjectTouchEvent(TouchPointCoordinateEqual(expected_out)));
+ InjectTestTouchEvent();
+}
+
+// Verify up scaling works.
+TEST_F(TouchInputFilterTest, UpScaling) {
+ const int kInputDimension = 20;
+ const int kScalingFactor = 2;
+ SetInputDimensions(kInputDimension, kInputDimension);
+ SetOutputDimensions(kInputDimension * kScalingFactor,
+ kInputDimension * kScalingFactor);
+
+ AddInputCoordinate({25.0f, 25.0f});
+ TouchEvent expected_out;
+ TouchEvent::Point* point = expected_out.add_touch_points();
+ point->set_x(39.0f);
+ point->set_y(39.0f);
+
+ EXPECT_CALL(mock_stub_,
+ InjectTouchEvent(TouchPointCoordinateEqual(expected_out)));
+ InjectTestTouchEvent();
+}
+
+// Verify down scaling works. All coordinates should fall inside the output
+// dimensions, after scaling, i.e. no clamping testing.
+TEST_F(TouchInputFilterTest, DownScalingNoClamp) {
+ const int kOutputDimension = 20;
+ const int kDownScalingFactor = 2;
+ SetInputDimensions(kOutputDimension * kDownScalingFactor,
+ kOutputDimension * kDownScalingFactor);
+ SetOutputDimensions(kOutputDimension, kOutputDimension);
+
+ AddInputCoordinate({2.0f, 2.0f});
+ TouchEvent expected_out;
+ TouchEvent::Point* point = expected_out.add_touch_points();
+ point->set_x(2.0f / kDownScalingFactor);
+ point->set_y(2.0f / kDownScalingFactor);
+
+ AddInputCoordinate({6.0f, 3.0f});
+ point = expected_out.add_touch_points();
+ point->set_x(6.0f / kDownScalingFactor);
+ point->set_y(3.0f / kDownScalingFactor);
+ EXPECT_CALL(mock_stub_,
+ InjectTouchEvent(TouchPointCoordinateEqual(expected_out)));
+ InjectTestTouchEvent();
+}
+
+// Verify down scaling works.
+TEST_F(TouchInputFilterTest, DownScaling) {
+ const int kOutputDimension = 20;
+ const int kDownScalingFactor = 2;
+ SetInputDimensions(kOutputDimension * kDownScalingFactor,
+ kOutputDimension * kDownScalingFactor);
+ SetOutputDimensions(kOutputDimension, kOutputDimension);
+
+ AddInputCoordinate({-20.0f, 10.0f});
+ TouchEvent expected_out;
+ TouchEvent::Point* point = expected_out.add_touch_points();
+ point->set_x(0.0f);
+ point->set_y(10.0f / kDownScalingFactor);
+
+ AddInputCoordinate({10.0f, -20.0f});
+ point = expected_out.add_touch_points();
+ point->set_x(10.0f / kDownScalingFactor);
+ point->set_y(0.0f);
+
+ AddInputCoordinate({6.0f, 80.0f});
+ point = expected_out.add_touch_points();
+ point->set_x(6.0f / kDownScalingFactor);
+ point->set_y(kOutputDimension - 1);
+
+ AddInputCoordinate({80.0f, 6.0f});
+ point = expected_out.add_touch_points();
+ point->set_x(kOutputDimension - 1);
+ point->set_y(6.0f / kDownScalingFactor);
+
+ EXPECT_CALL(mock_stub_,
+ InjectTouchEvent(TouchPointCoordinateEqual(expected_out)));
+ InjectTestTouchEvent();
+}
+
+} // namespace protocol
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698