aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickloader
diff options
context:
space:
mode:
authorWang Chuan <ouchuanm@outlook.com>2020-08-15 14:57:06 +0800
committerWang Chuan <ouchuanm@outlook.com>2020-08-22 15:59:12 +0000
commit3aa4cd682f52b70803cc3f72d732bde9987677dd (patch)
tree528594dd07ad45b26594256c2a018988a852b2c9 /tests/auto/quick/qquickloader
parenta29eb1c15200363a175c1b3a9ad2189b63b9765f (diff)
QQuickLoader: make sure the status property change properly
Since the invocation of [setSource] in qml will clear the old source url first, it is hard to decide whether we have changed the source url, especially when we call [setSource] with an empty string, and the loader's status won't change properly. Pick-to: 5.15 Fixes: QTBUG-85938 Change-Id: If61a33c790a4fd6562611c4c50756bc5e213363a Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/quick/qquickloader')
-rw-r--r--tests/auto/quick/qquickloader/data/setSourceAndCheckStatus.qml14
-rw-r--r--tests/auto/quick/qquickloader/tst_qquickloader.cpp18
2 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickloader/data/setSourceAndCheckStatus.qml b/tests/auto/quick/qquickloader/data/setSourceAndCheckStatus.qml
new file mode 100644
index 0000000000..70779047aa
--- /dev/null
+++ b/tests/auto/quick/qquickloader/data/setSourceAndCheckStatus.qml
@@ -0,0 +1,14 @@
+import QtQuick 2.12
+import QtQuick.Window 2.12
+
+Window {
+ id: root
+ visible: true; width: 640; height: 480
+ Loader {
+ id: loader
+ anchors.fill: parent
+ function load(url) {
+ loader.setSource(url)
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
index 047ca81186..ed3aa09767 100644
--- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp
+++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp
@@ -130,6 +130,8 @@ private slots:
void sourceURLKeepComponent();
void statusChangeOnlyEmittedOnce();
+
+ void setSourceAndCheckStatus();
};
Q_DECLARE_METATYPE(QList<QQmlError>)
@@ -1475,6 +1477,22 @@ void tst_QQuickLoader::statusChangeOnlyEmittedOnce()
QCOMPARE(root->property("statusChangedCounter").toInt(), 2); // 1xLoading + 1xReady*/
}
+void tst_QQuickLoader::setSourceAndCheckStatus()
+{
+ QQmlApplicationEngine engine;
+ auto url = testFileUrl("setSourceAndCheckStatus.qml");
+ engine.load(url);
+ auto root = engine.rootObjects().at(0);
+ QVERIFY(root);
+
+ QQuickLoader *loader = root->findChild<QQuickLoader *>();
+ QMetaObject::invokeMethod(loader, "load", Q_ARG(QVariant, QVariant::fromValue(QStringLiteral("./RedRect.qml"))));
+ QCOMPARE(loader->status(), QQuickLoader::Ready);
+
+ QMetaObject::invokeMethod(loader, "load", Q_ARG(QVariant, QVariant::fromValue(QStringLiteral(""))));
+ QCOMPARE(loader->status(), QQuickLoader::Null);
+}
+
QTEST_MAIN(tst_QQuickLoader)
#include "tst_qquickloader.moc"