diff options
author | Jani Honkonen <jani.honkonen@digia.com> | 2012-02-03 14:57:58 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-22 00:59:33 (GMT) |
commit | c09e9f71173a698670d6c728291ee24f53d50800 (patch) | |
tree | eece03b674f7783807205b4aa01a097914ce4a6e /tests | |
parent | 1de75716d6f0691cc57feb21768f250236eebfd4 (diff) | |
download | Qt-c09e9f71173a698670d6c728291ee24f53d50800.zip Qt-c09e9f71173a698670d6c728291ee24f53d50800.tar.gz Qt-c09e9f71173a698670d6c728291ee24f53d50800.tar.bz2 |
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.
Backported from Qt5 SHA1: 121062d8848986dcfaf421388a5603b3b48a1e58
Task-number: QTBUG-14226
Change-Id: Ia712f95e8a2e45537a95d48b70686a1a8dd95da2
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qlineedit/tst_qlineedit.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp index cbbe1e7..d96fc9b 100644 --- a/tests/auto/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/qlineedit/tst_qlineedit.cpp @@ -295,6 +295,9 @@ private slots: void bidiLogicalMovement_data(); void bidiLogicalMovement(); + void undoRedoAndEchoModes_data(); + void undoRedoAndEchoModes(); + protected slots: #ifdef QT3_SUPPORT void lostFocus(); @@ -3979,5 +3982,68 @@ void tst_QLineEdit::bidiLogicalMovement() } while (moved && i >= 0); } +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" |