qt5base-lts/tests/auto/gui/kernel
Gatis Paeglis ba3a26ea9f mouse handling: fix issue when mixing QTest::mouse* APIs
... that become apparent after switching qtestlib to use enhanced mouse
event (a37785ec76). With the old code path,
where QGuiApplication was deducing event type it would deduce mouse release
event even when there wasn't one. The new code path doesn't do that, which
revealed an obscure problem when mixing QTest::mouse* APIs (where QWindow
overload goes through QWindowSystemInterface API and QWidget overload goes
through QApplication::notify() and sets mouse_buttons from there). What
happened in this specific test case "./tst_qtreeview selection statusTip" was:

// tst_QTreeView::selection sets mouse_buttons = Qt::LeftButton from QApplication::notify
QTest::mousePress(widget, Qt::LeftButton, ..)

// tst_QTreeView::statusTip
QTest::mouseMove(window, )

The old code path sees that position and state has changed, creates a fake
mouse event, which gets deduced as mouse release even if there wasn't one.
And by luck this happened to set mouse_buttons=Qt::NoButton. So when we use
mouse_buttons later to create QMouseEvent everything works as expected. With
the enhanced mouse we don't clear the pressed button from mouse_buttons (set
in tst_QTreeView::selection) as this is done only from press/release events,
then pass it to QMouseEvent and later because of that QApplicationPrivate::
pickMouseReceiver() returns nullptr.

The fix here is to use e->buttons when constructing QMouseEvent, instead of
relying on mouse_buttons which gets changed from various places and has other
issues that can not be solved without invalidating the current documentation
of QGuiApplication::mouseButtons() (e.g QTBUG-33161). Tests and any Qt code
in general should avoid using the fragile QGuiApplication::mouseButtons() API.
This patch does not affect the old code path (it continues working as before)
and fixes the issue described above for the enhanced mouse API. The enhanced
mouse API actually is better in a way that it does not get affected by button
state from test functions that run earlier, as opposed to the old code path
where every subsequent test function uses mouse_buttons in whatever state it
was left by the test functions that run earlier.

Not relying on mouse_buttons when creating QMouseEvent helped also to discover
other logic error. This caused an in incorrect button state for a mouse move
event that is generated for a release event that simultaneously changes a mouse
position.

Task-number: QTBUG-64043
Change-Id: I6ad8e49d8437ab0858180c2d0d45694f3b3c2d60
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
2017-11-05 17:36:08 +00:00
..
noqteventloop tst_NoQtEventLoop: Pass with High DPI scaling active 2017-08-04 08:36:16 +00:00
qbackingstore Updated license headers 2016-01-21 18:55:18 +00:00
qclipboard Properly use the "process" feature 2017-02-27 15:44:46 +00:00
qcursor QCursor: Add equality operators 2017-03-21 17:22:41 +00:00
qdrag Updated license headers 2016-01-21 18:55:18 +00:00
qevent Updated license headers 2016-01-21 18:55:18 +00:00
qfileopenevent Fix test for sandboxed targets 2016-09-15 14:25:50 +00:00
qguiapplication Ensure result of all QTest::qWaitFor are verified 2017-10-05 15:15:36 +00:00
qguieventdispatcher QtGui tests: Remove DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 2013-03-27 03:54:42 +01:00
qguieventloop Fix race condition in the processEvents test 2017-07-19 12:29:53 +00:00
qguimetatype Remove tests/auto/qtest-config.h. 2016-04-12 14:56:49 +00:00
qguitimer Clean up OS version checks for Apple platforms 2017-09-29 03:30:13 +00:00
qguivariant Remove tests/auto/qtest-config.h. 2016-04-12 14:56:49 +00:00
qinputmethod Skip failing autotests with b2qt toolchain 2017-05-09 08:11:18 +00:00
qkeyevent tests: Unify license to GPL-EXCEPT 2017-04-03 07:18:46 +00:00
qkeysequence Remove remaining Carbon includes from QtCore, QtGui and QtWidgets 2017-03-07 01:04:40 +00:00
qmouseevent Add helper function to reset QMouseEvent localPos 2016-08-01 09:58:23 +00:00
qmouseevent_modal Updated license headers 2016-01-21 18:55:18 +00:00
qopenglwindow Merge remote-tracking branch 'origin/5.10' into dev 2017-10-17 10:34:24 +02:00
qpalette Updated license headers 2016-01-21 18:55:18 +00:00
qpixelformat Updated license headers 2016-01-21 18:55:18 +00:00
qrasterwindow Merge remote-tracking branch 'origin/5.10' into dev 2017-10-17 10:34:24 +02:00
qscreen Updated license headers 2016-01-21 18:55:18 +00:00
qsurfaceformat Updated license headers 2016-01-21 18:55:18 +00:00
qtouchevent Replace Q_NULLPTR with nullptr where possible 2017-09-19 11:53:55 +00:00
qwindow mouse handling: fix issue when mixing QTest::mouse* APIs 2017-11-05 17:36:08 +00:00
kernel.pro QCursor: Add equality operators 2017-03-21 17:22:41 +00:00