summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/tst_multiclient.qml21
-rw-r--r--tests/auto/qml/tst_webchannel.qml17
-rw-r--r--tests/auto/qml/tst_webchannelseparation.qml26
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp32
-rw-r--r--tests/auto/webchannel/tst_webchannel.h1
5 files changed, 70 insertions, 27 deletions
diff --git a/tests/auto/qml/tst_multiclient.qml b/tests/auto/qml/tst_multiclient.qml
index 115857d..4977e50 100644
--- a/tests/auto/qml/tst_multiclient.qml
+++ b/tests/auto/qml/tst_multiclient.qml
@@ -87,14 +87,14 @@ TestCase {
WebChannel.id: "myOtherObj"
}
+ property var lastFactoryObj
+ property var createdFactoryObjects: []
QtObject {
id: myFactory
- property var lastObj
- property var createdObjects: []
function cleanup() {
- while (createdObjects.length) {
- var obj = createdObjects.shift();
+ while (createdFactoryObjects.length) {
+ var obj = createdFactoryObjects.shift();
if (obj) {
obj.destroy();
}
@@ -103,9 +103,9 @@ TestCase {
function create(id)
{
- lastObj = component.createObject(myFactory, {objectName: id});
- createdObjects.push(lastObj);
- return lastObj;
+ lastFactoryObj = component.createObject(myFactory, {objectName: id});
+ createdFactoryObjects.push(lastFactoryObj);
+ return lastFactoryObj;
}
WebChannel.id: "myFactory"
}
@@ -139,7 +139,8 @@ TestCase {
client2.debug = false;
// delete all created objects
myFactory.cleanup();
- myFactory.lastObj = undefined;
+ lastFactoryObj = undefined;
+ createdFactoryObjects = [];
// reschedule current task to end of event loop
wait(1);
}
@@ -180,7 +181,7 @@ TestCase {
var channel1 = client1.createChannel(function (channel1) {
channel1.objects.myFactory.create("testObj1", function (obj1) {
- testObj1 = myFactory.lastObj;
+ testObj1 = lastFactoryObj;
testObj1Id = obj1.__id__;
// create second channel after factory has created first
@@ -227,7 +228,7 @@ TestCase {
channel2 = client2.createChannel(function (channel2) {
channel2.objects.myFactory.create("testObj2", function (obj2) {
- testObj2 = myFactory.lastObj;
+ testObj2 = lastFactoryObj;
testObj2Id = obj2.__id__;
});
});
diff --git a/tests/auto/qml/tst_webchannel.qml b/tests/auto/qml/tst_webchannel.qml
index f41c4fa..3bfbfc9 100644
--- a/tests/auto/qml/tst_webchannel.qml
+++ b/tests/auto/qml/tst_webchannel.qml
@@ -67,6 +67,8 @@ TestCase {
WebChannel.id: "myOtherObj"
}
property var lastFactoryObj
+ QtObject{ id: bar; objectName: "bar" }
+ QtObject{ id: baz; objectName: "baz" }
QtObject {
id: myFactory
function create(id)
@@ -74,9 +76,13 @@ TestCase {
lastFactoryObj = component.createObject(myFactory, {objectName: id});
return lastFactoryObj;
}
+ property var objectInProperty: QtObject {
+ objectName: "foo"
+ }
+ property var otherObject: myObj
+ property var objects: [ bar, baz ];
WebChannel.id: "myFactory"
}
-
Component {
id: component
QtObject {
@@ -276,6 +282,15 @@ TestCase {
lastFactoryObj.mySignal("foobar", 42);
client.awaitSignal();
+ // property should be wrapped
+ compare(channel.objects.myFactory.objectInProperty.objectName, "foo");
+ // list property as well
+ compare(channel.objects.myFactory.objects.length, 2);
+ compare(channel.objects.myFactory.objects[0].objectName, "bar");
+ compare(channel.objects.myFactory.objects[1].objectName, "baz");
+ // also works with properties that reference other registered objects
+ compare(channel.objects.myFactory.otherObject, channel.objects.myObj);
+
// deleteLater call
msg = client.awaitMessage();
compare(msg.type, JSClient.QWebChannelMessageTypes.invokeMethod);
diff --git a/tests/auto/qml/tst_webchannelseparation.qml b/tests/auto/qml/tst_webchannelseparation.qml
index 289f8b2..8a74243 100644
--- a/tests/auto/qml/tst_webchannelseparation.qml
+++ b/tests/auto/qml/tst_webchannelseparation.qml
@@ -91,15 +91,16 @@ TestCase {
}
WebChannel.id: "myObj3"
}
+
+ property var lastFactoryObj
+ property var createdFactoryObjects: []
QtObject {
id: myFactory
- property var lastObj
- property var createdObjects: []
function cleanup()
{
- while (createdObjects.length) {
- var obj = createdObjects.shift();
+ while (createdFactoryObjects.length) {
+ var obj = createdFactoryObjects.shift();
if (obj) {
obj.destroy();
}
@@ -108,9 +109,9 @@ TestCase {
function create(id)
{
- lastObj = component.createObject(myFactory, {objectName: id});
- createdObjects.push(lastObj);
- return lastObj;
+ lastFactoryObj = component.createObject(myFactory, {objectName: id});
+ createdFactoryObjects.push(lastFactoryObj);
+ return lastFactoryObj;
}
WebChannel.id: "myFactory"
}
@@ -146,7 +147,8 @@ TestCase {
client2.debug = false;
// delete all created objects
myFactory.cleanup();
- myFactory.lastObj = undefined;
+ lastFactoryObj = undefined;
+ createdFactoryObjects = [];
// reschedule current task to end of event loop
wait(1);
}
@@ -160,7 +162,7 @@ TestCase {
var channel1 = client1.createChannel(function (channel1) {
channel1.objects.myFactory.create("testObj1", function (obj1) {
- testObj1 = myFactory.lastObj;
+ testObj1 = lastFactoryObj;
testObj1Id = obj1.__id__;
obj1.mySignal.connect(function (arg1_1, arg1_2) {
@@ -182,7 +184,7 @@ TestCase {
channel2 = client2.createChannel(function (channel2) {
channel2.objects.myFactory.create("testObj2", function (obj2) {
- testObj2 = myFactory.lastObj;
+ testObj2 = lastFactoryObj;
testObj2Id = obj2.__id__;
obj2.mySignal.connect(function (arg2_1, arg2_2) {
console.debug("client 2 received signal 'mySignal'");
@@ -278,7 +280,7 @@ TestCase {
var channel1 = client1.createChannel(function (channel1) {
channel1.objects.myFactory.create("testObj1", function (obj1) {
- testObj1 = myFactory.lastObj;
+ testObj1 = lastFactoryObj;
testObj1Id = obj1.__id__;
obj1.myPropertyChanged.connect(function (arg1_1) {
@@ -300,7 +302,7 @@ TestCase {
channel2 = client2.createChannel(function (channel2) {
channel2.objects.myFactory.create("testObj2", function (obj2) {
- testObj2 = myFactory.lastObj;
+ testObj2 = lastFactoryObj;
testObj2Id = obj2.__id__;
obj2.myPropertyChanged.connect(function (arg1_1) {
console.debug("client 2 received property update 'myProperty' " + obj2.myProperty);
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index 5060028..3d77b42 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -83,13 +83,37 @@ void TestWebChannel::testRegisterObjects()
channel.registerObjects(objects);
}
+void TestWebChannel::testDeregisterObjects()
+{
+ QWebChannel channel;
+ TestObject testObject;
+ testObject.setObjectName("myTestObject");
+
+
+ channel.registerObject(testObject.objectName(), &testObject);
+
+ channel.connectTo(m_dummyTransport);
+ channel.d_func()->publisher->initializeClient(m_dummyTransport);
+
+ QJsonObject connectMessage =
+ QJsonDocument::fromJson(("{\"type\": 7,"
+ "\"object\": \"myTestObject\","
+ "\"signal\": " + QString::number(testObject.metaObject()->indexOfSignal("sig1()"))
+ + "}").toLatin1()).object();
+ channel.d_func()->publisher->handleMessage(connectMessage, m_dummyTransport);
+
+ emit testObject.sig1();
+ channel.deregisterObject(&testObject);
+ emit testObject.sig1();
+}
+
void TestWebChannel::testInfoForObject()
{
TestObject obj;
obj.setObjectName("myTestObject");
QWebChannel channel;
- const QJsonObject info = channel.d_func()->publisher->classInfoForObject(&obj);
+ const QJsonObject info = channel.d_func()->publisher->classInfoForObject(&obj, m_dummyTransport);
QCOMPARE(info.keys(), QStringList() << "enums" << "methods" << "properties" << "signals");
@@ -267,7 +291,7 @@ void TestWebChannel::benchClassInfo()
QBENCHMARK {
foreach (const QObject *object, objects) {
- channel.d_func()->publisher->classInfoForObject(object);
+ channel.d_func()->publisher->classInfoForObject(object, m_dummyTransport);
}
}
}
@@ -282,7 +306,7 @@ void TestWebChannel::benchInitializeClients()
QMetaObjectPublisher *publisher = channel.d_func()->publisher;
QBENCHMARK {
- publisher->initializeClient();
+ publisher->initializeClient(m_dummyTransport);
publisher->propertyUpdatesInitialized = false;
publisher->signalToPropertyMap.clear();
@@ -304,7 +328,7 @@ void TestWebChannel::benchPropertyUpdates()
}
channel.registerObjects(objects);
- channel.d_func()->publisher->initializeClient();
+ channel.d_func()->publisher->initializeClient(m_dummyTransport);
QBENCHMARK {
foreach (BenchObject *obj, objectList) {
diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h
index ad8c6a4..6564944 100644
--- a/tests/auto/webchannel/tst_webchannel.h
+++ b/tests/auto/webchannel/tst_webchannel.h
@@ -214,6 +214,7 @@ public:
private slots:
void testRegisterObjects();
+ void testDeregisterObjects();
void testInfoForObject();
void testInvokeMethodConversion();
void testDisconnect();