QTestLib: Add timestamp to mouse click events

Timestamp is necessary for testing custom mouse event handlers e.g. what
Qt WebEngine uses for handling triple and quadruple mouse clicks.

Based on commit 181ee8f9ff

Task-number: QTBUG-56223
Change-Id: I2bf840f326255333eec83ca8c42f087cb7deb1fb
Reviewed-by: Kai Koehne <kai.koehne@qt.io>
This commit is contained in:
Peter Varga 2016-09-28 11:20:54 +02:00 committed by Shawn Rutledge
parent 9bfe3ab71e
commit 8325808dcf

View File

@ -73,6 +73,11 @@ namespace QTest
extern Q_TESTLIB_EXPORT Qt::MouseButton lastMouseButton;
extern Q_TESTLIB_EXPORT int lastMouseTimestamp;
// This value is used to emulate timestamps to avoid creating double clicks by mistake.
// Use this constant instead of QStyleHints::mouseDoubleClickInterval property to avoid tests
// to depend on platform themes.
static const int mouseDoubleClickInterval = 500;
static void waitForEvents()
{
#ifdef Q_OS_MAC
@ -125,7 +130,7 @@ namespace QTest
Q_FALLTHROUGH();
case MouseRelease:
qt_handleMouseEvent(w, pos, global, Qt::NoButton, stateKey, ++lastMouseTimestamp);
lastMouseTimestamp += 500; // avoid double clicks being generated
lastMouseTimestamp += mouseDoubleClickInterval; // avoid double clicks being generated
lastMouseButton = Qt::NoButton;
break;
case MouseMove:
@ -176,8 +181,10 @@ namespace QTest
if (delay == -1 || delay < defaultMouseDelay())
delay = defaultMouseDelay();
if (delay > 0)
if (delay > 0) {
QTest::qWait(delay);
lastMouseTimestamp += delay;
}
if (action == MouseClick) {
mouseEvent(MousePress, widget, button, stateKey, pos);
@ -194,12 +201,16 @@ namespace QTest
{
case MousePress:
me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey);
me.setTimestamp(++lastMouseTimestamp);
break;
case MouseRelease:
me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, Qt::MouseButton(), stateKey);
me.setTimestamp(++lastMouseTimestamp);
lastMouseTimestamp += mouseDoubleClickInterval; // avoid double clicks being generated
break;
case MouseDClick:
me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey);
me.setTimestamp(++lastMouseTimestamp);
break;
case MouseMove:
QCursor::setPos(widget->mapToGlobal(pos));