summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel/qaction
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-06-16 10:54:53 +0200
committerLiang Qi <liang.qi@qt.io>2017-06-22 07:56:18 +0000
commit7323cd8dc29011dff49267bbf8f41f31eaf0a112 (patch)
tree5cb1e09fae6027352ee9ef7a228b14181a6eb42f /tests/auto/widgets/kernel/qaction
parenteecf64f61dbf2a0dafc8dfc809d5e87fb398d0f6 (diff)
testlib: add key sequence function
[ChangeLog][Qt Test] Added keySequence() function. Task-number: QTBUG-53381 Change-Id: Ib7c3f966fe607f00475ae74aaf070cb988d00141 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests/auto/widgets/kernel/qaction')
-rw-r--r--tests/auto/widgets/kernel/qaction/tst_qaction.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
index 83e1850524..ac6362168e 100644
--- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
+++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
@@ -62,6 +62,7 @@ private slots:
void task229128TriggeredSignalWithoutActiongroup();
void task229128TriggeredSignalWhenInActiongroup();
void repeat();
+ void keysequence(); // QTBUG-53381
private:
int m_lastEventType;
@@ -276,6 +277,40 @@ void tst_QAction::alternateShortcuts()
QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
}
+void tst_QAction::keysequence()
+{
+ MyWidget testWidget(this);
+ testWidget.show();
+ QApplication::setActiveWindow(&testWidget);
+
+ {
+ QAction act(&testWidget);
+ testWidget.addAction(&act);
+
+ QKeySequence ks(QKeySequence::SelectAll);
+
+ act.setShortcut(ks);
+
+ QSignalSpy spy(&act, &QAction::triggered);
+
+ act.setAutoRepeat(true);
+ QTest::keySequence(&testWidget, ks);
+ QCoreApplication::processEvents();
+ QCOMPARE(spy.count(), 1); // act should have been triggered
+
+ act.setAutoRepeat(false);
+ QTest::keySequence(&testWidget, ks);
+ QCoreApplication::processEvents();
+ QCOMPARE(spy.count(), 2); //act should have been triggered a 2nd time
+
+ // end of the scope of the action, it will be destroyed and removed from widget
+ // This action should also unregister its shortcuts
+ }
+
+ // this tests a crash (if the action did not unregister its alternate shortcuts)
+ QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
+}
+
void tst_QAction::enabledVisibleInteraction()
{
MyWidget testWidget(this);