diff options
author | Dave Andrews <jetdog330@hotmail.com> | 2016-08-22 22:43:55 -0400 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2016-09-29 15:04:25 +0000 |
commit | 7cb2d467c3421eced44ae7b887b8738cc68595fc (patch) | |
tree | 52f26037e5963d46383b9484b30f3937755d9c3b /tests/auto/webchannel/tst_webchannel.cpp | |
parent | e354bdc5cbe33621def2b200f01d6376291570fc (diff) | |
download | qtwebchannel-7cb2d467c3421eced44ae7b887b8738cc68595fc.tar.gz |
Fix asynchronous signals from QObjects in different threads
Switches the signal listener in QWebChannel from using
Qt::DirectConnection to Qt::AutoConnection to relay signals
from QObjects in different affinities than the QWebChannel.
Also adds a unit test in testAsyncObject() to verify that
QWebChannel no longer crashes when receiving such a signal,
and that such objects can be added and removed dynamically.
Task-number: QTBUG-51366
Change-Id: I51a4886286fec9257a21ea95360c1ea8889a584a
Reviewed-by: Dave Andrews <jetdog330@hotmail.com>
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'tests/auto/webchannel/tst_webchannel.cpp')
-rw-r--r-- | tests/auto/webchannel/tst_webchannel.cpp | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index 55723ea..2ab820b 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -376,6 +376,12 @@ void TestWebChannel::testInfoForObject() } { QJsonArray method; + method.append(QStringLiteral("fire")); + method.append(obj.metaObject()->indexOfMethod("fire()")); + expected.append(method); + } + { + QJsonArray method; method.append(QStringLiteral("method1")); method.append(obj.metaObject()->indexOfMethod("method1()")); expected.append(method); @@ -403,6 +409,12 @@ void TestWebChannel::testInfoForObject() signal.append(obj.metaObject()->indexOfMethod("sig2(QString)")); expected.append(signal); } + { + QJsonArray signal; + signal.append(QStringLiteral("replay")); + signal.append(obj.metaObject()->indexOfMethod("replay()")); + expected.append(signal); + } QCOMPARE(info["signals"].toArray(), expected); } @@ -735,10 +747,30 @@ void TestWebChannel::testAsyncObject() int method = obj.metaObject()->indexOfMethod("setProp(QString)"); QVERIFY(method != -1); - QSignalSpy spy(&obj, &TestObject::propChanged); - channel.d_func()->publisher->invokeMethod(&obj, method, args); - QVERIFY(spy.wait()); - QCOMPARE(spy.at(0).at(0).toString(), args.at(0).toString()); + { + QSignalSpy spy(&obj, &TestObject::propChanged); + channel.d_func()->publisher->invokeMethod(&obj, method, args); + QVERIFY(spy.wait()); + QCOMPARE(spy.at(0).at(0).toString(), args.at(0).toString()); + } + + channel.registerObject("myObj", &obj); + channel.d_func()->publisher->initializeClient(m_dummyTransport); + + QJsonObject connectMessage; + connectMessage["type"] = 7; + connectMessage["object"] = "myObj"; + connectMessage["signal"] = obj.metaObject()->indexOfSignal("replay()"); + channel.d_func()->publisher->handleMessage(connectMessage, m_dummyTransport); + + { + QSignalSpy spy(&obj, &TestObject::replay); + QMetaObject::invokeMethod(&obj, "fire"); + QVERIFY(spy.wait()); + channel.deregisterObject(&obj); + QMetaObject::invokeMethod(&obj, "fire"); + QVERIFY(spy.wait()); + } thread.quit(); thread.wait(); |