Priority: P2: Important
Affects Version/s: None
Fix Version/s: None
Component/s: Testing: qtestlib
QTestLlib: Stop using QCursor:pos() for mouse event geometry
QMouseEvent has a constructor which takes a single local position and then sets the global position by calling QCursor::pos(). This constructor is used several places in our unit tests, often in conjunction with a QCursor::setPos() call or a QTest::mouseEvent () call (see below).
On macOS 10.14+, QCursor::setPos() requires user approval (via system dialog interaction), and is no longer suitable for auto test use.
Existing QTestLib API:
- QTest::mouseEvent(MouseAction, QWindow *, LocalPosition, …)
Creates and sends a mouse event (correctly), using window->mapToGlobal() to get global coordinates.
- QTest::mouseEvent(MouseAction, QWidget *, LocalPosition, …)
As the QWindow version, except that it has an exception for MouseMove events: in this case (only), QCursor::setPos() is called, and no mouse event is created or sent.
- Manually patch tests code which creates QMouseEvents, starting with the ones that fail on macOS 10,14:
- Change QTest::mouseEvent() to send a mouse event in all cases, and port tests to use that.
- Introduce new API for creating mouse events: QTest::createMouseEvent()
- d130382776e8b9db491385a0db45a3daaa79890c added QWindow overload for mouseEvent()
- 1762bf3394219db3a7a9cc99306f4111e6cb8492 replaced the QCursor::setPos() call with QWindowSystemInterface::handleMouseEvent(), for the QWindow overload.