diff options
Diffstat (limited to 'tests/auto/widgets')
18 files changed, 243 insertions, 365 deletions
diff --git a/tests/auto/widgets/accessibility/BLACKLIST b/tests/auto/widgets/accessibility/BLACKLIST new file mode 100644 index 000000000..41d3635d2 --- /dev/null +++ b/tests/auto/widgets/accessibility/BLACKLIST @@ -0,0 +1,2 @@ +[focusChild] +* diff --git a/tests/auto/widgets/accessibility/tst_accessibility.cpp b/tests/auto/widgets/accessibility/tst_accessibility.cpp index 0c235382a..989ad0ee9 100644 --- a/tests/auto/widgets/accessibility/tst_accessibility.cpp +++ b/tests/auto/widgets/accessibility/tst_accessibility.cpp @@ -151,11 +151,11 @@ void tst_Accessibility::hierarchy() void tst_Accessibility::focusChild_data() { QTest::addColumn<QString>("interfaceName"); - QTest::addColumn<QVector<QAccessible::Role>>("ancestorRoles"); + QTest::addColumn<QList<QAccessible::Role>>("ancestorRoles"); - QTest::newRow("QWebEngineView") << QString("QWebEngineView") << QVector<QAccessible::Role>({QAccessible::Client}); - QTest::newRow("RenderWidgetHostViewQtDelegate") << QString("RenderWidgetHostViewQtDelegate") << QVector<QAccessible::Role>({QAccessible::Client}); - QTest::newRow("QMainWindow") << QString("QMainWindow") << QVector<QAccessible::Role>({QAccessible::Window, QAccessible::Client /* central widget */, QAccessible::Client /* view */}); + QTest::newRow("QWebEngineView") << QString("QWebEngineView") << QList<QAccessible::Role>({QAccessible::Client}); + QTest::newRow("RenderWidgetHostViewQtDelegate") << QString("RenderWidgetHostViewQtDelegate") << QList<QAccessible::Role>({QAccessible::Client}); + QTest::newRow("QMainWindow") << QString("QMainWindow") << QList<QAccessible::Role>({QAccessible::Window, QAccessible::Client /* central widget */, QAccessible::Client /* view */}); } void tst_Accessibility::focusChild() @@ -164,7 +164,7 @@ void tst_Accessibility::focusChild() QSKIP("Requires newer base Qt"); #endif auto traverseToWebDocumentAccessibleInterface = [](QAccessibleInterface *iface) -> QAccessibleInterface * { - QFETCH(QVector<QAccessible::Role>, ancestorRoles); + QFETCH(QList<QAccessible::Role>, ancestorRoles); for (int i = 0; i < ancestorRoles.size(); ++i) { if (iface->childCount() == 0 || iface->role() != ancestorRoles[i]) return nullptr; diff --git a/tests/auto/widgets/certificateerror/tst_certificateerror.cpp b/tests/auto/widgets/certificateerror/tst_certificateerror.cpp index c5b761818..063a53ae2 100644 --- a/tests/auto/widgets/certificateerror/tst_certificateerror.cpp +++ b/tests/auto/widgets/certificateerror/tst_certificateerror.cpp @@ -58,11 +58,18 @@ struct PageWithCertificateErrorHandler : QWebEnginePage QSignalSpy loadSpy; QScopedPointer<QWebEngineCertificateError> error; - bool certificateError(const QWebEngineCertificateError &e) override { + void certificateError(QWebEngineCertificateError e) override + { error.reset(new QWebEngineCertificateError(e)); - if (deferError) + if (deferError) { error->defer(); - return acceptCertificate; + return; + } + + if (acceptCertificate) + error->acceptCertificate(); + else + error->rejectCertificate(); } }; @@ -103,17 +110,14 @@ void tst_CertificateError::handleError() QCOMPARE(chain[1].serialNumber(), "6d:52:fb:b4:57:3b:b2:03:c8:62:7b:7e:44:45:5c:d3:08:87:74:17"); if (deferError) { - QVERIFY(page.error->deferred()); - QVERIFY(!page.error->answered()); QCOMPARE(page.loadSpy.count(), 0); QCOMPARE(toPlainTextSync(&page), QString()); if (acceptCertificate) - page.error->ignoreCertificateError(); + page.error->acceptCertificate(); else page.error->rejectCertificate(); - QVERIFY(page.error->answered()); page.error.reset(); } QTRY_COMPARE_WITH_TIMEOUT(page.loadSpy.count(), 1, 30000); diff --git a/tests/auto/widgets/loadsignals/tst_loadsignals.cpp b/tests/auto/widgets/loadsignals/tst_loadsignals.cpp index b4170587d..c1e9013df 100644 --- a/tests/auto/widgets/loadsignals/tst_loadsignals.cpp +++ b/tests/auto/widgets/loadsignals/tst_loadsignals.cpp @@ -215,12 +215,12 @@ void tst_LoadSignals::fileDownloadDoesNotTriggerLoadSignals_qtbug66661() // allow the download QTemporaryDir tempDir; QVERIFY(tempDir.isValid()); - QWebEngineDownloadItem::DownloadState downloadState = QWebEngineDownloadItem::DownloadRequested; + QWebEngineDownloadRequest::DownloadState downloadState = QWebEngineDownloadRequest::DownloadRequested; ScopedConnection sc1 = connect(&profile, &QWebEngineProfile::downloadRequested, - [&downloadState, &tempDir](QWebEngineDownloadItem *item) { - connect(item, &QWebEngineDownloadItem::stateChanged, - [&downloadState](QWebEngineDownloadItem::DownloadState newState) { + [&downloadState, &tempDir](QWebEngineDownloadRequest *item) { + connect(item, &QWebEngineDownloadRequest::stateChanged, + [&downloadState](QWebEngineDownloadRequest::DownloadState newState) { downloadState = newState; }); item->setDownloadDirectory(tempDir.path()); @@ -237,7 +237,7 @@ void tst_LoadSignals::fileDownloadDoesNotTriggerLoadSignals_qtbug66661() || (loadFinishedSpy.size() != 1), 10000, 100); // Download must have occurred - QTRY_COMPARE(downloadState, QWebEngineDownloadItem::DownloadCompleted); + QTRY_COMPARE(downloadState, QWebEngineDownloadRequest::DownloadCompleted); // No further loadStarted should have occurred within this time QCOMPARE(loadStartedSpy.size(), 1); diff --git a/tests/auto/widgets/origins/tst_origins.cpp b/tests/auto/widgets/origins/tst_origins.cpp index 93a496ac4..b9385516f 100644 --- a/tests/auto/widgets/origins/tst_origins.cpp +++ b/tests/auto/widgets/origins/tst_origins.cpp @@ -34,15 +34,16 @@ #include <QtWebEngineCore/qwebengineurlrequestjob.h> #include <QtWebEngineCore/qwebengineurlscheme.h> #include <QtWebEngineCore/qwebengineurlschemehandler.h> -#include <QtWebEngineWidgets/qwebenginepage.h> -#include <QtWebEngineWidgets/qwebengineprofile.h> -#include <QtWebEngineWidgets/qwebenginesettings.h> +#include <QtWebEngineCore/qwebenginesettings.h> +#include <QtWebEngineCore/qwebengineprofile.h> +#include <QtWebEngineCore/qwebenginepage.h> + #if defined(WEBSOCKETS) #include <QtWebSockets/qwebsocket.h> #include <QtWebSockets/qwebsocketserver.h> #include <QtWebChannel/qwebchannel.h> #endif -#include <QtWidgets/qaction.h> +#include <qaction.h> #define QSL QStringLiteral #define QBAL QByteArrayLiteral @@ -170,7 +171,7 @@ public: profile->installUrlSchemeHandler(QBAL("cors"), this); } - QVector<QUrl> &requests() { return m_requests; } + QList<QUrl> &requests() { return m_requests; } private: void requestStarted(QWebEngineUrlRequestJob *job) override @@ -199,7 +200,7 @@ private: job->reply(mimeType, file); } - QVector<QUrl> m_requests; + QList<QUrl> m_requests; }; class tst_Origins final : public QObject { diff --git a/tests/auto/widgets/proxy/proxy_server.cpp b/tests/auto/widgets/proxy/proxy_server.cpp index 3bf915609..3e52de4f2 100644 --- a/tests/auto/widgets/proxy/proxy_server.cpp +++ b/tests/auto/widgets/proxy/proxy_server.cpp @@ -39,7 +39,7 @@ ProxyServer::ProxyServer(QObject *parent) : QObject(parent) void ProxyServer::setCredentials(const QByteArray &user, const QByteArray password) { m_auth.append(user); - m_auth.append(QChar(':')); + m_auth.append(':'); m_auth.append(password); m_auth = m_auth.toBase64(); m_authenticate = true; diff --git a/tests/auto/widgets/qwebenginedownloaditem/qwebenginedownloaditem.pro b/tests/auto/widgets/qwebenginedownloadrequest/qwebenginedownloadrequest.pro index 18a66c466..18a66c466 100644 --- a/tests/auto/widgets/qwebenginedownloaditem/qwebenginedownloaditem.pro +++ b/tests/auto/widgets/qwebenginedownloadrequest/qwebenginedownloadrequest.pro diff --git a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp index ec88fc581..3c3f1054d 100644 --- a/tests/auto/widgets/qwebenginedownloaditem/tst_qwebenginedownloaditem.cpp +++ b/tests/auto/widgets/qwebenginedownloadrequest/tst_qwebenginedownloadrequest.cpp @@ -34,14 +34,14 @@ #include <QTemporaryDir> #include <QTest> #include <QRegularExpression> -#include <QWebEngineDownloadItem> +#include <QWebEngineDownloadRequest> #include <QWebEnginePage> #include <QWebEngineProfile> #include <QWebEngineSettings> #include <QWebEngineView> #include <httpserver.h> -class tst_QWebEngineDownloadItem : public QObject +class tst_QWebEngineDownloadRequest : public QObject { Q_OBJECT @@ -79,9 +79,6 @@ private Q_SLOTS: void downloadToDefaultLocation(); void downloadToNonExistentDir(); void downloadToReadOnlyDir(); -#if QT_DEPRECATED_SINCE(5, 14) - void downloadPathValidation(); -#endif void downloadToDirectoryWithFileName_data(); void downloadToDirectoryWithFileName(); @@ -90,34 +87,30 @@ private: void clickLink(QPoint linkPos); void simulateUserAction(QPoint linkPos, UserAction action); - QWebEngineDownloadItem::DownloadType expectedDownloadType( - UserAction userAction, - const QByteArray &contentDisposition = QByteArray()); - HttpServer *m_server; QWebEngineProfile *m_profile; QWebEnginePage *m_page; QWebEngineView *m_view; - QSet<QWebEngineDownloadItem *> m_requestedDownloads; - QSet<QWebEngineDownloadItem *> m_finishedDownloads; + QSet<QWebEngineDownloadRequest *> m_requestedDownloads; + QSet<QWebEngineDownloadRequest *> m_finishedDownloads; }; -Q_DECLARE_METATYPE(tst_QWebEngineDownloadItem::UserAction) -Q_DECLARE_METATYPE(tst_QWebEngineDownloadItem::FileAction) +Q_DECLARE_METATYPE(tst_QWebEngineDownloadRequest::UserAction) +Q_DECLARE_METATYPE(tst_QWebEngineDownloadRequest::FileAction) -void tst_QWebEngineDownloadItem::initTestCase() +void tst_QWebEngineDownloadRequest::initTestCase() { m_server = new HttpServer(); m_profile = new QWebEngineProfile; m_profile->setHttpCacheType(QWebEngineProfile::NoCache); m_profile->settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, false); - connect(m_profile, &QWebEngineProfile::downloadRequested, [this](QWebEngineDownloadItem *item) { + connect(m_profile, &QWebEngineProfile::downloadRequested, [this](QWebEngineDownloadRequest *item) { m_requestedDownloads.insert(item); - connect(item, &QWebEngineDownloadItem::destroyed, [this, item](){ + connect(item, &QWebEngineDownloadRequest::destroyed, [this, item](){ m_requestedDownloads.remove(item); m_finishedDownloads.remove(item); }); - connect(item, &QWebEngineDownloadItem::finished, [this, item](){ + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [this, item](){ m_finishedDownloads.insert(item); }); }); @@ -128,14 +121,14 @@ void tst_QWebEngineDownloadItem::initTestCase() m_view->show(); } -void tst_QWebEngineDownloadItem::init() +void tst_QWebEngineDownloadRequest::init() { QVERIFY(m_server->start()); } -void tst_QWebEngineDownloadItem::cleanup() +void tst_QWebEngineDownloadRequest::cleanup() { - for (QWebEngineDownloadItem *item : m_finishedDownloads) { + for (QWebEngineDownloadRequest *item : m_finishedDownloads) { item->deleteLater(); } QTRY_COMPARE(m_requestedDownloads.count(), 0); @@ -145,7 +138,7 @@ void tst_QWebEngineDownloadItem::cleanup() m_profile->setDownloadPath(""); } -void tst_QWebEngineDownloadItem::cleanupTestCase() +void tst_QWebEngineDownloadRequest::cleanupTestCase() { delete m_view; delete m_page; @@ -153,7 +146,7 @@ void tst_QWebEngineDownloadItem::cleanupTestCase() delete m_server; } -void tst_QWebEngineDownloadItem::saveLink(QPoint linkPos) +void tst_QWebEngineDownloadRequest::saveLink(QPoint linkPos) { // Simulate right-clicking on link and choosing "save link as" from menu. QSignalSpy menuSpy(m_view, &QWebEngineView::customContextMenuRequested); @@ -170,7 +163,7 @@ void tst_QWebEngineDownloadItem::saveLink(QPoint linkPos) m_page->triggerAction(QWebEnginePage::DownloadLinkToDisk); } -void tst_QWebEngineDownloadItem::clickLink(QPoint linkPos) +void tst_QWebEngineDownloadRequest::clickLink(QPoint linkPos) { // Simulate left-clicking on link. QTRY_VERIFY(m_view->focusWidget()); @@ -178,7 +171,7 @@ void tst_QWebEngineDownloadItem::clickLink(QPoint linkPos) QTest::mouseClick(renderWidget, Qt::LeftButton, {}, linkPos); } -void tst_QWebEngineDownloadItem::simulateUserAction(QPoint linkPos, UserAction action) +void tst_QWebEngineDownloadRequest::simulateUserAction(QPoint linkPos, UserAction action) { switch (action) { case SaveLink: return saveLink(linkPos); @@ -186,17 +179,7 @@ void tst_QWebEngineDownloadItem::simulateUserAction(QPoint linkPos, UserAction a } } -QWebEngineDownloadItem::DownloadType tst_QWebEngineDownloadItem::expectedDownloadType( - UserAction userAction, const QByteArray &contentDisposition) -{ - if (userAction == SaveLink) - return QWebEngineDownloadItem::UserRequested; - if (contentDisposition == QByteArrayLiteral("attachment")) - return QWebEngineDownloadItem::Attachment; - return QWebEngineDownloadItem::DownloadAttribute; -} - -void tst_QWebEngineDownloadItem::downloadLink_data() +void tst_QWebEngineDownloadRequest::downloadLink_data() { QTest::addColumn<UserAction>("userAction"); QTest::addColumn<bool>("anchorHasDownloadAttribute"); @@ -207,7 +190,6 @@ void tst_QWebEngineDownloadItem::downloadLink_data() QTest::addColumn<QByteArray>("fileDisposition"); QTest::addColumn<bool>("fileHasReferer"); QTest::addColumn<FileAction>("fileAction"); - QTest::addColumn<QWebEngineDownloadItem::DownloadType>("downloadType"); // SaveLink should always trigger a download, even for empty files. QTest::newRow("save link to empty file") @@ -393,7 +375,7 @@ void tst_QWebEngineDownloadItem::downloadLink_data() /* fileAction */ << FileIsDownloaded; } -void tst_QWebEngineDownloadItem::downloadLink() +void tst_QWebEngineDownloadRequest::downloadLink() { QFETCH(UserAction, userAction); QFETCH(bool, anchorHasDownloadAttribute); @@ -450,33 +432,31 @@ void tst_QWebEngineDownloadItem::downloadLink() QUrl downloadUrl = m_server->url(slashFileName); int acceptedCount = 0; int finishedCount = 0; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested); + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadRequested); QCOMPARE(item->isFinished(), false); QCOMPARE(item->totalBytes(), -1); QCOMPARE(item->receivedBytes(), 0); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->type(), expectedDownloadType(userAction, fileDisposition)); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); QCOMPARE(item->isSavePageDownload(), false); QCOMPARE(item->mimeType(), QString(fileMimeTypeDetected)); QCOMPARE(QDir(item->downloadDirectory()).filePath(item->downloadFileName()), suggestedPath); - QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat); + QCOMPARE(item->savePageFormat(), QWebEngineDownloadRequest::UnknownSaveFormat); QCOMPARE(item->url(), downloadUrl); - QCOMPARE(item->page(), m_page); + QCOMPARE(QWebEnginePage::fromDownloadRequest(item), m_page); - connect(item, &QWebEngineDownloadItem::finished, [&, item]() { - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&, item]() { + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadCompleted); QCOMPARE(item->isFinished(), true); QCOMPARE(item->totalBytes(), fileContents.size()); QCOMPARE(item->receivedBytes(), fileContents.size()); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->type(), expectedDownloadType(userAction, fileDisposition)); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); QCOMPARE(item->isSavePageDownload(), false); QCOMPARE(item->mimeType(), QString(fileMimeTypeDetected)); QCOMPARE(QDir(item->downloadDirectory()).filePath(item->downloadFileName()), downloadPath); - QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat); + QCOMPARE(item->savePageFormat(), QWebEngineDownloadRequest::UnknownSaveFormat); QCOMPARE(item->url(), downloadUrl); - QCOMPARE(item->page(), m_page); + QCOMPARE(QWebEnginePage::fromDownloadRequest(item), m_page); finishedCount++; }); @@ -520,7 +500,7 @@ void tst_QWebEngineDownloadItem::downloadLink() QCOMPARE(file.readAll(), fileContents); } -void tst_QWebEngineDownloadItem::downloadTwoLinks_data() +void tst_QWebEngineDownloadRequest::downloadTwoLinks_data() { QTest::addColumn<UserAction>("action1"); QTest::addColumn<UserAction>("action2"); @@ -530,7 +510,7 @@ void tst_QWebEngineDownloadItem::downloadTwoLinks_data() QTest::newRow("Click+Click") << ClickLink << ClickLink; } -void tst_QWebEngineDownloadItem::downloadTwoLinks() +void tst_QWebEngineDownloadRequest::downloadTwoLinks() { QFETCH(UserAction, action1); QFETCH(UserAction, action2); @@ -563,29 +543,23 @@ void tst_QWebEngineDownloadItem::downloadTwoLinks() QString standardDir = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); int acceptedCount = 0; int finishedCount = 0; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested); + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadRequested); QCOMPARE(item->isFinished(), false); QCOMPARE(item->totalBytes(), -1); QCOMPARE(item->receivedBytes(), 0); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->savePageFormat(), QWebEngineDownloadItem::UnknownSaveFormat); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); + QCOMPARE(item->savePageFormat(), QWebEngineDownloadRequest::UnknownSaveFormat); QCOMPARE(item->mimeType(), QStringLiteral("text/plain")); QString filePart = QChar('/') + item->url().fileName(); QString fileName = item->url().fileName(); QCOMPARE(QDir(item->downloadDirectory()).filePath(item->downloadFileName()), standardDir + filePart); // type() is broken due to race condition in DownloadManagerDelegateQt - if (action1 == ClickLink && action2 == ClickLink) { - if (filePart == QStringLiteral("/file1")) - QCOMPARE(item->type(), expectedDownloadType(action1)); - else if (filePart == QStringLiteral("/file2")) - QCOMPARE(item->type(), expectedDownloadType(action2, QByteArrayLiteral("attachment"))); - else + if (action1 == ClickLink && action2 == ClickLink && filePart != QStringLiteral("/file1") && filePart != QStringLiteral("/file2")) QFAIL(qPrintable("Unexpected file name: " + filePart)); - } - connect(item, &QWebEngineDownloadItem::finished, [&]() { + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&]() { finishedCount++; }); item->setDownloadDirectory(tmpDir.path()); @@ -611,20 +585,20 @@ void tst_QWebEngineDownloadItem::downloadTwoLinks() QTRY_COMPARE(finishedCount, 2); } -void tst_QWebEngineDownloadItem::downloadPage_data() +void tst_QWebEngineDownloadRequest::downloadPage_data() { QTest::addColumn<bool>("saveWithPageAction"); - QTest::addColumn<QWebEngineDownloadItem::SavePageFormat>("savePageFormat"); - QTest::newRow("SingleHtmlSaveFormat") << false << QWebEngineDownloadItem::SingleHtmlSaveFormat; - QTest::newRow("CompleteHtmlSaveFormat") << false << QWebEngineDownloadItem::CompleteHtmlSaveFormat; - QTest::newRow("MimeHtmlSaveFormat") << false << QWebEngineDownloadItem::MimeHtmlSaveFormat; - QTest::newRow("SavePageAction") << true << QWebEngineDownloadItem::MimeHtmlSaveFormat; + QTest::addColumn<QWebEngineDownloadRequest::SavePageFormat>("savePageFormat"); + QTest::newRow("SingleHtmlSaveFormat") << false << QWebEngineDownloadRequest::SingleHtmlSaveFormat; + QTest::newRow("CompleteHtmlSaveFormat") << false << QWebEngineDownloadRequest::CompleteHtmlSaveFormat; + QTest::newRow("MimeHtmlSaveFormat") << false << QWebEngineDownloadRequest::MimeHtmlSaveFormat; + QTest::newRow("SavePageAction") << true << QWebEngineDownloadRequest::MimeHtmlSaveFormat; } -void tst_QWebEngineDownloadItem::downloadPage() +void tst_QWebEngineDownloadRequest::downloadPage() { QFETCH(bool, saveWithPageAction); - QFETCH(QWebEngineDownloadItem::SavePageFormat, savePageFormat); + QFETCH(QWebEngineDownloadRequest::SavePageFormat, savePageFormat); // Set up HTTP server int indexRequestCount = 0; @@ -644,19 +618,18 @@ void tst_QWebEngineDownloadItem::downloadPage() QUrl downloadUrl = m_server->url("/"); int acceptedCount = 0; int finishedCount = 0; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { - QCOMPARE(item->state(), saveWithPageAction ? QWebEngineDownloadItem::DownloadRequested : QWebEngineDownloadItem::DownloadInProgress); + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { + QCOMPARE(item->state(), saveWithPageAction ? QWebEngineDownloadRequest::DownloadRequested : QWebEngineDownloadRequest::DownloadInProgress); QCOMPARE(item->isFinished(), false); QCOMPARE(item->totalBytes(), -1); QCOMPARE(item->receivedBytes(), 0); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->type(), QWebEngineDownloadItem::SavePage); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); QCOMPARE(item->isSavePageDownload(), true); // FIXME(juvaldma): why is mimeType always the same? QCOMPARE(item->mimeType(), QStringLiteral("application/x-mimearchive")); QCOMPARE(item->savePageFormat(), savePageFormat); QCOMPARE(item->url(), downloadUrl); - QCOMPARE(item->page(), m_page); + QCOMPARE(QWebEnginePage::fromDownloadRequest(item), m_page); if (saveWithPageAction) { QVERIFY(!item->downloadDirectory().isEmpty()); @@ -668,19 +641,18 @@ void tst_QWebEngineDownloadItem::downloadPage() QCOMPARE(QDir(item->downloadDirectory()).filePath(item->downloadFileName()), downloadPath); - connect(item, &QWebEngineDownloadItem::finished, [&, item]() { - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&, item]() { + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadCompleted); QCOMPARE(item->isFinished(), true); QCOMPARE(item->totalBytes(), item->receivedBytes()); QVERIFY(item->receivedBytes() > 0); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->type(), QWebEngineDownloadItem::SavePage); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); QCOMPARE(item->isSavePageDownload(), true); QCOMPARE(item->mimeType(), QStringLiteral("application/x-mimearchive")); QCOMPARE(QDir(item->downloadDirectory()).filePath(item->downloadFileName()), downloadPath); QCOMPARE(item->savePageFormat(), savePageFormat); QCOMPARE(item->url(), downloadUrl); - QCOMPARE(item->page(), m_page); + QCOMPARE(QWebEnginePage::fromDownloadRequest(item), m_page); finishedCount++; }); @@ -707,7 +679,7 @@ void tst_QWebEngineDownloadItem::downloadPage() QVERIFY(file.exists()); } -void tst_QWebEngineDownloadItem::downloadViaSetUrl() +void tst_QWebEngineDownloadRequest::downloadViaSetUrl() { // Reproduce the scenario described in QTBUG-63388 by triggering downloads // of the same file multiple times via QWebEnginePage::setUrl @@ -726,8 +698,8 @@ void tst_QWebEngineDownloadItem::downloadViaSetUrl() }); // Set up profile and download handler - QVector<QUrl> downloadUrls; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + QList<QUrl> downloadUrls; + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { downloadUrls.append(item->url()); }); @@ -758,7 +730,7 @@ void tst_QWebEngineDownloadItem::downloadViaSetUrl() } } -void tst_QWebEngineDownloadItem::downloadFileNot1() +void tst_QWebEngineDownloadRequest::downloadFileNot1() { // Trigger file download via download() but don't accept(). @@ -766,11 +738,11 @@ void tst_QWebEngineDownloadItem::downloadFileNot1() rr->sendResponse(404); }); - QPointer<QWebEngineDownloadItem> downloadItem; + QPointer<QWebEngineDownloadRequest> downloadItem; int downloadCount = 0; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { QVERIFY(item); - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested); + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadRequested); downloadItem = item; downloadCount++; }); @@ -780,7 +752,7 @@ void tst_QWebEngineDownloadItem::downloadFileNot1() QVERIFY(!downloadItem); } -void tst_QWebEngineDownloadItem::downloadFileNot2() +void tst_QWebEngineDownloadRequest::downloadFileNot2() { // Trigger file download via download() but call cancel() instead of accept(). @@ -788,11 +760,11 @@ void tst_QWebEngineDownloadItem::downloadFileNot2() rr->sendResponse(404); }); - QPointer<QWebEngineDownloadItem> downloadItem; + QPointer<QWebEngineDownloadRequest> downloadItem; int downloadCount = 0; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { QVERIFY(item); - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested); + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadRequested); item->cancel(); downloadItem = item; downloadCount++; @@ -801,19 +773,19 @@ void tst_QWebEngineDownloadItem::downloadFileNot2() m_page->download(m_server->url(QByteArrayLiteral("/file"))); QTRY_COMPARE(downloadCount, 1); QVERIFY(downloadItem); - QCOMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCancelled); + QCOMPARE(downloadItem->state(), QWebEngineDownloadRequest::DownloadCancelled); } -void tst_QWebEngineDownloadItem::downloadDeleted() +void tst_QWebEngineDownloadRequest::downloadDeleted() { - QPointer<QWebEngineDownloadItem> downloadItem; + QPointer<QWebEngineDownloadRequest> downloadItem; int downloadCount = 0, finishedCount = 0; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { QVERIFY(item); - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadRequested); + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadRequested); downloadItem = item; - connect(downloadItem, &QWebEngineDownloadItem::finished, [&]() { ++finishedCount; }); + connect(downloadItem, &QWebEngineDownloadRequest::isFinishedChanged, [&]() { ++finishedCount; }); ++downloadCount; // accept and schedule deletion, and check if it still finishes item->accept(); @@ -829,16 +801,16 @@ void tst_QWebEngineDownloadItem::downloadDeleted() QCOMPARE(finishedCount, 1); } -void tst_QWebEngineDownloadItem::downloadDeletedByProfile() +void tst_QWebEngineDownloadRequest::downloadDeletedByProfile() { QPointer<QWebEngineProfile> profile(new QWebEngineProfile); profile->setHttpCacheType(QWebEngineProfile::NoCache); profile->settings()->setAttribute(QWebEngineSettings::AutoLoadIconsForPage, false); bool downloadFinished = false; - QPointer<QWebEngineDownloadItem> downloadItem; - connect(profile, &QWebEngineProfile::downloadRequested, [&] (QWebEngineDownloadItem *item) { - connect(item, &QWebEngineDownloadItem::finished, [&] () { + QPointer<QWebEngineDownloadRequest> downloadItem; + connect(profile, &QWebEngineProfile::downloadRequested, [&] (QWebEngineDownloadRequest *item) { + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&] () { downloadFinished = true; }); downloadItem = item; @@ -858,7 +830,7 @@ void tst_QWebEngineDownloadItem::downloadDeletedByProfile() QTRY_COMPARE(downloadItem.isNull(), true); } -void tst_QWebEngineDownloadItem::downloadUniqueFilename_data() +void tst_QWebEngineDownloadRequest::downloadUniqueFilename_data() { QTest::addColumn<QString>("baseName"); QTest::addColumn<QString>("extension"); @@ -867,7 +839,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilename_data() QTest::newRow("tar.gz") << QString("test(1.test)") << QString("tar.gz"); } -void tst_QWebEngineDownloadItem::downloadUniqueFilename() +void tst_QWebEngineDownloadRequest::downloadUniqueFilename() { QFETCH(QString, baseName); QFETCH(QString, extension); @@ -882,7 +854,8 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilename() // Set up HTTP server ScopedConnection sc1 = connect(m_server, &HttpServer::newRequest, [&](HttpReqRep *rr) { - if (rr->requestMethod() == "GET" && rr->requestPath() == ("/" + fileName)) { + auto requestPath = QString::fromUtf8(rr->requestPath()); + if (rr->requestMethod() == "GET" && requestPath == ("/" + fileName)) { rr->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("application/octet-stream")); rr->setResponseHeader(QByteArrayLiteral("content-disposition"), QByteArrayLiteral("attachment")); rr->setResponseBody(QByteArrayLiteral("a")); @@ -893,16 +866,15 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilename() }); // Set up profile and download handler - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { suggestedFileName = item->suggestedFileName(); item->accept(); - connect(item, &QWebEngineDownloadItem::finished, [&, item]() { - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&, item]() { + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadCompleted); QCOMPARE(item->isFinished(), true); QCOMPARE(item->totalBytes(), item->receivedBytes()); QVERIFY(item->receivedBytes() > 0); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->type(), QWebEngineDownloadItem::Attachment); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); QCOMPARE(item->isSavePageDownload(), false); downloadedFilePath = QDir(item->downloadDirectory()).filePath(item->downloadFileName()); downloadFinished = true; @@ -924,7 +896,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilename() } } -void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() +void tst_QWebEngineDownloadRequest::downloadUniqueFilenameWithTimestamp() { // Set up HTTP server QString baseName("test(1.test)"); @@ -939,7 +911,8 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() m_profile->setDownloadPath(tmpDir.path()); ScopedConnection sc1 = connect(m_server, &HttpServer::newRequest, [&](HttpReqRep *rr) { - if (rr->requestMethod() == "GET" && rr->requestPath() == ("/" + fileName)) { + auto requestPath = QString::fromUtf8(rr->requestPath()); + if (rr->requestMethod() == "GET" && requestPath == ("/" + fileName)) { rr->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("application/octet-stream")); rr->setResponseHeader(QByteArrayLiteral("content-disposition"), QByteArrayLiteral("attachment")); rr->setResponseBody(QByteArrayLiteral("a")); @@ -950,16 +923,16 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() }); // Set up profile and download handler - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { suggestedFileName = item->suggestedFileName(); item->accept(); - connect(item, &QWebEngineDownloadItem::finished, [&, item]() { - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&, item]() { + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadCompleted); QCOMPARE(item->isFinished(), true); QCOMPARE(item->totalBytes(), item->receivedBytes()); QVERIFY(item->receivedBytes() > 0); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->page(), m_page); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); + QCOMPARE(QWebEnginePage::fromDownloadRequest(item), m_page); downloadFinished = true; downloadedFilePath = QDir(item->downloadDirectory()).filePath(item->downloadFileName()); }); @@ -1002,7 +975,7 @@ void tst_QWebEngineDownloadItem::downloadUniqueFilenameWithTimestamp() } } -void tst_QWebEngineDownloadItem::downloadToDefaultLocation() +void tst_QWebEngineDownloadRequest::downloadToDefaultLocation() { QTemporaryDir tmpDir; QVERIFY(tmpDir.isValid()); @@ -1019,7 +992,7 @@ void tst_QWebEngineDownloadItem::downloadToDefaultLocation() QCOMPARE(m_profile->downloadPath(), QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); } -void tst_QWebEngineDownloadItem::downloadToNonExistentDir() +void tst_QWebEngineDownloadRequest::downloadToNonExistentDir() { QString baseName("test(1.test)"); QString extension("txt"); @@ -1034,7 +1007,8 @@ void tst_QWebEngineDownloadItem::downloadToNonExistentDir() // Set up HTTP server ScopedConnection sc1 = connect(m_server, &HttpServer::newRequest, [&](HttpReqRep *rr) { - if (rr->requestMethod() == "GET" && rr->requestPath() == ("/" + fileName)) { + auto requestPath = QString::fromUtf8(rr->requestPath()); + if (rr->requestMethod() == "GET" && requestPath == ("/" + fileName)) { rr->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("application/octet-stream")); rr->setResponseHeader(QByteArrayLiteral("content-disposition"), QByteArrayLiteral("attachment")); rr->setResponseBody(QByteArrayLiteral("a")); @@ -1045,16 +1019,16 @@ void tst_QWebEngineDownloadItem::downloadToNonExistentDir() }); // Set up profile and download handler - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { suggestedFileName = item->suggestedFileName(); item->accept(); - connect(item, &QWebEngineDownloadItem::finished, [&, item]() { - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&, item]() { + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadCompleted); QCOMPARE(item->isFinished(), true); QCOMPARE(item->totalBytes(), item->receivedBytes()); QVERIFY(item->receivedBytes() > 0); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->page(), m_page); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); + QCOMPARE(QWebEnginePage::fromDownloadRequest(item), m_page); downloadFinished = true; downloadedFilePath = QDir(item->downloadDirectory()).filePath(item->downloadFileName()); }); @@ -1071,7 +1045,7 @@ void tst_QWebEngineDownloadItem::downloadToNonExistentDir() QCOMPARE(suggestedFileName, fileName); } -void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() +void tst_QWebEngineDownloadRequest::downloadToReadOnlyDir() { #ifdef Q_OS_WIN QSKIP("Cannot change file permissions on Windows."); @@ -1090,7 +1064,8 @@ void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() // Set up HTTP server ScopedConnection sc1 = connect(m_server, &HttpServer::newRequest, [&](HttpReqRep *rr) { - if (rr->requestMethod() == "GET" && rr->requestPath() == ("/" + fileName)) { + auto requestPath = QString::fromUtf8(rr->requestPath()); + if (rr->requestMethod() == "GET" && requestPath == ("/" + fileName)) { rr->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("application/octet-stream")); rr->setResponseHeader(QByteArrayLiteral("content-disposition"), QByteArrayLiteral("attachment")); rr->setResponseBody(QByteArrayLiteral("a")); @@ -1100,12 +1075,12 @@ void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() } }); - QPointer<QWebEngineDownloadItem> downloadItem; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + QPointer<QWebEngineDownloadRequest> downloadItem; + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { suggestedFileName = item->suggestedFileName(); downloadItem = item; item->accept(); - connect(item, &QWebEngineDownloadItem::finished, [&]() { + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&]() { downloadFinished = true; }); downloadAccepted = true; @@ -1119,9 +1094,9 @@ void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() QTRY_VERIFY(downloadAccepted); QVERIFY(downloadItem); - QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadInterrupted); + QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadRequest::DownloadInterrupted); QCOMPARE(downloadItem->isFinished(), false); - QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::FileAccessDenied); + QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadRequest::FileAccessDenied); QVERIFY(!QFile(downloadedFilePath).exists()); QCOMPARE(suggestedFileName, fileName); @@ -1131,125 +1106,7 @@ void tst_QWebEngineDownloadItem::downloadToReadOnlyDir() QFile(m_profile->downloadPath()).setPermissions(QFileDevice::WriteOwner); } -#if QT_DEPRECATED_SINCE(5, 14) -void tst_QWebEngineDownloadItem::downloadPathValidation() -{ - const QString fileName = "test.txt"; - QString downloadPath; - QString originalDownloadPath; - - QTemporaryDir tmpDir; - QVERIFY(tmpDir.isValid()); - m_profile->setDownloadPath(tmpDir.path()); - - // Set up HTTP server - ScopedConnection sc1 = connect(m_server, &HttpServer::newRequest, [&](HttpReqRep *rr) { - if (rr->requestMethod() == "GET" && rr->requestPath() == ("/" + fileName)) { - rr->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("application/octet-stream")); - rr->setResponseHeader(QByteArrayLiteral("content-disposition"), QByteArrayLiteral("attachment")); - rr->setResponseBody(QByteArrayLiteral("a")); - rr->sendResponse(); - } else { - rr->sendResponse(404); - } - }); - - // Set up profile and download handler - QPointer<QWebEngineDownloadItem> downloadItem; - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { - downloadItem = item; - originalDownloadPath = item->path(); - - item->setPath(downloadPath); - item->accept(); - - connect(item, &QWebEngineDownloadItem::stateChanged, [&, item](QWebEngineDownloadItem::DownloadState downloadState) { - if (downloadState == QWebEngineDownloadItem::DownloadInterrupted) { - item->cancel(); - } - }); - - connect(item, &QWebEngineDownloadItem::finished, [&, item]() { - QCOMPARE(item->isFinished(), true); - QCOMPARE(item->totalBytes(), item->receivedBytes()); - QVERIFY(item->receivedBytes() > 0); - QCOMPARE(item->page(), m_page); - }); - }); - - QString oldPath = QDir::currentPath(); - QDir::setCurrent(tmpDir.path()); - - // Set only the file name. - downloadItem.clear(); - originalDownloadPath = ""; - downloadPath = fileName; - m_page->setUrl(m_server->url("/" + fileName)); - QTRY_VERIFY(downloadItem); - QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCompleted); - QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(downloadItem->path(), fileName); - - // Set only the directory path. - downloadItem.clear(); - originalDownloadPath = ""; - downloadPath = tmpDir.path(); - m_page->setUrl(m_server->url("/" + fileName)); - QTRY_VERIFY(downloadItem); - QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCompleted); - QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(downloadItem->path(), originalDownloadPath); - - // Set only the directory path with separator. - downloadItem.clear(); - originalDownloadPath = ""; - downloadPath = tmpDir.path() + QDir::separator(); - m_page->setUrl(m_server->url("/" + fileName)); - QTRY_VERIFY(downloadItem); - QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCompleted); - QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(downloadItem->path(), originalDownloadPath); - - // Set only the directory with the current directory path without ending separator. - downloadItem.clear(); - originalDownloadPath = ""; - downloadPath = "."; - m_page->setUrl(m_server->url("/" + fileName)); - QTRY_VERIFY(downloadItem); - QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCompleted); - QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(downloadItem->path(), originalDownloadPath); - - // Set only the directory with the current directory path with ending separator. - downloadItem.clear(); - originalDownloadPath = ""; - downloadPath = "./"; - m_page->setUrl(m_server->url("/" + fileName)); - QTRY_VERIFY(downloadItem); - QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCompleted); - QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(downloadItem->path(), originalDownloadPath); - - downloadItem.clear(); - originalDownloadPath = ""; - downloadPath = "..."; - m_page->setUrl(m_server->url("/" + fileName)); - QTRY_VERIFY(downloadItem); -#if !defined(Q_OS_WIN) - QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCancelled); - QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::FileFailed); - QCOMPARE(downloadItem->path(), downloadPath); -#else - // Windows interprets the "..." path as a valid path. It will be the current path. - QTRY_COMPARE(downloadItem->state(), QWebEngineDownloadItem::DownloadCompleted); - QCOMPARE(downloadItem->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(downloadItem->path(), originalDownloadPath); -#endif // !defined(Q_OS_WIN) - QDir::setCurrent(oldPath); -} -#endif - -void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName_data() +void tst_QWebEngineDownloadRequest::downloadToDirectoryWithFileName_data() { QTest::addColumn<bool>("setDirectoryFirst"); @@ -1257,7 +1114,7 @@ void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName_data() QTest::newRow("setFileNameFirst") << false; } -void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName() +void tst_QWebEngineDownloadRequest::downloadToDirectoryWithFileName() { QFETCH(bool, setDirectoryFirst); QString downloadDirectory; @@ -1275,7 +1132,8 @@ void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName() // Set up HTTP server ScopedConnection sc1 = connect(m_server, &HttpServer::newRequest, [&](HttpReqRep *rr) { - if (rr->requestMethod() == "GET" && rr->requestPath() == ("/" + fileName)) { + auto requestPath = QString::fromUtf8(rr->requestPath()); + if (rr->requestMethod() == "GET" && requestPath == ("/" + fileName)) { rr->setResponseHeader(QByteArrayLiteral("content-type"), QByteArrayLiteral("application/octet-stream")); rr->setResponseHeader(QByteArrayLiteral("content-disposition"), QByteArrayLiteral("attachment")); rr->setResponseBody(QByteArrayLiteral("a")); @@ -1286,7 +1144,7 @@ void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName() }); // Set up profile and download handler - ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadItem *item) { + ScopedConnection sc2 = connect(m_profile, &QWebEngineProfile::downloadRequested, [&](QWebEngineDownloadRequest *item) { if (!downloadDirectory.isEmpty() && setDirectoryFirst) { item->setDownloadDirectory(downloadDirectory); @@ -1303,16 +1161,15 @@ void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName() QCOMPARE(item->downloadDirectory(), downloadDirectory); } - QCOMPARE(item->path(), QDir(item->downloadDirectory()).filePath(item->downloadFileName())); item->accept(); - connect(item, &QWebEngineDownloadItem::finished, [&, item]() { - QCOMPARE(item->state(), QWebEngineDownloadItem::DownloadCompleted); + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, [&, item]() { + QCOMPARE(item->state(), QWebEngineDownloadRequest::DownloadCompleted); QCOMPARE(item->isFinished(), true); QCOMPARE(item->totalBytes(), item->receivedBytes()); QVERIFY(item->receivedBytes() > 0); - QCOMPARE(item->interruptReason(), QWebEngineDownloadItem::NoReason); - QCOMPARE(item->page(), m_page); + QCOMPARE(item->interruptReason(), QWebEngineDownloadRequest::NoReason); + QCOMPARE(QWebEnginePage::fromDownloadRequest(item), m_page); downloadFinished = true; downloadedFilePath = QDir(item->downloadDirectory()).filePath(item->downloadFileName()); downloadedSuggestedFileName = item->suggestedFileName(); @@ -1349,7 +1206,7 @@ void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName() QCOMPARE(downloadedSuggestedFileName, fileName); // Download another file to the same directory and set file name by - // QWebEngineDownloadItem::setDownloadDirectory() and setDownloadFileName() to avoid uniquification. + // QWebEngineDownloadRequest::setDownloadDirectory() and setDownloadFileName() to avoid uniquification. downloadFinished = false; downloadDirectory = m_profile->downloadPath() + QDir::separator() + "test1" + QDir::separator(); downloadFileName = "test1.txt"; @@ -1370,7 +1227,7 @@ void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName() QCOMPARE(downloadedSuggestedFileName, fileName); // Download the same file to same directory and set file name by - // QWebEngineDownloadItem::setDownloadDirectory() and setDownloadFileName() to avoid uniquification. + // QWebEngineDownloadRequest::setDownloadDirectory() and setDownloadFileName() to avoid uniquification. downloadFinished = false; downloadDirectory = m_profile->downloadPath() + QDir::separator() + "test2" + QDir::separator(); downloadFileName = "test1.txt"; @@ -1392,5 +1249,5 @@ void tst_QWebEngineDownloadItem::downloadToDirectoryWithFileName() QCOMPARE(downloadedSuggestedFileName, fileName); } -QTEST_MAIN(tst_QWebEngineDownloadItem) -#include "tst_qwebenginedownloaditem.moc" +QTEST_MAIN(tst_QWebEngineDownloadRequest) +#include "tst_qwebenginedownloadrequest.moc" diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp index 797d4e4e7..6a4a5a965 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -31,11 +31,12 @@ #include <QMenu> #include <QMimeDatabase> #include <QNetworkProxy> -#include <QOpenGLWidget> #include <QPaintEngine> #include <QPushButton> #include <QScreen> -#include <QStateMachine> +#if defined(QT_STATEMACHINE_LIB) +# include <QStateMachine> +#endif #include <QtGui/QClipboard> #include <QtTest/QtTest> #include <QTextCharFormat> @@ -46,7 +47,7 @@ #include <qnetworkcookiejar.h> #include <qnetworkreply.h> #include <qnetworkrequest.h> -#include <qwebenginedownloaditem.h> +#include <qwebenginedownloadrequest.h> #include <qwebenginefindtextresult.h> #include <qwebenginefullscreenrequest.h> #include <qwebenginehistory.h> @@ -130,8 +131,10 @@ private Q_SLOTS: void findTextCalledOnMatch(); void findTextActiveMatchOrdinal(); void deleteQWebEngineViewTwice(); +#if defined(QT_STATEMACHINE_LIB) void loadSignalsOrder_data(); void loadSignalsOrder(); +#endif void openWindowDefaultSize(); #ifdef Q_OS_MAC @@ -381,7 +384,7 @@ void tst_QWebEnginePage::geolocationRequestJS() QFETCH(int, errorCode); QWebEngineView view; JSTestPage *newPage = new JSTestPage(&view); - newPage->setView(&view); + view.setPage(newPage); newPage->setGeolocationPermission(allowed); connect(newPage, SIGNAL(featurePermissionRequested(const QUrl&, QWebEnginePage::Feature)), @@ -1069,11 +1072,11 @@ void tst_QWebEnginePage::findText() void tst_QWebEnginePage::findTextResult() { QSignalSpy findTextSpy(m_view->page(), &QWebEnginePage::findTextFinished); - auto signalResult = [&findTextSpy]() -> QVector<int> { + auto signalResult = [&findTextSpy]() -> QList<int> { if (findTextSpy.count() != 1) - return QVector<int>({-1, -1}); + return QList<int>({-1, -1}); auto r = findTextSpy.takeFirst().value(0).value<QWebEngineFindTextResult>(); - return QVector<int>({ r.numberOfMatches(), r.activeMatch() }); + return QList<int>({ r.numberOfMatches(), r.activeMatch() }); }; // findText will abort in blink if the view has an empty size. @@ -1085,21 +1088,21 @@ void tst_QWebEnginePage::findTextResult() QTRY_COMPARE(loadSpy.count(), 1); QCOMPARE(findTextSync(m_page, ""), false); - QCOMPARE(signalResult(), QVector<int>({0, 0})); + QCOMPARE(signalResult(), QList<int>({0, 0})); const QStringList words = { "foo", "bar" }; for (const QString &subString : words) { QCOMPARE(findTextSync(m_page, subString), true); - QCOMPARE(signalResult(), QVector<int>({1, 1})); + QCOMPARE(signalResult(), QList<int>({1, 1})); QCOMPARE(findTextSync(m_page, ""), false); - QCOMPARE(signalResult(), QVector<int>({0, 0})); + QCOMPARE(signalResult(), QList<int>({0, 0})); } QCOMPARE(findTextSync(m_page, "blahhh"), false); - QCOMPARE(signalResult(), QVector<int>({0, 0})); + QCOMPARE(signalResult(), QList<int>({0, 0})); QCOMPARE(findTextSync(m_page, ""), false); - QCOMPARE(signalResult(), QVector<int>({0, 0})); + QCOMPARE(signalResult(), QList<int>({0, 0})); } void tst_QWebEnginePage::findTextSuccessiveShouldCallAllCallbacks() @@ -1358,6 +1361,8 @@ void tst_QWebEnginePage::deleteQWebEngineViewTwice() } } +// TODO: Reimplement test without QStateMachine or add qtscxml module dependency +#if defined(QT_STATEMACHINE_LIB) class SpyForLoadSignalsOrder : public QStateMachine { Q_OBJECT public: @@ -1415,6 +1420,7 @@ void tst_QWebEnginePage::loadSignalsOrder() page.load(url); QTRY_VERIFY_WITH_TIMEOUT(loadSpy.isFinished(), 20000); } +#endif // defined(QT_STATEMACHINE_LIB) void tst_QWebEnginePage::renderWidgetHostViewNotShowTopLevel() { @@ -1681,9 +1687,9 @@ void tst_QWebEnginePage::savePage() QWebEnginePage *page = view.page(); connect(page->profile(), &QWebEngineProfile::downloadRequested, - [] (QWebEngineDownloadItem *item) + [] (QWebEngineDownloadRequest *item) { - connect(item, &QWebEngineDownloadItem::finished, + connect(item, &QWebEngineDownloadRequest::isFinishedChanged, &QTestEventLoop::instance(), &QTestEventLoop::exitLoop, Qt::QueuedConnection); }); @@ -1697,7 +1703,7 @@ void tst_QWebEnginePage::savePage() // Save the loaded page as HTML. QTemporaryDir tempDir(QDir::tempPath() + "/tst_qwebengineview-XXXXXX"); const QString filePath = tempDir.path() + "/thingumbob.html"; - page->save(filePath, QWebEngineDownloadItem::CompleteHtmlSaveFormat); + page->save(filePath, QWebEngineDownloadRequest::CompleteHtmlSaveFormat); QTestEventLoop::instance().enterLoop(10); // Load something else. @@ -1717,9 +1723,9 @@ void tst_QWebEnginePage::openWindowDefaultSize() QSignalSpy spyFinished(&page, &QWebEnginePage::loadFinished); QSignalSpy windowCreatedSpy(&page, SIGNAL(windowCreated())); QWebEngineView view; - page.setView(&view); + view.setPage(&page); page.settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, true); - page.setUrl(QUrl("about:blank")); + view.setUrl(QUrl("about:blank")); view.show(); QTRY_COMPARE(spyFinished.count(), 1); @@ -2061,7 +2067,7 @@ private Q_SLOTS: void continueError() { - emit error(this->error()); + emit errorOccurred(this->error()); emit finished(); } }; @@ -2417,9 +2423,13 @@ void tst_QWebEnginePage::setContent_data() QString str = QString::fromUtf8("ὕαλον ϕαγεῖν δύναμαι· τοῦτο οὔ με βλάπτει"); QTest::newRow("UTF-8 plain text") << "text/plain; charset=utf-8" << str.toUtf8() << str; - QTextCodec *utf16 = QTextCodec::codecForName("UTF-16"); - if (utf16) - QTest::newRow("UTF-16 plain text") << "text/plain; charset=utf-16" << utf16->fromUnicode(str) << str; + QBuffer out16; + out16.open(QIODevice::WriteOnly); + QTextStream stream16(&out16); + stream16.setEncoding(QStringConverter::Utf16); + stream16 << str; + stream16.flush(); + QTest::newRow("UTF-16 plain text") << "text/plain; charset=utf-16" << out16.buffer() << str; str = QString::fromUtf8("Une chaîne de caractères à sa façon."); QTest::newRow("latin-1 plain text") << "text/plain; charset=iso-8859-1" << str.toLatin1() << str; @@ -4715,7 +4725,7 @@ void tst_QWebEnginePage::closeContents() QWebEngineView *dialogView = new QWebEngineView; QWebEnginePage *dialogPage = page.createdWindows[0]; - dialogPage->setView(dialogView); + dialogView->setPage(dialogPage); QCOMPARE(dialogPage->lifecycleState(), QWebEnginePage::LifecycleState::Active); // This should not crash. diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp index f4c0484eb..93a7c6acd 100644 --- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp +++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp @@ -35,11 +35,11 @@ #include <QtWebEngineCore/qwebenginecookiestore.h> #include <QtWebEngineCore/qwebengineurlscheme.h> #include <QtWebEngineCore/qwebengineurlschemehandler.h> -#include <QtWebEngineWidgets/qwebengineprofile.h> -#include <QtWebEngineWidgets/qwebenginepage.h> -#include <QtWebEngineWidgets/qwebenginesettings.h> +#include <QtWebEngineCore/qwebenginesettings.h> +#include <QtWebEngineCore/qwebengineprofile.h> +#include <QtWebEngineCore/qwebenginepage.h> +#include <QtWebEngineCore/qwebenginedownloadrequest.h> #include <QtWebEngineWidgets/qwebengineview.h> -#include <QtWebEngineWidgets/qwebenginedownloaditem.h> #if QT_CONFIG(webengine_webchannel) #include <QWebChannel> @@ -116,7 +116,7 @@ void tst_QWebEngineProfile::init() QCOMPARE(profile->persistentCookiesPolicy(), QWebEngineProfile::AllowPersistentCookies); QCOMPARE(profile->cachePath(), QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/QtWebEngine/Default")); - QCOMPARE(profile->persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QCOMPARE(profile->persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/QtWebEngine/Default")); } @@ -136,7 +136,7 @@ void tst_QWebEngineProfile::privateProfile() QCOMPARE(otrProfile.httpCacheType(), QWebEngineProfile::MemoryHttpCache); QCOMPARE(otrProfile.persistentCookiesPolicy(), QWebEngineProfile::NoPersistentCookies); QCOMPARE(otrProfile.cachePath(), QString()); - QCOMPARE(otrProfile.persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QCOMPARE(otrProfile.persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/QtWebEngine/OffTheRecord")); // TBD: setters do not really work otrProfile.setCachePath(QStringLiteral("/home/foo/bar")); @@ -159,7 +159,7 @@ void tst_QWebEngineProfile::testProfile() QCOMPARE(profile.persistentCookiesPolicy(), QWebEngineProfile::AllowPersistentCookies); QCOMPARE(profile.cachePath(), QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/QtWebEngine/Test")); - QCOMPARE(profile.persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QCOMPARE(profile.persistentStoragePath(), QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/QtWebEngine/Test")); } @@ -832,10 +832,10 @@ void tst_QWebEngineProfile::httpAcceptLanguage() void tst_QWebEngineProfile::downloadItem() { - qRegisterMetaType<QWebEngineDownloadItem *>(); + qRegisterMetaType<QWebEngineDownloadRequest *>(); QWebEngineProfile testProfile; QWebEnginePage page(&testProfile); - QSignalSpy downloadSpy(&testProfile, SIGNAL(downloadRequested(QWebEngineDownloadItem *))); + QSignalSpy downloadSpy(&testProfile, SIGNAL(downloadRequested(QWebEngineDownloadRequest *))); page.load(QUrl::fromLocalFile(QCoreApplication::applicationFilePath())); QTRY_COMPARE(downloadSpy.count(), 1); } @@ -845,9 +845,9 @@ void tst_QWebEngineProfile::changePersistentPath() TestServer server; QVERIFY(server.start()); - AutoDir dataDir1(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + AutoDir dataDir1(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/QtWebEngine/Test")); - AutoDir dataDir2(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + AutoDir dataDir2(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/QtWebEngine/Test2")); QWebEngineProfile testProfile(QStringLiteral("Test")); @@ -871,7 +871,7 @@ void tst_QWebEngineProfile::changeHttpUserAgent() TestServer server; QVERIFY(server.start()); - QVector<QByteArray> userAgents; + QList<QByteArray> userAgents; connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) { if (rr->requestPath() == "/hedgehog.html") userAgents.push_back(rr->requestHeader(QByteArrayLiteral("user-agent"))); @@ -898,7 +898,7 @@ void tst_QWebEngineProfile::changeHttpAcceptLanguage() TestServer server; QVERIFY(server.start()); - QVector<QByteArray> languages; + QList<QByteArray> languages; connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) { if (rr->requestPath() == "/hedgehog.html") languages.push_back(rr->requestHeader(QByteArrayLiteral("accept-language"))); diff --git a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp index a690d516e..5699f1d36 100644 --- a/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp +++ b/tests/auto/widgets/qwebenginescript/tst_qwebenginescript.cpp @@ -322,8 +322,8 @@ void tst_QWebEngineScript::scriptModifications() QVERIFY(spyFinished.wait()); QCOMPARE(evaluateJavaScriptSync(&page, "document.body.innerText"), QVariant::fromValue(QStringLiteral("SUCCESS"))); QVERIFY(page.scripts().count() == 1); - QWebEngineScript s = page.scripts().findScript(QStringLiteral("String1")); - QVERIFY(page.scripts().remove(s)); + QList<QWebEngineScript> s = page.scripts().find(QStringLiteral("String1")); + QVERIFY(page.scripts().remove(s.first())); QVERIFY(page.scripts().count() == 0); } diff --git a/tests/auto/widgets/qwebenginesettings/BLACKLIST b/tests/auto/widgets/qwebenginesettings/BLACKLIST new file mode 100644 index 000000000..d4a35a76a --- /dev/null +++ b/tests/auto/widgets/qwebenginesettings/BLACKLIST @@ -0,0 +1,2 @@ +[javascriptClipboard] +ubuntu-20.04 diff --git a/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp b/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp index a09901e69..a7c3ccb3c 100644 --- a/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp +++ b/tests/auto/widgets/qwebenginesettings/tst_qwebenginesettings.cpp @@ -177,7 +177,7 @@ void tst_QWebEngineSettings::setInAcceptNavigationRequest() { NavigationRequestOverride page; QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool))); - QWebEngineSettings::defaultSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); + QWebEngineProfile::defaultProfile()->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false); QVERIFY(!page.settings()->testAttribute(QWebEngineSettings::JavascriptEnabled)); page.load(QUrl("about:blank")); diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp index 8e23e02b4..234049a38 100644 --- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp +++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp @@ -28,8 +28,9 @@ #include <qwebengineview.h> #include <qwebenginepage.h> #include <qwebenginesettings.h> -#include <qnetworkrequest.h> +#include <qaction.h> #include <qdiriterator.h> +#include <qnetworkrequest.h> #include <qstackedlayout.h> #include <qtemporarydir.h> #include <QClipboard> @@ -44,7 +45,6 @@ #include <QTcpServer> #include <QTcpSocket> #include <QStyle> -#include <QtWidgets/qaction.h> #include <QWebEngineProfile> #include <QtCore/qregularexpression.h> @@ -307,7 +307,7 @@ void tst_QWebEngineView::changePage() if (!fromIsNullPage) { QVERIFY(!pageFrom->iconUrl().isEmpty()); QCOMPARE(spyIconUrl.last().value(0).toUrl(), pageFrom->iconUrl()); - QCOMPARE(spyIcon.last().value(0), QVariant::fromValue(pageFrom->icon())); + QCOMPARE(spyIcon.last().value(0).value<QIcon>(), pageFrom->icon()); } QScopedPointer<QWebEnginePage> pageTo(new QWebEnginePage); @@ -336,7 +336,7 @@ void tst_QWebEngineView::changePage() QCOMPARE(pageFrom->iconUrl() == pageTo->iconUrl(), iconIsSame); if (!iconIsSame) { QCOMPARE(spyIconUrl.last().value(0).toUrl(), pageTo->iconUrl()); - QCOMPARE(spyIcon.last().value(0), QVariant::fromValue(pageTo->icon())); + QCOMPARE(spyIcon.last().value(0).value<QIcon>(), pageTo->icon()); } // verify no emits on destroy with the same number of signals in spy @@ -573,10 +573,10 @@ void tst_QWebEngineView::focusInputTypes() class KeyEventRecordingWidget : public QWidget { public: - QList<QKeyEvent> pressEvents; - QList<QKeyEvent> releaseEvents; - void keyPressEvent(QKeyEvent *e) override { pressEvents << *e; } - void keyReleaseEvent(QKeyEvent *e) override { releaseEvents << *e; } + QList<QKeyEvent *> pressEvents; + QList<QKeyEvent *> releaseEvents; + void keyPressEvent(QKeyEvent *e) override { pressEvents << e->clone(); } + void keyReleaseEvent(QKeyEvent *e) override { releaseEvents << e->clone(); } }; void tst_QWebEngineView::unhandledKeyEventPropagation() @@ -622,15 +622,15 @@ void tst_QWebEngineView::unhandledKeyEventPropagation() // The page will consume the Tab key to change focus between elements while the arrow // keys won't be used. QCOMPARE(parentWidget.pressEvents.size(), 3); - QCOMPARE(parentWidget.pressEvents[0].key(), (int)Qt::Key_Right); - QCOMPARE(parentWidget.pressEvents[1].key(), (int)Qt::Key_Left); - QCOMPARE(parentWidget.pressEvents[2].key(), (int)Qt::Key_Y); + QCOMPARE(parentWidget.pressEvents[0]->key(), (int)Qt::Key_Right); + QCOMPARE(parentWidget.pressEvents[1]->key(), (int)Qt::Key_Left); + QCOMPARE(parentWidget.pressEvents[2]->key(), (int)Qt::Key_Y); // Key releases will all come back unconsumed. - QCOMPARE(parentWidget.releaseEvents[0].key(), (int)Qt::Key_Right); - QCOMPARE(parentWidget.releaseEvents[1].key(), (int)Qt::Key_Tab); - QCOMPARE(parentWidget.releaseEvents[2].key(), (int)Qt::Key_Left); - QCOMPARE(parentWidget.releaseEvents[3].key(), (int)Qt::Key_Y); + QCOMPARE(parentWidget.releaseEvents[0]->key(), (int)Qt::Key_Right); + QCOMPARE(parentWidget.releaseEvents[1]->key(), (int)Qt::Key_Tab); + QCOMPARE(parentWidget.releaseEvents[2]->key(), (int)Qt::Key_Left); + QCOMPARE(parentWidget.releaseEvents[3]->key(), (int)Qt::Key_Y); } void tst_QWebEngineView::horizontalScrollbarTest() @@ -918,7 +918,7 @@ public: private: int m_eventCounter; - QVector<QString> m_eventHistory; + QList<QString> m_eventHistory; }; void tst_QWebEngineView::doNotSendMouseKeyboardEventsWhenDisabled() @@ -1656,7 +1656,7 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts() }; // The input form is not focused. The action is triggered on pressing Shift+Delete. - action->setShortcut(Qt::SHIFT + Qt::Key_Delete); + action->setShortcut(Qt::SHIFT | Qt::Key_Delete); QTest::keyClick(view.windowHandle(), Qt::Key_Delete, Qt::ShiftModifier); QTRY_VERIFY(actionTriggered); QCOMPARE(inputFieldValue(), QString("x")); @@ -1692,7 +1692,7 @@ void tst_QWebEngineView::inputFieldOverridesShortcuts() // A Ctrl-1 action is no default Qt key binding and should be triggerable. evaluateJavaScriptSync(view.page(), "document.getElementById('input1').focus();"); QTRY_COMPARE(evaluateJavaScriptSync(view.page(), "document.activeElement.id").toString(), QStringLiteral("input1")); - action->setShortcut(Qt::CTRL + Qt::Key_1); + action->setShortcut(Qt::CTRL | Qt::Key_1); QTest::keyClick(view.windowHandle(), Qt::Key_1, Qt::ControlModifier); QTRY_VERIFY(actionTriggered); QCOMPARE(inputFieldValue(), QString("yxx")); @@ -3302,6 +3302,12 @@ void tst_QWebEngineView::switchPage() QWebEnginePage page2(&profile); QSignalSpy loadFinishedSpy1(&page1, SIGNAL(loadFinished(bool))); QSignalSpy loadFinishedSpy2(&page2, SIGNAL(loadFinished(bool))); + // TODO fixme: page without the view has no real widget behind, so + // reading graphical content will fail, add view for now. + QWebEngineView webView1; + QWebEngineView webView2; + webView1.setPage(&page1); + webView2.setPage(&page2); page1.setHtml("<html><body bgcolor=\"#000000\"></body></html>"); page2.setHtml("<html><body bgcolor=\"#ffffff\"></body></html>"); QTRY_VERIFY(loadFinishedSpy1.count() && loadFinishedSpy2.count()); @@ -3345,7 +3351,7 @@ void tst_QWebEngineView::setViewDeletesImplicitPage() QWebEngineView view; QPointer<QWebEnginePage> implicitPage = view.page(); QWebEnginePage explicitPage; - explicitPage.setView(&view); + view.setPage(&explicitPage); QCOMPARE(view.page(), &explicitPage); QVERIFY(!implicitPage); // should be deleted } @@ -3366,8 +3372,8 @@ void tst_QWebEngineView::setViewPreservesExplicitPage() QWebEngineView view; QPointer<QWebEnginePage> explicitPage1 = new QWebEnginePage(&view); QPointer<QWebEnginePage> explicitPage2 = new QWebEnginePage(&view); - explicitPage1->setView(&view); - explicitPage2->setView(&view); + view.setPage(explicitPage1.data()); + view.setPage(explicitPage2.data()); QCOMPARE(view.page(), explicitPage2.data()); QVERIFY(explicitPage1); // should not be deleted } diff --git a/tests/auto/widgets/spellchecking/tst_spellchecking.cpp b/tests/auto/widgets/spellchecking/tst_spellchecking.cpp index 801e2a76c..258071559 100644 --- a/tests/auto/widgets/spellchecking/tst_spellchecking.cpp +++ b/tests/auto/widgets/spellchecking/tst_spellchecking.cpp @@ -28,9 +28,8 @@ #include "util.h" #include <QtTest/QtTest> -#include <QtWebEngineWidgets/qwebenginecontextmenudata.h> -#include <QtWebEngineWidgets/qwebengineprofile.h> -#include <QtWebEngineWidgets/qwebenginepage.h> +#include <QtWebEngineCore/qwebengineprofile.h> +#include <QtWebEngineCore/qwebenginepage.h> #include <QtWebEngineWidgets/qwebengineview.h> #include <qwebenginesettings.h> @@ -47,10 +46,7 @@ public: QTest::mouseRelease(widget, Qt::RightButton, {}, position); } - const QWebEngineContextMenuData& data() - { - return m_data; - } + QWebEngineContextMenuRequest *data() { return m_data; } signals: void menuReady(); @@ -58,11 +54,11 @@ signals: protected: void contextMenuEvent(QContextMenuEvent *) { - m_data = page()->contextMenuData(); + m_data = lastContextMenuRequest(); emit menuReady(); } private: - QWebEngineContextMenuData m_data; + QWebEngineContextMenuRequest *m_data; }; class tst_Spellchecking : public QObject @@ -204,17 +200,17 @@ void tst_Spellchecking::spellcheck() return false; } - if (!m_view->data().isValid()) { + if (!m_view->data()) { detail = "invalid data"; return false; } - if (!m_view->data().isContentEditable()) { + if (!m_view->data()->isContentEditable()) { detail = "content is not editable"; return false; } - if (m_view->data().misspelledWord().isEmpty()) { + if (m_view->data()->misspelledWord().isEmpty()) { detail = "no misspelled word"; return false; }; @@ -224,10 +220,10 @@ void tst_Spellchecking::spellcheck() } (), qPrintable(QString("Context menu: %1").arg(detail))); // check misspelled word - QCOMPARE(m_view->data().misspelledWord(), QStringLiteral("lowe")); + QCOMPARE(m_view->data()->misspelledWord(), QStringLiteral("lowe")); // check suggestions - QCOMPARE(m_view->data().spellCheckerSuggestions(), suggestions); + QCOMPARE(m_view->data()->spellCheckerSuggestions(), suggestions); // check replace word m_view->page()->replaceMisspelledWord("love"); diff --git a/tests/auto/widgets/touchinput/tst_touchinput.cpp b/tests/auto/widgets/touchinput/tst_touchinput.cpp index 3c7d8ccbb..359b11eb2 100644 --- a/tests/auto/widgets/touchinput/tst_touchinput.cpp +++ b/tests/auto/widgets/touchinput/tst_touchinput.cpp @@ -31,11 +31,11 @@ #include <QtGui/qpa/qwindowsysteminterface.h> #include <QSignalSpy> #include <QTest> -#include <QTouchDevice> +#include <QPointingDevice> #include <QWebEngineSettings> #include <QWebEngineView> -static QTouchDevice* s_touchDevice = nullptr; +static QPointingDevice* s_touchDevice = nullptr; class TouchInputTest : public QObject { diff --git a/tests/auto/widgets/util.h b/tests/auto/widgets/util.h index 461baf9ac..3be9a91b9 100644 --- a/tests/auto/widgets/util.h +++ b/tests/auto/widgets/util.h @@ -226,7 +226,7 @@ static inline QRect elementGeometry(QWebEnginePage *page, const QString &id) #define W_QTEST_MAIN(TestObject, params) \ int main(int argc, char *argv[]) \ { \ - QVector<const char *> w_argv(argc); \ + QList<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) \ diff --git a/tests/auto/widgets/widgets.pro b/tests/auto/widgets/widgets.pro index 2dc1eefcd..4ec9e5d63 100644 --- a/tests/auto/widgets/widgets.pro +++ b/tests/auto/widgets/widgets.pro @@ -14,7 +14,7 @@ SUBDIRS += \ proxypac \ schemes \ shutdown \ - qwebenginedownloaditem \ + qwebenginedownloadrequest \ qwebenginepage \ qwebenginehistory \ qwebengineprofile \ @@ -51,4 +51,4 @@ boot2qt: SUBDIRS -= accessibility defaultsurfaceformat devtools \ qwebengineprofile \ qwebengineview -win32: SUBDIRS -= offscreen +darwin|win32: SUBDIRS -= offscreen |