summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-11-13 15:28:38 +0100
committerMilian Wolff <milian.wolff@kdab.com>2013-11-22 17:29:42 +0100
commitd08ec6ff4a6adb47590d657616fe04d007d8ce66 (patch)
tree553d233ba67c9d1e88eed0e9244c4327ba0e5ffa
parente8d890b6020e2f2ec2e4ee3b1295963d4dbb1637 (diff)
downloadqtwebchannel-d08ec6ff4a6adb47590d657616fe04d007d8ce66.tar.gz
Add a test for the property update grouping.
For performance reasons, we group property updates and send a single batch update notification. This is now tested to work as intended. This also uncovered a bug in webchannel.js when multiple functions subscribe to the same id. Change-Id: Ic8648d664dd1fe54df7e25fade6a6088386af992 Reviewed-by: Zeno Albisser <zeno.albisser@digia.com>
-rw-r--r--src/webchannel.js2
-rw-r--r--tests/qml/grouping.html20
-rw-r--r--tests/qml/tst_metaobjectpublisher.qml31
3 files changed, 51 insertions, 2 deletions
diff --git a/src/webchannel.js b/src/webchannel.js
index 15ae127..7789d84 100644
--- a/src/webchannel.js
+++ b/src/webchannel.js
@@ -101,7 +101,7 @@ var QWebChannel = function(baseUrl, initCallback)
this.subscribe = function(id, callback)
{
if (channel.subscriptions[id]) {
- channel.subscriptions[id].append(callback);
+ channel.subscriptions[id].push(callback);
} else {
channel.subscriptions[id] = [callback];
}
diff --git a/tests/qml/grouping.html b/tests/qml/grouping.html
new file mode 100644
index 0000000..bb804f4
--- /dev/null
+++ b/tests/qml/grouping.html
@@ -0,0 +1,20 @@
+<html>
+ <head>
+ <script type="text/javascript" src="qrc:///qwebchannel/webchannel.js"></script>
+ <script type="text/javascript" src="qrc:///qwebchannel/qobject.js"></script>
+ <script type="text/javascript">
+ //BEGIN SETUP
+ var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]);
+ window.channel = new QWebChannel(baseUrl, function(channel) {
+ setupQObjectWebChannel(channel, function() {
+ channel.subscribe("Qt.propertyUpdate", function() {
+ channel.exec({label: "gotPropertyUpdate", values: [myObj.myProperty(), myOtherObj.foo(), myOtherObj.bar()]});
+ });
+ });
+ });
+ //END SETUP
+ </script>
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/tests/qml/tst_metaobjectpublisher.qml b/tests/qml/tst_metaobjectpublisher.qml
index 7739b06..6f1d825 100644
--- a/tests/qml/tst_metaobjectpublisher.qml
+++ b/tests/qml/tst_metaobjectpublisher.qml
@@ -52,6 +52,11 @@ WebChannelTest {
lastMethodArg = arg;
}
}
+ QtObject {
+ id: myOtherObj
+ property var foo: 1
+ property var bar: 1
+ }
MetaObjectPublisher {
id: publisher
@@ -70,7 +75,8 @@ WebChannelTest {
function initTestCase()
{
publisher.registerObjects({
- "myObj": myObj
+ "myObj": myObj,
+ "myOtherObj": myOtherObj
});
}
@@ -94,6 +100,7 @@ WebChannelTest {
function test_property()
{
+ myObj.myProperty = 1
loadUrl("property.html");
awaitInit();
var msg = awaitMessage();
@@ -159,4 +166,26 @@ WebChannelTest {
compare(msg.data.label, "signalReceived");
compare(msg.data.value, "test");
}
+
+ function test_grouping()
+ {
+ loadUrl("grouping.html");
+ awaitInit();
+ awaitIdle();
+
+ // change properties a lot, we expect this to be grouped into a single update notification
+ for (var i = 0; i < 10; ++i) {
+ myObj.myProperty = i;
+ myOtherObj.foo = i;
+ myOtherObj.bar = i;
+ }
+
+ var msg = awaitMessage();
+ verify(msg);
+ compare(msg.data.label, "gotPropertyUpdate");
+ compare(msg.data.values, [myObj.myProperty, myOtherObj.foo, myOtherObj.bar]);
+
+ awaitIdle();
+ }
+
}