diff options
author | Lutz Schönemann <lutz.schoenemann@basyskom.com> | 2014-08-06 13:38:00 +0200 |
---|---|---|
committer | Lutz Schönemann <lutz.schoenemann@basyskom.com> | 2014-08-08 12:56:52 +0200 |
commit | 313db65d41c1a69053fd32a07ece1d8eca223916 (patch) | |
tree | c586fd264d6237f3dcd3447accaef87eb590c871 /tests/auto/qml | |
parent | cb01c71502898666d286e42c8e552b78b854fc2b (diff) | |
download | qtwebchannel-313db65d41c1a69053fd32a07ece1d8eca223916.tar.gz |
Call unwrapQObject for every response we get
The JS lib will miss to add QObjects to the local
object descriptions when receiving a new description
and the user has not registered a callback function.
This patch makes the lib execute unwrapQObject for
all responses received from a function call.
Change-Id: I72d872d65a7e7bec1d7e6ffb1eea674d0f6e50d7
Reviewed-by: Milian Wolff <milian.wolff@kdab.com>
Diffstat (limited to 'tests/auto/qml')
-rw-r--r-- | tests/auto/qml/tst_webchannel.qml | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/tests/auto/qml/tst_webchannel.qml b/tests/auto/qml/tst_webchannel.qml index 8ac59eb..cd7d14e 100644 --- a/tests/auto/qml/tst_webchannel.qml +++ b/tests/auto/qml/tst_webchannel.qml @@ -211,9 +211,11 @@ TestCase { var signalArgs; var testObjBeforeDeletion; var testObjAfterDeletion; + var testObjId; var channel = client.createChannel(function(channel) { channel.objects.myFactory.create("testObj", function(obj) { - channel.objects.testObj = obj; + testObjId = obj.__id__; + compare(channel.objects[testObjId], obj); obj.mySignal.connect(function() { signalArgs = arguments; testObjBeforeDeletion = obj; @@ -231,26 +233,26 @@ TestCase { compare(msg.object, "myFactory"); verify(myFactory.lastObj); compare(myFactory.lastObj.objectName, "testObj"); + compare(channel.objects[testObjId].objectName, "testObj"); // deleteLater signal connection msg = client.awaitMessage(); compare(msg.type, JSClient.QWebChannelMessageTypes.connectToSignal); - verify(msg.object); - var objId = msg.object; + compare(msg.object, testObjId); // mySignal connection msg = client.awaitMessage(); compare(msg.type, JSClient.QWebChannelMessageTypes.connectToSignal); - compare(msg.object, objId); + compare(msg.object, testObjId); msg = client.awaitMessage(); compare(msg.type, JSClient.QWebChannelMessageTypes.setProperty); - compare(msg.object, objId); + compare(msg.object, testObjId); compare(myFactory.lastObj.myProperty, 42); msg = client.awaitMessage(); compare(msg.type, JSClient.QWebChannelMessageTypes.invokeMethod); - compare(msg.object, objId); + compare(msg.object, testObjId); compare(msg.args, ["foobar"]); compare(lastMethodArg, "foobar"); @@ -259,7 +261,7 @@ TestCase { // deleteLater call msg = client.awaitMessage(); compare(msg.type, JSClient.QWebChannelMessageTypes.invokeMethod); - compare(msg.object, objId); + compare(msg.object, testObjId); compare(signalArgs, {"0": "foobar", "1": 42}); @@ -267,7 +269,38 @@ TestCase { compare(JSON.stringify(testObjBeforeDeletion), JSON.stringify({})); compare(JSON.stringify(testObjAfterDeletion), JSON.stringify({})); - compare(JSON.stringify(channel.objects.testObj), JSON.stringify({})); + compare(typeof channel.objects[testObjId], "undefined"); + } + + // test if returned QObjects get inserted into list of + // objects even if no callback function is set + function test_wrapper_wrapEveryQObject() + { + var channel = client.createChannel(function(channel) { + channel.objects.myFactory.create("testObj"); + }); + client.awaitInit(); + + // ignore first message (call to myFactory.create()) + client.awaitMessage(); + + // second message connects to destroyed signal and contains the new objects ID + var msg = client.awaitMessage(); + verify(msg.object); + + var testObjId = msg.object; + compare(msg.type, JSClient.QWebChannelMessageTypes.connectToSignal); + compare(typeof channel.objects[testObjId], "object"); + + channel.objects[testObjId].deleteLater(); + msg = client.awaitMessage(); + + // after receiving the destroyed signal the client deletes + // local objects and sends back a idle message + client.awaitIdle(); + + compare(myFactory.lastObj, null); + compare(typeof channel.objects[testObjId], "undefined"); } function test_disconnect() |