diff options
Diffstat (limited to 'tests')
11 files changed, 257 insertions, 10 deletions
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp index 5cc0d18df..7d793f1b3 100644 --- a/tests/auto/quick/publicapi/tst_publicapi.cpp +++ b/tests/auto/quick/publicapi/tst_publicapi.cpp @@ -66,6 +66,7 @@ static QList<const QMetaObject *> typesToCheck = QList<const QMetaObject *>() << &QQuickWebEngineScript::staticMetaObject << &QQuickWebEngineSettings::staticMetaObject << &QQuickWebEngineFullScreenRequest::staticMetaObject + << &QQuickWebEngineQuotaPermissionRequest::staticMetaObject << &QQuickWebEngineSingleton::staticMetaObject << &QQuickWebEngineAuthenticationDialogRequest::staticMetaObject << &QQuickWebEngineJavaScriptDialogRequest::staticMetaObject @@ -183,6 +184,7 @@ static QStringList expectedAPI = QStringList() << "QQuickWebEngineView.javaScriptConsoleMessage(JavaScriptConsoleMessageLevel,QString,int,QString) --> void" << "QQuickWebEngineView.certificateError(QQuickWebEngineCertificateError*) --> void" << "QQuickWebEngineView.fullScreenRequested(QQuickWebEngineFullScreenRequest) --> void" + << "QQuickWebEngineView.quotaPermissionRequested(QQuickWebEngineQuotaPermissionRequest) --> void" << "QQuickWebEngineView.isFullScreenChanged() --> void" << "QQuickWebEngineView.featurePermissionRequested(QUrl,Feature) --> void" << "QQuickWebEngineView.newViewRequested(QQuickWebEngineNewViewRequest*) --> void" @@ -529,6 +531,10 @@ static QStringList expectedAPI = QStringList() << "QQuickWebEngineFullScreenRequest.toggleOn --> bool" << "QQuickWebEngineFullScreenRequest.accept() --> void" << "QQuickWebEngineFullScreenRequest.reject() --> void" + << "QQuickWebEngineQuotaPermissionRequest.origin --> QUrl" + << "QQuickWebEngineQuotaPermissionRequest.requestedSize --> qlonglong" + << "QQuickWebEngineQuotaPermissionRequest.accept() --> void" + << "QQuickWebEngineQuotaPermissionRequest.reject() --> void" << "QQuickWebEngineSingleton.settings --> QQuickWebEngineSettings*" << "QQuickWebEngineSingleton.defaultProfile --> QQuickWebEngineProfile*" ; diff --git a/tests/auto/quick/qmltests/BLACKLIST b/tests/auto/quick/qmltests/BLACKLIST index f449f4949..54a3185d6 100644 --- a/tests/auto/quick/qmltests/BLACKLIST +++ b/tests/auto/quick/qmltests/BLACKLIST @@ -5,12 +5,6 @@ osx [WebViewGeopermission::test_geoPermissionRequest] osx -[DesktopWebEngineViewLinkHovered::test_linkHovered] -linux - -[DesktopWebEngineViewLinkHovered::test_linkHoveredDoesntEmitRepeated] -linux - [WebEngineViewSingleFileUpload::test_acceptDirectory] * diff --git a/tests/auto/quick/qmltests/data/TestWebEngineView.qml b/tests/auto/quick/qmltests/data/TestWebEngineView.qml index 8304a993a..9fb8c4bfe 100644 --- a/tests/auto/quick/qmltests/data/TestWebEngineView.qml +++ b/tests/auto/quick/qmltests/data/TestWebEngineView.qml @@ -28,7 +28,7 @@ import QtQuick 2.0 import QtTest 1.1 -import QtWebEngine 1.3 +import QtWebEngine 1.7 WebEngineView { property var loadStatus: null diff --git a/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.cpp b/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.cpp index 38311cad2..710561cce 100644 --- a/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.cpp +++ b/tests/auto/widgets/qwebenginefaviconmanager/tst_qwebenginefaviconmanager.cpp @@ -238,7 +238,7 @@ void tst_QWebEngineFaviconManager::errorPageEnabled() QUrl url("invalid://url"); m_page->load(url); - QTRY_COMPARE(loadFinishedSpy.count(), 1); + QTRY_COMPARE(loadFinishedSpy.count(), 2); QCOMPARE(iconUrlChangedSpy.count(), 0); QCOMPARE(iconChangedSpy.count(), 0); diff --git a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp index d9bbce173..7c8497fef 100644 --- a/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp +++ b/tests/auto/widgets/qwebenginehistory/tst_qwebenginehistory.cpp @@ -65,6 +65,7 @@ private Q_SLOTS: void saveAndRestore_crash_2(); void saveAndRestore_crash_3(); void saveAndRestore_crash_4(); + void saveAndRestore_InternalPage(); void popPushState_data(); void popPushState(); @@ -420,6 +421,26 @@ void tst_QWebEngineHistory::saveAndRestore_crash_4() QTRY_COMPARE(loadFinishedSpy2.count(), 1); } +void tst_QWebEngineHistory::saveAndRestore_InternalPage() +{ + QWebEngineView view; + view.show(); + QSignalSpy loadFinishedSpy(&view, &QWebEngineView::loadFinished); + view.load(QUrl("view-source:http://qt.io")); + QTRY_LOOP_IMPL((loadFinishedSpy.size() == 1), 30000, 200) + if (loadFinishedSpy.size() != 1 || !loadFinishedSpy.at(0).at(0).toBool()) + QSKIP("Couldn't load page from network, skipping test."); + + // get history + QByteArray data; + QDataStream stream1(&data, QIODevice::WriteOnly); + stream1 << *view.history(); + + // restore history - this should not crash. see QTBUG-57826 + QDataStream stream2(data); + stream2 >> *view.history(); +} + void tst_QWebEngineHistory::popPushState_data() { QTest::addColumn<QString>("script"); diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 1c9b668ae..f0ab74d6c 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -47,6 +47,7 @@ #include <qwebenginehistory.h> #include <qwebenginepage.h> #include <qwebengineprofile.h> +#include <qwebenginequotapermissionrequest.h> #include <qwebenginescript.h> #include <qwebenginescriptcollection.h> #include <qwebenginesettings.h> @@ -165,6 +166,7 @@ private Q_SLOTS: void runJavaScript(); void fullScreenRequested(); + void quotaPermissionRequested(); // Tests from tst_QWebEngineFrame @@ -3120,6 +3122,46 @@ void tst_QWebEnginePage::fullScreenRequested() QVERIFY(watcher.wait()); } +void tst_QWebEnginePage::quotaPermissionRequested() +{ + ConsolePage page; + QWebEngineView view; + view.setPage(&page); + QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool))); + page.load(QUrl("qrc:///resources/content.html")); + QVERIFY(loadFinishedSpy.wait()); + + connect(&page, &QWebEnginePage::quotaPermissionRequested, + [] (QWebEngineQuotaPermissionRequest request) + { + if (request.requestedSize() <= 5000) + request.accept(); + else + request.reject(); + }); + + evaluateJavaScriptSync(&page, + "navigator.webkitPersistentStorage.requestQuota(1024, function(grantedSize) {" \ + "console.log(grantedSize);" \ + "});"); + QTRY_COMPARE(page.messages.count(), 1); + QTRY_COMPARE(page.messages[0], QString("1024")); + + evaluateJavaScriptSync(&page, + "navigator.webkitPersistentStorage.requestQuota(6000, function(grantedSize) {" \ + "console.log(grantedSize);" \ + "});"); + QTRY_COMPARE(page.messages.count(), 2); + QTRY_COMPARE(page.messages[1], QString("1024")); + + evaluateJavaScriptSync(&page, + "navigator.webkitPersistentStorage.queryUsageAndQuota(function(usedBytes, grantedBytes) {" \ + "console.log(usedBytes + ', ' + grantedBytes);" \ + "});"); + QTRY_COMPARE(page.messages.count(), 3); + QTRY_COMPARE(page.messages[2], QString("0, 1024")); +} + void tst_QWebEnginePage::symmetricUrl() { QWebEngineView view; diff --git a/tests/auto/widgets/qwebengineschemes/BLACKLIST b/tests/auto/widgets/qwebengineschemes/BLACKLIST new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/auto/widgets/qwebengineschemes/BLACKLIST diff --git a/tests/auto/widgets/qwebengineschemes/qwebengineschemes.pro b/tests/auto/widgets/qwebengineschemes/qwebengineschemes.pro new file mode 100644 index 000000000..e56bbe8f7 --- /dev/null +++ b/tests/auto/widgets/qwebengineschemes/qwebengineschemes.pro @@ -0,0 +1,3 @@ +include(../tests.pri) +exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc +QT *= core-private gui-private diff --git a/tests/auto/widgets/qwebengineschemes/tst_qwebengineschemes.cpp b/tests/auto/widgets/qwebengineschemes/tst_qwebengineschemes.cpp new file mode 100644 index 000000000..cacfc1a3c --- /dev/null +++ b/tests/auto/widgets/qwebengineschemes/tst_qwebengineschemes.cpp @@ -0,0 +1,110 @@ +/**************************************************************************** +** +** Copyright (C) 2017 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 <QtTest/QtTest> + +#include <qwebengineview.h> +#include <qwebenginepage.h> +#include <qwebengineprofile.h> +#include <qwebenginesettings.h> + +class tst_QWebEngineSchemes : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void unknownUrlSchemePolicy(); +}; + +class AcceptNavigationRequestHandler : public QWebEnginePage +{ +public: + AcceptNavigationRequestHandler(QObject* parent = nullptr) + : QWebEnginePage(parent) + { + } + int acceptNavigationRequestCalls = 0; + bool acceptNavigationRequest(const QUrl &/*url*/, NavigationType /*type*/, bool /*isMainFrame*/) override + { + this->acceptNavigationRequestCalls++; + return false; + } +}; + +void tst_QWebEngineSchemes::unknownUrlSchemePolicy() +{ + QWebEngineView view; + AcceptNavigationRequestHandler page; + view.setPage(&page); + view.resize(400, 40); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + QWebEngineSettings *settings = view.page()->profile()->settings(); + settings->setAttribute(QWebEngineSettings::FocusOnNavigationEnabled, true); + QSignalSpy loadFinishedSpy(&view, &QWebEngineView::loadFinished); + + QWebEngineSettings::UnknownUrlSchemePolicy policies[6] = {QWebEngineSettings::DisallowUnknownUrlSchemes, + QWebEngineSettings::DisallowUnknownUrlSchemes, + QWebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction, + QWebEngineSettings::AllowUnknownUrlSchemesFromUserInteraction, + QWebEngineSettings::AllowAllUnknownUrlSchemes, + QWebEngineSettings::AllowAllUnknownUrlSchemes}; + // even iterations are for navigation-requests from javascript, + // odd iterations are for navigations-requests from user-interaction + for (int i = 0; i < 8; i++) { + if (i <= 5) + settings->setUnknownUrlSchemePolicy(policies[i]); + else + settings->resetUnknownUrlSchemePolicy(); + loadFinishedSpy.clear(); + page.acceptNavigationRequestCalls = 0; + bool shouldAccept; + + if (i % 2 == 0) { // navigation request coming from javascript + shouldAccept = (4 <= i && i <= 5); // only case AllowAllUnknownUrlSchemes + view.setHtml("<html><script>setTimeout(function(){ window.location.href='nonexistentscheme://somewhere'; }, 10);</script><body>testing...</body></html>"); + } else { // navigation request coming from user interaction + shouldAccept = (2 <= i); // all cases except DisallowUnknownUrlSchemes + view.setHtml("<html><body><a id='nonexlink' href='nonexistentscheme://somewhere'>nonexistentscheme://somewhere</a></body></html>"); + QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.size(), 1, 30000); + // focus and trigger the link + view.page()->runJavaScript("document.getElementById('nonexlink').focus();", [&view](const QVariant &result) { + Q_UNUSED(result); + QTest::sendKeyEvent(QTest::Press, view.focusProxy(), Qt::Key_Return, QString("\r"), Qt::NoModifier); + QTest::sendKeyEvent(QTest::Release, view.focusProxy(), Qt::Key_Return, QString("\r"), Qt::NoModifier); + }); + } + + bool errorPageEnabled = settings->testAttribute(QWebEngineSettings::ErrorPageEnabled); + QTRY_COMPARE_WITH_TIMEOUT(loadFinishedSpy.size(), 2 + (errorPageEnabled ? 1 : 0), 30000); + QCOMPARE(page.acceptNavigationRequestCalls, shouldAccept ? 1 : 0); + } +} + +QTEST_MAIN(tst_QWebEngineSchemes) +#include "tst_qwebengineschemes.moc" diff --git a/tests/auto/widgets/widgets.pro b/tests/auto/widgets/widgets.pro index 32a7806fe..28f8f56c1 100644 --- a/tests/auto/widgets/widgets.pro +++ b/tests/auto/widgets/widgets.pro @@ -11,6 +11,7 @@ SUBDIRS += \ qwebenginehistoryinterface \ qwebengineinspector \ qwebengineprofile \ + qwebengineschemes \ qwebenginescript \ qwebenginesettings \ qwebengineview @@ -30,5 +31,6 @@ qtConfig(webengine-spellchecker):!cross_compile { # QTBUG-60268 boot2qt: SUBDIRS -= qwebengineaccessibility qwebenginedefaultsurfaceformat \ qwebenginefaviconmanager qwebenginepage qwebenginehistory \ - qwebengineprofile qwebenginescript qwebengineview \ - qwebenginedownloads + qwebengineprofile qwebengineschemes qwebenginescript \ + qwebengineview qwebenginedownloads + diff --git a/tests/manual/html/pointer-events.html b/tests/manual/html/pointer-events.html new file mode 100644 index 000000000..c6e728662 --- /dev/null +++ b/tests/manual/html/pointer-events.html @@ -0,0 +1,69 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <title>Pointer event test</title> + </head> + <body> + +<p> + <canvas id="listener" width="500" height="500" style="border: silver 1px dotted;"></canvas> +</p> +<p> + Touch this circle with a stylus. Its size indicates your pressure; its position is the angle between your stylus and your tablet device; and the radius is the rotation - if your tablet supports it. +</p> + + </body> + <script> + +var canvas = document.getElementById("listener"); +var context = canvas.getContext('2d'); + +var eventName = [ + "pointerover", + "pointerenter", + "pointerdown", + "pointermove", + "pointerup", + "pointercancel", + "pointerout", + "pointerleave", + "gotpointercapture", + "lostpointercapture" +]; + +for (var i = 0; i < eventName.length; i++) { + canvas.addEventListener(eventName[i], function(ev) { + drawCircle(ev.pressure, ev.tiltX, ev.tiltY, ev.twist); + }, false); +} + +drawCircle(0, 0, 0, 0); + +function drawCircle(pressure, tiltX, tiltY, twist) { + var centerX = canvas.width / 2 + tiltX; + var centerY = canvas.height / 2 + tiltY; + var radius = 100 + 100 * pressure; + + context.clearRect(0, 0, canvas.width, canvas.height); + context.beginPath(); + context.arc(centerX, + centerY, + radius, + 0, + 2 * Math.PI, + false); + context.fillStyle = 'lightblue'; + context.fill(); + context.lineWidth = 3; + context.strokeStyle = '#008B8B'; + context.stroke(); + + context.beginPath(); + context.moveTo(centerX, centerY); + context.lineTo(centerX + radius * Math.cos(twist), centerY + radius * Math.sin(twist)); + context.stroke(); +} + +</script> +</html> |