summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2014-03-27 16:44:44 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-28 22:52:19 +0100
commitb980df3f3ced07f35bc9e817c53ae13d48f84994 (patch)
tree822271f41743bd3d0fd498aa93f07cb079abc90f
parent685f8fe550b2360546af8dc7fe4c3f747631645b (diff)
Stabilize tst_qtoolbutton for Windows 8.1.
Ensure triggered() and task176137_autoRepeatOfAction() are using an active main window. Change click timer in triggered() to repeat until the menu is visible and add a timer to close the widget and bail out if the simulated click fails to close the menu. Task-number: QTBUG-37822 Change-Id: If675660d02335bffd5caa89796914924dad1a909 Reviewed-by: Tony Sarajärvi <tony.sarajarvi@digia.com> Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
-rw-r--r--tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp80
1 files changed, 56 insertions, 24 deletions
diff --git a/tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp b/tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp
index aaff322c4b..168a17773e 100644
--- a/tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp
+++ b/tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp
@@ -48,6 +48,8 @@
#include <qmenu.h>
#include <qaction.h>
#include <qstyleoption.h>
+#include <qscreen.h>
+#include <qlabel.h>
class tst_QToolButton : public QObject
{
@@ -68,7 +70,7 @@ private slots:
protected slots:
void sendMouseClick();
private:
- QWidget *w;
+ QPointer<QWidget> m_menu;
};
tst_QToolButton::tst_QToolButton()
@@ -121,29 +123,39 @@ void tst_QToolButton::getSetCheck()
void tst_QToolButton::triggered()
{
qRegisterMetaType<QAction *>("QAction *");
- QToolButton tb;
- tb.show();
- QSignalSpy spy(&tb,SIGNAL(triggered(QAction*)));
- QMenu *menu = new QMenu("Menu");
+ QWidget mainWidget;
+ mainWidget.setWindowTitle(QStringLiteral("triggered"));
+ mainWidget.resize(200, 200);
+ mainWidget.move(QGuiApplication::primaryScreen()->availableGeometry().center() - QPoint(100, 100));
+ QToolButton *toolButton = new QToolButton(&mainWidget);
+ QSignalSpy spy(toolButton,SIGNAL(triggered(QAction*)));
+ QScopedPointer<QMenu> menu(new QMenu(QStringLiteral("Menu")));
QAction *one = menu->addAction("one");
menu->addAction("two");
- QAction *def = new QAction("def", this);
+ QAction *defaultAction = new QAction(QStringLiteral("def"), this);
- tb.setMenu(menu);
- tb.setDefaultAction(def);
+ toolButton->setMenu(menu.data());
+ toolButton->setDefaultAction(defaultAction);
+ mainWidget.show();
+ QApplication::setActiveWindow(&mainWidget);
+ QVERIFY(QTest::qWaitForWindowActive(&mainWidget));
- def->trigger();
+ defaultAction->trigger();
QCOMPARE(spy.count(),1);
- QCOMPARE(qvariant_cast<QAction *>(spy.at(0).at(0)), def);
+ QCOMPARE(qvariant_cast<QAction *>(spy.at(0).at(0)), defaultAction);
- w = menu;
- QTimer::singleShot(30, this, SLOT(sendMouseClick()));
- tb.showMenu();
+ m_menu = menu.data();
+
+ QTimer *timer = new QTimer(this);
+ timer->setInterval(50);
+ connect(timer, SIGNAL(timeout()), this, SLOT(sendMouseClick()));
+ timer->start();
+ QTimer::singleShot(10000, &mainWidget, SLOT(close())); // Emergency bail-out
+ toolButton->showMenu();
QTest::qWait(20);
QCOMPARE(spy.count(),2);
QCOMPARE(qvariant_cast<QAction *>(spy.at(1).at(0)), one);
- delete menu;
}
void tst_QToolButton::collapseTextOnPriority()
@@ -195,20 +207,30 @@ void tst_QToolButton::task230994_iconSize()
void tst_QToolButton::task176137_autoRepeatOfAction()
{
QAction action(0);
- QToolButton tb;
- tb.setDefaultAction (&action);
- tb.show();
+ QWidget mainWidget;
+ mainWidget.setWindowTitle(QStringLiteral("task176137_autoRepeatOfAction"));
+ mainWidget.resize(200, 200);
+ mainWidget.move(QGuiApplication::primaryScreen()->availableGeometry().center() - QPoint(100, 100));
+ QToolButton *toolButton = new QToolButton(&mainWidget);
+ toolButton->setDefaultAction (&action);
+ QLabel *label = new QLabel(QStringLiteral("This test takes a while."), &mainWidget);
+ label->move(0, 50);
+
+ mainWidget.show();
+ QApplication::setActiveWindow(&mainWidget);
+ QVERIFY(QTest::qWaitForWindowActive(&mainWidget));
+
QSignalSpy spy(&action,SIGNAL(triggered()));
- QTest::mousePress ( &tb, Qt::LeftButton);
- QTest::mouseRelease ( &tb, Qt::LeftButton, 0, QPoint (), 2000);
+ QTest::mousePress (toolButton, Qt::LeftButton);
+ QTest::mouseRelease (toolButton, Qt::LeftButton, 0, QPoint (), 2000);
QCOMPARE(spy.count(),1);
// try again with auto repeat
- tb.setAutoRepeat (true);
+ toolButton->setAutoRepeat (true);
QSignalSpy repeatSpy(&action,SIGNAL(triggered())); // new spy
- QTest::mousePress ( &tb, Qt::LeftButton);
- QTest::mouseRelease ( &tb, Qt::LeftButton, 0, QPoint (), 3000);
- qreal expected = (3000 - tb.autoRepeatDelay()) / tb.autoRepeatInterval() + 1;
+ QTest::mousePress (toolButton, Qt::LeftButton);
+ QTest::mouseRelease (toolButton, Qt::LeftButton, 0, QPoint (), 3000);
+ const qreal expected = (3000 - toolButton->autoRepeatDelay()) / toolButton->autoRepeatInterval() + 1;
//we check that the difference is small (on some systems timers are not super accurate)
qreal diff = (expected - repeatSpy.count()) / expected;
QVERIFY2(qAbs(diff) < 0.2, qPrintable(
@@ -221,7 +243,17 @@ void tst_QToolButton::task176137_autoRepeatOfAction()
void tst_QToolButton::sendMouseClick()
{
- QTest::mouseClick(w, Qt::LeftButton, 0, QPoint(7,7));
+ if (m_menu.isNull()) {
+ qWarning("m_menu is NULL");
+ return;
+ }
+ if (!m_menu->isVisible())
+ return;
+ QTest::mouseClick(m_menu.data(), Qt::LeftButton, 0, QPoint(7, 7));
+ if (QTimer *timer = qobject_cast<QTimer *>(sender())) {
+ timer->stop();
+ timer->deleteLater();
+ }
}
void tst_QToolButton::qtbug_26956_popupTimerDone()