diff options
Diffstat (limited to 'tests/auto/quick/inspectorserver/tst_inspectorserver.cpp')
-rw-r--r-- | tests/auto/quick/inspectorserver/tst_inspectorserver.cpp | 91 |
1 files changed, 51 insertions, 40 deletions
diff --git a/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp b/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp index 922c7769e..a9638bee4 100644 --- a/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp +++ b/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWebEngine module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include <QNetworkAccessManager> #include <QNetworkReply> @@ -33,7 +8,8 @@ #include <QtQml/QQmlEngine> #include <QtTest/QtTest> #include <QQuickWebEngineProfile> -#include <QtWebEngine/private/qquickwebengineview_p.h> +#include <QtWebEngineQuick/private/qquickwebengineview_p.h> +#include <QWebEnginePage> #define INSPECTOR_SERVER_PORT "23654" static const QUrl s_inspectorServerHttpBaseUrl("http://localhost:" INSPECTOR_SERVER_PORT); @@ -47,6 +23,7 @@ private Q_SLOTS: void init(); void cleanup(); + void testDevToolsId(); void testPageList(); void testRemoteDebuggingMessage(); void openRemoteDebuggingSession(); @@ -61,8 +38,9 @@ private: tst_InspectorServer::tst_InspectorServer() { + qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--remote-allow-origins=*"); qputenv("QTWEBENGINE_REMOTE_DEBUGGING", INSPECTOR_SERVER_PORT); - QtWebEngine::initialize(); + QtWebEngineQuick::initialize(); QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true); prepareWebViewComponent(); } @@ -70,12 +48,10 @@ tst_InspectorServer::tst_InspectorServer() void tst_InspectorServer::prepareWebViewComponent() { static QQmlEngine* engine = new QQmlEngine(this); - engine->addImportPath(QString::fromUtf8(IMPORT_DIR)); - m_component.reset(new QQmlComponent(engine, this)); - m_component->setData(QByteArrayLiteral("import QtQuick 2.0\n" - "import QtWebEngine 1.2\n" + m_component->setData(QByteArrayLiteral("import QtQuick\n" + "import QtWebEngine\n" "WebEngineView { }") , QUrl()); } @@ -105,17 +81,40 @@ inline QQuickWebEngineView* tst_InspectorServer::webView() const QJsonArray tst_InspectorServer::fetchPageList() const { QNetworkAccessManager qnam; - QScopedPointer<QNetworkReply> reply(qnam.get(QNetworkRequest(s_inspectorServerHttpBaseUrl.resolved(QUrl("json/list"))))); - QSignalSpy(reply.data(), SIGNAL(finished())).wait(); + QSignalSpy spy(&qnam, &QNetworkAccessManager::finished); + QNetworkRequest request(s_inspectorServerHttpBaseUrl.resolved(QUrl("json/list"))); + QScopedPointer<QNetworkReply> reply(qnam.get(request)); + spy.wait(); + // Work-around a network bug in Qt6: + if (reply->error() == QNetworkReply::ContentNotFoundError) { + reply.reset(qnam.get(request)); + spy.wait(); + } return QJsonDocument::fromJson(reply->readAll()).array(); } +void tst_InspectorServer::testDevToolsId() +{ + const QUrl testPageUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/html/basic_page.html")); + QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QWebEngineLoadingInfo))); + webView()->setUrl(testPageUrl); + QTRY_VERIFY_WITH_TIMEOUT(loadSpy.size() && !webView()->isLoading(), 10000); + + // Our page should be the only one in the list. + QJsonArray pageList = fetchPageList(); + QCOMPARE(pageList.size(), 1); + QCOMPARE(testPageUrl.toString(), pageList.at(0).toObject().value("url").toString()); + QCOMPARE(webView()->devToolsId(), pageList.at(0).toObject().value("id").toString()); +} + void tst_InspectorServer::testPageList() { - const QUrl testPageUrl = QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/basic_page.html")); - QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QQuickWebEngineLoadRequest*))); + const QUrl testPageUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/html/basic_page.html")); + QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QWebEngineLoadingInfo))); webView()->setUrl(testPageUrl); - QTRY_VERIFY(loadSpy.size() && !webView()->isLoading()); + QTRY_VERIFY_WITH_TIMEOUT(loadSpy.size() && !webView()->isLoading(), 10000); // Our page has developerExtrasEnabled and should be the only one in the list. QJsonArray pageList = fetchPageList(); @@ -125,6 +124,12 @@ void tst_InspectorServer::testPageList() void tst_InspectorServer::testRemoteDebuggingMessage() { + const QUrl testPageUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/html/basic_page.html")); + QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QWebEngineLoadingInfo))); + webView()->setUrl(testPageUrl); + QTRY_VERIFY_WITH_TIMEOUT(loadSpy.size() && !webView()->isLoading(), 10000); + QJsonArray pageList = fetchPageList(); QCOMPARE(pageList.size(), 1); QVERIFY(pageList.at(0).toObject().contains("webSocketDebuggerUrl")); @@ -149,11 +154,17 @@ void tst_InspectorServer::testRemoteDebuggingMessage() .arg(pageList.at(0).toObject().value("webSocketDebuggerUrl").toString()) .arg(jsExpression)); - QTRY_COMPARE(webSocketQueryWebView->title(), jsExpressionResult); + QTRY_COMPARE_WITH_TIMEOUT(webSocketQueryWebView->title(), jsExpressionResult, 10000); } void tst_InspectorServer::openRemoteDebuggingSession() { + const QUrl testPageUrl = QUrl::fromLocalFile(QDir(QT_TESTCASE_SOURCEDIR).canonicalPath() + + QLatin1String("/html/basic_page.html")); + QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QWebEngineLoadingInfo))); + webView()->setUrl(testPageUrl); + QTRY_VERIFY_WITH_TIMEOUT(loadSpy.size() && !webView()->isLoading(), 10000); + QJsonArray pageList = fetchPageList(); QCOMPARE(pageList.size(), 1); QVERIFY(pageList.at(0).toObject().contains("devtoolsFrontendUrl")); @@ -167,7 +178,7 @@ void tst_InspectorServer::openRemoteDebuggingSession() // - The page list didn't return a valid inspector URL // - Or the front-end couldn't be loaded through the inspector HTTP server // - Or the web socket connection couldn't be established between the front-end and the page through the inspector server - QTRY_VERIFY_WITH_TIMEOUT(inspectorWebView->title().startsWith("DevTools -"), 20000); + QTRY_VERIFY_WITH_TIMEOUT(inspectorWebView->title().startsWith("DevTools -"), 60000); } QTEST_MAIN(tst_InspectorServer) |