diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-08-31 10:20:42 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-09-07 10:49:06 +0200 |
commit | 4444cae6e06c45e8f1f3d8702abde655f6175ba9 (patch) | |
tree | f35cce1682c6500ecc8b6bb5ec6ad61d480310d8 /tests/auto/quick | |
parent | 40d808b53ded6bc091d7f642450c5fb9b09d6131 (diff) | |
parent | 7aa99d8d5b0dbf024019e70bf39b7d15796e1080 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Conflicts:
.qmake.conf
src/core/compositor/display_gl_output_surface_qsg.cpp
src/core/web_engine_context.cpp
tests/auto/quick/quick.pro
Change-Id: Iaf03434696788c89f5d3b524969513a89cb0a235
Diffstat (limited to 'tests/auto/quick')
-rw-r--r-- | tests/auto/quick/inspectorserver/BLACKLIST | 6 | ||||
-rw-r--r-- | tests/auto/quick/inspectorserver/tst_inspectorserver.cpp | 10 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/data/tst_newViewRequest.qml | 78 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/qmltests.pro | 1 | ||||
-rw-r--r-- | tests/auto/quick/qmltests/tst_qmltests.cpp | 5 | ||||
-rw-r--r-- | tests/auto/quick/qmltests_ssl/data/TestWebEngineView.qml | 122 | ||||
-rw-r--r-- | tests/auto/quick/qmltests_ssl/data/tst_certificateError.qml (renamed from tests/auto/quick/qmltests/data/tst_certificateError.qml) | 0 | ||||
-rw-r--r-- | tests/auto/quick/qmltests_ssl/qmltests_ssl.pro | 10 | ||||
-rw-r--r-- | tests/auto/quick/qmltests_ssl/tst_qmltests_ssl.cpp | 160 | ||||
-rw-r--r-- | tests/auto/quick/quick.pro | 2 |
10 files changed, 355 insertions, 39 deletions
diff --git a/tests/auto/quick/inspectorserver/BLACKLIST b/tests/auto/quick/inspectorserver/BLACKLIST deleted file mode 100644 index 92c76505a..000000000 --- a/tests/auto/quick/inspectorserver/BLACKLIST +++ /dev/null @@ -1,6 +0,0 @@ -[testRemoteDebuggingMessage] -osx - -[openRemoteDebuggingSession] -osx -msvc-2019 diff --git a/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp b/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp index 224814f7e..85257fcb7 100644 --- a/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp +++ b/tests/auto/quick/inspectorserver/tst_inspectorserver.cpp @@ -125,6 +125,11 @@ void tst_InspectorServer::testPageList() void tst_InspectorServer::testRemoteDebuggingMessage() { + const QUrl testPageUrl = QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/basic_page.html")); + QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QQuickWebEngineLoadRequest*))); + webView()->setUrl(testPageUrl); + QTRY_VERIFY(loadSpy.size() && !webView()->isLoading()); + QJsonArray pageList = fetchPageList(); QCOMPARE(pageList.size(), 1); QVERIFY(pageList.at(0).toObject().contains("webSocketDebuggerUrl")); @@ -154,6 +159,11 @@ void tst_InspectorServer::testRemoteDebuggingMessage() void tst_InspectorServer::openRemoteDebuggingSession() { + const QUrl testPageUrl = QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/basic_page.html")); + QSignalSpy loadSpy(webView(), SIGNAL(loadingChanged(QQuickWebEngineLoadRequest*))); + webView()->setUrl(testPageUrl); + QTRY_VERIFY(loadSpy.size() && !webView()->isLoading()); + QJsonArray pageList = fetchPageList(); QCOMPARE(pageList.size(), 1); QVERIFY(pageList.at(0).toObject().contains("devtoolsFrontendUrl")); diff --git a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml index a671c2ec7..80389e9f8 100644 --- a/tests/auto/quick/qmltests/data/tst_newViewRequest.qml +++ b/tests/auto/quick/qmltests/data/tst_newViewRequest.qml @@ -37,6 +37,7 @@ TestWebEngineView { property var newViewRequest: null property var dialog: null + property string viewType: "" SignalSpy { id: newViewRequestedSpy @@ -60,7 +61,12 @@ TestWebEngineView { " TestWebEngineView { id: webView; anchors.fill: parent }\n" + "}", webEngineView); - request.openIn(dialog.webEngineView); + if (viewType === "dialog") + request.openIn(dialog.webEngineView); + else if (viewType === "null") + request.openIn(0); + else if (viewType === "webEngineView") + request.openIn(webEngineView); } TestCase { @@ -74,6 +80,7 @@ TestWebEngineView { newViewRequestedSpy.clear(); newViewRequest = null; + viewType = ""; } function cleanup() { @@ -81,7 +88,17 @@ TestWebEngineView { dialog.destroy(); } - function test_jsWindowOpen() { + function test_loadNewViewRequest_data() { + return [ + { tag: "dialog", viewType: "dialog" }, + { tag: "invalid", viewType: "null" }, + { tag: "unhandled", viewType: "" }, + { tag: "webEngineView", viewType: "webEngineView" }, + ]; + } + + function test_loadNewViewRequest(row) { + viewType = row.viewType; var url = 'data:text/html,%3Chtml%3E%3Cbody%3ETest+Page%3C%2Fbody%3E%3C%2Fhtml%3E'; // Open an empty page in a new tab @@ -96,12 +113,14 @@ TestWebEngineView { compare(newViewRequest.destination, WebEngineView.NewViewInTab); verify(!newViewRequest.userInitiated); - verify(dialog.webEngineView.waitForLoadSucceeded()); - compare(dialog.webEngineView.url, ""); + if (viewType === "dialog") { + verify(dialog.webEngineView.waitForLoadSucceeded()); + compare(dialog.webEngineView.url, ""); + dialog.destroy(); + } // https://chromium-review.googlesource.com/c/chromium/src/+/1300395 compare(newViewRequest.requestedUrl, 'about:blank#blocked'); newViewRequestedSpy.clear(); - dialog.destroy(); // Open a page in a new dialog webEngineView.loadHtml( @@ -115,30 +134,35 @@ TestWebEngineView { compare(newViewRequest.destination, WebEngineView.NewViewInDialog); compare(newViewRequest.requestedUrl, url); verify(!newViewRequest.userInitiated); - verify(dialog.webEngineView.waitForLoadSucceeded()); + if (viewType === "dialog") { + verify(dialog.webEngineView.waitForLoadSucceeded()); + dialog.destroy(); + } newViewRequestedSpy.clear(); - dialog.destroy(); - // Open a page in a new dialog by user - webEngineView.loadHtml( - "<html><head><script>" + - " function popup() { window.open('" + url + "', '_blank', 'width=200,height=100'); }" + - "</script></head>" + - "<body onload=\"document.getElementById('popupButton').focus();\">" + - " <button id='popupButton' onclick='popup()'>Pop Up!</button>" + - "</body></html>"); - verify(webEngineView.waitForLoadSucceeded()); - verifyElementHasFocus("popupButton"); - keyPress(Qt.Key_Enter); - tryCompare(newViewRequestedSpy, "count", 1); - compare(newViewRequest.requestedUrl, url); - - compare(newViewRequest.destination, WebEngineView.NewViewInDialog); - verify(newViewRequest.userInitiated); - verify(dialog.webEngineView.waitForLoadSucceeded()); - newViewRequestedSpy.clear(); - dialog.destroy(); + if (viewType !== "webEngineView") { + // Open a page in a new dialog by user + webEngineView.loadHtml( + "<html><head><script>" + + " function popup() { window.open('" + url + "', '_blank', 'width=200,height=100'); }" + + "</script></head>" + + "<body onload=\"document.getElementById('popupButton').focus();\">" + + " <button id='popupButton' onclick='popup()'>Pop Up!</button>" + + "</body></html>"); + verify(webEngineView.waitForLoadSucceeded()); + verifyElementHasFocus("popupButton"); + keyPress(Qt.Key_Enter); + tryCompare(newViewRequestedSpy, "count", 1); + compare(newViewRequest.requestedUrl, url); + + compare(newViewRequest.destination, WebEngineView.NewViewInDialog); + verify(newViewRequest.userInitiated); + if (viewType === "dialog") { + verify(dialog.webEngineView.waitForLoadSucceeded()); + dialog.destroy(); + } + newViewRequestedSpy.clear(); + } } } } - diff --git a/tests/auto/quick/qmltests/qmltests.pro b/tests/auto/quick/qmltests/qmltests.pro index 6bec6dc0d..5c57f7ad9 100644 --- a/tests/auto/quick/qmltests/qmltests.pro +++ b/tests/auto/quick/qmltests/qmltests.pro @@ -1,5 +1,4 @@ include(../tests.pri) -include(../../shared/https.pri) QT += qmltest diff --git a/tests/auto/quick/qmltests/tst_qmltests.cpp b/tests/auto/quick/qmltests/tst_qmltests.cpp index d7dcb78e7..ba74079b4 100644 --- a/tests/auto/quick/qmltests/tst_qmltests.cpp +++ b/tests/auto/quick/qmltests/tst_qmltests.cpp @@ -26,8 +26,6 @@ ** ****************************************************************************/ -#include <httpsserver.h> - #include <QtCore/QScopedPointer> #include <QTemporaryDir> #include <QtQuickTest/quicktest.h> @@ -145,9 +143,6 @@ int main(int argc, char **argv) qmlRegisterType<TempDir>("Test.util", 1, 0, "TempDir"); QTEST_SET_MAIN_SOURCE_PATH - - qmlRegisterSingletonType<HttpsServer>("Test.Shared", 1, 0, "HttpsServer", [&] (QQmlEngine *, QJSEngine *) { return new HttpsServer; }); - int i = quick_test_main(argc, argv, "qmltests", QUICK_TEST_SOURCE_DIR); return i; } diff --git a/tests/auto/quick/qmltests_ssl/data/TestWebEngineView.qml b/tests/auto/quick/qmltests_ssl/data/TestWebEngineView.qml new file mode 100644 index 000000000..6db076ae8 --- /dev/null +++ b/tests/auto/quick/qmltests_ssl/data/TestWebEngineView.qml @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtTest 1.1 +import QtWebEngine 1.7 + +WebEngineView { + property var loadStatus: null + property bool windowCloseRequestedSignalEmitted: false + settings.focusOnNavigationEnabled: true + + function waitForLoadSucceeded(timeout) { + var success = _waitFor(function() { return loadStatus == WebEngineView.LoadSucceededStatus }, timeout) + loadStatus = null + return success + } + function waitForLoadFailed(timeout) { + var failure = _waitFor(function() { return loadStatus == WebEngineView.LoadFailedStatus }, timeout) + loadStatus = null + return failure + } + function waitForLoadStopped(timeout) { + var stop = _waitFor(function() { return loadStatus == WebEngineView.LoadStoppedStatus }, timeout) + loadStatus = null + return stop + } + function waitForWindowCloseRequested() { + return _waitFor(function() { return windowCloseRequestedSignalEmitted; }); + } + function _waitFor(predicate, timeout) { + if (timeout === undefined) + timeout = 12000; + var i = 0 + while (i < timeout && !predicate()) { + testResult.wait(50) + i += 50 + } + return predicate() + } + + function getActiveElementId() { + var activeElementId; + runJavaScript("document.activeElement.id", function(result) { + activeElementId = result; + }); + testCase.tryVerify(function() { return activeElementId != undefined }); + return activeElementId; + } + + function verifyElementHasFocus(element) { + testCase.tryVerify(function() { return getActiveElementId() == element; }, 5000, + "Element \"" + element + "\" has focus"); + } + + function setFocusToElement(element) { + runJavaScript("document.getElementById('" + element + "').focus()"); + verifyElementHasFocus(element); + } + + function getElementCenter(element) { + var center; + runJavaScript("(function() {" + + " var elem = document.getElementById('" + element + "');" + + " var rect = elem.getBoundingClientRect();" + + " return { 'x': (rect.left + rect.right) / 2, 'y': (rect.top + rect.bottom) / 2 };" + + "})();", function(result) { center = result } ); + testCase.tryVerify(function() { return center !== undefined; }); + return center; + } + + function getTextSelection() { + var textSelection; + runJavaScript("window.getSelection().toString()", function(result) { textSelection = result }); + testCase.tryVerify(function() { return textSelection !== undefined; }); + return textSelection; + } + + TestResult { id: testResult } + TestCase { id: testCase } + + onLoadingChanged: { + loadStatus = loadRequest.status + } + + onWindowCloseRequested: { + windowCloseRequestedSignalEmitted = true; + } + + function getBodyText() { + let text + runJavaScript('document.body.innerText', function(t) { text = t }) + testCase.tryVerify(function() { return text !== undefined }) + return text + } +} + diff --git a/tests/auto/quick/qmltests/data/tst_certificateError.qml b/tests/auto/quick/qmltests_ssl/data/tst_certificateError.qml index a4bd9597a..a4bd9597a 100644 --- a/tests/auto/quick/qmltests/data/tst_certificateError.qml +++ b/tests/auto/quick/qmltests_ssl/data/tst_certificateError.qml diff --git a/tests/auto/quick/qmltests_ssl/qmltests_ssl.pro b/tests/auto/quick/qmltests_ssl/qmltests_ssl.pro new file mode 100644 index 000000000..a8325e497 --- /dev/null +++ b/tests/auto/quick/qmltests_ssl/qmltests_ssl.pro @@ -0,0 +1,10 @@ +include(../tests.pri) +include(../../shared/https.pri) +QT += qmltest + +IMPORTPATH += $$PWD/data + +OTHER_FILES += $$PWD/data/tst_certificateError.qml + +load(qt_build_paths) +DEFINES += QUICK_TEST_SOURCE_DIR=\\\"$$re_escape($$PWD$${QMAKE_DIR_SEP}data)\\\" diff --git a/tests/auto/quick/qmltests_ssl/tst_qmltests_ssl.cpp b/tests/auto/quick/qmltests_ssl/tst_qmltests_ssl.cpp new file mode 100644 index 000000000..1f54ffd8e --- /dev/null +++ b/tests/auto/quick/qmltests_ssl/tst_qmltests_ssl.cpp @@ -0,0 +1,160 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QtWebEngineCore/qtwebenginecoreglobal.h> +#include <QtNetwork/qtnetwork-config.h> + +#if QT_CONFIG(ssl) +#include <httpsserver.h> +#endif + +#include <QtCore/QScopedPointer> +#include <QTemporaryDir> +#include <QtQuickTest/quicktest.h> +#include <QtWebEngine/QQuickWebEngineProfile> +#include <QQmlEngine> +#include "qt_webengine_quicktest.h" + +#if defined(Q_OS_LINUX) && defined(QT_DEBUG) +#include <fcntl.h> +#include <signal.h> +#include <unistd.h> +#endif + +#if defined(Q_OS_LINUX) && defined(QT_DEBUG) +static bool debuggerPresent() +{ + int fd = open("/proc/self/status", O_RDONLY); + if (fd == -1) + return false; + char buffer[2048]; + ssize_t size = read(fd, buffer, sizeof(buffer) - 1); + if (size == -1) { + close(fd); + return false; + } + buffer[size] = 0; + const char tracerPidToken[] = "\nTracerPid:"; + char *tracerPid = strstr(buffer, tracerPidToken); + if (!tracerPid) { + close(fd); + return false; + } + tracerPid += sizeof(tracerPidToken); + long int pid = strtol(tracerPid, &tracerPid, 10); + close(fd); + return pid != 0; +} + +static void stackTrace() +{ + bool ok = false; + const int disableStackDump = qEnvironmentVariableIntValue("QTEST_DISABLE_STACK_DUMP", &ok); + if (ok && disableStackDump == 1) + return; + + if (debuggerPresent()) + return; + + fprintf(stderr, "\n========= Received signal, dumping stack ==============\n"); + char cmd[512]; + qsnprintf(cmd, 512, "gdb --pid %d 2>/dev/null <<EOF\n" + "set prompt\n" + "set height 0\n" + "thread apply all where full\n" + "detach\n" + "quit\n" + "EOF\n", + (int)getpid()); + + if (system(cmd) == -1) + fprintf(stderr, "calling gdb failed\n"); + fprintf(stderr, "========= End of stack trace ==============\n"); +} + +static void sigSegvHandler(int signum) +{ + stackTrace(); + qFatal("Received signal %d", signum); +} +#endif + +class TempDir : public QObject { + Q_OBJECT + +public: + Q_INVOKABLE QString path() { + Q_ASSERT(tempDir.isValid()); + return tempDir.isValid() ? tempDir.path() : QString(); + } + +private: + QTemporaryDir tempDir; +}; + +int main(int argc, char **argv) +{ +#if defined(Q_OS_LINUX) && defined(QT_DEBUG) + struct sigaction sigAction; + + sigemptyset(&sigAction.sa_mask); + sigAction.sa_handler = &sigSegvHandler; + sigAction.sa_flags = 0; + + sigaction(SIGSEGV, &sigAction, 0); +#endif + + QScopedPointer<Application> app; + + // Force to use English language for testing due to error message checks + QLocale::setDefault(QLocale("en")); + + static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")}; + QVector<const char *> w_argv(argc); \ + for (int i = 0; i < argc; ++i) \ + w_argv[i] = argv[i]; \ + for (int i = 0; i < params.size(); ++i) \ + w_argv.append(params[i].data()); \ + int w_argc = w_argv.size(); \ + + if (!QCoreApplication::instance()) { + app.reset(new Application(w_argc, const_cast<char **>(w_argv.data()))); + } + QtWebEngine::initialize(); + QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true); + qmlRegisterType<TempDir>("Test.util", 1, 0, "TempDir"); + + QTEST_SET_MAIN_SOURCE_PATH +#if QT_CONFIG(ssl) + qmlRegisterSingletonType<HttpsServer>("Test.Shared", 1, 0, "HttpsServer", [&] (QQmlEngine *, QJSEngine *) { return new HttpsServer; }); +#endif + int i = quick_test_main(argc, argv, "qmltests", QUICK_TEST_SOURCE_DIR); + return i; +} + +#include "tst_qmltests_ssl.moc" diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index e6dccae4d..4690047b7 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -21,5 +21,7 @@ qtConfig(webengine-testsupport) { !qtHaveModule(quickcontrols): SUBDIRS -= qmltests +qtConfig(ssl): SUBDIRS += qmltests_ssl + # QTBUG-66055 boot2qt: SUBDIRS -= inspectorserver qquickwebengineview qmltests qmltests2 |