aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2020-01-03 10:32:01 +0100
committerSimon Hausmann <simon.hausmann@qt.io>2020-01-03 12:02:18 +0000
commit01bbd7e41ac8444d2282ac6ca1862c3748f685a1 (patch)
treead46297d0f39957fd2597f19f2e5eacbeb0240d5 /tests
parenta4150b040e8492e070d6bfefb190ae0852644f11 (diff)
QV4::ExecutionEngine: provide QNAM accessor
In XMLHttpRequest, we need to get the QNetworkAccessManager from the engine. However, if the request originates from a WorkerScript, there exists no qmlEngine. We therefore add a new indirection to access the QNAM, and set it up accordinly in registerWorkerScript. Fixes: QTBUG-81055 Change-Id: I8915202b6d6b7139c8386304b3d1d7a22a82045e Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qquickworkerscript/data/doRequest.mjs6
-rw-r--r--tests/auto/qml/qquickworkerscript/data/xmlHttpRequest.qml16
-rw-r--r--tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp8
3 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qquickworkerscript/data/doRequest.mjs b/tests/auto/qml/qquickworkerscript/data/doRequest.mjs
new file mode 100644
index 0000000000..d607c3400d
--- /dev/null
+++ b/tests/auto/qml/qquickworkerscript/data/doRequest.mjs
@@ -0,0 +1,6 @@
+WorkerScript.onMessage = function(message)
+{
+ var req = new XMLHttpRequest();
+ req.open("GET", message.url, true);
+ req.send();
+};
diff --git a/tests/auto/qml/qquickworkerscript/data/xmlHttpRequest.qml b/tests/auto/qml/qquickworkerscript/data/xmlHttpRequest.qml
new file mode 100644
index 0000000000..42136d78f0
--- /dev/null
+++ b/tests/auto/qml/qquickworkerscript/data/xmlHttpRequest.qml
@@ -0,0 +1,16 @@
+import QtQuick 2.14
+
+Rectangle
+{
+ width: 100
+ height: 100
+
+ WorkerScript
+ {
+ source: "doRequest.mjs"
+ Component.onCompleted:
+ {
+ sendMessage({"url": "https://example.com"});
+ }
+ }
+}
diff --git a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp
index bea9978f0b..d11e7bde4b 100644
--- a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp
+++ b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp
@@ -59,6 +59,7 @@ private slots:
void script_function();
void script_var();
void stressDispose();
+ void xmlHttpRequest();
private:
void waitForEchoMessage(QQuickWorkerScript *worker) {
@@ -341,6 +342,13 @@ void tst_QQuickWorkerScript::stressDispose()
}
}
+void tst_QQuickWorkerScript::xmlHttpRequest()
+{
+ QQmlComponent component(&m_engine, testFileUrl("xmlHttpRequest.qml"));
+ QScopedPointer<QObject> root{component.create()}; // should not crash
+ QVERIFY(root);
+}
+
QTEST_MAIN(tst_QQuickWorkerScript)
#include "tst_qquickworkerscript.moc"