summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/publicapi/tst_publicapi.cpp2
-rw-r--r--tests/auto/quick/qmltests/data/tst_userScripts.qml19
-rw-r--r--tests/auto/quick/qquickwebengineview/qquickwebengineview.pro5
-rw-r--r--tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp45
-rw-r--r--tests/auto/widgets/qwebenginepage/qwebenginepage.pro2
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp13
-rw-r--r--tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp135
7 files changed, 215 insertions, 6 deletions
diff --git a/tests/auto/quick/publicapi/tst_publicapi.cpp b/tests/auto/quick/publicapi/tst_publicapi.cpp
index f9fd854cc..5cc0d18df 100644
--- a/tests/auto/quick/publicapi/tst_publicapi.cpp
+++ b/tests/auto/quick/publicapi/tst_publicapi.cpp
@@ -34,6 +34,7 @@
#include <QQmlListProperty>
#include <QtTest/QtTest>
#include <QtWebEngine/QQuickWebEngineProfile>
+#include <QtWebEngine/QQuickWebEngineScript>
#include <private/qquickwebengineview_p.h>
#include <private/qquickwebenginecertificateerror_p.h>
#include <private/qquickwebenginedialogrequests_p.h>
@@ -42,7 +43,6 @@
#include <private/qquickwebengineloadrequest_p.h>
#include <private/qquickwebenginenavigationrequest_p.h>
#include <private/qquickwebenginenewviewrequest_p.h>
-#include <private/qquickwebenginescript_p.h>
#include <private/qquickwebenginesettings_p.h>
#include <private/qquickwebenginesingleton_p.h>
#include <private/qquickwebenginecontextmenurequest_p.h>
diff --git a/tests/auto/quick/qmltests/data/tst_userScripts.qml b/tests/auto/quick/qmltests/data/tst_userScripts.qml
index 88fa6f6e3..e9a4eba99 100644
--- a/tests/auto/quick/qmltests/data/tst_userScripts.qml
+++ b/tests/auto/quick/qmltests/data/tst_userScripts.qml
@@ -61,6 +61,12 @@ Item {
}
TestWebEngineView {
+ id: webEngineView2
+ width: 400
+ height: 300
+ }
+
+ TestWebEngineView {
id: webEngineViewWithConditionalUserScripts
width: 400
height: 300
@@ -82,6 +88,7 @@ Item {
function init() {
webEngineView.url = "";
webEngineView.userScripts = [];
+ webEngineView.profile.userScripts = [];
}
function test_oneScript() {
@@ -173,5 +180,17 @@ Item {
webEngineView.waitForLoadSucceeded();
tryCompare(webEngineView, "title", "Test page with huge link area");
}
+
+ function test_profileWideScript() {
+ webEngineView.profile.userScripts = [ changeDocumentTitleScript ];
+
+ webEngineView.url = Qt.resolvedUrl("test1.html");
+ webEngineView.waitForLoadSucceeded();
+ compare(webEngineView.title, "New title");
+
+ webEngineView2.url = Qt.resolvedUrl("test1.html");
+ webEngineView2.waitForLoadSucceeded();
+ compare(webEngineView2.title, "New title");
+ }
}
}
diff --git a/tests/auto/quick/qquickwebengineview/qquickwebengineview.pro b/tests/auto/quick/qquickwebengineview/qquickwebengineview.pro
index 36e74a2a8..df9b3e1b7 100644
--- a/tests/auto/quick/qquickwebengineview/qquickwebengineview.pro
+++ b/tests/auto/quick/qquickwebengineview/qquickwebengineview.pro
@@ -4,3 +4,8 @@ exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc
QT_PRIVATE += webengine-private gui-private
HEADERS += ../shared/util.h
+
+use?(pdf) {
+ DEFINES += ENABLE_PDF
+}
+
diff --git a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
index 2a43c9c1c..8df84e048 100644
--- a/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
+++ b/tests/auto/quick/qquickwebengineview/tst_qquickwebengineview.cpp
@@ -34,6 +34,7 @@
#include <QtGui/qpa/qwindowsysteminterface.h>
#include <QtQml/QQmlEngine>
#include <QtTest/QtTest>
+#include <QtWebEngine/QQuickWebEngineProfile>
#include <private/qquickwebengineview_p.h>
#include <functional>
@@ -77,6 +78,7 @@ private Q_SLOTS:
void inputEventForwardingDisabledWhenActiveFocusOnPressDisabled();
void changeLocale();
+ void userScripts();
private:
inline QQuickWebEngineView *newWebEngineView();
@@ -277,6 +279,10 @@ void tst_QQuickWebEngineView::showWebEngineView()
void tst_QQuickWebEngineView::removeFromCanvas()
{
+#ifdef Q_OS_LINUX
+ QSKIP("QTBUG-58472 - crashes on some linux CI");
+#else
+
showWebEngineView();
// This should not crash.
@@ -287,6 +293,7 @@ void tst_QQuickWebEngineView::removeFromCanvas()
webEngineView()->setParentItem(parent);
webEngineView()->setVisible(true);
QTest::qWait(200);
+#endif
}
void tst_QQuickWebEngineView::multipleWebEngineViewWindows()
@@ -499,15 +506,22 @@ void tst_QQuickWebEngineView::setZoomFactor()
void tst_QQuickWebEngineView::printToPdf()
{
+#if !defined(ENABLE_PDF)
+ QSKIP("ENABLE_PDF");
+#else
QTemporaryDir tempDir(QDir::tempPath() + "/tst_qwebengineview-XXXXXX");
QVERIFY(tempDir.isValid());
QQuickWebEngineView *view = webEngineView();
view->setUrl(urlFromTestPath("html/basic_page.html"));
QVERIFY(waitForLoadSucceeded(view));
+ QSignalSpy savePdfSpy(view, SIGNAL(pdfPrintingFinished(const QString&, bool)));
QString path = tempDir.path() + "/print_success.pdf";
view->printToPdf(path, QQuickWebEngineView::A4, QQuickWebEngineView::Portrait);
- QTRY_VERIFY(QFile::exists(path));
+ QTRY_VERIFY2(savePdfSpy.count() == 1, "Printing to PDF file failed without signal");
+ QList<QVariant> successArguments = savePdfSpy.takeFirst();
+ QVERIFY2(successArguments.at(0).toString() == path, "File path for first saved PDF does not match arguments");
+ QVERIFY2(successArguments.at(1).toBool() == true, "Printing to PDF file failed though it should succeed");
#if !defined(Q_OS_WIN)
path = tempDir.path() + "/print_//fail.pdf";
@@ -515,7 +529,11 @@ void tst_QQuickWebEngineView::printToPdf()
path = tempDir.path() + "/print_|fail.pdf";
#endif // #if !defined(Q_OS_WIN)
view->printToPdf(path, QQuickWebEngineView::A4, QQuickWebEngineView::Portrait);
- QTRY_VERIFY(!QFile::exists(path));
+ QTRY_VERIFY2(savePdfSpy.count() == 1, "Printing to PDF file failed without signal");
+ QList<QVariant> failedArguments = savePdfSpy.takeFirst();
+ QVERIFY2(failedArguments.at(0).toString() == path, "File path for second saved PDF does not match arguments");
+ QVERIFY2(failedArguments.at(1).toBool() == false, "Printing to PDF file succeeded though it should fail");
+#endif // !defined(ENABLE_PDF)
}
void tst_QQuickWebEngineView::stopSettingFocusWhenDisabled()
@@ -704,5 +722,28 @@ void tst_QQuickWebEngineView::changeLocale()
delete viewEN;
}
+void tst_QQuickWebEngineView::userScripts()
+{
+ QScopedPointer<QQuickWebEngineView> webEngineView1(newWebEngineView());
+ webEngineView1->setParentItem(m_window->contentItem());
+ QScopedPointer<QQuickWebEngineView> webEngineView2(newWebEngineView());
+ webEngineView2->setParentItem(m_window->contentItem());
+
+ QQmlListReference list(webEngineView1->profile(), "userScripts");
+ QQuickWebEngineScript script;
+ script.setSourceCode("document.title = 'New title';");
+ list.append(&script);
+
+ webEngineView1->setUrl(urlFromTestPath("html/basic_page.html"));
+ QVERIFY(waitForLoadSucceeded(webEngineView1.data()));
+ QTRY_COMPARE(webEngineView1->title(), QStringLiteral("New title"));
+
+ webEngineView2->setUrl(urlFromTestPath("html/basic_page.html"));
+ QVERIFY(waitForLoadSucceeded(webEngineView2.data()));
+ QTRY_COMPARE(webEngineView2->title(), QStringLiteral("New title"));
+
+ list.clear();
+}
+
QTEST_MAIN(tst_QQuickWebEngineView)
#include "tst_qquickwebengineview.moc"
diff --git a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro
index 6446cdd7a..e0765736e 100644
--- a/tests/auto/widgets/qwebenginepage/qwebenginepage.pro
+++ b/tests/auto/widgets/qwebenginepage/qwebenginepage.pro
@@ -1,4 +1,4 @@
include(../tests.pri)
QT *= core-private
-contains(WEBENGINE_CONFIG, enable_pdf): DEFINES+=QWEBENGINEPAGE_PDFPRINTINGENABLED
+contains(WEBENGINE_CONFIG, use_pdf): DEFINES+=QWEBENGINEPAGE_PDFPRINTINGENABLED
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index cde09f5c6..7e78e2b0e 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -4690,10 +4690,15 @@ void tst_QWebEnginePage::printToPdf()
page.load(QUrl("qrc:///resources/basic_printing_page.html"));
QTRY_VERIFY(spy.count() == 1);
+ QSignalSpy savePdfSpy(&page, SIGNAL(pdfPrintingFinished(const QString&, bool)));
QPageLayout layout(QPageSize(QPageSize::A4), QPageLayout::Portrait, QMarginsF(0.0, 0.0, 0.0, 0.0));
QString path = tempDir.path() + "/print_1_success.pdf";
page.printToPdf(path, layout);
- QTRY_VERIFY(QFile::exists(path));
+ QTRY_VERIFY2(savePdfSpy.count() == 1, "Printing to PDF file failed without signal");
+
+ QList<QVariant> successArguments = savePdfSpy.takeFirst();
+ QVERIFY2(successArguments.at(0).toString() == path, "File path for first saved PDF does not match arguments");
+ QVERIFY2(successArguments.at(1).toBool() == true, "Printing to PDF file failed though it should succeed");
#if !defined(Q_OS_WIN)
path = tempDir.path() + "/print_//2_failed.pdf";
@@ -4701,7 +4706,11 @@ void tst_QWebEnginePage::printToPdf()
path = tempDir.path() + "/print_|2_failed.pdf";
#endif
page.printToPdf(path, QPageLayout());
- QTRY_VERIFY(!QFile::exists(path));
+ QTRY_VERIFY2(savePdfSpy.count() == 1, "Printing to PDF file failed without signal");
+
+ QList<QVariant> failedArguments = savePdfSpy.takeFirst();
+ QVERIFY2(failedArguments.at(0).toString() == path, "File path for second saved PDF does not match arguments");
+ QVERIFY2(failedArguments.at(1).toBool() == false, "Printing to PDF file succeeded though it should fail");
CallbackSpy<QByteArray> successfulSpy;
page.printToPdf(successfulSpy.ref(), layout);
diff --git a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
index 151b82b61..b173c3474 100644
--- a/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
+++ b/tests/auto/widgets/qwebengineview/tst_qwebengineview.cpp
@@ -38,6 +38,9 @@
#include <QHBoxLayout>
#include <QQuickItem>
#include <QQuickWidget>
+#include <QtWebEngineCore/qwebenginehttprequest.h>
+#include <QTcpServer>
+#include <QTcpSocket>
#include <QStyle>
#define VERIFY_INPUTMETHOD_HINTS(actual, expect) \
@@ -90,6 +93,7 @@ private Q_SLOTS:
void inputMethodsTextFormat();
void keyboardEvents();
void keyboardFocusAfterPopup();
+ void postData();
void softwareInputPanel();
void hiddenText();
@@ -1089,6 +1093,137 @@ void tst_QWebEngineView::keyboardFocusAfterPopup()
QTRY_COMPARE(evaluateJavaScriptSync(webView->page(), "document.getElementById('input1').value").toString(), QStringLiteral("x"));
}
+void tst_QWebEngineView::postData()
+{
+ QMap<QString, QString> postData;
+ // use reserved characters to make the test harder to pass
+ postData[QStringLiteral("Spä=m")] = QStringLiteral("ëgg:s");
+ postData[QStringLiteral("foo\r\n")] = QStringLiteral("ba&r");
+
+ QEventLoop eventloop;
+
+ // Set up dummy "HTTP" server
+ QTcpServer server;
+ connect(&server, &QTcpServer::newConnection, this, [this, &server, &eventloop, &postData](){
+ QTcpSocket* socket = server.nextPendingConnection();
+
+ connect(socket, &QAbstractSocket::disconnected, this, [&eventloop](){
+ eventloop.quit();
+ });
+
+ connect(socket, &QIODevice::readyRead, this, [this, socket, &server, &postData](){
+ QByteArray rawData = socket->readAll();
+ QStringList lines = QString::fromLocal8Bit(rawData).split("\r\n");
+
+ // examine request
+ QStringList request = lines[0].split(" ", QString::SkipEmptyParts);
+ bool requestOk = request.length() > 2
+ && request[2].toUpper().startsWith("HTTP/")
+ && request[0].toUpper() == "POST"
+ && request[1] == "/";
+ if (!requestOk) // POST and HTTP/... can be switched(?)
+ requestOk = request.length() > 2
+ && request[0].toUpper().startsWith("HTTP/")
+ && request[2].toUpper() == "POST"
+ && request[1] == "/";
+
+ // examine headers
+ int line = 1;
+ bool headersOk = true;
+ for (; headersOk && line < lines.length(); line++) {
+ QStringList headerParts = lines[line].split(":");
+ if (headerParts.length() < 2)
+ break;
+ QString headerKey = headerParts[0].trimmed().toLower();
+ QString headerValue = headerParts[1].trimmed().toLower();
+
+ if (headerKey == "host")
+ headersOk = headersOk && (headerValue == "127.0.0.1")
+ && (headerParts.length() == 3)
+ && (headerParts[2].trimmed()
+ == QString::number(server.serverPort()));
+ if (headerKey == "content-type")
+ headersOk = headersOk && (headerValue == "application/x-www-form-urlencoded");
+ }
+
+ // examine body
+ bool bodyOk = true;
+ if (lines.length() == line+2) {
+ QStringList postedFields = lines[line+1].split("&");
+ QMap<QString, QString> postedData;
+ for (int i = 0; bodyOk && i < postedFields.length(); i++) {
+ QStringList postedField = postedFields[i].split("=");
+ if (postedField.length() == 2)
+ postedData[QUrl::fromPercentEncoding(postedField[0].toLocal8Bit())]
+ = QUrl::fromPercentEncoding(postedField[1].toLocal8Bit());
+ else
+ bodyOk = false;
+ }
+ bodyOk = bodyOk && (postedData == postData);
+ } else { // no body at all or more than 1 line
+ bodyOk = false;
+ }
+
+ // send response
+ socket->write("HTTP/1.1 200 OK\r\n");
+ socket->write("Content-Type: text/html\r\n");
+ socket->write("Content-Length: 39\r\n\r\n");
+ if (requestOk && headersOk && bodyOk)
+ // 6 6 11 7 7 2 = 39 (Content-Length)
+ socket->write("<html><body>Test Passed</body></html>\r\n");
+ else
+ socket->write("<html><body>Test Failed</body></html>\r\n");
+ socket->flush();
+
+ if (!requestOk || !headersOk || !bodyOk) {
+ qDebug() << "Dummy HTTP Server: received request was not as expected";
+ qDebug() << rawData;
+ QVERIFY(requestOk); // one of them will yield useful output and make the test fail
+ QVERIFY(headersOk);
+ QVERIFY(bodyOk);
+ }
+
+ socket->close();
+ });
+ });
+ if (!server.listen())
+ QFAIL("Dummy HTTP Server: listen() failed");
+
+ // Manual, hard coded client (commented out, but not removed - for reference and just in case)
+ /*
+ QTcpSocket client;
+ connect(&client, &QIODevice::readyRead, this, [&client, &eventloop](){
+ qDebug() << "Dummy HTTP client: data received";
+ qDebug() << client.readAll();
+ eventloop.quit();
+ });
+ connect(&client, &QAbstractSocket::connected, this, [&client](){
+ client.write("HTTP/1.1 / GET\r\n\r\n");
+ });
+ client.connectToHost(QHostAddress::LocalHost, server.serverPort());
+ */
+
+ // send the POST request
+ QWebEngineView view;
+ QString sPort = QString::number(server.serverPort());
+ view.load(QWebEngineHttpRequest::postRequest(QUrl("http://127.0.0.1:"+sPort), postData));
+
+ // timeout after 10 seconds
+ QTimer timeoutGuard(this);
+ connect(&timeoutGuard, &QTimer::timeout, this, [&eventloop](){
+ eventloop.quit();
+ QFAIL("Dummy HTTP Server: waiting for data timed out");
+ });
+ timeoutGuard.setSingleShot(true);
+ timeoutGuard.start(10000);
+
+ // start the test
+ eventloop.exec();
+
+ timeoutGuard.stop();
+ server.close();
+}
+
class TestInputContext : public QPlatformInputContext
{
public: