[Development] QTestLib: sending mouse move and release events outside windows

Gatis Paeglis Gatis.Paeglis at qt.io
Mon Apr 16 17:08:11 CEST 2018


> I was thinking of something that would be public API, as any user who wants to tests drags that end up outside a window will run into the same issue.


That kind of API I think requires serious redesign in qtestlib. If you want to drag outside a window and then back to test Enter/Leave events (system generated, not the synthetic ones for alien widgets), then we have to use system APIs to emulate mouse (e.g. via XTest on X11), instead of mocking events. Both modes are useful, mocked vs system events, but that is another story.


If you want to move outside a window and keep on receiving all mouse events, then you need to grab the mouse/pointer. That is different API from the above Enter/Leave scenario. QTestLib currently does not support any of the above.


________________________________
From: Mitch Curtis
Sent: Monday, April 16, 2018 1:14:23 PM
To: Gatis Paeglis; development at qt-project.org
Subject: RE: QTestLib: sending mouse move and release events outside windows


> That warning message was added by [1]. I have never fully understood the motivation for that warning. The documentation from [2] does not say if global coordinates are allowed.



I suppose it could be useful if you didn’t intend to send events outside of the window.



> QTest sends all mouse events down to QWindowSystemInterface, which does expect a window as an argument, or nullptr on window-less systems (eglfs). So if you want to simulate a mouse move/press/release outside a window you could try to use that code path...



I was thinking of something that would be public API, as any user who wants to tests drags that end up outside a window will run into the same issue.



What do you think about a flag that can be set for the duration of a function (i.e. automatically reset at the end of that function)? setWarnOnEventsOutsideWindow?



Or, to involve the discussion about failing on warnings, we could add a more generic flag getter/setter. We already have [1] a bunch of currentTestFunction functions:



const char *currentAppName()

const char *currentDataTag()

bool currentTestFailed()

const char *currentTestFunction()



So, perhaps we could add currentTestFunctionFlags()/setCurrentTestFunctionFlags().



TestFunctionFlag {

    WarnOnEventsOutsideWindow = 0x01, // enabled by default

    FailOnWarnings = 0x02 // disabled by default

};



[1] http://doc.qt.io/qt-5/qtest.html#keyClicks



From: Gatis Paeglis
Sent: Monday, 16 April 2018 12:29 PM
To: Mitch Curtis <mitch.curtis at qt.io>; development at qt-project.org
Subject: Re: QTestLib: sending mouse move and release events outside windows



That warning message was added by [1]. I have never fully understood the motivation for that warning. The documentation from [2] does not say if global coordinates are allowed. QTest sends all mouse events down to QWindowSystemInterface, which does expect a window as an argument, or nullptr on window-less systems (eglfs). So if you want to simulate a mouse move/press/release outside a window you could try to use that code path... but it won't work AFAICT ?? see [3], if we don't find a window under mouse, then QGuiApplicationPrivate::processMouseEvent() returns. Otherwise, where should we send the event?



[1] https://codereview.qt-project.org/#/c/53474/

[2] http://doc.qt.io/qt-5/qtest.html#mouseMove

[3] http://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/kernel/qguiapplication.cpp#n2021

________________________________

From: Development <development-bounces+gatis.paeglis=qt.io at qt-project.org<mailto:development-bounces+gatis.paeglis=qt.io at qt-project.org>> on behalf of Mitch Curtis <mitch.curtis at qt.io<mailto:mitch.curtis at qt.io>>
Sent: Monday, April 16, 2018 11:56:56 AM
To: development at qt-project.org<mailto:development at qt-project.org>
Subject: [Development] QTestLib: sending mouse move and release events outside windows



https://bugreports.qt.io/browse/QTBUG-67702 explains that sending mouse move and release events outside of a window causes warnings:

void Test::test_case1()
{
    QWindow window;
    window.resize(400, 400);

    // Start inside and drag outside (e.g. moving a selection to the edge of a
    // canvas should scroll the canvas).
    QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 200));

    const QRegularExpression regex(".*Mouse event at .* occurs outside of target window.*");
    QVERIFY(regex.isValid());

    const QRegularExpressionMatch match(regex.match("Mouse event at 600, 600 occurs outside of target window (400x400)."));
    QVERIFY(match.hasMatch());

    QTest::ignoreMessage(QtWarningMsg, regex);
    QTest::mouseMove(&window, QPoint(600, 600));

    QTest::ignoreMessage(QtWarningMsg, regex);
    QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(600, 600));
}

Output:

********* Start testing of Test *********
Config: Using QtTest library 5.11.0, Qt 5.11.0 (x86_64-little_endian-llp64 shared (dynamic) debug build; by MSVC 2017)
PASS   : Test::initTestCase()
WARNING: Test::test_case1() Mouse event at 600, 600 occurs outside of target window (400x400).
WARNING: Test::test_case1() Mouse event at 600, 600 occurs outside of target window (400x400).
INFO   : Test::test_case1() Did not receive any message matching: ".*Mouse event at .* occurs outside of target window.*"
INFO   : Test::test_case1() Did not receive any message matching: ".*Mouse event at .* occurs outside of target window.*"
FAIL!  : Test::test_case1() Not all expected messages were received
PASS   : Test::cleanupTestCase()
Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 1ms
********* Finished testing of Test *********

Mouse move and release events occurring outside of a window is not uncommon, so there should be a way to disable these warnings.

Using QTest::ignoreWarning() has no effect here, because the message logger system is (probably intentionally) bypassed.

Does anyone know why this is the case?

Also, does anyone have any ideas about how to solve this?

One suggestion was QTest::mouse*OutsideWindow(), which would work, but could be a bit cumbersome if you need to switch from mouseMove to mouseMoveOutsideWindow halfway through a "drag" loop.

Another idea could be to have a flag or construct that only applies for the duration of a test function, and is reset at the end of that function. I think something like this could also be useful for the opposite use case: failing a test upon any warnings (something that would be useful for QML applications). Something like https://codereview.qt-project.org/#/c/89178/ except it's automatically reset for you at the end of each test.
_______________________________________________
Development mailing list
Development at qt-project.org<mailto:Development at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180416/711277e2/attachment.html>


More information about the Development mailing list