| Index: remoting/protocol/test_event_matchers.h
|
| diff --git a/remoting/protocol/test_event_matchers.h b/remoting/protocol/test_event_matchers.h
|
| index 18a6fc34479d79f1bf047de0d83fa755eb50fa06..a8e4afcef68fa8b154ef778d9bfe1d733f3d3147 100644
|
| --- a/remoting/protocol/test_event_matchers.h
|
| +++ b/remoting/protocol/test_event_matchers.h
|
| @@ -5,13 +5,61 @@
|
| #ifndef REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
|
| #define REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
|
|
|
| +#include <cmath>
|
| +
|
| +#include "remoting/proto/event.pb.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
|
|
| -// This file contains matchers for events.
|
| +// This file contains matchers for protocol events.
|
| namespace remoting {
|
| namespace protocol {
|
| +namespace test {
|
| +
|
| +MATCHER_P2(EqualsKeyEvent, usb_keycode, pressed, "") {
|
| + return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
|
| + arg.pressed() == pressed;
|
| +}
|
| +
|
| +MATCHER_P2(EqualsKeyEventWithCapsLock, usb_keycode, pressed, "") {
|
| + return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
|
| + arg.pressed() == pressed &&
|
| + arg.lock_states() == KeyEvent::LOCK_STATES_CAPSLOCK;
|
| +}
|
| +
|
| +MATCHER_P2(EqualsKeyEventWithNumLock, usb_keycode, pressed, "") {
|
| + return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
|
| + arg.pressed() == pressed &&
|
| + arg.lock_states() == KeyEvent::LOCK_STATES_NUMLOCK;
|
| +}
|
| +
|
| +MATCHER_P2(EqualsKeyEventWithoutLockStates, usb_keycode, pressed, "") {
|
| + return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
|
| + arg.pressed() == pressed &&
|
| + !arg.has_lock_states();
|
| +}
|
|
|
| -MATCHER_P(TouchEventEqual, expected_event, "Expect touch events equal.") {
|
| +MATCHER_P(EqualsTextEvent, text, "") {
|
| + return arg.text() == text;
|
| +}
|
| +
|
| +MATCHER_P2(EqualsMouseMoveEvent, x, y, "") {
|
| + return arg.x() == x && arg.y() == y;
|
| +}
|
| +
|
| +MATCHER_P2(EqualsMouseButtonEvent, button, button_down, "") {
|
| + return arg.button() == button && arg.button_down() == button_down;
|
| +}
|
| +
|
| +MATCHER_P4(EqualsMouseEvent, x, y, button, down, "") {
|
| + return arg.x() == x && arg.y() == y && arg.button() == button &&
|
| + arg.button_down() == down;
|
| +}
|
| +
|
| +MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") {
|
| + return arg.mime_type() == mime_type && arg.data() == data;
|
| +}
|
| +
|
| +MATCHER_P(EqualsTouchEvent, expected_event, "") {
|
| if (arg.event_type() != expected_event.event_type())
|
| return false;
|
|
|
| @@ -19,9 +67,8 @@ MATCHER_P(TouchEventEqual, expected_event, "Expect touch events equal.") {
|
| return false;
|
|
|
| for (int i = 0; i < expected_event.touch_points().size(); ++i) {
|
| - const protocol::TouchEventPoint& expected_point =
|
| - expected_event.touch_points(i);
|
| - const protocol::TouchEventPoint& actual_point = arg.touch_points(i);
|
| + const TouchEventPoint& expected_point = expected_event.touch_points(i);
|
| + const TouchEventPoint& actual_point = arg.touch_points(i);
|
|
|
| const bool equal = expected_point.id() == actual_point.id() &&
|
| expected_point.x() == actual_point.x() &&
|
| @@ -37,10 +84,57 @@ MATCHER_P(TouchEventEqual, expected_event, "Expect touch events equal.") {
|
| return true;
|
| }
|
|
|
| -MATCHER(IsTouchCancelEvent, "expect touch cancel event") {
|
| - return arg.event_type() == protocol::TouchEvent::TOUCH_POINT_CANCEL;
|
| +// If the rounding error for the coordinates checked in TouchPoint* matcher are
|
| +// within 1 pixel diff, it is acceptable.
|
| +const float kTestTouchErrorEpsilon = 1.0f;
|
| +
|
| +MATCHER_P(EqualsTouchPointCoordinates, expected_event, "") {
|
| + if (arg.touch_points().size() != expected_event.touch_points().size())
|
| + return false;
|
| +
|
| + for (int i = 0; i < expected_event.touch_points().size(); ++i) {
|
| + const TouchEventPoint& arg_point = arg.touch_points(i);
|
| + const TouchEventPoint& expected_point = expected_event.touch_points(i);
|
| + if (std::abs(expected_point.x() - arg_point.x()) >= kTestTouchErrorEpsilon)
|
| + return false;
|
| +
|
| + if (std::abs(expected_point.y() - arg_point.y()) >= kTestTouchErrorEpsilon)
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +MATCHER_P(EqualsTouchPointRadii, expected_event, "") {
|
| + if (arg.touch_points().size() != expected_event.touch_points().size())
|
| + return false;
|
| +
|
| + for (int i = 0; i < expected_event.touch_points().size(); ++i) {
|
| + const TouchEventPoint& arg_point = arg.touch_points(i);
|
| + const TouchEventPoint& expected_point = expected_event.touch_points(i);
|
| + if (std::abs(expected_point.radius_x() - arg_point.radius_x()) >=
|
| + kTestTouchErrorEpsilon) {
|
| + return false;
|
| + }
|
| +
|
| + if (std::abs(expected_point.radius_y() - arg_point.radius_y()) >=
|
| + kTestTouchErrorEpsilon) {
|
| + return false;
|
| + }
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +MATCHER_P2(EqualsTouchEventTypeAndId, type, id, "") {
|
| + if (arg.event_type() != type)
|
| + return false;
|
| +
|
| + if (arg.touch_points().size() != 1)
|
| + return false;
|
| +
|
| + return arg.touch_points(0).id() == id;
|
| }
|
|
|
| +} // namespace test
|
| } // namespace protocol
|
| } // namespace remoting
|
|
|
|
|