1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL21$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
32 ****************************************************************************/
37 #include <QHostAddress>
40 #include <QtCore/QLibraryInfo>
42 #include "../shared/debugutil_p.h"
43 #include "../../../shared/util.h"
44 #include "qqmlinspectorclient.h"
45 #include "qqmlenginedebugclient.h"
47 #define STR_PORT_FROM "3776"
48 #define STR_PORT_TO "3786"
50 class tst_QQmlEngineDebugInspectorIntegration : public QQmlDataTest
55 tst_QQmlEngineDebugInspectorIntegration()
57 , m_inspectorClient(0)
58 , m_engineDebugClient(0)
64 void init(bool restrictServices);
65 QmlDebugObjectReference findRootObject();
67 QQmlDebugProcess *m_process;
68 QQmlInspectorClient *m_inspectorClient;
69 QQmlEngineDebugClient *m_engineDebugClient;
76 void clearObjectReferenceHashonReloadQml();
80 QmlDebugObjectReference tst_QQmlEngineDebugInspectorIntegration::findRootObject()
83 m_engineDebugClient->queryAvailableEngines(&success);
85 QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
87 m_engineDebugClient->queryRootContexts(m_engineDebugClient->engines()[0].debugId, &success);
88 QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
89 int count = m_engineDebugClient->rootContext().contexts.count();
90 m_engineDebugClient->queryObject(
91 m_engineDebugClient->rootContext().contexts[count - 1].objects[0], &success);
92 QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()));
93 return m_engineDebugClient->object();
97 void tst_QQmlEngineDebugInspectorIntegration::init(bool restrictServices)
99 const QString argument = QString::fromLatin1("-qmljsdebugger=port:%1,%2,block%3")
100 .arg(STR_PORT_FROM).arg(STR_PORT_TO)
101 .arg(restrictServices ? QStringLiteral(",services:QmlDebugger,QmlInspector") :
104 // ### Still using qmlscene because of QTBUG-33376
105 m_process = new QQmlDebugProcess(QLibraryInfo::location(QLibraryInfo::BinariesPath)
106 + "/qmlscene", this);
107 m_process->start(QStringList() << argument << testFile("qtquick2.qml"));
108 QVERIFY2(m_process->waitForSessionStart(),
109 "Could not launch application, or did not get 'Waiting for connection'.");
111 QQmlDebugConnection *m_connection = new QQmlDebugConnection(this);
112 m_inspectorClient = new QQmlInspectorClient(m_connection);
113 m_engineDebugClient = new QQmlEngineDebugClient(m_connection);
115 m_connection->connectToHost(QLatin1String("127.0.0.1"), m_process->debugPort());
116 QVERIFY(m_connection->waitForConnected());
119 void tst_QQmlEngineDebugInspectorIntegration::cleanup()
121 if (QTest::currentTestFailed()) {
122 qDebug() << "Process State:" << m_process->state();
123 qDebug() << "Application Output:" << m_process->output();
126 delete m_engineDebugClient;
127 delete m_inspectorClient;
130 void tst_QQmlEngineDebugInspectorIntegration::connect_data()
132 QTest::addColumn<bool>("restrictMode");
133 QTest::newRow("unrestricted") << false;
134 QTest::newRow("restricted") << true;
137 void tst_QQmlEngineDebugInspectorIntegration::connect()
139 QFETCH(bool, restrictMode);
141 QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled);
142 QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled);
145 void tst_QQmlEngineDebugInspectorIntegration::clearObjectReferenceHashonReloadQml()
148 QTRY_COMPARE(m_engineDebugClient->state(), QQmlDebugClient::Enabled);
149 bool success = false;
150 QmlDebugObjectReference rootObject = findRootObject();
151 const QString fileName = QFileInfo(rootObject.source.url.toString()).fileName();
152 int lineNumber = rootObject.source.lineNumber;
153 int columnNumber = rootObject.source.columnNumber;
154 m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
155 columnNumber, &success);
157 QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
159 foreach (QmlDebugObjectReference child, rootObject.children) {
161 lineNumber = child.source.lineNumber;
162 columnNumber = child.source.columnNumber;
163 m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
164 columnNumber, &success);
166 QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
169 QTRY_COMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled);
172 contents.append("import QtQuick 2.0\n"
178 QHash<QString, QByteArray> changesHash;
179 changesHash.insert("test.qml", contents);
180 m_inspectorClient->reloadQml(changesHash);
181 QVERIFY(QQmlDebugTest::waitForSignal(m_inspectorClient, SIGNAL(responseReceived())));
183 lineNumber = rootObject.source.lineNumber;
184 columnNumber = rootObject.source.columnNumber;
186 m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
187 columnNumber, &success);
189 QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
191 foreach (QmlDebugObjectReference child, rootObject.children) {
193 lineNumber = child.source.lineNumber;
194 columnNumber = child.source.columnNumber;
195 m_engineDebugClient->queryObjectsForLocation(fileName, lineNumber,
196 columnNumber, &success);
198 QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result())));
202 QTEST_MAIN(tst_QQmlEngineDebugInspectorIntegration)
204 #include "tst_qqmlenginedebuginspectorintegration.moc"