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.cpp73
1 files changed, 70 insertions, 3 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 5d53c0468..df290babf 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2016 The Qt Company Ltd.
Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
Copyright (C) 2010 Holger Hans Peter Freyther
@@ -20,6 +20,7 @@
*/
#include "../util.h"
+#include <QByteArray>
#include <QClipboard>
#include <QDir>
#include <QGraphicsWidget>
@@ -31,6 +32,7 @@
#include <QPushButton>
#include <QStateMachine>
#include <QStyle>
+#include <QtGui/QClipboard>
#include <QtTest/QtTest>
#include <QTextCharFormat>
#include <QWebChannel>
@@ -120,6 +122,7 @@ private Q_SLOTS:
void geolocationRequestJS();
void loadFinished();
void actionStates();
+ void pasteImage();
void popupFormSubmission();
void userStyleSheet();
void userStyleSheetFromLocalFileUrl();
@@ -238,6 +241,8 @@ private Q_SLOTS:
void toPlainTextLoadFinishedRace();
void setZoomFactor();
+ void printToPdf();
+
private:
QWebEngineView* m_view;
QWebEnginePage* m_page;
@@ -459,6 +464,35 @@ void tst_QWebEnginePage::actionStates()
QTRY_VERIFY(!stopAction->isEnabled());
}
+static QImage imageWithoutAlpha(const QImage &image)
+{
+ QImage result = image;
+ QPainter painter(&result);
+ painter.fillRect(result.rect(), Qt::green);
+ painter.drawImage(0, 0, image);
+ return result;
+}
+
+void tst_QWebEnginePage::pasteImage()
+{
+ // Pixels with an alpha value of 0 will have different RGB values after the
+ // test -> clipboard -> webengine -> test roundtrip.
+ // Clear the alpha channel to make QCOMPARE happy.
+ const QImage origImage = imageWithoutAlpha(QImage(":/resources/image.png"));
+ QClipboard *clipboard = QGuiApplication::clipboard();
+ clipboard->setImage(origImage);
+ QWebEnginePage *page = m_view->page();
+ page->load(QUrl("qrc:///resources/pasteimage.html"));
+ QVERIFY(waitForSignal(m_view, SIGNAL(loadFinished(bool))));
+ page->triggerAction(QWebEnginePage::Paste);
+ QTRY_VERIFY(evaluateJavaScriptSync(page,
+ "window.myImageDataURL ? window.myImageDataURL.length : 0").toInt() > 0);
+ QByteArray data = evaluateJavaScriptSync(page, "window.myImageDataURL").toByteArray();
+ data.remove(0, data.indexOf(";base64,") + 8);
+ const QImage image = QImage::fromData(QByteArray::fromBase64(data), "PNG");
+ QCOMPARE(image, origImage);
+}
+
class ConsolePage : public QWebEnginePage
{
public:
@@ -3307,9 +3341,9 @@ void tst_QWebEnginePage::loadSignalsOrder()
QFETCH(QUrl, url);
QWebEnginePage page;
SpyForLoadSignalsOrder loadSpy(&page);
- waitForSignal(&loadSpy, SIGNAL(started()));
+ waitForSignal(&loadSpy, SIGNAL(started()), 500);
page.load(url);
- QTRY_VERIFY(loadSpy.isFinished());
+ QTRY_VERIFY_WITH_TIMEOUT(loadSpy.isFinished(), 500);
}
void tst_QWebEnginePage::undoActionHaveCustomText()
@@ -3980,7 +4014,9 @@ void tst_QWebEnginePage::setHtmlWithImageResource()
page.setHtml(html);
waitForSignal(&page, SIGNAL(loadFinished(bool)));
QCOMPARE(evaluateJavaScriptSync(&page, "document.images.length").toInt(), 1);
+ QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=118659", Continue);
QCOMPARE(evaluateJavaScriptSync(&page, "document.images[0].width").toInt(), 0);
+ QEXPECT_FAIL("", "https://bugs.webkit.org/show_bug.cgi?id=118659", Continue);
QCOMPARE(evaluateJavaScriptSync(&page, "document.images[0].height").toInt(), 0);
}
@@ -5004,5 +5040,36 @@ void tst_QWebEnginePage::setZoomFactor()
delete page;
}
+void tst_QWebEnginePage::printToPdf()
+{
+ 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);
+
+ 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));
+
+#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_VERIFY(!QFile::exists(path));
+
+ 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);
+}
+
QTEST_MAIN(tst_QWebEnginePage)
#include "tst_qwebenginepage.moc"