summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/kernel')
-rw-r--r--tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp6
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp100
-rw-r--r--tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp7
-rw-r--r--tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp26
4 files changed, 129 insertions, 10 deletions
diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
index c39c770316..570caf851d 100644
--- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
+++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
@@ -160,7 +160,7 @@ void tst_QBoxLayout::sizeHint()
lay1->addLayout(lay2);
window.setLayout(lay1);
window.show();
- QTest::qWaitForWindowExposed(&window);
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
label->setText("foooooooo baaaaaaar");
QSize sh = lay1->sizeHint();
QApplication::processEvents();
@@ -181,7 +181,7 @@ void tst_QBoxLayout::sizeConstraints()
lay->setSizeConstraint(QLayout::SetFixedSize);
window.setLayout(lay);
window.show();
- QTest::qWaitForWindowExposed(&window);
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
QSize sh = window.sizeHint();
delete lay->takeAt(1);
QVERIFY(sh.width() >= window.sizeHint().width() &&
@@ -228,7 +228,7 @@ void tst_QBoxLayout::setStyleShouldChangeSpacing()
style1->hspacing = 6;
window.setStyle(style1.data());
window.show();
- QTest::qWaitForWindowExposed(&window);
+ QVERIFY(QTest::qWaitForWindowExposed(&window));
int spacing = pb2->geometry().left() - pb1->geometry().right() - 1;
QCOMPARE(spacing, 6);
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 81fb332a62..df6eab7a45 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -199,6 +199,7 @@ private slots:
void defaultTabOrder();
void reverseTabOrder();
void tabOrderWithProxy();
+ void tabOrderWithCompoundWidgets();
#ifdef Q_OS_WIN
void activation();
#endif
@@ -1665,22 +1666,26 @@ public:
class Composite : public QFrame
{
public:
- Composite(QWidget* parent = 0, const char* name = 0)
+ Composite(QWidget* parent = 0, const QString &name = 0)
: QFrame(parent)
{
setObjectName(name);
lineEdit1 = new QLineEdit;
lineEdit2 = new QLineEdit;
+ lineEdit3 = new QLineEdit;
+ lineEdit3->setEnabled(false);
QHBoxLayout* hbox = new QHBoxLayout(this);
hbox->addWidget(lineEdit1);
hbox->addWidget(lineEdit2);
+ hbox->addWidget(lineEdit3);
}
public:
QLineEdit *lineEdit1;
QLineEdit *lineEdit2;
+ QLineEdit *lineEdit3;
};
void tst_QWidget::defaultTabOrder()
@@ -1851,6 +1856,93 @@ void tst_QWidget::tabOrderWithProxy()
QVERIFY(firstEdit->hasFocus());
}
+void tst_QWidget::tabOrderWithCompoundWidgets()
+{
+ const int compositeCount = 4;
+ Container container;
+ Composite *composite[compositeCount];
+
+ QLineEdit *firstEdit = new QLineEdit();
+ container.box->addWidget(firstEdit);
+
+ for (int i = 0; i < compositeCount; i++) {
+ composite[i] = new Composite(0, QStringLiteral("Composite: ") + QString::number(i));
+ container.box->addWidget(composite[i]);
+
+ // Let the composite handle focus, and set a child as focus proxy (use the second child, just
+ // to ensure that we don't just tab to the first child by coinsidence). This will make the
+ // composite "compound". Also enable the last line edit to have a bit more data to check when
+ // tabbing forwards.
+ composite[i]->setFocusPolicy(Qt::StrongFocus);
+ composite[i]->setFocusProxy(composite[i]->lineEdit2);
+ composite[i]->lineEdit3->setEnabled(true);
+ }
+
+ QLineEdit *lastEdit = new QLineEdit();
+ container.box->addWidget(lastEdit);
+
+ // Reverse tab order between each composite
+ // (but not inside them), including first and last line edit.
+ // The result should not affect local tab order inside each
+ // composite, only between them.
+ QWidget::setTabOrder(lastEdit, composite[compositeCount - 1]);
+ for (int i = compositeCount - 1; i >= 1; --i)
+ QWidget::setTabOrder(composite[i], composite[i-1]);
+ QWidget::setTabOrder(composite[0], firstEdit);
+
+ container.show();
+ container.activateWindow();
+ qApp->setActiveWindow(&container);
+ QVERIFY(QTest::qWaitForWindowActive(&container));
+
+ lastEdit->setFocus();
+ QTRY_VERIFY(lastEdit->hasFocus());
+
+ // Check that focus moves between the line edits in the normal
+ // order when tabbing inside each compound, but in the reverse
+ // order when tabbing between them. Since the composites have
+ // lineEdit2 as focus proxy, lineEdit2 will be the first with focus
+ // when the compound gets focus, and lineEdit1 will therefore be skipped.
+ for (int i = compositeCount - 1; i >= 0; --i) {
+ container.tab();
+ Composite *c = composite[i];
+ QVERIFY(!c->lineEdit1->hasFocus());
+ QVERIFY(c->lineEdit2->hasFocus());
+ QVERIFY(!c->lineEdit3->hasFocus());
+ container.tab();
+ QVERIFY(!c->lineEdit1->hasFocus());
+ QVERIFY(!c->lineEdit2->hasFocus());
+ QVERIFY(c->lineEdit3->hasFocus());
+ }
+
+ container.tab();
+ QVERIFY(firstEdit->hasFocus());
+
+ // Check that focus moves in reverse order when backTab inside the composites, but
+ // in the 'correct' order when backTab between them (since the composites are in reverse tab
+ // order from before, which cancels it out). Note that when we backtab into a compound, we start
+ // at lineEdit3 rather than the focus proxy, since that is the reverse of what happens when we tab
+ // forward. And this time we will also backtab to lineEdit1, since there is no focus proxy that interferes.
+ for (int i = 0; i < compositeCount; ++i) {
+ container.backTab();
+ Composite *c = composite[i];
+ QVERIFY(!c->lineEdit1->hasFocus());
+ QVERIFY(!c->lineEdit2->hasFocus());
+ QVERIFY(c->lineEdit3->hasFocus());
+ container.backTab();
+ QVERIFY(!c->lineEdit1->hasFocus());
+ QVERIFY(c->lineEdit2->hasFocus());
+ QVERIFY(!c->lineEdit3->hasFocus());
+ container.backTab();
+ QVERIFY(c->lineEdit1->hasFocus());
+ QVERIFY(!c->lineEdit2->hasFocus());
+ QVERIFY(!c->lineEdit3->hasFocus());
+ }
+
+ container.backTab();
+ QVERIFY(lastEdit->hasFocus());
+}
+
#ifdef Q_OS_WIN
void tst_QWidget::activation()
{
@@ -2207,7 +2299,7 @@ void tst_QWidget::resizeEvent()
wParent.resize(200, 200);
ResizeWidget wChild(&wParent);
wParent.show();
- QTest::qWaitForWindowExposed(&wParent);
+ QVERIFY(QTest::qWaitForWindowExposed(&wParent));
QCOMPARE (wChild.m_resizeEventCount, 1); // initial resize event before paint
wParent.hide();
QSize safeSize(640,480);
@@ -2223,7 +2315,7 @@ void tst_QWidget::resizeEvent()
ResizeWidget wTopLevel;
wTopLevel.resize(200, 200);
wTopLevel.show();
- QTest::qWaitForWindowExposed(&wTopLevel);
+ QVERIFY(QTest::qWaitForWindowExposed(&wTopLevel));
QCOMPARE (wTopLevel.m_resizeEventCount, 1); // initial resize event before paint for toplevels
wTopLevel.hide();
QSize safeSize(640,480);
@@ -2232,7 +2324,7 @@ void tst_QWidget::resizeEvent()
wTopLevel.resize(safeSize);
QCOMPARE (wTopLevel.m_resizeEventCount, 1);
wTopLevel.show();
- QTest::qWaitForWindowExposed(&wTopLevel);
+ QVERIFY(QTest::qWaitForWindowExposed(&wTopLevel));
QCOMPARE (wTopLevel.m_resizeEventCount, 2);
}
}
diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
index a158b6cbc9..71faf99790 100644
--- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
+++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
@@ -851,7 +851,7 @@ void tst_QWidget_window::QTBUG_50561_QCocoaBackingStore_paintDevice_crash()
QMainWindow w;
w.addToolBar(new QToolBar(&w));
w.show();
- QTest::qWaitForWindowExposed(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
// Simulate window system close
QCloseEvent *e = new QCloseEvent;
@@ -907,7 +907,8 @@ void tst_QWidget_window::setWindowState()
w.show();
QCOMPARE(w.windowState(), state);
QCOMPARE(w.windowHandle()->windowStates(), state);
- QTest::qWaitForWindowExposed(&w);
+ if (!(state & Qt::WindowMinimized))
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QTRY_COMPARE(w.windowState(), state);
QCOMPARE(w.windowHandle()->windowStates(), state);
@@ -925,7 +926,7 @@ void tst_QWidget_window::nativeShow()
QWidget w;
w.winId();
w.windowHandle()->setVisible(true);
- QTest::qWaitForWindowExposed(&w);
+ QVERIFY(QTest::qWaitForWindowExposed(&w));
QVERIFY(w.isVisible());
// ... and that we can hide it
diff --git a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
index 6ec1b754d0..a3e549aa50 100644
--- a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
+++ b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
@@ -74,6 +74,7 @@ private slots:
void testOwnership();
void testBehindTheScenesDeletion();
void testUnparenting();
+ void testUnparentReparent();
void testActivation();
void testAncestorChange();
void testDockWidget();
@@ -241,6 +242,31 @@ void tst_QWindowContainer::testUnparenting()
QVERIFY(!window->isVisible());
}
+void tst_QWindowContainer::testUnparentReparent()
+{
+ QWidget root;
+
+ QWindow *window = new QWindow();
+ QScopedPointer<QWidget> container(QWidget::createWindowContainer(window, &root));
+ container->setWindowTitle(QTest::currentTestFunction());
+ container->setGeometry(m_availableGeometry.x() + 100, m_availableGeometry.y() + 100, 200, 100);
+
+ root.show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(&root));
+
+ QTRY_VERIFY(window->isVisible());
+
+ container->setParent(nullptr);
+ QTRY_VERIFY(!window->isVisible());
+
+ container->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+ QTRY_VERIFY(window->isVisible());
+
+ container->setParent(&root); // This should not crash (QTBUG-63168)
+}
+
void tst_QWindowContainer::testAncestorChange()
{
QWidget root;