summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp46
-rw-r--r--tests/auto/widgets/qwebengineprofile/BLACKLIST3
-rw-r--r--tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro1
-rw-r--r--tests/auto/widgets/qwebengineprofile/resources/hedgehog.html9
-rw-r--r--tests/auto/widgets/qwebengineprofile/resources/hedgehog.pngbin0 -> 11273 bytes
-rw-r--r--tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp297
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp40
7 files changed, 290 insertions, 106 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 7fdf897ca..f500652c7 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -701,7 +701,7 @@ public:
CursorTrackedPage(QWidget *parent = 0): QWebEnginePage(parent) {
}
- QString selectedText() {
+ QString jsSelectedText() {
return evaluateJavaScriptSync(this, "window.getSelection().toString()").toString();
}
@@ -717,42 +717,52 @@ public:
int isSelectionCollapsed() {
return evaluateJavaScriptSync(this, "window.getSelection().getRangeAt(0).collapsed").toBool();
}
- bool hasSelection()
- {
- return !selectedText().isEmpty();
- }
};
void tst_QWebEnginePage::textSelection()
{
- QWebEngineView view;
- CursorTrackedPage *page = new CursorTrackedPage(&view);
- QString content("<html><body><p id=one>The quick brown fox</p>" \
+ CursorTrackedPage page;
+
+ QString textToSelect("The quick brown fox");
+ QString content = QString("<html><body><p id=one>%1</p>" \
"<p id=two>jumps over the lazy dog</p>" \
- "<p>May the source<br/>be with you!</p></body></html>");
- page->setView(&view);
- QSignalSpy loadSpy(&view, SIGNAL(loadFinished(bool)));
- page->setHtml(content);
+ "<p>May the source<br/>be with you!</p></body></html>").arg(textToSelect);
+
+ QSignalSpy loadSpy(&page, SIGNAL(loadFinished(bool)));
+ page.setHtml(content);
QTRY_COMPARE_WITH_TIMEOUT(loadSpy.count(), 1, 20000);
// these actions must exist
- QVERIFY(page->action(QWebEnginePage::SelectAll) != 0);
+ QVERIFY(page.action(QWebEnginePage::SelectAll) != 0);
// ..but SelectAll is disabled because the page has no focus due to disabled FocusOnNavigationEnabled.
- QCOMPARE(page->action(QWebEnginePage::SelectAll)->isEnabled(), false);
+ QCOMPARE(page.action(QWebEnginePage::SelectAll)->isEnabled(), false);
// Verify hasSelection returns false since there is no selection yet...
- QCOMPARE(page->hasSelection(), false);
+ QVERIFY(!page.hasSelection());
+ QVERIFY(page.jsSelectedText().isEmpty());
// this will select the first paragraph
QString selectScript = "var range = document.createRange(); " \
"var node = document.getElementById(\"one\"); " \
"range.selectNode(node); " \
"getSelection().addRange(range);";
- evaluateJavaScriptSync(page, selectScript);
- QCOMPARE(page->selectedText().trimmed(), QString::fromLatin1("The quick brown fox"));
+ evaluateJavaScriptSync(&page, selectScript);
+
// Make sure hasSelection returns true, since there is selected text now...
- QCOMPARE(page->hasSelection(), true);
+ QTRY_VERIFY(page.hasSelection());
+ QCOMPARE(page.selectedText().trimmed(), textToSelect);
+
+ QCOMPARE(page.jsSelectedText().trimmed(), textToSelect);
+
+ // navigate away and check that selection is cleared
+ page.load(QUrl("about:blank"));
+ QTRY_COMPARE(loadSpy.count(), 2);
+
+ QVERIFY(!page.hasSelection());
+ QVERIFY(page.selectedText().isEmpty());
+
+ QVERIFY(page.jsSelectedText().isEmpty());
}
diff --git a/tests/auto/widgets/qwebengineprofile/BLACKLIST b/tests/auto/widgets/qwebengineprofile/BLACKLIST
deleted file mode 100644
index 55806eec4..000000000
--- a/tests/auto/widgets/qwebengineprofile/BLACKLIST
+++ /dev/null
@@ -1,3 +0,0 @@
-[disableCache]
-*
-
diff --git a/tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro b/tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro
index e56bbe8f7..ca16cee39 100644
--- a/tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro
+++ b/tests/auto/widgets/qwebengineprofile/qwebengineprofile.pro
@@ -1,3 +1,4 @@
include(../tests.pri)
+include(../../shared/http.pri)
exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc
QT *= core-private gui-private
diff --git a/tests/auto/widgets/qwebengineprofile/resources/hedgehog.html b/tests/auto/widgets/qwebengineprofile/resources/hedgehog.html
new file mode 100644
index 000000000..d8abbcd48
--- /dev/null
+++ b/tests/auto/widgets/qwebengineprofile/resources/hedgehog.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+ <head>
+ <title>BREAKING NEWS: 15 Hedgehogs With Things That Look Like Hedgehogs</title>
+ </head>
+ <body>
+ <img src="hedgehog.png"/>
+ </body>
+</html>
diff --git a/tests/auto/widgets/qwebengineprofile/resources/hedgehog.png b/tests/auto/widgets/qwebengineprofile/resources/hedgehog.png
new file mode 100644
index 000000000..4d56d8633
--- /dev/null
+++ b/tests/auto/widgets/qwebengineprofile/resources/hedgehog.png
Binary files differ
diff --git a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
index 1dd8a38c8..1f8162941 100644
--- a/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
+++ b/tests/auto/widgets/qwebengineprofile/tst_qwebengineprofile.cpp
@@ -28,6 +28,7 @@
#include "../util.h"
#include <QtCore/qbuffer.h>
+#include <QtCore/qmimedatabase.h>
#include <QtTest/QtTest>
#include <QtWebEngineCore/qwebengineurlrequestinterceptor.h>
#include <QtWebEngineCore/qwebengineurlrequestjob.h>
@@ -44,6 +45,9 @@
#include <QWebChannel>
#endif
+#include <httpserver.h>
+#include <httpreqrep.h>
+
#include <map>
#include <mutex>
@@ -72,6 +76,10 @@ private Q_SLOTS:
void httpAcceptLanguage();
void downloadItem();
void changePersistentPath();
+ void changeHttpUserAgent();
+ void changeHttpAcceptLanguage();
+ void changeUseForGlobalCertificateVerification();
+ void changePersistentCookiesPolicy();
void initiator();
void badDeleteOrder();
void qtbug_71895(); // this should be the last test
@@ -83,6 +91,7 @@ void tst_QWebEngineProfile::initTestCase()
QWebEngineUrlScheme stream("stream");
QWebEngineUrlScheme letterto("letterto");
QWebEngineUrlScheme aviancarrier("aviancarrier");
+ QWebEngineUrlScheme myscheme("myscheme");
foo.setSyntax(QWebEngineUrlScheme::Syntax::Host);
stream.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort);
stream.setDefaultPort(8080);
@@ -93,6 +102,7 @@ void tst_QWebEngineProfile::initTestCase()
QWebEngineUrlScheme::registerScheme(stream);
QWebEngineUrlScheme::registerScheme(letterto);
QWebEngineUrlScheme::registerScheme(aviancarrier);
+ QWebEngineUrlScheme::registerScheme(myscheme);
}
void tst_QWebEngineProfile::init()
@@ -152,75 +162,125 @@ void tst_QWebEngineProfile::testProfile()
+ QStringLiteral("/QtWebEngine/Test"));
}
+class AutoDir : public QDir
+{
+public:
+ AutoDir(const QString &p) : QDir(p)
+ {
+ makeAbsolute();
+ removeRecursively();
+ }
+
+ ~AutoDir() { removeRecursively(); }
+};
+qint64 totalSize(QDir dir)
+{
+ qint64 sum = 0;
+ const QDir::Filters filters{QDir::Dirs, QDir::Files, QDir::NoSymLinks, QDir::NoDotAndDotDot};
+ for (const QFileInfo &entry : dir.entryInfoList(filters)) {
+ if (entry.isFile())
+ sum += entry.size();
+ else if (entry.isDir())
+ sum += totalSize(entry.filePath());
+ }
+ return sum;
+}
+
+class TestServer : public HttpServer
+{
+public:
+ TestServer()
+ {
+ connect(this, &HttpServer::newRequest, this, &TestServer::onNewRequest);
+ }
+
+private:
+ void onNewRequest(HttpReqRep *rr)
+ {
+ const QDir resourceDir(TESTS_SOURCE_DIR "qwebengineprofile/resources");
+ QString path = rr->requestPath();
+ path.remove(0, 1);
+
+ if (rr->requestMethod() != "GET" || !resourceDir.exists(path))
+ {
+ rr->setResponseStatus(404);
+ rr->sendResponse();
+ return;
+ }
+
+ QFile file(resourceDir.filePath(path));
+ file.open(QIODevice::ReadOnly);
+ QByteArray data = file.readAll();
+ rr->setResponseBody(data);
+ QMimeDatabase db;
+ QMimeType mime = db.mimeTypeForFileNameAndData(file.fileName(), data);
+ rr->setResponseHeader(QByteArrayLiteral("content-type"), mime.name().toUtf8());
+ if (!mime.inherits("text/html"))
+ rr->setResponseHeader(QByteArrayLiteral("cache-control"),
+ QByteArrayLiteral("public, max-age=31536000"));
+ rr->sendResponse();
+ }
+};
+
+static bool loadSync(QWebEnginePage *page, const QUrl &url, bool ok = true)
+{
+ QSignalSpy spy(page, &QWebEnginePage::loadFinished);
+ page->load(url);
+ return (!spy.empty() || spy.wait(20000)) && (spy.front().value(0).toBool() == ok);
+}
+
+static bool loadSync(QWebEngineView *view, const QUrl &url, bool ok = true)
+{
+ return loadSync(view->page(), url, ok);
+}
+
void tst_QWebEngineProfile::clearDataFromCache()
{
- QDir cacheDir("./tst_QWebEngineProfile_cacheDir");
- cacheDir.makeAbsolute();
- if (cacheDir.exists())
- cacheDir.removeRecursively();
- cacheDir.mkpath(cacheDir.path());
+ TestServer server;
+ QVERIFY(server.start());
+
+ AutoDir cacheDir("./tst_QWebEngineProfile_clearDataFromCache");
QWebEngineProfile profile(QStringLiteral("Test"));
profile.setCachePath(cacheDir.path());
profile.setHttpCacheType(QWebEngineProfile::DiskHttpCache);
- QWebEnginePage page(&profile, nullptr);
-
- QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
- page.load(QUrl("http://qt-project.org"));
- if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool())
- QSKIP("Couldn't load page from network, skipping test.");
-
- cacheDir.refresh();
- QVERIFY(cacheDir.entryList().contains("Cache"));
- cacheDir.cd("./Cache");
- int filesBeforeClear = cacheDir.entryList().count();
-
- QFileSystemWatcher fileSystemWatcher;
- fileSystemWatcher.addPath(cacheDir.path());
- QSignalSpy directoryChangedSpy(&fileSystemWatcher, SIGNAL(directoryChanged(const QString &)));
+ QWebEnginePage page(&profile);
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
- // It deletes most of the files, but not all of them.
+ QVERIFY(cacheDir.exists("Cache"));
+ qint64 sizeBeforeClear = totalSize(cacheDir);
profile.clearHttpCache();
+ // Wait for cache to be cleared.
QTest::qWait(1000);
- QTRY_VERIFY(directoryChangedSpy.count() > 0);
+ QVERIFY(sizeBeforeClear > totalSize(cacheDir));
- cacheDir.refresh();
- QVERIFY(filesBeforeClear > cacheDir.entryList().count());
-
- cacheDir.removeRecursively();
+ QVERIFY(server.stop());
}
void tst_QWebEngineProfile::disableCache()
{
- QWebEnginePage page;
- QDir cacheDir("./tst_QWebEngineProfile_cacheDir");
- if (cacheDir.exists())
- cacheDir.removeRecursively();
- cacheDir.mkpath(cacheDir.path());
+ TestServer server;
+ QVERIFY(server.start());
+
+ AutoDir cacheDir("./tst_QWebEngineProfile_disableCache");
+ QWebEnginePage page;
QWebEngineProfile *profile = page.profile();
profile->setCachePath(cacheDir.path());
- QVERIFY(!cacheDir.entryList().contains("Cache"));
+ QVERIFY(!cacheDir.exists("Cache"));
profile->setHttpCacheType(QWebEngineProfile::NoCache);
- QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
- page.load(QUrl("http://qt-project.org"));
- if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool())
- QSKIP("Couldn't load page from network, skipping test.");
-
- cacheDir.refresh();
- QVERIFY(!cacheDir.entryList().contains("Cache"));
+ // Wait for cache to be cleared.
+ QTest::qWait(1000);
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(!cacheDir.exists("Cache"));
profile->setHttpCacheType(QWebEngineProfile::DiskHttpCache);
- page.load(QUrl("http://qt-project.org"));
- if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(1).at(0).toBool())
- QSKIP("Couldn't load page from network, skipping test.");
-
- cacheDir.refresh();
- QVERIFY(cacheDir.entryList().contains("Cache"));
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(cacheDir.exists("Cache"));
- cacheDir.removeRecursively();
+ QVERIFY(server.stop());
}
class RedirectingUrlSchemeHandler : public QWebEngineUrlSchemeHandler
@@ -332,21 +392,6 @@ public:
}
};
-static bool loadSync(QWebEngineView *view, const QUrl &url, int timeout = 5000)
-{
- // Ripped off QTRY_VERIFY.
- QSignalSpy loadFinishedSpy(view, SIGNAL(loadFinished(bool)));
- view->load(url);
- if (loadFinishedSpy.isEmpty())
- QTest::qWait(0);
- for (int i = 0; i < timeout; i += 50) {
- if (!loadFinishedSpy.isEmpty())
- return true;
- QTest::qWait(50);
- }
- return false;
-}
-
void tst_QWebEngineProfile::urlSchemeHandlers()
{
RedirectingUrlSchemeHandler lettertoHandler;
@@ -369,7 +414,7 @@ void tst_QWebEngineProfile::urlSchemeHandlers()
// Remove the letterto scheme, and check whether it is not handled anymore.
profile.removeUrlScheme("letterto");
emailAddress = QStringLiteral("kjeld@olsen-banden.dk");
- QVERIFY(loadSync(&view, QUrl(QStringLiteral("letterto:") + emailAddress)));
+ QVERIFY(loadSync(&view, QUrl(QStringLiteral("letterto:") + emailAddress), false));
QVERIFY(toPlainTextSync(view.page()) != emailAddress);
// Check if gopher is still working after removing letterto.
@@ -380,7 +425,7 @@ void tst_QWebEngineProfile::urlSchemeHandlers()
// Does removeAll work?
profile.removeAllUrlSchemeHandlers();
url = QUrl(QStringLiteral("gopher://olsen-banden.dk/harry"));
- QVERIFY(loadSync(&view, url));
+ QVERIFY(loadSync(&view, url, false));
QVERIFY(toPlainTextSync(view.page()) != url.toString());
// Install a handler that is owned by the view. Make sure this doesn't crash on shutdown.
@@ -801,28 +846,132 @@ void tst_QWebEngineProfile::downloadItem()
QWebEngineProfile testProfile;
QWebEnginePage page(&testProfile);
QSignalSpy downloadSpy(&testProfile, SIGNAL(downloadRequested(QWebEngineDownloadItem *)));
- connect(&testProfile, &QWebEngineProfile::downloadRequested, this, [=] (QWebEngineDownloadItem *item) { item->accept(); });
page.load(QUrl::fromLocalFile(QCoreApplication::applicationFilePath()));
QTRY_COMPARE(downloadSpy.count(), 1);
}
void tst_QWebEngineProfile::changePersistentPath()
{
+ TestServer server;
+ QVERIFY(server.start());
+
+ AutoDir dataDir1(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
+ + QStringLiteral("/QtWebEngine/Test"));
+ AutoDir dataDir2(QStandardPaths::writableLocation(QStandardPaths::DataLocation)
+ + QStringLiteral("/QtWebEngine/Test2"));
+
QWebEngineProfile testProfile(QStringLiteral("Test"));
- const QString oldPath = testProfile.persistentStoragePath();
- QVERIFY(oldPath.endsWith(QStringLiteral("Test")));
+ QCOMPARE(testProfile.persistentStoragePath(), dataDir1.path());
- // Make sure the profile has been used and the url-request-context-getter instantiated:
+ // Make sure the profile has been used:
QWebEnginePage page(&testProfile);
- QSignalSpy loadFinishedSpy(&page, SIGNAL(loadFinished(bool)));
- page.load(QUrl("http://qt-project.org"));
- if (!loadFinishedSpy.wait(10000) || !loadFinishedSpy.at(0).at(0).toBool())
- QSKIP("Couldn't load page from network, skipping test.");
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
// Test we do not crash (QTBUG-55322):
- testProfile.setPersistentStoragePath(oldPath + QLatin1Char('2'));
- const QString newPath = testProfile.persistentStoragePath();
- QVERIFY(newPath.endsWith(QStringLiteral("Test2")));
+ testProfile.setPersistentStoragePath(dataDir2.path());
+ QCOMPARE(testProfile.persistentStoragePath(), dataDir2.path());
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(dataDir2.exists());
+
+ QVERIFY(server.stop());
+}
+
+void tst_QWebEngineProfile::changeHttpUserAgent()
+{
+ TestServer server;
+ QVERIFY(server.start());
+
+ QVector<QByteArray> userAgents;
+ connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) {
+ if (rr->requestPath() == "/hedgehog.html")
+ userAgents.push_back(rr->requestHeader(QByteArrayLiteral("user-agent")));
+ });
+
+ QWebEngineProfile profile(QStringLiteral("Test"));
+ std::unique_ptr<QWebEnginePage> page;
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+ page.reset();
+ profile.setHttpUserAgent("webturbine/42");
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+
+ QCOMPARE(userAgents.size(), 2);
+ QCOMPARE(userAgents[1], "webturbine/42");
+ QVERIFY(userAgents[0] != userAgents[1]);
+
+ QVERIFY(server.stop());
+}
+
+void tst_QWebEngineProfile::changeHttpAcceptLanguage()
+{
+ TestServer server;
+ QVERIFY(server.start());
+
+ QVector<QByteArray> languages;
+ connect(&server, &HttpServer::newRequest, [&](HttpReqRep *rr) {
+ if (rr->requestPath() == "/hedgehog.html")
+ languages.push_back(rr->requestHeader(QByteArrayLiteral("accept-language")));
+ });
+
+ QWebEngineProfile profile(QStringLiteral("Test"));
+ std::unique_ptr<QWebEnginePage> page;
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+ page.reset();
+ profile.setHttpAcceptLanguage("fi");
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+
+ QCOMPARE(languages.size(), 2);
+ QCOMPARE(languages[1], "fi");
+ QVERIFY(languages[0] != languages[1]);
+
+ QVERIFY(server.stop());
+}
+
+void tst_QWebEngineProfile::changeUseForGlobalCertificateVerification()
+{
+ QSKIP("Needs 3rdparty fix");
+
+ TestServer server;
+ QVERIFY(server.start());
+
+ // Check that we don't crash
+
+ QWebEngineProfile profile(QStringLiteral("Test"));
+ std::unique_ptr<QWebEnginePage> page;
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+ page.reset();
+ profile.setUseForGlobalCertificateVerification(true);
+ page.reset(new QWebEnginePage(&profile));
+ QVERIFY(loadSync(page.get(), server.url("/hedgehog.html")));
+ QVERIFY(server.stop());
+}
+
+void tst_QWebEngineProfile::changePersistentCookiesPolicy()
+{
+ TestServer server;
+ QVERIFY(server.start());
+
+ AutoDir dataDir("./tst_QWebEngineProfile_dataDir");
+
+ QWebEngineProfile profile(QStringLiteral("Test"));
+ QWebEnginePage page(&profile);
+
+ profile.setPersistentStoragePath(dataDir.path());
+ profile.setPersistentCookiesPolicy(QWebEngineProfile::NoPersistentCookies);
+
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(!dataDir.exists("Cookies"));
+
+ profile.setPersistentCookiesPolicy(QWebEngineProfile::ForcePersistentCookies);
+
+ QVERIFY(loadSync(&page, server.url("/hedgehog.html")));
+ QVERIFY(dataDir.exists("Cookies"));
+
+ QVERIFY(server.stop());
}
class InitiatorSpy : public QWebEngineUrlSchemeHandler
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index f15a65469..b733e509c 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -199,6 +199,7 @@ private Q_SLOTS:
void visibilityState();
void visibilityState2();
void visibilityState3();
+ void jsKeyboardEvent_data();
void jsKeyboardEvent();
void deletePage();
void closeOpenerTab();
@@ -3383,6 +3384,28 @@ void tst_QWebEngineView::visibilityState3()
QCOMPARE(evaluateJavaScriptSync(&page2, "document.visibilityState").toString(), QStringLiteral("visible"));
}
+void tst_QWebEngineView::jsKeyboardEvent_data()
+{
+ QTest::addColumn<char>("key");
+ QTest::addColumn<Qt::KeyboardModifiers>("modifiers");
+ QTest::addColumn<QString>("expected");
+
+#if defined(Q_OS_MACOS)
+ // See Qt::AA_MacDontSwapCtrlAndMeta
+ Qt::KeyboardModifiers controlModifier = Qt::MetaModifier;
+#else
+ Qt::KeyboardModifiers controlModifier = Qt::ControlModifier;
+#endif
+
+ QTest::newRow("Ctrl+Shift+A") << 'A' << (controlModifier | Qt::ShiftModifier) << QStringLiteral(
+ "16,ShiftLeft,Shift,false,true,false;"
+ "17,ControlLeft,Control,true,true,false;"
+ "65,KeyA,A,true,true,false;");
+ QTest::newRow("Ctrl+z") << 'z' << controlModifier << QStringLiteral(
+ "17,ControlLeft,Control,true,false,false;"
+ "90,KeyZ,z,true,false,false;");
+}
+
void tst_QWebEngineView::jsKeyboardEvent()
{
QWebEngineView view;
@@ -3392,18 +3415,13 @@ void tst_QWebEngineView::jsKeyboardEvent()
"addEventListener('keydown', (ev) => {"
" log += [ev.keyCode, ev.code, ev.key, ev.ctrlKey, ev.shiftKey, ev.altKey].join(',') + ';';"
"});");
+
+ QFETCH(char, key);
+ QFETCH(Qt::KeyboardModifiers, modifiers);
+ QFETCH(QString, expected);
+
// Note that this only tests the fallback code path where native scan codes are not used.
-#if defined(Q_OS_MACOS)
- // See Qt::AA_MacDontSwapCtrlAndMeta
- QTest::keyClick(view.focusProxy(), 'A', Qt::MetaModifier | Qt::ShiftModifier);
-#else
- QTest::keyClick(view.focusProxy(), 'A', Qt::ControlModifier | Qt::ShiftModifier);
-#endif
- QString expected = QStringLiteral(
- "16,ShiftLeft,Shift,false,true,false;"
- "17,ControlLeft,Control,true,true,false;"
- "65,KeyA,A,true,true,false;"
- );
+ QTest::keyClick(view.focusProxy(), key, modifiers);
QTRY_VERIFY(evaluateJavaScriptSync(view.page(), "log") != QVariant(QString()));
QCOMPARE(evaluateJavaScriptSync(view.page(), "log"), expected);
}