diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-07-19 15:15:58 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-06 02:58:47 +0200 |
commit | 249754bf7fe4a195c723eea73f2dd55a2bd905cb (patch) | |
tree | c51ba606064b5fbb258f31c3de8019ec246a5c25 /tests/auto/declarative/qsgtextinput | |
parent | c0fe60cad2c48f18e618c3ca4589abe73752389e (diff) |
Delay masking the last character in Password echo mode.
If QT_GUI_PASSWORD_ECHO_DELAY is defined in qplatformdefs.h with an
integer value in milliseconds, QLineEdit and TextInput will display
the last character entered unmasked for that delay period and then
mask the character as normal. If QT_GUI_PASSWORD_ECHO_DELAY is
not defined then the behaviour is unchanged.
Task-number: QTBUG-17003
Reviewed-by: Martin Jones
(cherry picked from commit f9e7aee2019d321edd655bfde7de43f20a106971)
Change-Id: Iddfa0daa1b39f0589cab27e5003fdd86ad81ff89
Reviewed-on: http://codereview.qt.nokia.com/4170
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qsgtextinput')
-rw-r--r-- | tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp index 32e59c2a6d..1ada6895c0 100644 --- a/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp +++ b/tests/auto/declarative/qsgtextinput/tst_qsgtextinput.cpp @@ -55,6 +55,8 @@ #include <QtOpenGL/QGLShaderProgram> #include <math.h> +#include "qplatformdefs.h" + #ifdef Q_OS_SYMBIAN // In Symbian OS test data is located in applications private dir #define SRCDIR "." @@ -132,6 +134,9 @@ private slots: void focusOutClearSelection(); void echoMode(); +#ifdef QT_GUI_PASSWORD_ECHO_DELAY + void passwordEchoDelay(); +#endif void geometrySignals(); void testQtQuick11Attributes(); void testQtQuick11Attributes_data(); @@ -1944,6 +1949,59 @@ void tst_qsgtextinput::echoMode() QCOMPARE(input->inputMethodQuery(Qt::ImSurroundingText).toString(), initial); } +#ifdef QT_GUI_PASSWORD_ECHO_DELAY +void tst_qdeclarativetextinput::passwordEchoDelay() +{ + QSGView canvas(QUrl::fromLocalFile(SRCDIR "/data/echoMode.qml")); + canvas.show(); + canvas.setFocus(); + QApplication::setActiveWindow(&canvas); + QTest::qWaitForWindowShown(&canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&canvas)); + + QVERIFY(canvas.rootObject() != 0); + + QSGTextInput *input = qobject_cast<QSGTextInput *>(qvariant_cast<QObject *>(canvas.rootObject()->property("myInput"))); + + QChar fillChar = QLatin1Char('*'); + + input->setEchoMode(QDeclarativeTextInput::Password); + QCOMPARE(input->displayText(), QString(8, fillChar)); + input->setText(QString()); + QCOMPARE(input->displayText(), QString()); + + QTest::keyPress(&canvas, '0'); + QTest::keyPress(&canvas, '1'); + QTest::keyPress(&canvas, '2'); + QCOMPARE(input->displayText(), QString(2, fillChar) + QLatin1Char('2')); + QTest::keyPress(&canvas, '3'); + QTest::keyPress(&canvas, '4'); + QCOMPARE(input->displayText(), QString(4, fillChar) + QLatin1Char('4')); + QTest::keyPress(&canvas, Qt::Key_Backspace); + QCOMPARE(input->displayText(), QString(4, fillChar)); + QTest::keyPress(&canvas, '4'); + QCOMPARE(input->displayText(), QString(4, fillChar) + QLatin1Char('4')); + QTest::qWait(QT_GUI_PASSWORD_ECHO_DELAY); + QTRY_COMPARE(input->displayText(), QString(5, fillChar)); + QTest::keyPress(&canvas, '5'); + QCOMPARE(input->displayText(), QString(5, fillChar) + QLatin1Char('5')); + input->setFocus(false); + QVERIFY(!input->hasFocus()); + QCOMPARE(input->displayText(), QString(6, fillChar)); + input->setFocus(true); + QTRY_VERIFY(input->hasFocus()); + QCOMPARE(input->displayText(), QString(6, fillChar)); + QTest::keyPress(&canvas, '6'); + QCOMPARE(input->displayText(), QString(6, fillChar) + QLatin1Char('6')); + + QInputMethodEvent ev; + ev.setCommitString(QLatin1String("7")); + QApplication::sendEvent(&canvas, &ev); + QCOMPARE(input->displayText(), QString(7, fillChar) + QLatin1Char('7')); +} +#endif + + void tst_qsgtextinput::simulateKey(QSGView *view, int key) { QKeyEvent press(QKeyEvent::KeyPress, key, 0); |