diff options
author | Liang Qi <liang.qi@qt.io> | 2016-05-20 06:08:18 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2016-05-20 06:08:18 +0200 |
commit | 6c344184df2dd6573681a0d2022daa55b6a36f38 (patch) | |
tree | 91493089f958b95138bdbd3f838188450e4349bb /tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | |
parent | bfc5eb719d30decaf5c65e2747d49a6eec28794d (diff) | |
parent | bc317d32a65eb08da7df10bec6417829533cfc3a (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts:
src/3rdparty
src/core/browser_context_adapter.cpp
src/core/web_contents_adapter.cpp
tests/auto/widgets/qwebenginepage/BLACKLIST
Change-Id: I45ee0a33f6316f585555d58fede8072fe514aecf
Diffstat (limited to 'tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp')
-rw-r--r-- | tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp | 31 |
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 d617c23a0..df290babf 100644 --- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp +++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp @@ -32,6 +32,7 @@ #include <QPushButton> #include <QStateMachine> #include <QStyle> +#include <QtGui/QClipboard> #include <QtTest/QtTest> #include <QTextCharFormat> #include <QWebChannel> @@ -121,6 +122,7 @@ private Q_SLOTS: void geolocationRequestJS(); void loadFinished(); void actionStates(); + void pasteImage(); void popupFormSubmission(); void userStyleSheet(); void userStyleSheetFromLocalFileUrl(); @@ -462,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: |