diff options
author | Kai Dohmen <psykai1993@googlemail.com> | 2016-04-11 19:38:50 +0200 |
---|---|---|
committer | Milian Wolff <milian.wolff@kdab.com> | 2016-06-21 09:50:33 +0000 |
commit | f48e8c9711fbeb350ccf70f852ce3732844d4287 (patch) | |
tree | 43756259e8794b89801cdc2aa936840af92c5d98 /tests/auto/webchannel/tst_webchannel.cpp | |
parent | 3be67a7799aa1960d459548a43ddf54044f80ec1 (diff) | |
download | qtwebchannel-f48e8c9711fbeb350ccf70f852ce3732844d4287.tar.gz |
Make passing objects from website to server possible
If you get an object from the server and want to pass it back to the
server via a function the id of the object is passed instead of the
whole json object. On the server side QMetaObjectPublisher::invokeMethod
now looks up the object in QMetaObjectPublisher::wrappedObjects by the
passed object-id.
Task-number: QTBUG-50075
Change-Id: Id0df2dfaa79bcba12ca48391ae7537ac1a086898
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 | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp index 93c7aa8..7ae6f78 100644 --- a/tests/auto/webchannel/tst_webchannel.cpp +++ b/tests/auto/webchannel/tst_webchannel.cpp @@ -345,6 +345,12 @@ void TestWebChannel::testInfoForObject() } { QJsonArray method; + method.append(QStringLiteral("setReturnedObject")); + method.append(obj.metaObject()->indexOfMethod("setReturnedObject(TestObject*)")); + expected.append(method); + } + { + QJsonArray method; method.append(QStringLiteral("setObjectProperty")); method.append(obj.metaObject()->indexOfMethod("setObjectProperty(QObject*)")); expected.append(method); @@ -446,6 +452,19 @@ void TestWebChannel::testInfoForObject() property.append(QJsonValue::fromVariant(QVariant::fromValue(obj.objectProperty()))); expected.append(property); } + { + QJsonArray property; + property.append(obj.metaObject()->indexOfProperty("returnedObject")); + property.append(QStringLiteral("returnedObject")); + { + QJsonArray signal; + signal.append(1); + signal.append(obj.metaObject()->indexOfMethod("returnedObjectChanged()")); + property.append(signal); + } + property.append(QJsonValue::fromVariant(QVariant::fromValue(obj.returnedObject()))); + expected.append(property); + } QCOMPARE(info["properties"].toArray(), expected); } } @@ -587,6 +606,36 @@ void TestWebChannel::testWrapRegisteredObject() QCOMPARE(obj.objectName(), returnedId); } +void TestWebChannel::testPassWrappedObjectBack() +{ + QWebChannel channel; + TestObject registeredObj; + TestObject returnedObjMethod; + TestObject returnedObjProperty; + + registeredObj.setObjectName("registeredObject"); + + channel.registerObject(registeredObj.objectName(), ®isteredObj); + channel.connectTo(m_dummyTransport); + channel.d_func()->publisher->initializeClient(m_dummyTransport); + + QMetaObjectPublisher *pub = channel.d_func()->publisher; + QJsonObject returnedObjMethodInfo = pub->wrapResult(QVariant::fromValue(&returnedObjMethod), m_dummyTransport).toObject(); + QJsonObject returnedObjPropertyInfo = pub->wrapResult(QVariant::fromValue(&returnedObjProperty), m_dummyTransport).toObject(); + + QJsonArray argsMethod; + QJsonObject argMethod0; + argMethod0["id"] = returnedObjMethodInfo["id"]; + argsMethod << argMethod0; + QJsonObject argProperty; + argProperty["id"] = returnedObjPropertyInfo["id"]; + + pub->invokeMethod(®isteredObj, registeredObj.metaObject()->indexOfSlot("setReturnedObject(TestObject*)"), argsMethod); + QCOMPARE(registeredObj.mReturnedObject, &returnedObjMethod); + pub->setProperty(®isteredObj, registeredObj.metaObject()->indexOfProperty("returnedObject"), argProperty); + QCOMPARE(registeredObj.mReturnedObject, &returnedObjProperty); +} + void TestWebChannel::testInfiniteRecursion() { QWebChannel channel; @@ -739,6 +788,7 @@ void TestWebChannel::qtbug46548_overriddenProperties() #endif // WEBCHANNEL_TESTS_CAN_USE_JS_ENGINE } + QTEST_MAIN(TestWebChannel) #include "tst_webchannel.moc" |