diff options
author | Michal Klocek <michal.klocek@qt.io> | 2020-08-12 09:41:40 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2020-08-18 12:10:55 +0200 |
commit | 09222ab2cd57d2412ce6cbf9b32a6b1d88cd719a (patch) | |
tree | 2e58e0538452187ed7f1d06e3800e1e85bda567e /tests/auto/quick | |
parent | 7b6f30c13717654ec3b95e67edde88a03da45e22 (diff) |
Check for ssl when compling qml tests
Do not include certificate error qml test if no ssl.
This change does some copy-paste but this will
be handled in qt6.
Change-Id: I8cc6d37074d78ca9f55333f479fb410ef927385d
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/quick')
-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 |
7 files changed, 294 insertions, 6 deletions
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 0d830931d..819f0b07c 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 0629be175..0629be175 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 865ec718e..41ea5c4c1 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -18,5 +18,7 @@ qtConfig(webengine-testsupport) { qquickwebengineviewgraphics } +qtConfig(ssl): SUBDIRS += qmltests_ssl + # QTBUG-66055 boot2qt: SUBDIRS -= inspectorserver qquickwebengineview qmltests qmltests2 |