Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / remoting / protocol / test_event_matchers.h
bloba8e4afcef68fa8b154ef778d9bfe1d733f3d3147
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.
5 #ifndef REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
6 #define REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
8 #include <cmath>
10 #include "remoting/proto/event.pb.h"
11 #include "testing/gmock/include/gmock/gmock.h"
13 // This file contains matchers for protocol events.
14 namespace remoting {
15 namespace protocol {
16 namespace test {
18 MATCHER_P2(EqualsKeyEvent, usb_keycode, pressed, "") {
19 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
20 arg.pressed() == pressed;
23 MATCHER_P2(EqualsKeyEventWithCapsLock, usb_keycode, pressed, "") {
24 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
25 arg.pressed() == pressed &&
26 arg.lock_states() == KeyEvent::LOCK_STATES_CAPSLOCK;
29 MATCHER_P2(EqualsKeyEventWithNumLock, usb_keycode, pressed, "") {
30 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
31 arg.pressed() == pressed &&
32 arg.lock_states() == KeyEvent::LOCK_STATES_NUMLOCK;
35 MATCHER_P2(EqualsKeyEventWithoutLockStates, usb_keycode, pressed, "") {
36 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
37 arg.pressed() == pressed &&
38 !arg.has_lock_states();
41 MATCHER_P(EqualsTextEvent, text, "") {
42 return arg.text() == text;
45 MATCHER_P2(EqualsMouseMoveEvent, x, y, "") {
46 return arg.x() == x && arg.y() == y;
49 MATCHER_P2(EqualsMouseButtonEvent, button, button_down, "") {
50 return arg.button() == button && arg.button_down() == button_down;
53 MATCHER_P4(EqualsMouseEvent, x, y, button, down, "") {
54 return arg.x() == x && arg.y() == y && arg.button() == button &&
55 arg.button_down() == down;
58 MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") {
59 return arg.mime_type() == mime_type && arg.data() == data;
62 MATCHER_P(EqualsTouchEvent, expected_event, "") {
63 if (arg.event_type() != expected_event.event_type())
64 return false;
66 if (arg.touch_points().size() != expected_event.touch_points().size())
67 return false;
69 for (int i = 0; i < expected_event.touch_points().size(); ++i) {
70 const TouchEventPoint& expected_point = expected_event.touch_points(i);
71 const TouchEventPoint& actual_point = arg.touch_points(i);
73 const bool equal = expected_point.id() == actual_point.id() &&
74 expected_point.x() == actual_point.x() &&
75 expected_point.y() == actual_point.y() &&
76 expected_point.radius_x() == actual_point.radius_x() &&
77 expected_point.radius_y() == actual_point.radius_y() &&
78 expected_point.angle() == actual_point.angle() &&
79 expected_point.pressure() == actual_point.pressure();
80 if (!equal)
81 return false;
84 return true;
87 // If the rounding error for the coordinates checked in TouchPoint* matcher are
88 // within 1 pixel diff, it is acceptable.
89 const float kTestTouchErrorEpsilon = 1.0f;
91 MATCHER_P(EqualsTouchPointCoordinates, expected_event, "") {
92 if (arg.touch_points().size() != expected_event.touch_points().size())
93 return false;
95 for (int i = 0; i < expected_event.touch_points().size(); ++i) {
96 const TouchEventPoint& arg_point = arg.touch_points(i);
97 const TouchEventPoint& expected_point = expected_event.touch_points(i);
98 if (std::abs(expected_point.x() - arg_point.x()) >= kTestTouchErrorEpsilon)
99 return false;
101 if (std::abs(expected_point.y() - arg_point.y()) >= kTestTouchErrorEpsilon)
102 return false;
104 return true;
107 MATCHER_P(EqualsTouchPointRadii, expected_event, "") {
108 if (arg.touch_points().size() != expected_event.touch_points().size())
109 return false;
111 for (int i = 0; i < expected_event.touch_points().size(); ++i) {
112 const TouchEventPoint& arg_point = arg.touch_points(i);
113 const TouchEventPoint& expected_point = expected_event.touch_points(i);
114 if (std::abs(expected_point.radius_x() - arg_point.radius_x()) >=
115 kTestTouchErrorEpsilon) {
116 return false;
119 if (std::abs(expected_point.radius_y() - arg_point.radius_y()) >=
120 kTestTouchErrorEpsilon) {
121 return false;
124 return true;
127 MATCHER_P2(EqualsTouchEventTypeAndId, type, id, "") {
128 if (arg.event_type() != type)
129 return false;
131 if (arg.touch_points().size() != 1)
132 return false;
134 return arg.touch_points(0).id() == id;
137 } // namespace test
138 } // namespace protocol
139 } // namespace remoting
141 #endif // REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_