summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qdeclarativetextinput
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qdeclarativetextinput')
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/data/echoMode.qml11
-rw-r--r--tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp39
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/auto/declarative/qdeclarativetextinput/data/echoMode.qml b/tests/auto/declarative/qdeclarativetextinput/data/echoMode.qml
new file mode 100644
index 0000000..5773cc2
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativetextinput/data/echoMode.qml
@@ -0,0 +1,11 @@
+import Qt 4.7
+
+Rectangle {
+ property var myInput: input
+
+ width: 400; height: 200; color: "green"
+
+ TextInput { id: input; focus: true
+ text: "ABCDefgh"
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
index dd74c09..9a66a36 100644
--- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
+++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp
@@ -75,6 +75,7 @@ private slots:
void setHAlignClearCache();
void focusOutClearSelection();
+ void echoMode();
private:
void simulateKey(QDeclarativeView *, int key);
QDeclarativeView *createView(const QString &filename);
@@ -630,6 +631,44 @@ void tst_qdeclarativetextinput::readOnly()
delete canvas;
}
+void tst_qdeclarativetextinput::echoMode()
+{
+ QDeclarativeView *canvas = createView(SRCDIR "/data/echoMode.qml");
+ canvas->show();
+ canvas->setFocus();
+
+ QVERIFY(canvas->rootObject() != 0);
+
+ QDeclarativeTextInput *input = qobject_cast<QDeclarativeTextInput *>(qvariant_cast<QObject *>(canvas->rootObject()->property("myInput")));
+
+ QVERIFY(input != 0);
+ QTRY_VERIFY(input->hasFocus() == true);
+ QString initial = input->text();
+ QCOMPARE(initial, QLatin1String("ABCDefgh"));
+ QCOMPARE(input->echoMode(), QDeclarativeTextInput::Normal);
+ QCOMPARE(input->displayText(), input->text());
+ input->setEchoMode(QDeclarativeTextInput::NoEcho);
+ QCOMPARE(input->text(), initial);
+ QCOMPARE(input->displayText(), QLatin1String(""));
+ QCOMPARE(input->passwordCharacter(), QLatin1String("*"));
+ input->setEchoMode(QDeclarativeTextInput::Password);
+ QCOMPARE(input->text(), initial);
+ QCOMPARE(input->displayText(), QLatin1String("********"));
+ input->setPasswordCharacter(QChar('Q'));
+ QCOMPARE(input->passwordCharacter(), QLatin1String("Q"));
+ QCOMPARE(input->text(), initial);
+ QCOMPARE(input->displayText(), QLatin1String("QQQQQQQQ"));
+ input->setEchoMode(QDeclarativeTextInput::PasswordEchoOnEdit);
+ QCOMPARE(input->text(), initial);
+ QCOMPARE(input->displayText(), QLatin1String("QQQQQQQQ"));
+ QTest::keyPress(canvas, Qt::Key_A);//Clearing previous entry is part of PasswordEchoOnEdit
+ QTest::keyRelease(canvas, Qt::Key_A, Qt::NoModifier ,10);
+ QCOMPARE(input->text(), QLatin1String("a"));
+ QCOMPARE(input->displayText(), QLatin1String("a"));
+ input->setFocus(false);
+ QCOMPARE(input->displayText(), QLatin1String("Q"));
+}
+
void tst_qdeclarativetextinput::simulateKey(QDeclarativeView *view, int key)
{
QKeyEvent press(QKeyEvent::KeyPress, key, 0);