summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-09-29 06:34:58 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-09-29 06:34:58 (GMT)
commit275d62f364da0eee08726d95888bca2a8e0fb6e6 (patch)
tree345d11916a9e5c644e3170e118624507c4fd853b
parent1d65aff4f6c0339752c92f859ce78f1a59450a28 (diff)
downloadQt-275d62f364da0eee08726d95888bca2a8e0fb6e6.zip
Qt-275d62f364da0eee08726d95888bca2a8e0fb6e6.tar.gz
Qt-275d62f364da0eee08726d95888bca2a8e0fb6e6.tar.bz2
TextEdit navigation testcase
-rw-r--r--tests/auto/declarative/qfxtextedit/data/navigation.qml23
-rw-r--r--tests/auto/declarative/qfxtextedit/qfxtextedit.pro3
-rw-r--r--tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp56
3 files changed, 81 insertions, 1 deletions
diff --git a/tests/auto/declarative/qfxtextedit/data/navigation.qml b/tests/auto/declarative/qfxtextedit/data/navigation.qml
new file mode 100644
index 0000000..5b8613f
--- /dev/null
+++ b/tests/auto/declarative/qfxtextedit/data/navigation.qml
@@ -0,0 +1,23 @@
+import Qt 4.6
+
+Rectangle {
+ property var myInput: Input
+
+ width: 800; height: 600; color: "blue"
+
+ Item {
+ id: FirstItem;
+ KeyNavigation.right: Input
+ }
+
+ TextEdit { id: Input; focus: true
+ KeyNavigation.left: FirstItem
+ KeyNavigation.right: LastItem
+ KeyNavigation.up: FirstItem
+ KeyNavigation.down: LastItem
+ }
+ Item {
+ id: LastItem
+ KeyNavigation.left: Input
+ }
+}
diff --git a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro
index 59ab6e5..90546a4 100644
--- a/tests/auto/declarative/qfxtextedit/qfxtextedit.pro
+++ b/tests/auto/declarative/qfxtextedit/qfxtextedit.pro
@@ -1,3 +1,6 @@
load(qttest_p4)
contains(QT_CONFIG,declarative): QT += declarative gui
SOURCES += tst_qfxtextedit.cpp
+
+# Define SRCDIR equal to test's source directory
+DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
index e38e0e7..7ab598f 100644
--- a/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
+++ b/tests/auto/declarative/qfxtextedit/tst_qfxtextedit.cpp
@@ -1,4 +1,6 @@
#include <qtest.h>
+#include "../../../shared/util.h"
+#include <QFile>
#include <QTextDocument>
#include <QtDeclarative/qmlengine.h>
#include <QtDeclarative/qmlcontext.h>
@@ -6,6 +8,7 @@
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qfxtextedit.h>
#include <QFontMetrics>
+#include <QmlView>
class tst_qfxtextedit : public QObject
@@ -27,8 +30,12 @@ private slots:
void selection();
void cursorDelegate();
+ void navigation();
private:
+ void simulateKey(QmlView *, int key);
+ QmlView *createView(const QString &filename);
+
QStringList standard;
QStringList richText;
@@ -424,7 +431,6 @@ void tst_qfxtextedit::selection()
QVERIFY(textEditObject->selectedText().size() == 10);
}
-#include <QmlView>
void tst_qfxtextedit::cursorDelegate()
{
QmlView* view = new QmlView(0);
@@ -452,6 +458,54 @@ void tst_qfxtextedit::cursorDelegate()
QVERIFY(!textEditObject->findChild<QFxItem*>("cursorInstance"));
}
+/*
+TextEdit element should only handle left/right keys until the cursor reaches
+the extent of the text, then they should ignore the keys.
+*/
+void tst_qfxtextedit::navigation()
+{
+ QmlView *canvas = createView(SRCDIR "/data/navigation.qml");
+ canvas->execute();
+ canvas->show();
+
+ QVERIFY(canvas->root() != 0);
+
+ QFxItem *input = qobject_cast<QFxItem *>(qvariant_cast<QObject *>(canvas->root()->property("myInput")));
+
+ QVERIFY(input != 0);
+ QTRY_VERIFY(input->hasFocus() == true);
+ simulateKey(canvas, Qt::Key_Left);
+ QVERIFY(input->hasFocus() == false);
+ simulateKey(canvas, Qt::Key_Right);
+ QVERIFY(input->hasFocus() == true);
+ simulateKey(canvas, Qt::Key_Right);
+ QVERIFY(input->hasFocus() == false);
+ simulateKey(canvas, Qt::Key_Left);
+ QVERIFY(input->hasFocus() == true);
+}
+
+void tst_qfxtextedit::simulateKey(QmlView *view, int key)
+{
+ QKeyEvent press(QKeyEvent::KeyPress, key, 0);
+ QKeyEvent release(QKeyEvent::KeyRelease, key, 0);
+
+ QApplication::sendEvent(view, &press);
+ QApplication::sendEvent(view, &release);
+}
+
+QmlView *tst_qfxtextedit::createView(const QString &filename)
+{
+ QmlView *canvas = new QmlView(0);
+
+ QFile file(filename);
+ file.open(QFile::ReadOnly);
+ QString xml = file.readAll();
+ canvas->setQml(xml, filename);
+
+ return canvas;
+}
+
+
QTEST_MAIN(tst_qfxtextedit)
#include "tst_qfxtextedit.moc"