diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-07-19 05:15:58 (GMT) |
---|---|---|
committer | Andrew den Exter <andrew.den-exter@nokia.com> | 2011-07-19 05:57:22 (GMT) |
commit | f9e7aee2019d321edd655bfde7de43f20a106971 (patch) | |
tree | d031fdfe4c9f1b63bffb395e8572454578e339d0 /tests/auto/declarative | |
parent | cf23188de237009136fa1480ab8fd9e3ca364769 (diff) | |
download | Qt-f9e7aee2019d321edd655bfde7de43f20a106971.zip Qt-f9e7aee2019d321edd655bfde7de43f20a106971.tar.gz Qt-f9e7aee2019d321edd655bfde7de43f20a106971.tar.bz2 |
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.
Change-Id: I55f527932d34453828caba88e93ad57e012e79be
Task-number: QTBUG-17003
Reviewed-by: Martin Jones
Diffstat (limited to 'tests/auto/declarative')
-rw-r--r-- | tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 19b7a76..280f952 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -52,6 +52,8 @@ #include <QInputContext> #include <private/qapplication_p.h> +#include "qplatformdefs.h" + #ifdef Q_OS_SYMBIAN // In Symbian OS test data is located in applications private dir #define SRCDIR "." @@ -133,6 +135,9 @@ private slots: void focusOutClearSelection(); void echoMode(); +#ifdef QT_GUI_PASSWORD_ECHO_DELAY + void passwordEchoDelay(); +#endif void geometrySignals(); void testQtQuick11Attributes(); void testQtQuick11Attributes_data(); @@ -2051,6 +2056,62 @@ void tst_qdeclarativetextinput::echoMode() delete canvas; } + +#ifdef QT_GUI_PASSWORD_ECHO_DELAY +void tst_qdeclarativetextinput::passwordEchoDelay() +{ + QDeclarativeView *canvas = createView(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); + + QDeclarativeTextInput *input = qobject_cast<QDeclarativeTextInput *>(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')); + + delete canvas; +} +#endif + + void tst_qdeclarativetextinput::simulateKey(QDeclarativeView *view, int key) { QKeyEvent press(QKeyEvent::KeyPress, key, 0); |