diff options
Diffstat (limited to 'tests/auto/widgets/widgets')
3 files changed, 71 insertions, 10 deletions
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index c38c254b9a..40496dbebb 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -53,6 +53,7 @@ #include <qdialog.h> #include <qevent.h> #include <qlineedit.h> +#include <qlabel.h> #include <qlistview.h> #include <qheaderview.h> #include <qlistwidget.h> @@ -131,6 +132,7 @@ private slots: void pixmapIcon(); void mouseWheel_data(); void mouseWheel(); + void wheelClosingPopup(); void layoutDirection(); void itemListPosition(); void separatorItem_data(); @@ -2041,6 +2043,32 @@ void tst_QComboBox::mouseWheel() } } +void tst_QComboBox::wheelClosingPopup() +{ + // QTBUG-40656, combo and other popups should close when the main window gets a wheel event. + QScrollArea scrollArea; + scrollArea.move(300, 300); + QWidget *widget = new QWidget; + scrollArea.setWidget(widget); + QVBoxLayout *layout = new QVBoxLayout(widget); + layout->setSizeConstraint(QLayout::SetMinAndMaxSize); + layout->addSpacing(100); + QComboBox *comboBox = new QComboBox; + comboBox->addItems(QStringList() << QStringLiteral("Won") << QStringLiteral("Too") + << QStringLiteral("3") << QStringLiteral("fore")); + layout->addWidget(comboBox); + layout->addSpacing(100); + const QPoint sizeP(scrollArea.width(), scrollArea.height()); + scrollArea.move(QGuiApplication::primaryScreen()->availableGeometry().center() - sizeP / 2); + scrollArea.show(); + QVERIFY(QTest::qWaitForWindowExposed(&scrollArea)); + comboBox->showPopup(); + QTRY_VERIFY(comboBox->view() && comboBox->view()->isVisible()); + QWheelEvent event(QPointF(10, 10), WHEEL_DELTA, Qt::NoButton, Qt::NoModifier); + QVERIFY(QCoreApplication::sendEvent(scrollArea.windowHandle(), &event)); + QTRY_VERIFY(!comboBox->view()->isVisible()); +} + void tst_QComboBox::layoutDirection() { QComboBox box; diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 0094a1112b..c7fba1c871 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -244,6 +244,7 @@ private slots: #ifndef QT_NO_CLIPBOARD void cut(); + void cutWithoutSelection(); #endif void maxLengthAndInputMask(); void returnPressedKeyEvent(); @@ -2977,7 +2978,37 @@ void tst_QLineEdit::cut() testWidget->cut(); QCOMPARE(testWidget->text(), QString("Abcdefg defg hijklmno")); } -#endif + +void tst_QLineEdit::cutWithoutSelection() +{ + enum { selectionLength = 1 }; + + if (QKeySequence(QKeySequence::Cut).toString() != QLatin1String("Ctrl+X")) + QSKIP("Platform with non-standard keybindings"); + QClipboard *clipboard = QGuiApplication::clipboard(); + if (!PlatformClipboard::isAvailable() + || !QGuiApplication::platformName().compare("xcb", Qt::CaseInsensitive)) { // Avoid unstable X11 clipboard + clipboard = Q_NULLPTR; + } + + if (clipboard) + clipboard->clear(); + const QString origText = QStringLiteral("test"); + QLineEdit lineEdit(origText); + lineEdit.setCursorPosition(0); + QVERIFY(!lineEdit.hasSelectedText()); + QTest::keyClick(&lineEdit, Qt::Key_X, Qt::ControlModifier); + QCOMPARE(lineEdit.text(), origText); // No selection, unmodified. + if (clipboard) + QVERIFY(clipboard->text().isEmpty()); + lineEdit.setSelection(0, selectionLength); + QTest::keyClick(&lineEdit, Qt::Key_X, Qt::ControlModifier); + QCOMPARE(lineEdit.text(), origText.right(origText.size() - selectionLength)); + if (clipboard) + QCOMPARE(clipboard->text(), origText.left(selectionLength)); +} + +#endif // !QT_NO_CLIPBOARD class InputMaskValidator : public QValidator { diff --git a/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp b/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp index 8dd191e621..38eae1d19d 100644 --- a/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp +++ b/tests/auto/widgets/widgets/qstatusbar/tst_qstatusbar.cpp @@ -285,17 +285,21 @@ void tst_QStatusBar::QTBUG25492_msgtimeout() QCOMPARE(testWidget->currentMessage(), QString("Ready")); QCOMPARE(testWidget->currentMessage(), currentMessage); - QTest::qWait(1000); - - // Set display message for 2 seconds again - testWidget->showMessage("Ready", 2000); - QCOMPARE(testWidget->currentMessage(), QString("Ready")); + // Set display message for 2 seconds + QElapsedTimer t; + t.start(); + testWidget->showMessage("Ready 2000", 2000); + QCOMPARE(testWidget->currentMessage(), QString("Ready 2000")); QCOMPARE(testWidget->currentMessage(), currentMessage); - QTest::qWait(1500); - // Message disappears after 2 seconds QTRY_VERIFY(testWidget->currentMessage().isNull()); + qint64 ts = t.elapsed(); + + // XXX: ideally ts should be 2000, but sometimes it appears to go away early, probably due to timer granularity. + QVERIFY2(ts >= 1800, qPrintable("Timer was " + QString::number(ts))); + if (ts < 2000) + qWarning("QTBUG25492_msgtimeout: message vanished early, should be >= 2000, was %lld", ts); QVERIFY(currentMessage.isNull()); // Set display message for 2 seconds first @@ -303,8 +307,6 @@ void tst_QStatusBar::QTBUG25492_msgtimeout() QCOMPARE(testWidget->currentMessage(), QString("Ready 25492")); QCOMPARE(testWidget->currentMessage(), currentMessage); - QTest::qWait(1000); - // Set display message forever again testWidget->showMessage("Ready 25492", 0); QCOMPARE(testWidget->currentMessage(), QString("Ready 25492")); |