summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp134
1 files changed, 70 insertions, 64 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 7bdad1bda..8b36d5a6f 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -20,6 +20,7 @@
*/
#include "../util.h"
+#include <QtWebEngineCore/qtwebenginecore-config.h>
#include <QByteArray>
#include <QClipboard>
#include <QDir>
@@ -39,7 +40,9 @@
#include <QtGui/QClipboard>
#include <QtTest/QtTest>
#include <QTextCharFormat>
+#if QT_CONFIG(webengine_webchannel)
#include <QWebChannel>
+#endif
#include <httpserver.h>
#include <qnetworkcookiejar.h>
#include <qnetworkreply.h>
@@ -161,6 +164,7 @@ private Q_SLOTS:
#endif
void runJavaScript();
+ void runJavaScriptDisabled();
void fullScreenRequested();
void quotaRequested();
@@ -201,15 +205,15 @@ private Q_SLOTS:
void loadInSignalHandlers_data();
void loadInSignalHandlers();
void loadFromQrc();
-
+#if QT_CONFIG(webengine_webchannel)
void restoreHistory();
+#endif
void toPlainTextLoadFinishedRace_data();
void toPlainTextLoadFinishedRace();
void setZoomFactor();
void mouseButtonTranslation();
void mouseMovementProperties();
- void printToPdf();
void viewSource();
void viewSourceURL_data();
void viewSourceURL();
@@ -221,6 +225,7 @@ private Q_SLOTS:
void devTools();
void openLinkInDifferentProfile();
void triggerActionWithoutMenu();
+ void dynamicFrame();
private:
static QPoint elementCenter(QWebEnginePage *page, const QString &id);
@@ -398,6 +403,11 @@ void tst_QWebEnginePage::geolocationRequestJS()
QSignalSpy spyLoadFinished(newPage, SIGNAL(loadFinished(bool)));
newPage->setHtml(QString("<html><body>test</body></html>"), QUrl("qrc://secure/origin"));
QTRY_COMPARE(spyLoadFinished.count(), 1);
+
+ // Geolocation is only enabled for visible WebContents.
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+
if (evaluateJavaScriptSync(newPage, QLatin1String("!navigator.geolocation")).toBool())
W_QSKIP("Geolocation is not supported.", SkipSingle);
@@ -773,7 +783,8 @@ void tst_QWebEnginePage::updatePositionDependentActionsCrash()
QPoint pos(0, 0);
view.page()->updatePositionDependentActions(pos);
QMenu* contextMenu = 0;
- foreach (QObject* child, view.children()) {
+ const QList<QObject *> children = view.children();
+ for (QObject *child : children) {
contextMenu = qobject_cast<QMenu*>(child);
if (contextMenu)
break;
@@ -795,7 +806,8 @@ void tst_QWebEnginePage::contextMenuCrash()
view.page()->swallowContextMenuEvent(&event);
view.page()->updatePositionDependentActions(pos);
QMenu* contextMenu = 0;
- foreach (QObject* child, view.children()) {
+ const QList<QObject *> children = view.children();
+ for (QObject *child : children) {
contextMenu = qobject_cast<QMenu*>(child);
if (contextMenu)
break;
@@ -1839,8 +1851,8 @@ void tst_QWebEnginePage::findTextResult()
QCOMPARE(findTextSync(m_page, ""), false);
- QStringList words = (QStringList() << "foo" << "bar");
- foreach (QString subString, words) {
+ const QStringList words = { "foo", "bar" };
+ for (const QString &subString : words) {
QCOMPARE(findTextSync(m_page, subString), true);
QCOMPARE(findTextSync(m_page, ""), false);
}
@@ -1900,7 +1912,8 @@ void tst_QWebEnginePage::supportedContentType()
#endif
// Add supported image types...
- Q_FOREACH (const QByteArray& imageType, QImageWriter::supportedImageFormats()) {
+ const QList<QByteArray> supportedImageFormats = QImageWriter::supportedImageFormats();
+ for (const QByteArray &imageType : supportedImageFormats) {
const QString mimeType = getMimeTypeForExtension(imageType);
if (!mimeType.isEmpty())
contentTypes << mimeType;
@@ -1909,10 +1922,10 @@ void tst_QWebEnginePage::supportedContentType()
// Get the mime types supported by webengine...
const QStringList supportedContentTypes = m_page->supportedContentTypes();
- Q_FOREACH (const QString& mimeType, contentTypes)
+ for (const QString &mimeType : qAsConst(contentTypes))
QVERIFY2(supportedContentTypes.contains(mimeType), QString("'%1' is not a supported content type!").arg(mimeType).toLatin1());
- Q_FOREACH (const QString& mimeType, contentTypes)
+ for (const QString &mimeType : qAsConst(contentTypes))
QVERIFY2(m_page->supportsContentType(mimeType), QString("Cannot handle content types '%1'!").arg(mimeType).toLatin1());
#endif
}
@@ -2283,7 +2296,8 @@ void tst_QWebEnginePage::renderWidgetHostViewNotShowTopLevel()
// Make sure that RenderWidgetHostViewQtDelegateWidgets are not shown as top-level.
// They should only be made visible when parented to a QWebEngineView.
- foreach (QWidget *widget, QApplication::topLevelWidgets())
+ const QList<QWidget *> widgets = QApplication::topLevelWidgets();
+ for (QWidget *widget : widgets)
QCOMPARE(widget->isVisible(), false);
}
@@ -2392,6 +2406,15 @@ void tst_QWebEnginePage::getUserMediaRequest()
QFETCH(QWebEnginePage::Feature, feature);
GetUserMediaTestPage page;
+ if (feature == QWebEnginePage::DesktopVideoCapture || feature == QWebEnginePage::DesktopAudioVideoCapture) {
+ // Desktop capture needs to be on a desktop.
+ QWebEngineView view;
+ view.setPage(&page);
+ view.resize(640, 480);
+ view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
+ }
+
QTRY_VERIFY_WITH_TIMEOUT(page.loadSucceeded(), 20000);
page.settings()->setAttribute(QWebEngineSettings::ScreenCaptureEnabled, true);
@@ -2755,6 +2778,21 @@ void tst_QWebEnginePage::runJavaScript()
QVERIFY(watcher.wait());
}
+void tst_QWebEnginePage::runJavaScriptDisabled()
+{
+ QWebEnginePage page;
+ QSignalSpy spy(&page, &QWebEnginePage::loadFinished);
+ page.settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, false);
+ // Settings changes take effect asynchronously. The load and wait ensure
+ // that the settings are applied by the time we start to execute JavaScript.
+ page.load(QStringLiteral("about:blank"));
+ QTRY_COMPARE(spy.count(), 1);
+ QCOMPARE(evaluateJavaScriptSyncInWorld(&page, QStringLiteral("1+1"), QWebEngineScript::MainWorld),
+ QVariant());
+ QCOMPARE(evaluateJavaScriptSyncInWorld(&page, QStringLiteral("1+1"), QWebEngineScript::ApplicationWorld),
+ QVariant(2));
+}
+
void tst_QWebEnginePage::fullScreenRequested()
{
JavaScriptCallbackWatcher watcher;
@@ -3025,7 +3063,7 @@ void tst_QWebEnginePage::requestedUrlAfterSetAndLoadFailures()
const QUrl first("http://abcdef.abcdef/");
page.setUrl(first);
- QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 12000);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
QCOMPARE(page.url(), first);
QCOMPARE(page.requestedUrl(), first);
QVERIFY(!spy.at(0).first().toBool());
@@ -3034,7 +3072,7 @@ void tst_QWebEnginePage::requestedUrlAfterSetAndLoadFailures()
QVERIFY(first != second);
page.load(second);
- QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 2, 12000);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 2, 20000);
QCOMPARE(page.url(), second);
QCOMPARE(page.requestedUrl(), second);
QVERIFY(!spy.at(1).first().toBool());
@@ -3284,8 +3322,8 @@ void tst_QWebEnginePage::scrollPosition()
// try to set the scroll offset programmatically
view.page()->runJavaScript("window.scrollTo(23, 29);");
- QTRY_COMPARE(view.page()->scrollPosition().x(), qreal(23));
- QCOMPARE(view.page()->scrollPosition().y(), qreal(29));
+ QTRY_COMPARE(view.page()->scrollPosition().x(), 23 * view.windowHandle()->devicePixelRatio());
+ QCOMPARE(view.page()->scrollPosition().y(), 29 * view.windowHandle()->devicePixelRatio());
int x = evaluateJavaScriptSync(view.page(), "window.scrollX").toInt();
int y = evaluateJavaScriptSync(view.page(), "window.scrollY").toInt();
@@ -3568,7 +3606,7 @@ void tst_QWebEnginePage::setUrlToBadDomain()
page.setUrl(url1);
QTRY_COMPARE(urlSpy.count(), 1);
- QTRY_COMPARE_WITH_TIMEOUT(titleSpy.count(), 1, 12000);
+ QTRY_COMPARE_WITH_TIMEOUT(titleSpy.count(), 1, 20000);
QTRY_COMPARE(loadSpy.count(), 1);
QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), url1);
@@ -3581,7 +3619,7 @@ void tst_QWebEnginePage::setUrlToBadDomain()
page.setUrl(url2);
QTRY_COMPARE(urlSpy.count(), 1);
- QTRY_COMPARE_WITH_TIMEOUT(titleSpy.count(), 1, 12000);
+ QTRY_COMPARE_WITH_TIMEOUT(titleSpy.count(), 1, 20000);
QTRY_COMPARE(loadSpy.count(), 1);
QCOMPARE(urlSpy.takeFirst().value(0).toUrl(), url2);
@@ -3636,7 +3674,8 @@ void tst_QWebEnginePage::setUrlToBadPort()
static QStringList collectHistoryUrls(QWebEngineHistory *history)
{
QStringList urls;
- foreach (const QWebEngineHistoryItem &i, history->items())
+ const QList<QWebEngineHistoryItem> items = history->items();
+ for (const QWebEngineHistoryItem &i : items)
urls << i.url().toString();
return urls;
}
@@ -3824,11 +3863,11 @@ void tst_QWebEnginePage::loadFinishedAfterNotFoundError()
page.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, false);
page.setUrl(QUrl("http://non.existent/url"));
- QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 12000);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 1, 20000);
page.settings()->setAttribute(QWebEngineSettings::ErrorPageEnabled, true);
page.setUrl(QUrl("http://another.non.existent/url"));
- QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 2, 12000);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 2, 20000);
}
class URLSetter : public QObject {
@@ -3955,6 +3994,7 @@ void tst_QWebEnginePage::loadFromQrc()
QCOMPARE(spy.takeFirst().value(0).toBool(), false);
}
+#if QT_CONFIG(webengine_webchannel)
void tst_QWebEnginePage::restoreHistory()
{
QWebChannel channel;
@@ -3982,6 +4022,7 @@ void tst_QWebEnginePage::restoreHistory()
QCOMPARE(page.webChannel(), &channel);
QVERIFY(page.scripts().contains(script));
}
+#endif
void tst_QWebEnginePage::toPlainTextLoadFinishedRace_data()
{
@@ -4003,7 +4044,7 @@ void tst_QWebEnginePage::toPlainTextLoadFinishedRace()
QCOMPARE(toPlainTextSync(page.data()), QString("foobarbaz"));
page->load(QUrl("http://fail.invalid/"));
- QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 2, 12000);
+ QTRY_COMPARE_WITH_TIMEOUT(spy.count(), 2, 20000);
QString s = toPlainTextSync(page.data());
QVERIFY(s.contains("foobarbaz") == !enableErrorPage);
@@ -4037,50 +4078,6 @@ void tst_QWebEnginePage::setZoomFactor()
QVERIFY(qFuzzyCompare(page.zoomFactor(), 2.5));
}
-void tst_QWebEnginePage::printToPdf()
-{
-#if !defined(QWEBENGINEPAGE_PDFPRINTINGENABLED)
- QSKIP("QWEBENGINEPAGE_PDFPRINTINGENABLED");
-#else
- QTemporaryDir tempDir(QDir::tempPath() + "/tst_qwebengineview-XXXXXX");
- QVERIFY(tempDir.isValid());
- QWebEnginePage page;
- QSignalSpy spy(&page, SIGNAL(loadFinished(bool)));
- 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_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";
-#else
- path = tempDir.path() + "/print_|2_failed.pdf";
-#endif
- page.printToPdf(path, QPageLayout());
- 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);
- QVERIFY(successfulSpy.waitForResult().length() > 0);
-
- CallbackSpy<QByteArray> failedInvalidLayoutSpy;
- page.printToPdf(failedInvalidLayoutSpy.ref(), QPageLayout());
- QCOMPARE(failedInvalidLayoutSpy.waitForResult().length(), 0);
-#endif
-}
-
void tst_QWebEnginePage::mouseButtonTranslation()
{
QWebEngineView view;
@@ -4453,6 +4450,15 @@ void tst_QWebEnginePage::triggerActionWithoutMenu()
page.triggerAction(QWebEnginePage::DownloadLinkToDisk);
}
+void tst_QWebEnginePage::dynamicFrame()
+{
+ QWebEnginePage page;
+ QSignalSpy spy(&page, &QWebEnginePage::loadFinished);
+ page.load(QStringLiteral("qrc:/resources/dynamicFrame.html"));
+ QVERIFY(spy.wait());
+ QCOMPARE(toPlainTextSync(&page).trimmed(), QStringLiteral("foo"));
+}
+
static QByteArrayList params = {QByteArrayLiteral("--use-fake-device-for-media-stream")};
W_QTEST_MAIN(tst_QWebEnginePage, params)