| Index: ui/events/test/motion_event_test_utils.cc
|
| diff --git a/ui/events/test/motion_event_test_utils.cc b/ui/events/test/motion_event_test_utils.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7ddc5b5607d9310eeb96f08a0521429f3d2e3b97
|
| --- /dev/null
|
| +++ b/ui/events/test/motion_event_test_utils.cc
|
| @@ -0,0 +1,72 @@
|
| +// Copyright 2014 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 "ui/events/test/motion_event_test_utils.h"
|
| +
|
| +#include <sstream>
|
| +
|
| +#include "ui/events/gesture_detection/bitset_32.h"
|
| +#include "ui/events/gesture_detection/motion_event.h"
|
| +
|
| +namespace ui {
|
| +
|
| +bool operator==(const MotionEvent& lhs, const MotionEvent& rhs) {
|
| + // Re-using the string conversion for equality testing is sensible because it
|
| + // 1) is only used in testing (where performance is not a chief concern), and
|
| + // 2) simplifies maintenance by consolidating the necessary property checks.
|
| + std::stringstream lhs_ss, rhs_ss;
|
| + lhs_ss << lhs;
|
| + rhs_ss << rhs;
|
| + return lhs_ss.str() == rhs_ss.str();
|
| +}
|
| +
|
| +std::ostream& operator<<(std::ostream& os, const MotionEvent& event) {
|
| + os << "MotionEvent {"
|
| + << "\n ID: " << event.GetId() << "\n Action: " << event.GetAction()
|
| + << "\n ActionIndex: " << event.GetActionIndex()
|
| + << "\n Flags: " << event.GetFlags()
|
| + << "\n ButtonState: " << event.GetButtonState() << "\n Pointers: [";
|
| + const size_t pointer_count = event.GetPointerCount();
|
| + const size_t history_size = event.GetHistorySize();
|
| +
|
| + BitSet32 pointer_ids;
|
| + for (size_t i = 0; i < pointer_count; ++i) {
|
| + pointer_ids.mark_bit(event.GetPointerId(i));
|
| +
|
| + // Print the pointers sorted by id.
|
| + while (!pointer_ids.is_empty()) {
|
| + int pi = event.FindPointerIndexOfId(pointer_ids.first_marked_bit());
|
| + DCHECK_GE(pi, 0);
|
| + pointer_ids.clear_first_marked_bit();
|
| + os << "{"
|
| + << "\n Pos: (" << event.GetX(pi) << ", " << event.GetY(pi) << ")"
|
| + << "\n RawPos: (" << event.GetX(pi) << ", " << event.GetY(pi) << ")"
|
| + << "\n Size: (" << event.GetTouchMajor(pi) << ", "
|
| + << event.GetTouchMinor(pi) << ")"
|
| + << "\n Orientation: " << event.GetOrientation(pi)
|
| + << "\n Pressure: " << event.GetOrientation(pi)
|
| + << "\n Tool: " << event.GetToolType(pi);
|
| + if (history_size) {
|
| + os << "\n History: [";
|
| + for (size_t h = 0; h < history_size; ++h) {
|
| + os << "\n { " << event.GetHistoricalX(pi, h) << ", "
|
| + << event.GetHistoricalY(pi, h) << ", "
|
| + << event.GetHistoricalTouchMajor(pi, h) << ", "
|
| + << event.GetHistoricalEventTime(pi).ToInternalValue() << " }";
|
| + if (h + 1 < history_size)
|
| + os << ",";
|
| + }
|
| + os << "\n ]";
|
| + }
|
| + os << "\n }";
|
| + if (i + 1 < pointer_count)
|
| + os << ", ";
|
| + }
|
| + os << "]\n}";
|
| + }
|
| +
|
| + return os;
|
| +}
|
| +
|
| +} // namespace ui
|
|
|