tests: fix window activation usage in tst_QGraphicsWidget

- Skip tests that depend on programmatic window activation on platforms
  where this is not supported, such as Wayland.
- Change tests that don't rely on the window being activated to use
  qWaitForWindowExposed() instead.

Task-number: QTBUG-107153
Change-Id: Ieb4280343a725a2cbdc46a8ac5c657beeb2e7e57
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
(cherry picked from commit a247da320cc221c19c309962f5f6d888f66d9225)
Reviewed-by: Liang Qi <liang.qi@qt.io>
This commit is contained in:
Liang Qi 2022-10-04 11:25:16 +02:00
parent 8da325be2d
commit 09b39af9bc

View File

@ -17,6 +17,8 @@
#include <qstylefactory.h>
#include <qscreen.h>
#include <qsignalspy.h>
#include <private/qguiapplication_p.h>
#include <qpa/qplatformintegration.h>
typedef QList<QGraphicsItem *> QGraphicsItemList;
@ -144,8 +146,16 @@ private slots:
void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems();
void QT_BUG_12056_tabFocusFirstUnsetWhenRemovingItems();
void QTBUG_45867_send_itemChildAddedChange_to_parent();
private:
static bool hasWindowActivation();
};
bool tst_QGraphicsWidget::hasWindowActivation()
{
return (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation));
}
// Subclass that exposes the protected functions.
class SubQGraphicsWidget : public QGraphicsWidget {
public:
@ -1049,7 +1059,10 @@ void tst_QGraphicsWidget::initStyleOption()
QGraphicsView view(&scene);
view.resize(300, 300);
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
if (hasWindowActivation())
QVERIFY(QTest::qWaitForWindowActive(&view));
else
QVERIFY(QTest::qWaitForWindowExposed(&view));
view.setAlignment(Qt::AlignTop | Qt::AlignLeft);
SubQGraphicsWidget *widget = new SubQGraphicsWidget;
@ -1063,10 +1076,12 @@ void tst_QGraphicsWidget::initStyleOption()
QFETCH(bool, enabled);
widget->setEnabled(enabled);
QFETCH(bool, focus);
if (focus) {
widget->setFlag(QGraphicsItem::ItemIsFocusable, true);
widget->setFocus();
QVERIFY(widget->hasFocus());
if (hasWindowActivation()) {
if (focus) {
widget->setFlag(QGraphicsItem::ItemIsFocusable, true);
widget->setFocus();
QVERIFY(widget->hasFocus());
}
}
QFETCH(bool, underMouse);
if (underMouse) {
@ -1085,8 +1100,10 @@ void tst_QGraphicsWidget::initStyleOption()
bool isEnabled = option.state & QStyle::State_Enabled;
QCOMPARE(isEnabled, enabled);
bool hasFocus = option.state & QStyle::State_HasFocus;
QCOMPARE(hasFocus, focus);
if (hasWindowActivation()) {
bool hasFocus = option.state & QStyle::State_HasFocus;
QCOMPARE(hasFocus, focus);
}
bool isUnderMouse = option.state & QStyle::State_MouseOver;
QCOMPARE(isUnderMouse, underMouse);
// if (layoutDirection != Qt::LeftToRight)
@ -1713,6 +1730,9 @@ void tst_QGraphicsWidget::verifyFocusChain()
void tst_QGraphicsWidget::updateFocusChainWhenChildDie()
{
if (!hasWindowActivation())
QSKIP("Window activation is not supported");
const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
QGraphicsScene scene;
QGraphicsView view(&scene);