Trying to stabilize pageviewtest which is a bit flaky locally
ClosedPublic

Authored by ervin on Apr 11 2020, 12:26 PM.

Diff Detail

Repository
R4 Zanshin
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ervin requested review of this revision.Apr 11 2020, 12:26 PM
ervin created this revision.
dfaure requested changes to this revision.Apr 11 2020, 1:06 PM

This window needs to actually get focus for centralView->hasFocus() to work, so I think the real fix is

page.show();
page.activateWindow();
QVERIFY(QTest::qWaitForWindowActive(&page));

(see also https://bugreports.qt.io/browse/QTBUG-71137 which isn't an actual bug, but has more info on the above API)

This revision now requires changes to proceed.Apr 11 2020, 1:06 PM
ervin updated this revision to Diff 79843.Apr 11 2020, 1:55 PM

Address dfaure's comment

You didn't replace qWaitForWindowExposed with qWaitForWindowActive.
But note that you should do that (activateWindow + qWaitForWindowActive) *only* if the test is about focus.
I don't see how the last hunk, shouldDisplayMessageOnError, needs focus, for instance. The first two hunks do need it. The one after that doesn't, etc.

The reason to not abuse activateWindow + qWaitForWindowActive is that it's annoying when trying to use one's computer during ctest :-)

ervin updated this revision to Diff 79847.Apr 11 2020, 2:15 PM

Address dfaure's comment

Indeed I totally missed the "Exposed" vs "Active" and got carried a bit on the last test.

IMO, most tests need the window active though since they revolve around keyboard input and shortcuts.

dfaure added inline comments.Apr 11 2020, 2:18 PM
tests/units/widgets/pageviewtest.cpp
564

Well, my point is you don't need focus when explicitly sending a keyevent to a widget.

ervin added inline comments.Apr 11 2020, 2:20 PM
tests/units/widgets/pageviewtest.cpp
564

Yes, but the centralView needs to have received the focus still (see above the setFocus() call).

dfaure accepted this revision.Apr 11 2020, 2:24 PM

Ah, OK. Weird though, widget code doesn't typically check hasFocus() so I'm not sure why this is needed. Oh well.

This revision is now accepted and ready to land.Apr 11 2020, 2:24 PM
This revision was automatically updated to reflect the committed changes.