aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAntti Hoelttae <ahoelttae@luxoft.com>2019-03-11 08:45:16 -0700
committerAntti Hölttä <AHoelttae@luxoft.com>2019-03-18 16:43:04 +0100
commit4b5670aad31bd066abfbc62354a8b91796d7183a (patch)
tree8892cdf34f332959f453307bee0e210c520e5537 /tests
parent13427797da2464f60412b80b2ad2c4559fc63711 (diff)
Reparenting test
Diffstat (limited to 'tests')
-rw-r--r--tests/reparenting.qml104
-rw-r--r--tests/tests.pro3
-rw-r--r--tests/tst_cursornavigation.cpp92
3 files changed, 196 insertions, 3 deletions
diff --git a/tests/reparenting.qml b/tests/reparenting.qml
new file mode 100644
index 0000000..070a6ff
--- /dev/null
+++ b/tests/reparenting.qml
@@ -0,0 +1,104 @@
+import QtQuick 2.12
+import QtQuick.Controls 2.5
+import QtQuick.Window 2.12
+import CursorNavigation 1.0
+
+Window {
+ id: window0
+ objectName: "window0"
+ width: 100
+ height: 100
+
+ CNRect {
+ id: cn0
+ objectName: "win0Item0"
+ CursorNavigation.objectName: "win0Item0Attached"
+ x: 10
+ y: 10
+ }
+
+ CNRect {
+ id: cn1
+ objectName: "movedItem0"
+ CursorNavigation.objectName: "movedItem0Attached"
+ x: 40
+ y: 10
+ }
+
+ CNRect {
+ id: cn2
+ objectName: "movedItem1"
+ x: 70
+ y: 10
+ }
+
+ function reparent() {
+ cn1.parent = window1.contentItem;
+ cn2.parent = window1.contentItem;
+ }
+
+ Button {
+ x: 30
+ y: 30
+ onClicked: {
+ window0.reparent();
+ }
+ }
+
+ //window that already has CursorNavigation initialized
+ Window {
+ id: window1
+ objectName: "window1"
+ width: 100
+ height: 100
+ visible: true
+
+ CNRect {
+ id: cn1_0
+ objectName: "win1Item0"
+ CursorNavigation.objectName: "win1Item0Attached"
+ x: 10
+ y: 10
+ }
+
+ function reparent() {
+ cn1.parent = window2.contentItem;
+ cn2.parent = window2.contentItem;
+ }
+
+ Button {
+ x: 30
+ y: 30
+ onClicked: {
+ window1.reparent();
+ }
+ }
+
+ }
+
+ //window that does not have CursorNavigation initialized
+ Window {
+ id: window2
+ objectName: "window2"
+ width: 100
+ height: 100
+ visible: true
+
+ function reparent() {
+ cn1.parent = window0.contentItem;
+ cn2.parent = window0.contentItem;
+ }
+
+ Button {
+ x: 30
+ y: 30
+ onClicked: {
+ window2.reparent();
+ }
+ }
+
+ }
+
+}
+
+
diff --git a/tests/tests.pro b/tests/tests.pro
index 6654a27..ac192f3 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -13,4 +13,5 @@ INCLUDEPATH += ../plugin
DISTFILES += \
basics.qml \
CNRect.qml \
- 4WayTest.qml
+ 4WayTest.qml \
+ reparenting.qml
diff --git a/tests/tst_cursornavigation.cpp b/tests/tst_cursornavigation.cpp
index bb810aa..e02df40 100644
--- a/tests/tst_cursornavigation.cpp
+++ b/tests/tst_cursornavigation.cpp
@@ -1,4 +1,5 @@
#include <QtTest>
+#include <qqmlapplicationengine.h>
#include "cursornavigationattached.h"
#include <QSignalSpy>
@@ -21,9 +22,10 @@ private slots:
void test_callbacks();
void test_navigation4Directions();
void test_navigation360();
- void testRedirects();
+ void test_redirects();
void test_trapping();
void test_targetDeletions();
+ void test_reparenting();
};
TestCursorNavigation::TestCursorNavigation()
@@ -229,7 +231,7 @@ void TestCursorNavigation::test_navigation360()
}
-void TestCursorNavigation::testRedirects()
+void TestCursorNavigation::test_redirects()
{
}
@@ -244,6 +246,92 @@ void TestCursorNavigation::test_targetDeletions()
}
+void TestCursorNavigation::test_reparenting()
+{
+ QQmlApplicationEngine *engine = new QQmlApplicationEngine(QFINDTESTDATA("reparenting.qml"));
+
+ QQuickWindow *window0 = nullptr;
+ QQuickWindow *window1 = nullptr;
+ QQuickWindow *window2 = nullptr;
+
+ for (auto i : engine->rootObjects()) {
+ if (i->objectName()=="window0") {
+ window0 = qobject_cast<QQuickWindow*>(i);
+ }
+ }
+
+ QVERIFY(window0 != nullptr);
+
+ window1 = window0->findChild<QQuickWindow*>(QLatin1String("window1"));
+ window2 = window0->findChild<QQuickWindow*>(QLatin1String("window2"));
+
+ QVERIFY(window1 != nullptr);
+ QVERIFY(window2 != nullptr);
+
+ window0->show();
+ window1->show();
+ window2->show();
+ window0->requestActivate();
+
+ QVERIFY(QTest::qWaitForWindowActive(window0));
+ QTRY_COMPARE(window0, qGuiApp->focusWindow());
+
+ QQuickItem *win0Item0 = window0->findChild<QQuickItem*>(QLatin1String("win0Item0"));
+ QQuickItem *movedItem0 = window0->findChild<QQuickItem*>(QLatin1String("movedItem0"));
+ QQuickItem *movedItem1 = window0->findChild<QQuickItem*>(QLatin1String("movedItem1"));
+ QQuickItem *win1Item0 = window1->findChild<QQuickItem*>(QLatin1String("win1Item0"));
+
+ QObject *win0Item0Attached = win0Item0->findChild<QObject*>(QLatin1String("win0Item0Attached"));
+ QObject *win1Item0Attached = win1Item0->findChild<QObject*>(QLatin1String("win1Item0Attached"));
+ QObject *movedItem0Attached = movedItem0->findChild<QObject*>(QLatin1String("movedItem0Attached"));
+
+ QQmlProperty win0Item0HasCursor(win0Item0, "CursorNavigation.hasCursor", qmlContext(win0Item0));
+ QQmlProperty movedItem0HasCursor(movedItem0, "CursorNavigation.hasCursor", qmlContext(movedItem0));
+ QQmlProperty movedItem1HasCursor(movedItem1, "CursorNavigation.hasCursor", qmlContext(movedItem1));
+ QQmlProperty win1Item0HasCursor(win1Item0, "CursorNavigation.hasCursor", qmlContext(win1Item0));
+
+ QVERIFY(win0Item0HasCursor.isValid());
+ QVERIFY(movedItem0HasCursor.isValid());
+
+ //move items from the starting window to the next window that already has cursor navigation available. see that navigation works
+ QMetaObject::invokeMethod(window0, "reparent");
+
+ window1->requestActivate();
+
+ QVERIFY(QTest::qWaitForWindowActive(window1));
+ QTRY_COMPARE(window1, qGuiApp->focusWindow());
+
+ win1Item0->forceActiveFocus();
+ QVERIFY(win1Item0HasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(win1Item0Attached, "moveRight");
+ QVERIFY(movedItem0HasCursor.read().toBool());
+ QMetaObject::invokeMethod(win1Item0Attached, "moveRight");
+ QVERIFY(movedItem1HasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(win1Item0Attached, "moveLeft");
+ QMetaObject::invokeMethod(win1Item0Attached, "moveLeft");
+ QVERIFY(win1Item0HasCursor.read().toBool());
+
+ //move items to the third window that does not have cursor navigation available. see that navigation works
+ QMetaObject::invokeMethod(window1, "reparent");
+
+ QVERIFY(win1Item0HasCursor.read().toBool());
+ QMetaObject::invokeMethod(win1Item0Attached, "moveRight");
+ QVERIFY(win1Item0HasCursor.read().toBool());
+
+ window2->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window2));
+ QTRY_COMPARE(window2, qGuiApp->focusWindow());
+
+ movedItem0->forceActiveFocus();
+ QVERIFY(movedItem0HasCursor.read().toBool());
+ QMetaObject::invokeMethod(movedItem0Attached, "moveRight");
+ QVERIFY(movedItem1HasCursor.read().toBool());
+
+ delete engine;
+}
+
QTEST_MAIN(TestCursorNavigation)
#include "tst_cursornavigation.moc"