summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/widgets/qlineedit
diff options
context:
space:
mode:
authorJani Honkonen <jani.honkonen@digia.com>2012-08-06 13:18:48 +0300
committerQt by Nokia <qt-info@nokia.com>2012-08-15 11:38:37 +0200
commit121062d8848986dcfaf421388a5603b3b48a1e58 (patch)
tree08d92b7e0cb90d6bd49b868d75df8f394913810e /tests/auto/widgets/widgets/qlineedit
parentd19589b90adca7130129b59b662e515226a943e1 (diff)
Fix undo and redo in QLineEdit when in password mode
There are some security issues with undo/redo. User should not be able to get the erased password back in any situation. Therefore redo must be disabled completely and undo is limited only for erasing previously entered text. Task-number: QTBUG-14226 Change-Id: I2b38aca84adbad1c14db76b56ad6303d56b35b4d Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests/auto/widgets/widgets/qlineedit')
-rw-r--r--tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
index 956f970b85..ed53a133e4 100644
--- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp
@@ -287,6 +287,9 @@ private slots:
void inputMethodQueryImHints_data();
void inputMethodQueryImHints();
+ void undoRedoAndEchoModes_data();
+ void undoRedoAndEchoModes();
+
protected slots:
void editingFinished();
@@ -3954,5 +3957,68 @@ void tst_QLineEdit::inputMethodQueryImHints()
QCOMPARE(static_cast<Qt::InputMethodHints>(value.toInt()), hints);
}
+void tst_QLineEdit::undoRedoAndEchoModes_data()
+{
+ QTest::addColumn<int>("echoMode");
+ QTest::addColumn<QStringList>("input");
+ QTest::addColumn<QStringList>("expected");
+
+ QStringList input(QList<QString>() << "aaa" << "bbb" << "ccc");
+
+ QTest::newRow("Normal")
+ << (int) QLineEdit::Normal
+ << input
+ << QStringList(QList<QString>() << "aaa" << "ccc" << "");
+
+ QTest::newRow("NoEcho")
+ << (int) QLineEdit::NoEcho
+ << input
+ << QStringList(QList<QString>() << "" << "" << "");
+
+ QTest::newRow("Password")
+ << (int) QLineEdit::Password
+ << input
+ << QStringList(QList<QString>() << "" << "" << "");
+
+ QTest::newRow("PasswordEchoOnEdit")
+ << (int) QLineEdit::PasswordEchoOnEdit
+ << input
+ << QStringList(QList<QString>() << "" << "" << "");
+}
+
+void tst_QLineEdit::undoRedoAndEchoModes()
+{
+ QFETCH(int, echoMode);
+ QFETCH(QStringList, input);
+ QFETCH(QStringList, expected);
+
+ // create some history for the QLineEdit
+ testWidget->clear();
+ testWidget->setEchoMode(QLineEdit::EchoMode(echoMode));
+ testWidget->insert(input.at(0));
+ testWidget->selectAll();
+ testWidget->backspace();
+ testWidget->insert(input.at(1));
+
+ // test undo
+ QVERIFY(testWidget->isUndoAvailable());
+ testWidget->undo();
+ QCOMPARE(testWidget->text(), expected.at(0));
+ testWidget->insert(input.at(2));
+ testWidget->selectAll();
+ testWidget->backspace();
+ QCOMPARE(testWidget->isUndoAvailable(), echoMode == QLineEdit::Normal);
+ testWidget->undo();
+ QCOMPARE(testWidget->text(), expected.at(1));
+
+ // test redo
+ QCOMPARE(testWidget->isRedoAvailable(), echoMode == QLineEdit::Normal);
+ testWidget->redo();
+ QCOMPARE(testWidget->text(), expected.at(2));
+ QVERIFY(!testWidget->isRedoAvailable());
+ testWidget->redo();
+ QCOMPARE(testWidget->text(), expected.at(2));
+}
+
QTEST_MAIN(tst_QLineEdit)
#include "tst_qlineedit.moc"