diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2014-01-10 14:21:05 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-06 16:32:20 +0100 |
commit | 54f66cc7a1e17155e90a1d3b5c33f627dbd0d50f (patch) | |
tree | 6dd4b35eda74487977bfae5bb0b81a133dfc1bf4 /tests/webchannel | |
parent | 05bafd509ca302fc63465fece7cd0c33ec602e31 (diff) | |
download | qtwebchannel-54f66cc7a1e17155e90a1d3b5c33f627dbd0d50f.tar.gz |
Make the underlying transport mechanism of the webchannel pluggable.
This enables us to optionally use navigator.qt instead of a WebSocket,
which is nicer setup-wise and is also slightly faster:
navigator.qt:
284.0 msecs per iteration (total: 2,840, iterations: 10)
WebSocket:
295.8 msecs per iteration (total: 2,959, iterations: 10)
The baseline is ca. 203 msecs, which would mean a performance boost
of ca. 12.7%.
Furthermore, this sets the fundation to eventually add a WebEngine
transport mechanism. The WebViewTransport should also be removed and
instead the WebView itself should directly implement the
WebChannelTransportInterface.
Change-Id: I368bb27e38ffa2f17ffeb7f5ae695690f6f5ad21
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'tests/webchannel')
-rw-r--r-- | tests/webchannel/tst_webchannel.cpp | 28 | ||||
-rw-r--r-- | tests/webchannel/tst_webchannel.h | 23 |
2 files changed, 35 insertions, 16 deletions
diff --git a/tests/webchannel/tst_webchannel.cpp b/tests/webchannel/tst_webchannel.cpp index 0d05913..bb08c21 100644 --- a/tests/webchannel/tst_webchannel.cpp +++ b/tests/webchannel/tst_webchannel.cpp @@ -44,11 +44,13 @@ #include <qwebchannel.h> #include <qwebchannel_p.h> #include <qmetaobjectpublisher_p.h> +#include <qwebsockettransport.h> #include <QtTest> TestWebChannel::TestWebChannel(QObject *parent) : QObject(parent) + , m_dummyTransport(new DummyTransport(this)) , m_lastInt(0) , m_lastDouble(0) { @@ -74,19 +76,18 @@ void TestWebChannel::setVariant(const QVariant &v) m_lastVariant = v; } -void TestWebChannel::testInitChannel() +void TestWebChannel::testInitWebSocketTransport() { - QWebChannel channel; - - QSignalSpy initSpy(&channel, SIGNAL(initialized())); - QSignalSpy baseUrlSpy(&channel, SIGNAL(baseUrlChanged(QString))); + QWebSocketTransport transport; + QSignalSpy initSpy(&transport, SIGNAL(initialized())); + QSignalSpy baseUrlSpy(&transport, SIGNAL(baseUrlChanged(QString))); QVERIFY(initSpy.wait()); QCOMPARE(initSpy.size(), 1); QCOMPARE(baseUrlSpy.size(), 1); QCOMPARE(baseUrlSpy.first().size(), 1); - QCOMPARE(channel.baseUrl(), baseUrlSpy.first().first().toString()); - QVERIFY(!channel.baseUrl().isEmpty()); + QCOMPARE(transport.baseUrl(), baseUrlSpy.first().first().toString()); + QVERIFY(!transport.baseUrl().isEmpty()); } void TestWebChannel::testRegisterObjects() @@ -233,6 +234,7 @@ void TestWebChannel::testInfoForObject() void TestWebChannel::testInvokeMethodConversion() { QWebChannel channel; + channel.connectTo(m_dummyTransport); QJsonArray args; args.append(QJsonValue(1000)); @@ -271,8 +273,7 @@ static QHash<QString, QObject*> createObjects(QObject *parent) void TestWebChannel::benchClassInfo() { QWebChannel channel; - QSignalSpy initSpy(&channel, SIGNAL(initialized())); - QVERIFY(initSpy.wait()); + channel.connectTo(m_dummyTransport); QObject parent; const QHash<QString, QObject*> objects = createObjects(&parent); @@ -287,8 +288,7 @@ void TestWebChannel::benchClassInfo() void TestWebChannel::benchInitializeClients() { QWebChannel channel; - QSignalSpy initSpy(&channel, SIGNAL(initialized())); - QVERIFY(initSpy.wait()); + channel.connectTo(m_dummyTransport); QObject parent; channel.registerObjects(createObjects(&parent)); @@ -306,8 +306,7 @@ void TestWebChannel::benchInitializeClients() void TestWebChannel::benchPropertyUpdates() { QWebChannel channel; - QSignalSpy initSpy(&channel, SIGNAL(initialized())); - QVERIFY(initSpy.wait()); + channel.connectTo(m_dummyTransport); QObject parent; const QHash<QString, QObject*> objects = createObjects(&parent); @@ -333,8 +332,7 @@ void TestWebChannel::benchPropertyUpdates() void TestWebChannel::benchRegisterObjects() { QWebChannel channel; - QSignalSpy initSpy(&channel, SIGNAL(initialized())); - QVERIFY(initSpy.wait()); + channel.connectTo(m_dummyTransport); QObject parent; const QHash<QString, QObject*> objects = createObjects(&parent); diff --git a/tests/webchannel/tst_webchannel.h b/tests/webchannel/tst_webchannel.h index 7fd0bcc..26aa913 100644 --- a/tests/webchannel/tst_webchannel.h +++ b/tests/webchannel/tst_webchannel.h @@ -44,6 +44,25 @@ #include <QObject> #include <QVariant> +#include <qwebchanneltransportinterface.h> + +class DummyTransport : public QObject, public QWebChannelTransportInterface +{ + Q_OBJECT + Q_INTERFACES(QWebChannelTransportInterface) +public: + explicit DummyTransport(QObject *parent) + : QObject(parent) + {} + ~DummyTransport() {}; + + void sendMessage(const QString &/*message*/) const Q_DECL_OVERRIDE + {} + void sendMessage(const QByteArray &/*message*/) const Q_DECL_OVERRIDE + {} + void setMessageHandler(QWebChannelMessageHandlerInterface * /*handler*/) Q_DECL_OVERRIDE + {} +}; class TestObject : public QObject { @@ -197,7 +216,7 @@ public: Q_INVOKABLE void setVariant(const QVariant &v); private slots: - void testInitChannel(); + void testInitWebSocketTransport(); void testRegisterObjects(); void testInfoForObject(); void testInvokeMethodConversion(); @@ -208,6 +227,8 @@ private slots: void benchRegisterObjects(); private: + DummyTransport *m_dummyTransport; + int m_lastInt; double m_lastDouble; QVariant m_lastVariant; |