summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@qt.io>2016-05-18 14:55:13 +0200
committerLiang Qi <liang.qi@qt.io>2016-05-19 18:47:23 +0000
commitf4b806ffbc2f11a5a64fab2856dfe68ae7d603c8 (patch)
treee0549b086cdb024b5c360c1a949b5a9988873049 /tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
parentf2370c0d09998f382364a9a58932cf717c28a764 (diff)
Fix pasting images to web pages
WebKit expects pasted images to have the MIME type image/png (see code and comment in DataObjectItem::getAsFile()). Task-number: QTBUG-53409 Change-Id: I2b0c1244d309687ad190db26c5b00718ed0c4258 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp')
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
index 5d53c0468..f29b24933 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp
@@ -31,6 +31,7 @@
#include <QPushButton>
#include <QStateMachine>
#include <QStyle>
+#include <QtGui/QClipboard>
#include <QtTest/QtTest>
#include <QTextCharFormat>
#include <QWebChannel>
@@ -120,6 +121,7 @@ private Q_SLOTS:
void geolocationRequestJS();
void loadFinished();
void actionStates();
+ void pasteImage();
void popupFormSubmission();
void userStyleSheet();
void userStyleSheetFromLocalFileUrl();
@@ -459,6 +461,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: