diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/quick/certificateerror/WebView.qml | 64 | ||||
-rw-r--r-- | tests/auto/quick/certificateerror/certificateerror.pro | 7 | ||||
-rw-r--r-- | tests/auto/quick/certificateerror/certificateerror.qrc | 5 | ||||
-rw-r--r-- | tests/auto/quick/certificateerror/testhandler.cpp | 61 | ||||
-rw-r--r-- | tests/auto/quick/certificateerror/testhandler.h | 58 | ||||
-rw-r--r-- | tests/auto/quick/certificateerror/tst_certificateerror.cpp | 112 | ||||
-rw-r--r-- | tests/auto/quick/quick.pro | 3 |
7 files changed, 309 insertions, 1 deletions
diff --git a/tests/auto/quick/certificateerror/WebView.qml b/tests/auto/quick/certificateerror/WebView.qml new file mode 100644 index 000000000..97abdfb98 --- /dev/null +++ b/tests/auto/quick/certificateerror/WebView.qml @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 QtWebEngine 1.4 +import QtQuick.Window 2.0 +import QtTest 1.0 +import io.qt.tester 1.0 + +Window { + width: 50 + height: 50 + visible: true + + TestHandler { + id: handler + onLoadPage: function(url) { + view.url = url + } + } + + WebEngineView { + id: view + anchors.fill: parent + onLoadingChanged: function(request) { + if (request.status === WebEngineView.LoadSucceededStatus) { + handler.loadSuccess = true + } else if (request.status === WebEngineView.LoadFailedStatus) { + handler.loadSuccess = false + } + } + onCertificateError: function(error) { + handler.certificateError = error + } + Component.onCompleted: { + view.settings.errorPageEnabled = false + } + } +} diff --git a/tests/auto/quick/certificateerror/certificateerror.pro b/tests/auto/quick/certificateerror/certificateerror.pro new file mode 100644 index 000000000..27d5a3cc1 --- /dev/null +++ b/tests/auto/quick/certificateerror/certificateerror.pro @@ -0,0 +1,7 @@ +include(../tests.pri) +include(../../shared/https.pri) +QT *= webenginecore-private webengine webengine-private +HEADERS += $$PWD/testhandler.h +SOURCES += $$PWD/testhandler.cpp +RESOURCES += certificateerror.qrc + diff --git a/tests/auto/quick/certificateerror/certificateerror.qrc b/tests/auto/quick/certificateerror/certificateerror.qrc new file mode 100644 index 000000000..bfc3013e7 --- /dev/null +++ b/tests/auto/quick/certificateerror/certificateerror.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>WebView.qml</file> + </qresource> +</RCC> diff --git a/tests/auto/quick/certificateerror/testhandler.cpp b/tests/auto/quick/certificateerror/testhandler.cpp new file mode 100644 index 000000000..6fb55f44a --- /dev/null +++ b/tests/auto/quick/certificateerror/testhandler.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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 "testhandler.h" + +TestHandler::TestHandler(QObject *parent) : QObject(parent) +{ + setObjectName(QStringLiteral("TestListner")); +} + +void TestHandler::load(const QUrl &page) +{ + emit loadPage(page); +} + +void TestHandler::setLoadSuccess(bool success) +{ + if (m_loadSuccess != success) { + m_loadSuccess = success; + emit loadSuccessChanged(); + } +} + +QQuickWebEngineCertificateError *TestHandler::certificateError() const +{ + return m_error; +} + +void TestHandler::setCertificateError(QQuickWebEngineCertificateError *error) +{ + if (m_error == error) + return; + m_error = error; + + emit certificateErrorChanged(); +} diff --git a/tests/auto/quick/certificateerror/testhandler.h b/tests/auto/quick/certificateerror/testhandler.h new file mode 100644 index 000000000..d954ed5fc --- /dev/null +++ b/tests/auto/quick/certificateerror/testhandler.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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$ +** +****************************************************************************/ + +#ifndef TESTHANDLER_H +#define TESTHANDLER_H + +#include <QtWebEngine/private/qquickwebenginecertificateerror_p.h> + +class TestHandler : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickWebEngineCertificateError *certificateError READ certificateError WRITE + setCertificateError NOTIFY certificateErrorChanged) + Q_PROPERTY(bool loadSuccess READ loadSuccess WRITE setLoadSuccess NOTIFY loadSuccessChanged) +public: + explicit TestHandler(QObject *parent = nullptr); + QQuickWebEngineCertificateError *certificateError() const; + + void setCertificateError(QQuickWebEngineCertificateError *error); + void setLoadSuccess(bool success); + bool loadSuccess() const; + void load(const QUrl &page); + +signals: + void loadPage(const QUrl &page); + void certificateErrorChanged(); + +private: + QQuickWebEngineCertificateError *m_error = nullptr; + bool m_loadSuccess = false; +}; + +#endif // TESTHANDLER_H diff --git a/tests/auto/quick/certificateerror/tst_certificateerror.cpp b/tests/auto/quick/certificateerror/tst_certificateerror.cpp new file mode 100644 index 000000000..6201800bd --- /dev/null +++ b/tests/auto/quick/certificateerror/tst_certificateerror.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 "testhandler.h" +#include <httpsserver.h> +#include <util.h> +#include <QtWebEngine/private/qquickwebenginecertificateerror_p.h> +#include <QQuickWebEngineProfile> +#include <QQmlApplicationEngine> +#include <QQuickWindow> +#include <QtTest/QtTest> + +class tst_CertificateError : public QObject +{ + Q_OBJECT +public: + tst_CertificateError() { } + +private Q_SLOTS: + void initTestCase(); + void handleError_data(); + void handleError(); + +private: + QScopedPointer<QQmlApplicationEngine> m_engine; + QQuickWindow *m_widnow = nullptr; + TestHandler *m_handler = nullptr; +}; + +void tst_CertificateError::initTestCase() +{ + QQuickWebEngineProfile::defaultProfile()->setOffTheRecord(true); + qmlRegisterType<TestHandler>("io.qt.tester", 1, 0, "TestHandler"); + m_engine.reset(new QQmlApplicationEngine()); + m_engine->load(QUrl(QStringLiteral("qrc:/WebView.qml"))); + m_widnow = qobject_cast<QQuickWindow *>(m_engine->rootObjects().first()); + Q_ASSERT(m_widnow); + m_handler = m_widnow->findChild<TestHandler *>(QStringLiteral("TestListner")); + Q_ASSERT(m_handler); +} + +void tst_CertificateError::handleError_data() +{ + QTest::addColumn<bool>("deferError"); + QTest::addColumn<bool>("acceptCertificate"); + QTest::addColumn<QString>("expectedContent"); + QTest::addRow("Reject") << false << false << QString(); + QTest::addRow("DeferReject") << true << false << QString(); + QTest::addRow("DeferAccept") << true << true << "TEST"; +} + +void tst_CertificateError::handleError() +{ + HttpsServer server; + server.setExpectError(true); + QVERIFY(server.start()); + + connect(&server, &HttpsServer::newRequest, [&](HttpReqRep *rr) { + rr->setResponseBody(QByteArrayLiteral("<html><body>TEST</body></html>")); + rr->sendResponse(); + }); + + QFETCH(bool, deferError); + QFETCH(bool, acceptCertificate); + QFETCH(QString, expectedContent); + + QSignalSpy certificateErrorSpy(m_handler, &TestHandler::certificateErrorChanged); + m_handler->load(server.url()); + QTRY_COMPARE(certificateErrorSpy.count(), 1); + QQuickWebEngineCertificateError *error = m_handler->certificateError(); + QVERIFY(error); + + if (deferError) { + error->defer(); + return; + } + + if (acceptCertificate) + error->ignoreCertificateError(); + else + error->rejectCertificate(); + + QVERIFY(error->overridable()); +} + +static QByteArrayList params; +W_QTEST_MAIN(tst_CertificateError, params) +#include <tst_certificateerror.moc> diff --git a/tests/auto/quick/quick.pro b/tests/auto/quick/quick.pro index 285330460..e6dccae4d 100644 --- a/tests/auto/quick/quick.pro +++ b/tests/auto/quick/quick.pro @@ -10,7 +10,8 @@ SUBDIRS += \ publicapi \ qquickwebenginedefaultsurfaceformat \ qquickwebengineview \ - qtbug-70248 + qtbug-70248 \ + certificateerror qtConfig(webengine-testsupport) { SUBDIRS += \ |