summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2013-11-06 17:35:43 +0100
committerMilian Wolff <milian.wolff@kdab.com>2013-11-14 16:42:38 +0100
commit1ec37d6f216cae021990cfea6fb8034af499dbfc (patch)
treeba77318348fc4cdba92f832aefcd8a58144ad297 /tests
parent6e88c68e1bd46faa2a96bbc409052f27bf445736 (diff)
downloadqtwebchannel-1ec37d6f216cae021990cfea6fb8034af499dbfc.tar.gz
Add test for webchannel.respond on the QML and .exec on the HTML side.
Change-Id: I5eec7bc87bc56de6dd918d90f2fe9ee86d72b434 Reviewed-by: Pierre Rossi <pierre.rossi@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/qml/respond.html17
-rw-r--r--tests/qml/tst_webchannel.qml12
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/qml/respond.html b/tests/qml/respond.html
new file mode 100644
index 0000000..29e47b8
--- /dev/null
+++ b/tests/qml/respond.html
@@ -0,0 +1,17 @@
+<html>
+ <head>
+ <script type="text/javascript" src="qrc:///qwebchannel/webchannel.js"></script>
+ <script type="text/javascript">
+ //BEGIN SETUP
+ var baseUrl = (/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]);
+ new QWebChannel(baseUrl, function(channel) {
+ channel.exec("foobar", function(response) {
+ channel.send("received:"+response);
+ });
+ });
+ //END SETUP
+ </script>
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/tests/qml/tst_webchannel.qml b/tests/qml/tst_webchannel.qml
index 2336b39..36fa18c 100644
--- a/tests/qml/tst_webchannel.qml
+++ b/tests/qml/tst_webchannel.qml
@@ -105,5 +105,17 @@ TestCase {
rawMessageSpy.wait(500);
compare(rawMessageSpy.signalArguments[0][0], "myMessagePong:foobar");
}
+
+ function test_respondMessage()
+ {
+ loadUrl("respond.html");
+ rawMessageSpy.wait(500);
+ var msg = JSON.parse(rawMessageSpy.signalArguments[0][0]);
+ verify(msg.id);
+ compare(msg.data, "foobar");
+ webChannel.respond(msg.id, "barfoo");
+ rawMessageSpy.wait(500);
+ compare(rawMessageSpy.signalArguments[1][0], "received:barfoo");
+ }
//END TESTS
}