summaryrefslogtreecommitdiffstats
path: root/tests/webkitwidgets/hybridPixmap
diff options
context:
space:
mode:
authorQt Forward Merge Bot <[email protected]>2019-10-11 12:44:19 +0200
committerQt Forward Merge Bot <[email protected]>2019-10-11 12:44:19 +0200
commitab1bd15209abaf7effc51dbc2f272c5681af7223 (patch)
tree680bfbc4ab13514a9d2288609377bd8461f1d9f6 /tests/webkitwidgets/hybridPixmap
parent5909e6d0d10de3e1370b3ea0bc596f580101e3b4 (diff)
parent2eac3aeb98fca0e6c13aaaff481861c5ef679e68 (diff)
Merge remote-tracking branch 'origin/5.212' into devHEADdev
Diffstat (limited to 'tests/webkitwidgets/hybridPixmap')
-rw-r--r--tests/webkitwidgets/hybridPixmap/hybridPixmap.pro10
-rw-r--r--tests/webkitwidgets/hybridPixmap/test.html99
-rw-r--r--tests/webkitwidgets/hybridPixmap/tst_hybridPixmap.cpp52
-rw-r--r--tests/webkitwidgets/hybridPixmap/tst_hybridPixmap.qrc5
-rw-r--r--tests/webkitwidgets/hybridPixmap/widget.cpp126
-rw-r--r--tests/webkitwidgets/hybridPixmap/widget.h74
-rw-r--r--tests/webkitwidgets/hybridPixmap/widget.ui95
7 files changed, 461 insertions, 0 deletions
diff --git a/tests/webkitwidgets/hybridPixmap/hybridPixmap.pro b/tests/webkitwidgets/hybridPixmap/hybridPixmap.pro
new file mode 100644
index 000000000..68e565941
--- /dev/null
+++ b/tests/webkitwidgets/hybridPixmap/hybridPixmap.pro
@@ -0,0 +1,10 @@
+# -------------------------------------------------
+# Project created by QtCreator 2009-12-10T11:25:02
+# -------------------------------------------------
+include(../tests.pri)
+TARGET = hybridPixmap
+SOURCES += widget.cpp
+HEADERS += widget.h
+FORMS += widget.ui
+RESOURCES += tst_hybridPixmap.qrc
+CONFIG += console
diff --git a/tests/webkitwidgets/hybridPixmap/test.html b/tests/webkitwidgets/hybridPixmap/test.html
new file mode 100644
index 000000000..a6cbed1fb
--- /dev/null
+++ b/tests/webkitwidgets/hybridPixmap/test.html
@@ -0,0 +1,99 @@
+<html>
+ <head>
+ <style>
+ img { display: block; border-style: groove}
+ </style>
+ <script>
+ function testImageData() {
+ var obj = myWidget.image;
+ var pxm = myWidget.pixmap;
+
+ function compareImageDataSize(o, imageData) {
+ myWidget.compare(imageData.height, o.height);
+ myWidget.compare(imageData.width, o.width);
+ }
+ compareImageDataSize(obj, obj.toImageData());
+ compareImageDataSize(pxm, pxm.toImageData());
+
+ function compareImageDataPixel(o, imageData) {
+ compareImageDataSize(o, imageData);
+ // Make sure pixels are 0xAABBCCFF
+ var data = imageData.data;
+ for (var i = 0; i < data.length; i += 4) {
+ myWidget.compare(data[i], 0xaa); // R
+ myWidget.compare(data[i+1], 0xbb); // G
+ myWidget.compare(data[i+2], 0xcc); // B
+ myWidget.compare(data[i+3], 0xff); // A
+ }
+ }
+ var objARGB32 = myWidget.abcImage(5);
+ compareImageDataPixel(objARGB32, objARGB32.toImageData());
+ var objRGB32 = myWidget.abcImage(4);
+ compareImageDataPixel(objRGB32, objRGB32.toImageData());
+ var objRGB888 = myWidget.abcImage(13);
+ compareImageDataPixel(objRGB888, objRGB888.toImageData());
+ var objRGB444 = myWidget.abcImage(14);
+ compareImageDataPixel(objRGB444, objRGB444.toImageData());
+ }
+
+ function startTest()
+ {
+ testImageData();
+
+ var obj = myWidget.image;
+ var pxm = myWidget.pixmap;
+
+ var img = new Image;
+ obj.assignToHTMLImageElement(img);
+ var img1 = document.getElementById("img1");
+ var img2 = document.getElementById("img2");
+ var img3 = document.getElementById("img3");
+ var img4 = document.getElementById("img4");
+ document.body.appendChild(img);
+ obj.assignToHTMLImageElement(img3);
+ pxm.assignToHTMLImageElement(img4);
+ myWidget.compare(pxm.width, img4.width);
+ myWidget.compare(obj.width, img3.width);
+ var signalsFired = 0;
+ myWidget.compare(obj.toString(),"[Qt Native Pixmap "+obj.width+","+obj.height+"]");
+ myWidget.compare(String(pxm),"[Qt Native Pixmap "+pxm.width+","+pxm.height+"]");
+
+ // this shouldn't work but shouldn't crash
+ myWidget.randomSlot("foobar");
+
+ myWidget.pixmapSignal.connect(function(imgFromSignal) {
+ myWidget.compare(imgFromSignal.height, img2.height);
+ if (++signalsFired == 2)
+ myWidget.completeTest();
+ });
+
+ myWidget.imageSignal.connect(function(imgFromSignal) {
+ myWidget.compare(pxm.height, img2.height);
+ if (++signalsFired == 2)
+ myWidget.completeTest();
+ });
+
+ function continueTestAfterImagesAreLoaded()
+ {
+ if (img1.complete && img2.complete) {
+ myWidget.compare(pxm.height, img2.height);
+ myWidget.pixmapSlot(img);
+ myWidget.imageSlot(pxm);
+ }
+ }
+ img1.onload = continueTestAfterImagesAreLoaded;
+ img2.onload = continueTestAfterImagesAreLoaded;
+ img1.src = obj.toDataUrl();
+ img2.src = myWidget.pixmap.toDataUrl();
+ myWidget.image = pxm;
+ myWidget.pixmap = img;
+ }
+ </script>
+ </head>
+ <body onload="startTest()">
+ <img id="img1" />
+ <img id="img2" />
+ <img id="img3" />
+ <img id="img4" />
+ </body>
+</html>
diff --git a/tests/webkitwidgets/hybridPixmap/tst_hybridPixmap.cpp b/tests/webkitwidgets/hybridPixmap/tst_hybridPixmap.cpp
new file mode 100644
index 000000000..84891580a
--- /dev/null
+++ b/tests/webkitwidgets/hybridPixmap/tst_hybridPixmap.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "../util.h"
+
+#include "widget.h"
+#include <QtTest/QtTest>
+
+class tst_hybridPixmap : public QObject {
+ Q_OBJECT
+
+public:
+ tst_hybridPixmap(QObject* o = 0) : QObject(o) {}
+
+public Q_SLOTS:
+ void init()
+ {
+ }
+
+ void cleanup()
+ {
+ }
+
+private Q_SLOTS:
+ void hybridPixmap()
+ {
+ Widget widget;
+ widget.show();
+ widget.start();
+ waitForSignal(&widget, SIGNAL(testComplete()));
+ }
+};
+
+QTEST_MAIN(tst_hybridPixmap)
+
+#include <tst_hybridPixmap.moc>
diff --git a/tests/webkitwidgets/hybridPixmap/tst_hybridPixmap.qrc b/tests/webkitwidgets/hybridPixmap/tst_hybridPixmap.qrc
new file mode 100644
index 000000000..5fd47e32d
--- /dev/null
+++ b/tests/webkitwidgets/hybridPixmap/tst_hybridPixmap.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>test.html</file>
+ </qresource>
+</RCC>
diff --git a/tests/webkitwidgets/hybridPixmap/widget.cpp b/tests/webkitwidgets/hybridPixmap/widget.cpp
new file mode 100644
index 000000000..6c4d2cd49
--- /dev/null
+++ b/tests/webkitwidgets/hybridPixmap/widget.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include "widget.h"
+
+#include "qwebelement.h"
+#include "qwebframe.h"
+#include "ui_widget.h"
+#include <QPainter>
+#include <QtTest/QtTest>
+
+Widget::Widget(QWidget* parent) :
+ QWidget(parent),
+ ui(new Ui::Widget),
+ abcFilledImage(32, 32, QImage::Format_ARGB32)
+{
+ ui->setupUi(this);
+ abcFilledImage.fill(qRgba(0xaa, 0xbb, 0xcc, 0xff));
+}
+
+void Widget::refreshJS()
+{
+ ui->webView->page()->mainFrame()->addToJavaScriptWindowObject("myWidget", this);
+}
+void Widget::start()
+{
+ ui->webView->load(QUrl("qrc:///test.html"));
+ connect(ui->webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(refreshJS()));
+ ui->webView->page()->mainFrame()->addToJavaScriptWindowObject("myWidget", this);
+}
+
+void Widget::completeTest()
+{
+ QCOMPARE(ui->lbl1->pixmap()->size(), ui->lbl2->size());
+ QCOMPARE(ui->lbl3->size(), ui->lbl4->pixmap()->size());
+ QCOMPARE(ui->lbl2->size().width(), ui->webView->page()->mainFrame()->findFirstElement("#img1").evaluateJavaScript("this.width").toInt());
+ QCOMPARE(ui->lbl3->size().width(), ui->webView->page()->mainFrame()->findFirstElement("#img2").evaluateJavaScript("this.width").toInt());
+ emit testComplete();
+}
+
+void Widget::setPixmap(const QPixmap& p)
+{
+ ui->lbl1->setPixmap(p);
+}
+QPixmap Widget::pixmap() const
+{
+ QPixmap px(ui->lbl3->size());
+ {
+ QPainter p(&px);
+ ui->lbl3->render(&p);
+ }
+ return px;
+}
+void Widget::setImage(const QImage& img)
+{
+ ui->lbl4->setPixmap(QPixmap::fromImage(img));
+}
+
+QImage Widget::image() const
+{
+ QImage img(ui->lbl2->size(), QImage::Format_ARGB32);
+ {
+ QPainter p(&img);
+ ui->lbl2->render(&p);
+ }
+ return img;
+}
+
+QImage Widget::abcImage(int format)
+{
+ return abcFilledImage.convertToFormat(static_cast<QImage::Format>(format));
+}
+
+Widget::~Widget()
+{
+ delete ui;
+}
+
+void Widget::changeEvent(QEvent* e)
+{
+ QWidget::changeEvent(e);
+ switch (e->type()) {
+ case QEvent::LanguageChange:
+ ui->retranslateUi(this);
+ break;
+ default:
+ break;
+ }
+}
+void Widget::compare(const QVariant& a, const QVariant& b)
+{
+ QCOMPARE(a, b);
+}
+
+void Widget::imageSlot(const QImage& img)
+{
+ QCOMPARE(img.size(), ui->lbl3->size());
+ emit pixmapSignal(QPixmap::fromImage(img));
+}
+
+void Widget::pixmapSlot(const QPixmap& pxm)
+{
+ QCOMPARE(pxm.size(), ui->lbl2->size());
+ emit imageSignal(ui->lbl4->pixmap()->toImage());
+}
+
+void Widget::randomSlot(const QPixmap& pxm)
+{
+ QVERIFY(pxm.isNull());
+}
diff --git a/tests/webkitwidgets/hybridPixmap/widget.h b/tests/webkitwidgets/hybridPixmap/widget.h
new file mode 100644
index 000000000..b78df8b5e
--- /dev/null
+++ b/tests/webkitwidgets/hybridPixmap/widget.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef widget_h
+#define widget_h
+
+#include <QImage>
+#include <QPixmap>
+#include <QWidget>
+#include "qwebview.h"
+
+typedef QWebView WebView;
+
+QT_BEGIN_NAMESPACE
+namespace Ui {
+class Widget;
+}
+QT_END_NAMESPACE
+
+class Widget : public QWidget {
+ Q_OBJECT
+ Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
+ Q_PROPERTY(QImage image READ image WRITE setImage)
+
+public:
+ Widget(QWidget* parent = 0);
+ ~Widget();
+ void setPixmap(const QPixmap&);
+ QPixmap pixmap() const;
+ void setImage(const QImage&);
+ QImage image() const;
+
+private Q_SLOTS:
+ void refreshJS();
+
+public Q_SLOTS:
+ void completeTest();
+ void start();
+ void compare(const QVariant& a, const QVariant& b);
+ void imageSlot(const QImage&);
+ void pixmapSlot(const QPixmap&);
+ void randomSlot(const QPixmap&);
+ QImage abcImage(int format);
+
+Q_SIGNALS:
+ void testComplete();
+ void imageSignal(const QImage&);
+ void pixmapSignal(const QPixmap&);
+
+protected:
+ void changeEvent(QEvent* e);
+
+private:
+ Ui::Widget* ui;
+ QImage abcFilledImage;
+};
+
+#endif // widget_h
diff --git a/tests/webkitwidgets/hybridPixmap/widget.ui b/tests/webkitwidgets/hybridPixmap/widget.ui
new file mode 100644
index 000000000..272d6a71f
--- /dev/null
+++ b/tests/webkitwidgets/hybridPixmap/widget.ui
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Widget</class>
+ <widget class="QWidget" name="Widget">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>600</width>
+ <height>400</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string notr="true">Widget</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="WebView" name="webView" native="true">
+ <property name="url" stdset="0">
+ <url>
+ <string notr="true">about:blank</string>
+ </url>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="lbl1">
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="lbl2">
+ <property name="minimumSize">
+ <size>
+ <width>120</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="maximumSize">
+ <size>
+ <width>120</width>
+ <height>30</height>
+ </size>
+ </property>
+ <property name="text">
+ <string notr="true">Image from Qt to HTML</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="lbl3">
+ <property name="text">
+ <string notr="true">Pixmap from Qt to HTML</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="lbl4">
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>WebView</class>
+ <extends>QWidget</extends>
+ <header>widget.h</header>
+ </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>