From e89a17af703250f06002e16fd00e9ed407769fc4 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 9 Jul 2012 16:33:21 +1000 Subject: [PATCH] Add tests for instantiating cursor delegates in the Loading state. Components created by QML are usually (always?) ready when assigned to n property, but it possible for an externally supplied component to still be loading, as in the test and the code handles it. Change-Id: I2058e3479e2e711b52af2a0128e6e4c4c3ff7504 Reviewed-by: Martin Jones --- .../quick/qquicktextedit/data/RemoteCursor.qml | 5 +++ .../quick/qquicktextedit/data/cursorTestRemote.qml | 13 +++++++ .../quick/qquicktextedit/tst_qquicktextedit.cpp | 41 ++++++++++++++++++++-- .../quick/qquicktextinput/data/RemoteCursor.qml | 5 +++ .../qquicktextinput/data/cursorTestRemote.qml | 12 +++++++ .../auto/quick/qquicktextinput/qquicktextinput.pro | 5 ++- .../quick/qquicktextinput/tst_qquicktextinput.cpp | 37 +++++++++++++++++++ 7 files changed, 114 insertions(+), 4 deletions(-) create mode 100644 tests/auto/quick/qquicktextedit/data/RemoteCursor.qml create mode 100644 tests/auto/quick/qquicktextedit/data/cursorTestRemote.qml create mode 100644 tests/auto/quick/qquicktextinput/data/RemoteCursor.qml create mode 100644 tests/auto/quick/qquicktextinput/data/cursorTestRemote.qml diff --git a/tests/auto/quick/qquicktextedit/data/RemoteCursor.qml b/tests/auto/quick/qquicktextedit/data/RemoteCursor.qml new file mode 100644 index 0000000..7f459f5 --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/RemoteCursor.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Rectangle { + objectName: "cursorInstance" +} diff --git a/tests/auto/quick/qquicktextedit/data/cursorTestRemote.qml b/tests/auto/quick/qquicktextedit/data/cursorTestRemote.qml new file mode 100644 index 0000000..77e070d --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/cursorTestRemote.qml @@ -0,0 +1,13 @@ +import QtQuick 2.0 + +Rectangle { width: 300; height: 300; color: "white" + property string contextualProperty: "Hello" + TextEdit { + text: "Hello world!" + id: textEditObject; + objectName: "textEditObject" + width: 300; height: 300 + wrapMode: TextEdit.WordWrap + cursorDelegate: contextDelegate + } +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index 61c2df2..26d64e7 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -68,6 +68,8 @@ #include #endif +#define SERVER_PORT 42332 +#define SERVER_ADDR "http://localhost:42332" Q_DECLARE_METATYPE(QQuickTextEdit::SelectionMode) Q_DECLARE_METATYPE(Qt::Key) @@ -138,6 +140,7 @@ private slots: void cursorDelegate_data(); void cursorDelegate(); + void remoteCursorDelegate(); void cursorVisible(); void delegateLoading_data(); void delegateLoading(); @@ -2161,6 +2164,38 @@ void tst_qquicktextedit::cursorDelegate() QVERIFY(!textEditObject->findChild("cursorInstance")); } +void tst_qquicktextedit::remoteCursorDelegate() +{ + TestHTTPServer server(SERVER_PORT); + server.serveDirectory(dataDirectory()); + + QQuickView view; + + QQmlComponent component(view.engine(), QUrl(SERVER_ADDR "/RemoteCursor.qml")); + + view.rootContext()->setContextProperty("contextDelegate", &component); + view.setSource(testFileUrl("cursorTestRemote.qml")); + view.show(); + view.requestActivateWindow(); + QQuickTextEdit *textEditObject = view.rootObject()->findChild("textEditObject"); + QVERIFY(textEditObject != 0); + + // Delegate is created on demand, and so won't be available immediately. Focus in or + // setCursorVisible(true) will trigger creation. + QTRY_VERIFY(!textEditObject->findChild("cursorInstance")); + QVERIFY(!textEditObject->isCursorVisible()); + + textEditObject->setFocus(true); + QVERIFY(textEditObject->isCursorVisible()); + + QCOMPARE(component.status(), QQmlComponent::Loading); + QVERIFY(!textEditObject->findChild("cursorInstance")); + + // Wait for component to load. + QTRY_COMPARE(component.status(), QQmlComponent::Ready); + QVERIFY(textEditObject->findChild("cursorInstance")); +} + void tst_qquicktextedit::cursorVisible() { QQuickTextEdit edit; @@ -2270,12 +2305,12 @@ void tst_qquicktextedit::delegateLoading() QFETCH(QString, qmlfile); QFETCH(QString, error); - TestHTTPServer server(42332); + TestHTTPServer server(SERVER_PORT); server.serveDirectory(testFile("httpfail"), TestHTTPServer::Disconnect); server.serveDirectory(testFile("httpslow"), TestHTTPServer::Delay); server.serveDirectory(testFile("http")); - QQuickView view(QUrl(QLatin1String("http://localhost:42332/") + qmlfile)); + QQuickView view(QUrl(QLatin1String(SERVER_ADDR "/") + qmlfile)); view.show(); view.requestActivateWindow(); @@ -4504,7 +4539,7 @@ void tst_qquicktextedit::embeddedImages() QFETCH(QUrl, qmlfile); QFETCH(QString, error); - TestHTTPServer server(42332); + TestHTTPServer server(SERVER_PORT); server.serveDirectory(testFile("http")); if (!error.isEmpty()) diff --git a/tests/auto/quick/qquicktextinput/data/RemoteCursor.qml b/tests/auto/quick/qquicktextinput/data/RemoteCursor.qml new file mode 100644 index 0000000..7f459f5 --- /dev/null +++ b/tests/auto/quick/qquicktextinput/data/RemoteCursor.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 + +Rectangle { + objectName: "cursorInstance" +} diff --git a/tests/auto/quick/qquicktextinput/data/cursorTestRemote.qml b/tests/auto/quick/qquicktextinput/data/cursorTestRemote.qml new file mode 100644 index 0000000..8ae872a --- /dev/null +++ b/tests/auto/quick/qquicktextinput/data/cursorTestRemote.qml @@ -0,0 +1,12 @@ +import QtQuick 2.0 + +Rectangle { width: 300; height: 300; color: "white" + TextInput { + text: "Hello world!" + id: textInputObject; + objectName: "textInputObject" + width: 300; height: 300 + wrapMode: TextInput.Wrap + cursorDelegate: contextDelegate + } +} diff --git a/tests/auto/quick/qquicktextinput/qquicktextinput.pro b/tests/auto/quick/qquicktextinput/qquicktextinput.pro index 13b087e..76cb177 100644 --- a/tests/auto/quick/qquicktextinput/qquicktextinput.pro +++ b/tests/auto/quick/qquicktextinput/qquicktextinput.pro @@ -2,7 +2,10 @@ CONFIG += testcase TARGET = tst_qquicktextinput macx:CONFIG -= app_bundle -SOURCES += tst_qquicktextinput.cpp +SOURCES += tst_qquicktextinput.cpp \ + ../../shared/testhttpserver.cpp + +HEADERS += ../../shared/testhttpserver.h include (../../shared/util.pri) diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 4261faf..4626767 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -41,6 +41,7 @@ #include #include #include "../../shared/util.h" +#include "../../shared/testhttpserver.h" #include #include #include @@ -62,6 +63,9 @@ #include "qplatformdefs.h" #include "../../shared/platforminputcontext.h" +#define SERVER_PORT 14460 +#define SERVER_ADDR "http://localhost:14460" + Q_DECLARE_METATYPE(QQuickTextInput::SelectionMode) Q_DECLARE_METATYPE(QQuickTextInput::EchoMode) Q_DECLARE_METATYPE(Qt::Key) @@ -142,6 +146,7 @@ private slots: void passwordCharacter(); void cursorDelegate_data(); void cursorDelegate(); + void remoteCursorDelegate(); void cursorVisible(); void cursorRectangle_data(); void cursorRectangle(); @@ -2603,6 +2608,38 @@ void tst_qquicktextinput::cursorDelegate() QVERIFY(!textInputObject->findChild("cursorInstance")); } +void tst_qquicktextinput::remoteCursorDelegate() +{ + TestHTTPServer server(SERVER_PORT); + server.serveDirectory(dataDirectory()); + + QQuickView view; + + QQmlComponent component(view.engine(), QUrl(SERVER_ADDR "/RemoteCursor.qml")); + + view.rootContext()->setContextProperty("contextDelegate", &component); + view.setSource(testFileUrl("cursorTestRemote.qml")); + view.show(); + view.requestActivateWindow(); + QQuickTextInput *textInputObject = view.rootObject()->findChild("textInputObject"); + QVERIFY(textInputObject != 0); + + // Delegate is created on demand, and so won't be available immediately. Focus in or + // setCursorVisible(true) will trigger creation. + QTRY_VERIFY(!textInputObject->findChild("cursorInstance")); + QVERIFY(!textInputObject->isCursorVisible()); + + textInputObject->setFocus(true); + QVERIFY(textInputObject->isCursorVisible()); + + QCOMPARE(component.status(), QQmlComponent::Loading); + QVERIFY(!textInputObject->findChild("cursorInstance")); + + // Wait for component to load. + QTRY_COMPARE(component.status(), QQmlComponent::Ready); + QVERIFY(textInputObject->findChild("cursorInstance")); +} + void tst_qquicktextinput::cursorVisible() { QQuickTextInput input; -- 2.7.4