diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-17 16:53:05 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2018-08-21 06:33:27 +0000 |
commit | 4b73fc5bd2fd3df10f1e7499c82da08fbd417055 (patch) | |
tree | 2eb2bbe263a9e4639c18f359a8fd1a20b4e6f28b /tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp | |
parent | 1d769f0c5f76ad06466f873b0421e59e984a263b (diff) |
Add support for ECMASCript modules in WorkerScript elements
Similar to script imports from .qml files, the .mjs extension is used to
distinguish between ES modules and plain script files.
Change-Id: Id5f9b59fb77e99e3c9d6a404e6d091d96b501ad6
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp')
-rw-r--r-- | tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp index e21a53b4f3..4ad58ba56c 100644 --- a/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp +++ b/tests/auto/qml/qquickworkerscript/tst_qquickworkerscript.cpp @@ -77,24 +77,30 @@ private: void tst_QQuickWorkerScript::source() { QQmlComponent component(&m_engine, testFileUrl("worker.qml")); - QQuickWorkerScript *worker = qobject_cast<QQuickWorkerScript*>(component.create()); + QScopedPointer<QQuickWorkerScript>worker(qobject_cast<QQuickWorkerScript*>(component.create())); QVERIFY(worker != nullptr); const QMetaObject *mo = worker->metaObject(); QVariant value(100); - QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); - waitForEchoMessage(worker); - QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value<QVariant>(), value); + QVERIFY(QMetaObject::invokeMethod(worker.data(), "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker.data()); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker.data()).value<QVariant>(), value); QUrl source = testFileUrl("script_fixed_return.js"); worker->setSource(source); QCOMPARE(worker->source(), source); - QVERIFY(QMetaObject::invokeMethod(worker, "testSend", Q_ARG(QVariant, value))); - waitForEchoMessage(worker); - QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker).value<QVariant>(), qVariantFromValue(QString("Hello_World"))); + QVERIFY(QMetaObject::invokeMethod(worker.data(), "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker.data()); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker.data()).value<QVariant>(), qVariantFromValue(QString("Hello_World"))); + + source = testFileUrl("script_module.mjs"); + worker->setSource(source); + QCOMPARE(worker->source(), source); + QVERIFY(QMetaObject::invokeMethod(worker.data(), "testSend", Q_ARG(QVariant, value))); + waitForEchoMessage(worker.data()); + QCOMPARE(mo->property(mo->indexOfProperty("response")).read(worker.data()).value<QVariant>(), qVariantFromValue(QString("Hello from the module"))); qApp->processEvents(); - delete worker; } void tst_QQuickWorkerScript::messaging() |