summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-05-20 06:08:18 +0200
committerLiang Qi <liang.qi@qt.io>2016-05-20 06:08:18 +0200
commit6c344184df2dd6573681a0d2022daa55b6a36f38 (patch)
tree91493089f958b95138bdbd3f838188450e4349bb /tests
parentbfc5eb719d30decaf5c65e2747d49a6eec28794d (diff)
parentbc317d32a65eb08da7df10bec6417829533cfc3a (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')
-rw-r--r--tests/auto/widgets/qwebenginepage/BLACKLIST3
-rw-r--r--tests/auto/widgets/qwebenginepage/resources/pasteimage.html30
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.cpp31
-rw-r--r--tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc1
4 files changed, 65 insertions, 0 deletions
diff --git a/tests/auto/widgets/qwebenginepage/BLACKLIST b/tests/auto/widgets/qwebenginepage/BLACKLIST
index d4481dc3f..30b43d6b7 100644
--- a/tests/auto/widgets/qwebenginepage/BLACKLIST
+++ b/tests/auto/widgets/qwebenginepage/BLACKLIST
@@ -6,3 +6,6 @@ osx
[getUserMediaRequest]
windows
+
+[setHtmlWithImageResource]
+*
diff --git a/tests/auto/widgets/qwebenginepage/resources/pasteimage.html b/tests/auto/widgets/qwebenginepage/resources/pasteimage.html
new file mode 100644
index 000000000..cc37d9319
--- /dev/null
+++ b/tests/auto/widgets/qwebenginepage/resources/pasteimage.html
@@ -0,0 +1,30 @@
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <script>
+ window.onload = function() {
+ document.getElementById("pasteArea").focus();
+ }
+ document.onpaste = function(event) {
+ var items = (event.clipboardData || event.originalEvent.clipboardData).items;
+ var blob = null;
+ for (var i = 0; i < items.length; ++i) {
+ if (items[i].type.indexOf("image/png") !== -1) {
+ blob = items[i].getAsFile();
+ break;
+ }
+ }
+ if (!blob)
+ return;
+ var reader = new FileReader();
+ reader.onload = function(event) {
+ window.myImageDataURL = event.target.result;
+ }
+ reader.readAsDataURL(blob);
+ };
+ </script>
+ </head>
+ <body>
+ <textarea id="pasteArea" placeholder="paste here"></textarea>
+ </body>
+</html>
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:
diff --git a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc
index c7bffd5bb..91adeb694 100644
--- a/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc
+++ b/tests/auto/widgets/qwebenginepage/tst_qwebenginepage.qrc
@@ -12,6 +12,7 @@
<file>resources/script.html</file>
<file>resources/user.css</file>
<file>resources/image.png</file>
+ <file>resources/pasteimage.html</file>
<file>resources/style.css</file>
<file>resources/test1.html</file>
<file>resources/test2.html</file>