1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include <QHostAddress>
48 #include "../../../../../src/plugins/qmltooling/shared/qqmlinspectorprotocol.h"
49 #include "../shared/debugutil_p.h"
51 using namespace QmlJSDebugger;
54 #define STR_PORT "13772"
56 class QQmlInspectorClient : public QQmlDebugClient
61 QQmlInspectorClient(QQmlDebugConnection *connection)
62 : QQmlDebugClient(QLatin1String("QDeclarativeObserverMode"), connection)
63 , m_showAppOnTop(false)
67 bool showAppOnTop() const { return m_showAppOnTop; }
68 void setShowAppOnTop(bool showOnTop);
71 void showAppOnTopChanged();
74 void messageReceived(const QByteArray &message);
80 class tst_QQmlInspector : public QObject
94 QQmlDebugProcess *m_process;
95 QQmlDebugConnection *m_connection;
96 QQmlInspectorClient *m_client;
100 void cleanupTestCase();
109 void QQmlInspectorClient::setShowAppOnTop(bool showOnTop)
112 QDataStream ds(&message, QIODevice::WriteOnly);
113 ds << InspectorProtocol::ShowAppOnTop << showOnTop;
115 sendMessage(message);
118 void QQmlInspectorClient::messageReceived(const QByteArray &message)
120 QDataStream ds(message);
121 InspectorProtocol::Message type;
125 case InspectorProtocol::ShowAppOnTop:
126 ds >> m_showAppOnTop;
127 emit showAppOnTopChanged();
130 qDebug() << "Unhandled message " << (int)type;
134 void tst_QQmlInspector::initTestCase()
138 void tst_QQmlInspector::cleanupTestCase()
142 void tst_QQmlInspector::init()
144 #if defined(Q_OS_WIN)
145 const QString executable = "app\\app.exe";
147 const QString executable = "app/app";
149 const QString argument = "-qmljsdebugger=port:"STR_PORT",block";
151 m_process = new QQmlDebugProcess(executable);
152 m_process->start(QStringList() << argument);
153 QVERIFY2(m_process->waitForSessionStart(),
154 "Could not launch application, or did not get 'Waiting for connection'.");
156 QQmlDebugConnection *m_connection = new QQmlDebugConnection();
157 m_client = new QQmlInspectorClient(m_connection);
159 m_connection->connectToHost(QLatin1String("127.0.0.1"), PORT);
162 void tst_QQmlInspector::cleanup()
164 if (QTest::currentTestFailed()) {
165 qDebug() << "Process State:" << m_process->state();
166 qDebug() << "Application Output:" << m_process->output();
173 void tst_QQmlInspector::connect()
175 QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled);
178 void tst_QQmlInspector::showAppOnTop()
180 QTRY_COMPARE(m_client->state(), QQmlDebugClient::Enabled);
182 m_client->setShowAppOnTop(true);
183 QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(showAppOnTopChanged())));
184 QCOMPARE(m_client->showAppOnTop(), true);
186 m_client->setShowAppOnTop(false);
187 QVERIFY(QQmlDebugTest::waitForSignal(m_client, SIGNAL(showAppOnTopChanged())));
188 QCOMPARE(m_client->showAppOnTop(), false);
191 QTEST_MAIN(tst_QQmlInspector)
193 #include "tst_qqmlinspector.moc"