Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ | 5 #ifndef REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ |
| 6 #define REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ | 6 #define REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ |
| 7 | 7 |
| 8 #include <cmath> | |
| 9 | |
| 10 #include "remoting/proto/event.pb.h" | |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 9 | 12 |
| 10 // This file contains matchers for events. | 13 // This file contains matchers for events. |
| 11 namespace remoting { | 14 namespace remoting { |
| 12 namespace protocol { | 15 namespace protocol { |
|
Wez
2015/03/12 00:13:58
I'd recommend putting these in a test namespace, e
Rintaro Kuroiwa
2015/03/12 18:51:27
Done.
| |
| 13 | 16 |
| 14 MATCHER_P(TouchEventEqual, expected_event, "Expect touch events equal.") { | 17 MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { |
|
Wez
2015/03/12 00:13:58
These should be EqualsKeyEvent, since we no longer
Rintaro Kuroiwa
2015/03/12 18:51:27
Done.
| |
| 18 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && | |
| 19 arg.pressed() == pressed; | |
| 20 } | |
| 21 | |
| 22 MATCHER_P2(EqualsUsbEventWithCapsLock, usb_keycode, pressed, "") { | |
| 23 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && | |
| 24 arg.pressed() == pressed && | |
| 25 // |lock_states| is hardcoded to LOCK_STATES_CAPSLOCK in all key | |
| 26 // events. | |
|
Wez
2015/03/12 00:13:58
You mean in all tests, here and below?
Rintaro Kuroiwa
2015/03/12 18:51:27
Oops, this is me trying to be smart about keeping
| |
| 27 arg.lock_states() == KeyEvent::LOCK_STATES_CAPSLOCK; | |
| 28 } | |
| 29 | |
| 30 MATCHER_P2(EqualsUsbEventWithNumLock, usb_keycode, pressed, "") { | |
| 31 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && | |
| 32 arg.pressed() == pressed && | |
| 33 // |lock_states| is hardcoded to LOCK_STATES_NUMLOCK in all key events. | |
| 34 arg.lock_states() == KeyEvent::LOCK_STATES_NUMLOCK; | |
| 35 } | |
| 36 | |
| 37 // Verify the usb key code and the "pressed" state. | |
| 38 // Also verify that the event doesn't have |lock_states| set. | |
| 39 MATCHER_P2(EqualsUsbEventWithoutLockStates, usb_keycode, pressed, "") { | |
| 40 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && | |
| 41 arg.pressed() == pressed && | |
| 42 !arg.has_lock_states(); | |
| 43 } | |
| 44 | |
| 45 MATCHER_P(EqualsTextEvent, text, "") { | |
| 46 return arg.text() == text; | |
| 47 } | |
| 48 | |
| 49 MATCHER_P2(EqualsMouseMoveEvent, x, y, "") { | |
| 50 return arg.x() == x && arg.y() == y; | |
| 51 } | |
| 52 | |
| 53 MATCHER_P2(EqualsMouseButtonEvent, button, button_down, "") { | |
| 54 return arg.button() == button && arg.button_down() == button_down; | |
| 55 } | |
| 56 | |
| 57 MATCHER_P4(EqualsMouseEvent, x, y, button, down, "") { | |
| 58 return arg.x() == x && arg.y() == y && arg.button() == button && | |
| 59 arg.button_down() == down; | |
| 60 } | |
| 61 | |
| 62 MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") { | |
| 63 return arg.mime_type() == mime_type && arg.data() == data; | |
| 64 } | |
| 65 | |
| 66 MATCHER_P(EqualsTouchEvent, expected_event, "") { | |
| 15 if (arg.event_type() != expected_event.event_type()) | 67 if (arg.event_type() != expected_event.event_type()) |
| 16 return false; | 68 return false; |
| 17 | 69 |
| 18 if (arg.touch_points().size() != expected_event.touch_points().size()) | 70 if (arg.touch_points().size() != expected_event.touch_points().size()) |
| 19 return false; | 71 return false; |
| 20 | 72 |
| 21 for (int i = 0; i < expected_event.touch_points().size(); ++i) { | 73 for (int i = 0; i < expected_event.touch_points().size(); ++i) { |
| 22 const protocol::TouchEventPoint& expected_point = | 74 const TouchEventPoint& expected_point = expected_event.touch_points(i); |
| 23 expected_event.touch_points(i); | 75 const TouchEventPoint& actual_point = arg.touch_points(i); |
| 24 const protocol::TouchEventPoint& actual_point = arg.touch_points(i); | |
| 25 | 76 |
| 26 const bool equal = expected_point.id() == actual_point.id() && | 77 const bool equal = expected_point.id() == actual_point.id() && |
| 27 expected_point.x() == actual_point.x() && | 78 expected_point.x() == actual_point.x() && |
| 28 expected_point.y() == actual_point.y() && | 79 expected_point.y() == actual_point.y() && |
| 29 expected_point.radius_x() == actual_point.radius_x() && | 80 expected_point.radius_x() == actual_point.radius_x() && |
| 30 expected_point.radius_y() == actual_point.radius_y() && | 81 expected_point.radius_y() == actual_point.radius_y() && |
| 31 expected_point.angle() == actual_point.angle() && | 82 expected_point.angle() == actual_point.angle() && |
| 32 expected_point.pressure() == actual_point.pressure(); | 83 expected_point.pressure() == actual_point.pressure(); |
| 33 if (!equal) | 84 if (!equal) |
| 34 return false; | 85 return false; |
| 35 } | 86 } |
| 36 | 87 |
| 37 return true; | 88 return true; |
| 38 } | 89 } |
| 39 | 90 |
| 40 MATCHER(IsTouchCancelEvent, "expect touch cancel event") { | 91 // If the rounding error for the coordinates checked in TouchPoint* matcher are |
| 41 return arg.event_type() == protocol::TouchEvent::TOUCH_POINT_CANCEL; | 92 // within 1 pixel diff, it is acceptable. |
| 93 const float kTestTouchErrorEpsilon = 1.0f; | |
| 94 | |
| 95 MATCHER_P(EqualsTouchPointCoordinates, expected_event, "") { | |
| 96 if (arg.touch_points().size() != expected_event.touch_points().size()) | |
| 97 return false; | |
| 98 | |
| 99 for (int i = 0; i < expected_event.touch_points().size(); ++i) { | |
| 100 const TouchEventPoint& arg_point = arg.touch_points(i); | |
| 101 const TouchEventPoint& expected_point = expected_event.touch_points(i); | |
| 102 if (std::abs(expected_point.x() - arg_point.x()) >= kTestTouchErrorEpsilon) | |
| 103 return false; | |
| 104 | |
| 105 if (std::abs(expected_point.y() - arg_point.y()) >= kTestTouchErrorEpsilon) | |
| 106 return false; | |
| 107 } | |
| 108 return true; | |
| 109 } | |
| 110 | |
| 111 MATCHER_P(EqualsTouchPointRadii, expected_event, "") { | |
| 112 if (arg.touch_points().size() != expected_event.touch_points().size()) | |
| 113 return false; | |
| 114 | |
| 115 for (int i = 0; i < expected_event.touch_points().size(); ++i) { | |
| 116 const TouchEventPoint& arg_point = arg.touch_points(i); | |
| 117 const TouchEventPoint& expected_point = expected_event.touch_points(i); | |
| 118 if (std::abs(expected_point.radius_x() - arg_point.radius_x()) >= | |
| 119 kTestTouchErrorEpsilon) { | |
| 120 return false; | |
| 121 } | |
| 122 | |
| 123 if (std::abs(expected_point.radius_y() - arg_point.radius_y()) >= | |
| 124 kTestTouchErrorEpsilon) { | |
| 125 return false; | |
| 126 } | |
| 127 } | |
| 128 return true; | |
| 129 } | |
| 130 | |
| 131 MATCHER_P2(EqualsTouchEventTypeAndId, type, id, "") { | |
| 132 if (arg.event_type() != type) | |
| 133 return false; | |
| 134 | |
| 135 // Expect only one touch point. | |
| 136 if (arg.touch_points().size() != 1) | |
| 137 return false; | |
| 138 | |
| 139 return arg.touch_points(0).id() == id; | |
| 42 } | 140 } |
| 43 | 141 |
| 44 } // namespace protocol | 142 } // namespace protocol |
| 45 } // namespace remoting | 143 } // namespace remoting |
| 46 | 144 |
| 47 #endif // REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ | 145 #endif // REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ |
| OLD | NEW |