diff options
Diffstat (limited to 'Source/WebKit/qt/tests')
17 files changed, 813 insertions, 9 deletions
diff --git a/Source/WebKit/qt/tests/benchmarks/webgl/10000_triangles.html b/Source/WebKit/qt/tests/benchmarks/webgl/10000_triangles.html new file mode 100644 index 0000000..fd061aa --- /dev/null +++ b/Source/WebKit/qt/tests/benchmarks/webgl/10000_triangles.html @@ -0,0 +1,59 @@ +<html> + <body style="margin: 0"> + <canvas width="1000" height="1000"></canvas> + </body> +</html> +<script> + var canvas = document.getElementsByTagName("canvas")[0]; + gl = canvas.getContext("experimental-webgl"); + gl.clearColor(0.0, 1.0, 0.0, 1.0); + gl.viewport(0, 0, canvas.width, canvas.height); + + var vertexShader = gl.createShader(gl.VERTEX_SHADER); + gl.shaderSource(vertexShader, "attribute vec4 vPosition;\nvoid main() { gl_Position = vPosition; }"); + gl.compileShader(vertexShader); + + var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); + gl.shaderSource(fragmentShader, "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }"); + gl.compileShader(fragmentShader); + + var shaderProgram = gl.createProgram(); + gl.attachShader(shaderProgram, vertexShader); + gl.attachShader(shaderProgram, fragmentShader); + gl.bindAttribLocation(shaderProgram, 0, "vPosition"); + gl.linkProgram(shaderProgram); + + gl.useProgram(shaderProgram); + + var buffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + + var vertices = []; + var seedX = -1.0; + var seedY = 1.0; + for (var i = 1; i <= 10000; ++i) { + vertices.push(seedX); + vertices.push(seedY); + vertices.push(0); + seedX += 0.01; + vertices.push(seedX); + vertices.push(seedY - 0.02); + vertices.push(0); + seedX += 0.01; + vertices.push(seedX); + vertices.push(seedY); + vertices.push(0); + if (!(i % 100)) { + seedX = -1.0; + seedY -= 0.02; + } + } + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); + + + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); + gl.enableVertexAttribArray(0); + gl.clear(gl.COLOR_BUFFER_BIT); + gl.drawArrays(gl.TRIANGLES, 0, 30000); + gl.flush(); +</script> diff --git a/Source/WebKit/qt/tests/benchmarks/webgl/tst_webgl.cpp b/Source/WebKit/qt/tests/benchmarks/webgl/tst_webgl.cpp new file mode 100644 index 0000000..bd865a2 --- /dev/null +++ b/Source/WebKit/qt/tests/benchmarks/webgl/tst_webgl.cpp @@ -0,0 +1,130 @@ +/* + Copyright (C) 2011 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 Library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#include "../../util.h" +#include <QGLWidget> +#include <QGraphicsView> +#include <QGraphicsWebView> +#include <QScopedPointer> +#include <QWebFrame> +#include <QtTest/QtTest> + +class GraphicsView; + +class tst_WebGlPerformance : public QObject { + Q_OBJECT + +private slots: + void init(); + void cleanup(); + + void benchSoftwareFallbackRgb16(); + void benchSoftwareFallbackRgb32(); + void benchSoftwareFallbackArgb32(); + void benchSoftwareFallbackArgb32Premultiplied(); + +private: + void benchmarkFrameRenderingOnImage(QImage::Format); + + QScopedPointer<GraphicsView> m_view; +}; + +class GraphicsView : public QGraphicsView { +public: + GraphicsView(); + QGraphicsWebView* m_webView; + +protected: + void resizeEvent(QResizeEvent*); +}; + +GraphicsView::GraphicsView() +{ + QGraphicsScene* const scene = new QGraphicsScene(this); + setScene(scene); + + m_webView = new QGraphicsWebView; + scene->addItem(m_webView); + + m_webView->page()->settings()->setAttribute(QWebSettings::WebGLEnabled, true); + + resize(800, 600); + setFrameShape(QFrame::NoFrame); + setViewport(new QGLWidget); +} + +void GraphicsView::resizeEvent(QResizeEvent* event) +{ + QGraphicsView::resizeEvent(event); + QRectF rect(QPoint(0, 0), event->size()); + m_webView->setGeometry(rect); + scene()->setSceneRect(rect); +} + +void tst_WebGlPerformance::init() +{ + m_view.reset(new GraphicsView); + m_view->showMaximized(); + QTest::qWaitForWindowShown(m_view.data()); +} + +void tst_WebGlPerformance::cleanup() +{ + m_view.reset(); +} + +void tst_WebGlPerformance::benchSoftwareFallbackRgb16() +{ + benchmarkFrameRenderingOnImage(QImage::Format_RGB16); +} + +void tst_WebGlPerformance::benchSoftwareFallbackRgb32() +{ + benchmarkFrameRenderingOnImage(QImage::Format_RGB32); +} + +void tst_WebGlPerformance::benchSoftwareFallbackArgb32() +{ + benchmarkFrameRenderingOnImage(QImage::Format_ARGB32); +} + +void tst_WebGlPerformance::benchSoftwareFallbackArgb32Premultiplied() +{ + benchmarkFrameRenderingOnImage(QImage::Format_ARGB32_Premultiplied); +} + +void tst_WebGlPerformance::benchmarkFrameRenderingOnImage(QImage::Format format) +{ + m_view->m_webView->load(QUrl(QLatin1String("qrc:///testcases/10000_triangles.html"))); + const bool pageLoaded = waitForSignal(m_view->m_webView, SIGNAL(loadFinished(bool))); + Q_ASSERT(pageLoaded); + Q_UNUSED(pageLoaded); + + QImage target(m_view->size(), format); + QBENCHMARK { + QPainter painter(&target); + m_view->render(&painter); + painter.end(); + } +} + +QTEST_MAIN(tst_WebGlPerformance) + +#include "tst_webgl.moc" diff --git a/Source/WebKit/qt/tests/benchmarks/webgl/tst_webgl.qrc b/Source/WebKit/qt/tests/benchmarks/webgl/tst_webgl.qrc new file mode 100644 index 0000000..b849448 --- /dev/null +++ b/Source/WebKit/qt/tests/benchmarks/webgl/tst_webgl.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/testcases"> + <file>10000_triangles.html</file> + </qresource> +</RCC> diff --git a/Source/WebKit/qt/tests/benchmarks/webgl/webgl.pro b/Source/WebKit/qt/tests/benchmarks/webgl/webgl.pro new file mode 100644 index 0000000..fb21bc8 --- /dev/null +++ b/Source/WebKit/qt/tests/benchmarks/webgl/webgl.pro @@ -0,0 +1,4 @@ +isEmpty(OUTPUT_DIR): OUTPUT_DIR = ../../../../.. +include(../../tests.pri) +exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc +QT += opengl diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml b/Source/WebKit/qt/tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml new file mode 100644 index 0000000..2edc794 --- /dev/null +++ b/Source/WebKit/qt/tests/qdeclarativewebview/resources/webviewbackgroundcolor.qml @@ -0,0 +1,10 @@ +import Qt 4.7 +import QtWebKit 1.1 + +WebView { + id: myweb + height: 300 + width: 300 + focus: true + backgroundColor : "red" +} diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp b/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp index 0025d6c..8fcab71 100644 --- a/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp +++ b/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.cpp @@ -1,4 +1,5 @@ #include "../util.h" +#include <QColor> #include <QDebug> #include <QDeclarativeComponent> #include <QDeclarativeEngine> @@ -22,6 +23,9 @@ private slots: void preferredHeightTest(); void preferredWidthDefaultTest(); void preferredHeightDefaultTest(); +#if QT_VERSION >= 0x040703 + void backgroundColor(); +#endif private: void checkNoErrors(const QDeclarativeComponent&); @@ -82,6 +86,36 @@ void tst_QDeclarativeWebView::preferredHeightDefaultTest() QCOMPARE(wv->property("prefHeight").toDouble(), view.preferredHeight()); } +#if QT_VERSION >= 0x040703 +void tst_QDeclarativeWebView::backgroundColor() +{ + // We test here the rendering of the background. + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, QUrl("qrc:///resources/webviewbackgroundcolor.qml")); + checkNoErrors(component); + QObject* wv = component.create(); + QVERIFY(wv); + QCOMPARE(wv->property("backgroundColor").value<QColor>(), QColor(Qt::red)); + QDeclarativeView view; + view.setSource(QUrl("qrc:///resources/webviewbackgroundcolor.qml")); + view.show(); + QTest::qWaitForWindowShown(&view); + QPixmap result(view.width(), view.height()); + QPainter painter(&result); + view.render(&painter); + QPixmap reference(view.width(), view.height()); + reference.fill(Qt::red); + QCOMPARE(reference, result); + + // We test the emission of the backgroundColorChanged signal. + QSignalSpy spyColorChanged(wv, SIGNAL(backgroundColorChanged())); + wv->setProperty("backgroundColor", Qt::red); + QCOMPARE(spyColorChanged.count(), 0); + wv->setProperty("backgroundColor", Qt::green); + QCOMPARE(spyColorChanged.count(), 1); +} +#endif + void tst_QDeclarativeWebView::checkNoErrors(const QDeclarativeComponent& component) { // Wait until the component is ready diff --git a/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc b/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc index 9c27409..e14c333 100644 --- a/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc +++ b/Source/WebKit/qt/tests/qdeclarativewebview/tst_qdeclarativewebview.qrc @@ -3,5 +3,6 @@ <file>resources/webviewtestdefault.qml</file> <file>resources/webviewtest.qml</file> <file>resources/sample.html</file> + <file>resources/webviewbackgroundcolor.qml</file> </qresource> </RCC> diff --git a/Source/WebKit/qt/tests/qgraphicswebview/qgraphicswebview.pro b/Source/WebKit/qt/tests/qgraphicswebview/qgraphicswebview.pro index e915d60..e5494ae 100644 --- a/Source/WebKit/qt/tests/qgraphicswebview/qgraphicswebview.pro +++ b/Source/WebKit/qt/tests/qgraphicswebview/qgraphicswebview.pro @@ -1,3 +1,6 @@ isEmpty(OUTPUT_DIR): OUTPUT_DIR = ../../../.. include(../tests.pri) exists($${TARGET}.qrc):RESOURCES += $${TARGET}.qrc +contains(DEFINES, ENABLE_WEBGL=1) { + QT += opengl +} diff --git a/Source/WebKit/qt/tests/qgraphicswebview/resources/pointing_right.html b/Source/WebKit/qt/tests/qgraphicswebview/resources/pointing_right.html new file mode 100644 index 0000000..bc592fb --- /dev/null +++ b/Source/WebKit/qt/tests/qgraphicswebview/resources/pointing_right.html @@ -0,0 +1,45 @@ +<html> + <body style="margin: 0"> + <canvas width="100" height="100"></canvas> + </body> +</html> +<script> + var canvas = document.getElementsByTagName("canvas")[0]; + gl = canvas.getContext("experimental-webgl"); + gl.clearColor(0.0, 1.0, 0.0, 1.0); + gl.viewport(0, 0, canvas.width, canvas.height); + + var vertexShader = gl.createShader(gl.VERTEX_SHADER); + gl.shaderSource(vertexShader, "attribute vec4 vPosition;\nvoid main() { gl_Position = vPosition; }"); + gl.compileShader(vertexShader); + + var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); + gl.shaderSource(fragmentShader, "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }"); + gl.compileShader(fragmentShader); + + var shaderProgram = gl.createProgram(); + gl.attachShader(shaderProgram, vertexShader); + gl.attachShader(shaderProgram, fragmentShader); + gl.bindAttribLocation(shaderProgram, 0, "vPosition"); + gl.linkProgram(shaderProgram); + + gl.useProgram(shaderProgram); + + var buffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + + var vertices = [-1.0, -1.0, + 0.0, 0.0, + -1.0, 1.0]; + var seedX = -1.0; + var seedY = 1.0; + vertices + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); + + + gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0); + gl.enableVertexAttribArray(0); + gl.clear(gl.COLOR_BUFFER_BIT); + gl.drawArrays(gl.TRIANGLES, 0, 3); + gl.flush(); +</script> diff --git a/Source/WebKit/qt/tests/qgraphicswebview/resources/pointing_up.html b/Source/WebKit/qt/tests/qgraphicswebview/resources/pointing_up.html new file mode 100644 index 0000000..474a56d --- /dev/null +++ b/Source/WebKit/qt/tests/qgraphicswebview/resources/pointing_up.html @@ -0,0 +1,46 @@ +<html> + <body style="margin: 0"> + <canvas width="100" height="100"></canvas> + </body> +</html> +<script> + var canvas = document.getElementsByTagName("canvas")[0]; + gl = canvas.getContext("experimental-webgl"); + gl.clearColor(0.0, 1.0, 0.0, 1.0); + gl.viewport(0, 0, canvas.width, canvas.height); + + var vertexShader = gl.createShader(gl.VERTEX_SHADER); + gl.shaderSource(vertexShader, "attribute vec4 vPosition;\nvoid main() { gl_Position = vPosition; }"); + gl.compileShader(vertexShader); + + var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER); + gl.shaderSource(fragmentShader, "void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }"); + gl.compileShader(fragmentShader); + + var shaderProgram = gl.createProgram(); + gl.attachShader(shaderProgram, vertexShader); + gl.attachShader(shaderProgram, fragmentShader); + gl.bindAttribLocation(shaderProgram, 0, "vPosition"); + gl.linkProgram(shaderProgram); + + gl.useProgram(shaderProgram); + + var buffer = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, buffer); + + var vertices = [-1.0, -1.0, + 0.0, 0.0, + 1.0, -1.0]; + var seedX = -1.0; + var seedY = 1.0; + vertices + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); + + + gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0); + gl.enableVertexAttribArray(0); + gl.clear(gl.COLOR_BUFFER_BIT); + gl.drawArrays(gl.TRIANGLES, 0, 3); + gl.flush(); + gl.finish(); +</script> diff --git a/Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp b/Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp index f8a4359..7cc88db 100644 --- a/Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp +++ b/Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.cpp @@ -25,6 +25,10 @@ #include <qwebpage.h> #include <qwebframe.h> +#if defined(ENABLE_WEBGL) && ENABLE_WEBGL +#include <QGLWidget> +#endif + class tst_QGraphicsWebView : public QObject { Q_OBJECT @@ -38,6 +42,15 @@ private slots: void widgetsRenderingThroughCache(); void setPalette_data(); void setPalette(); + void renderHints(); + +#if defined(ENABLE_WEBGL) && ENABLE_WEBGL + void webglSoftwareFallbackVerticalOrientation(); + void webglSoftwareFallbackHorizontalOrientation(); + +private: + void compareCanvasToImage(const QUrl&, const QImage&); +#endif }; void tst_QGraphicsWebView::qgraphicswebview() @@ -191,9 +204,9 @@ void tst_QGraphicsWebView::microFocusCoordinates() page->mainFrame()->setHtml("<html><body>" \ "<input type='text' id='input1' style='font--family: serif' value='' maxlength='20'/><br>" \ - "<canvas id='canvas1' width='500' height='500'/>" \ + "<canvas id='canvas1' width='500' height='500'></canvas>" \ "<input type='password'/><br>" \ - "<canvas id='canvas2' width='500' height='500'/>" \ + "<canvas id='canvas2' width='500' height='500'></canvas>" \ "</body></html>"); page->mainFrame()->setFocus(); @@ -409,6 +422,146 @@ void tst_QGraphicsWebView::setPalette() QVERIFY(img1 != img2); } +void tst_QGraphicsWebView::renderHints() +{ + QGraphicsWebView webView; + + // default is only text antialiasing + smooth pixmap transform + QVERIFY(!(webView.renderHints() & QPainter::Antialiasing)); + QVERIFY(webView.renderHints() & QPainter::TextAntialiasing); + QVERIFY(webView.renderHints() & QPainter::SmoothPixmapTransform); + QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing)); + + webView.setRenderHint(QPainter::Antialiasing, true); + QVERIFY(webView.renderHints() & QPainter::Antialiasing); + QVERIFY(webView.renderHints() & QPainter::TextAntialiasing); + QVERIFY(webView.renderHints() & QPainter::SmoothPixmapTransform); + QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing)); + + webView.setRenderHint(QPainter::Antialiasing, false); + QVERIFY(!(webView.renderHints() & QPainter::Antialiasing)); + QVERIFY(webView.renderHints() & QPainter::TextAntialiasing); + QVERIFY(webView.renderHints() & QPainter::SmoothPixmapTransform); + QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing)); + + webView.setRenderHint(QPainter::SmoothPixmapTransform, true); + QVERIFY(!(webView.renderHints() & QPainter::Antialiasing)); + QVERIFY(webView.renderHints() & QPainter::TextAntialiasing); + QVERIFY(webView.renderHints() & QPainter::SmoothPixmapTransform); + QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing)); + + webView.setRenderHint(QPainter::SmoothPixmapTransform, false); + QVERIFY(webView.renderHints() & QPainter::TextAntialiasing); + QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform)); + QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing)); +} + +class GraphicsView : public QGraphicsView { +public: + GraphicsView(); + QGraphicsWebView* m_webView; +}; + +#if defined(ENABLE_WEBGL) && ENABLE_WEBGL +bool compareImagesFuzzyPixelCount(const QImage& image1, const QImage& image2, qreal tolerance = 0.05) +{ + if (image1.size() != image2.size()) + return false; + + unsigned diffPixelCount = 0; + for (int row = 0; row < image1.size().width(); ++row) { + for (int column = 0; column < image1.size().height(); ++column) + if (image1.pixel(row, column) != image2.pixel(row, column)) + ++diffPixelCount; + } + + if (diffPixelCount > (image1.size().width() * image1.size().height()) * tolerance) + return false; + + return true; +} + +GraphicsView::GraphicsView() +{ + QGraphicsScene* const scene = new QGraphicsScene(this); + setScene(scene); + + m_webView = new QGraphicsWebView; + scene->addItem(m_webView); + + m_webView->page()->settings()->setAttribute(QWebSettings::WebGLEnabled, true); + m_webView->setResizesToContents(true); + + setFrameShape(QFrame::NoFrame); + setViewport(new QGLWidget); +} + +void tst_QGraphicsWebView::webglSoftwareFallbackVerticalOrientation() +{ + QSize canvasSize(100, 100); + QImage reference(canvasSize, QImage::Format_ARGB32); + reference.fill(0xFF00FF00); + { // Reference. + QPainter painter(&reference); + QPolygonF triangleUp; + triangleUp << QPointF(0, canvasSize.height()) + << QPointF(canvasSize.width(), canvasSize.height()) + << QPointF(canvasSize.width() / 2.0, canvasSize.height() / 2.0); + painter.setPen(Qt::NoPen); + painter.setBrush(Qt::red); + painter.drawPolygon(triangleUp); + } + + compareCanvasToImage(QUrl(QLatin1String("qrc:///resources/pointing_up.html")), reference); +} + +void tst_QGraphicsWebView::webglSoftwareFallbackHorizontalOrientation() +{ + QSize canvasSize(100, 100); + QImage reference(canvasSize, QImage::Format_ARGB32); + reference.fill(0xFF00FF00); + { // Reference. + QPainter painter(&reference); + QPolygonF triangleUp; + triangleUp << QPointF(0, 0) + << QPointF(0, canvasSize.height()) + << QPointF(canvasSize.width() / 2.0, canvasSize.height() / 2.0); + painter.setPen(Qt::NoPen); + painter.setBrush(Qt::red); + painter.drawPolygon(triangleUp); + } + + compareCanvasToImage(QUrl(QLatin1String("qrc:///resources/pointing_right.html")), reference); +} + +void tst_QGraphicsWebView::compareCanvasToImage(const QUrl& url, const QImage& reference) +{ + GraphicsView view; + view.show(); + QTest::qWaitForWindowShown(&view); + + QGraphicsWebView* const graphicsWebView = view.m_webView; + graphicsWebView->load(url); + QVERIFY(waitForSignal(graphicsWebView, SIGNAL(loadFinished(bool)))); + { // Force a render, to create the accelerated compositing tree. + QPixmap pixmap(view.size()); + QPainter painter(&pixmap); + view.render(&painter); + } + QApplication::syncX(); + + const QSize imageSize = reference.size(); + + QImage target(imageSize, QImage::Format_ARGB32); + { // Web page content. + QPainter painter(&target); + QRectF renderRect(0, 0, imageSize.width(), imageSize.height()); + view.scene()->render(&painter, renderRect, renderRect); + } + QVERIFY(compareImagesFuzzyPixelCount(target, reference, 0.01)); +} +#endif + QTEST_MAIN(tst_QGraphicsWebView) #include "tst_qgraphicswebview.moc" diff --git a/Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.qrc b/Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.qrc index c91bb9c..1488fcf 100644 --- a/Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.qrc +++ b/Source/WebKit/qt/tests/qgraphicswebview/tst_qgraphicswebview.qrc @@ -1,6 +1,7 @@ -<!DOCTYPE RCC><RCC version="1.0"> -<qresource> - <file>resources/input_types.html</file> -</qresource> +<RCC> + <qresource prefix="/"> + <file>resources/input_types.html</file> + <file>resources/pointing_right.html</file> + <file>resources/pointing_up.html</file> + </qresource> </RCC> - diff --git a/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp b/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp index bc1594a..2c44e4c 100644 --- a/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp +++ b/Source/WebKit/qt/tests/qwebframe/tst_qwebframe.cpp @@ -650,6 +650,9 @@ private slots: void setCacheLoadControlAttribute(); void setUrlWithPendingLoads(); void setUrlWithFragment(); + void setUrlToEmpty(); + void setUrlToInvalid(); + void setUrlHistory(); private: QString evalJS(const QString&s) { @@ -3340,5 +3343,148 @@ void tst_QWebFrame::setUrlWithFragment() QCOMPARE(page.mainFrame()->url(), url); } +void tst_QWebFrame::setUrlToEmpty() +{ + int expectedLoadFinishedCount = 0; + const QUrl aboutBlank("about:blank"); + const QUrl url("qrc:/test2.html"); + + QWebPage page; + QWebFrame* frame = page.mainFrame(); + QCOMPARE(frame->url(), QUrl()); + QCOMPARE(frame->requestedUrl(), QUrl()); + QCOMPARE(frame->baseUrl(), QUrl()); + + QSignalSpy spy(frame, SIGNAL(loadFinished(bool))); + + // Set existing url + frame->setUrl(url); + expectedLoadFinishedCount++; + ::waitForSignal(frame, SIGNAL(loadFinished(bool))); + + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), url); + QCOMPARE(frame->requestedUrl(), url); + QCOMPARE(frame->baseUrl(), url); + + // Set empty url + frame->setUrl(QUrl()); + expectedLoadFinishedCount++; + + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), aboutBlank); + QCOMPARE(frame->requestedUrl(), QUrl()); + QCOMPARE(frame->baseUrl(), aboutBlank); + + // Set existing url + frame->setUrl(url); + expectedLoadFinishedCount++; + ::waitForSignal(frame, SIGNAL(loadFinished(bool))); + + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), url); + QCOMPARE(frame->requestedUrl(), url); + QCOMPARE(frame->baseUrl(), url); + + // Load empty url + frame->load(QUrl()); + expectedLoadFinishedCount++; + + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), aboutBlank); + QCOMPARE(frame->requestedUrl(), QUrl()); + QCOMPARE(frame->baseUrl(), aboutBlank); +} + +void tst_QWebFrame::setUrlToInvalid() +{ + QWebPage page; + QWebFrame* frame = page.mainFrame(); + + const QUrl invalidUrl("http://strange;hostname/here"); + QVERIFY(!invalidUrl.isEmpty()); + QVERIFY(!invalidUrl.isValid()); + QVERIFY(invalidUrl != QUrl()); + + frame->setUrl(invalidUrl); + QCOMPARE(frame->url(), invalidUrl); + QCOMPARE(frame->requestedUrl(), invalidUrl); + QCOMPARE(frame->baseUrl(), invalidUrl); + + // QUrls equivalent to QUrl() will be treated as such. + const QUrl aboutBlank("about:blank"); + const QUrl anotherInvalidUrl("1http://bugs.webkit.org"); + QVERIFY(!anotherInvalidUrl.isEmpty()); // and they are not necessarily empty. + QVERIFY(!anotherInvalidUrl.isValid()); + QCOMPARE(anotherInvalidUrl, QUrl()); + + frame->setUrl(anotherInvalidUrl); + QCOMPARE(frame->url(), aboutBlank); + QCOMPARE(frame->requestedUrl(), anotherInvalidUrl); + QCOMPARE(frame->baseUrl(), aboutBlank); +} + +void tst_QWebFrame::setUrlHistory() +{ + const QUrl aboutBlank("about:blank"); + QUrl url; + int expectedLoadFinishedCount = 0; + QWebFrame* frame = m_page->mainFrame(); + QSignalSpy spy(frame, SIGNAL(loadFinished(bool))); + + QCOMPARE(m_page->history()->count(), 0); + + frame->setUrl(QUrl()); + expectedLoadFinishedCount++; + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), aboutBlank); + QCOMPARE(frame->requestedUrl(), QUrl()); + QCOMPARE(m_page->history()->count(), 0); + + url = QUrl("http://non.existant/"); + frame->setUrl(url); + ::waitForSignal(m_page, SIGNAL(loadFinished(bool))); + expectedLoadFinishedCount++; + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), url); + QCOMPARE(frame->requestedUrl(), url); + QCOMPARE(m_page->history()->count(), 0); + + url = QUrl("qrc:/test1.html"); + frame->setUrl(url); + ::waitForSignal(m_page, SIGNAL(loadFinished(bool))); + expectedLoadFinishedCount++; + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), url); + QCOMPARE(frame->requestedUrl(), url); + QCOMPARE(m_page->history()->count(), 1); + + frame->setUrl(QUrl()); + expectedLoadFinishedCount++; + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), aboutBlank); + QCOMPARE(frame->requestedUrl(), QUrl()); + QCOMPARE(m_page->history()->count(), 1); + + // Loading same page as current in history, so history count doesn't change. + url = QUrl("qrc:/test1.html"); + frame->setUrl(url); + ::waitForSignal(m_page, SIGNAL(loadFinished(bool))); + expectedLoadFinishedCount++; + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), url); + QCOMPARE(frame->requestedUrl(), url); + QCOMPARE(m_page->history()->count(), 1); + + url = QUrl("qrc:/test2.html"); + frame->setUrl(url); + ::waitForSignal(m_page, SIGNAL(loadFinished(bool))); + expectedLoadFinishedCount++; + QCOMPARE(spy.count(), expectedLoadFinishedCount); + QCOMPARE(frame->url(), url); + QCOMPARE(frame->requestedUrl(), url); + QCOMPARE(m_page->history()->count(), 2); +} + QTEST_MAIN(tst_QWebFrame) #include "tst_qwebframe.moc" diff --git a/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp b/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp index 4417ac5..d43b2de 100644 --- a/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp +++ b/Source/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp @@ -126,6 +126,11 @@ private slots: void screenshot_data(); void screenshot(); +#if defined(ENABLE_WEBGL) && ENABLE_WEBGL + void acceleratedWebGLScreenshotWithoutView(); + void unacceleratedWebGLScreenshotWithoutView(); +#endif + void originatingObjectInNetworkRequests(); void testJSPrompt(); void showModalDialog(); @@ -135,6 +140,7 @@ private slots: void infiniteLoopJS(); void navigatorCookieEnabled(); void deleteQWebViewTwice(); + void renderOnRepaintRequestedShouldNotRecurse(); #ifdef Q_OS_MAC void macCopyUnicodeToClipboard(); @@ -2117,6 +2123,28 @@ void tst_QWebPage::inputMethods() clickOnPage(page, inputElement.geometry().center()); QVERIFY(!viewEventSpy.contains(QEvent::RequestSoftwareInputPanel)); + + // START - Newline test for textarea + qApp->processEvents(); + page->mainFrame()->setHtml("<html><body>" \ + "<textarea rows='5' cols='1' id='input5' value=''/>" \ + "</body></html>"); + page->mainFrame()->evaluateJavaScript("var inputEle = document.getElementById('input5'); inputEle.focus(); inputEle.select();"); + QKeyEvent keyEnter(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier); + page->event(&keyEnter); + QList<QInputMethodEvent::Attribute> attribs; + + QInputMethodEvent eventText("\n", attribs); + page->event(&eventText); + + QInputMethodEvent eventText2("third line", attribs); + page->event(&eventText2); + qApp->processEvents(); + + QString inputValue2 = page->mainFrame()->evaluateJavaScript("document.getElementById('input5').value").toString(); + QCOMPARE(inputValue2, QString("\n\nthird line")); + // END - Newline test for textarea + delete container; } @@ -2473,6 +2501,33 @@ void tst_QWebPage::screenshot() QDir::setCurrent(QApplication::applicationDirPath()); } +#if defined(ENABLE_WEBGL) && ENABLE_WEBGL +// https://bugs.webkit.org/show_bug.cgi?id=54138 +static void webGLScreenshotWithoutView(bool accelerated) +{ + QWebPage page; + page.settings()->setAttribute(QWebSettings::WebGLEnabled, true); + page.settings()->setAttribute(QWebSettings::AcceleratedCompositingEnabled, accelerated); + QWebFrame* mainFrame = page.mainFrame(); + mainFrame->setHtml("<html><body>" + "<canvas id='webgl' width='300' height='300'></canvas>" + "<script>document.getElementById('webgl').getContext('experimental-webgl')</script>" + "</body></html>"); + + takeScreenshot(&page); +} + +void tst_QWebPage::acceleratedWebGLScreenshotWithoutView() +{ + webGLScreenshotWithoutView(true); +} + +void tst_QWebPage::unacceleratedWebGLScreenshotWithoutView() +{ + webGLScreenshotWithoutView(false); +} +#endif + void tst_QWebPage::originatingObjectInNetworkRequests() { TestNetworkManager* networkManager = new TestNetworkManager(m_page); @@ -2766,5 +2821,54 @@ void tst_QWebPage::deleteQWebViewTwice() } } +class RepaintRequestedRenderer : public QObject { + Q_OBJECT +public: + RepaintRequestedRenderer(QWebPage* page, QPainter* painter) + : m_page(page) + , m_painter(painter) + , m_recursionCount(0) + { + connect(m_page, SIGNAL(repaintRequested(QRect)), this, SLOT(onRepaintRequested(QRect))); + } + +signals: + void finished(); + +private slots: + void onRepaintRequested(const QRect& rect) + { + QCOMPARE(m_recursionCount, 0); + + m_recursionCount++; + m_page->mainFrame()->render(m_painter, rect); + m_recursionCount--; + + QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); + } + +private: + QWebPage* m_page; + QPainter* m_painter; + int m_recursionCount; +}; + +void tst_QWebPage::renderOnRepaintRequestedShouldNotRecurse() +{ + QSize viewportSize(720, 576); + QWebPage page; + + QImage image(viewportSize, QImage::Format_ARGB32); + QPainter painter(&image); + + page.setPreferredContentsSize(viewportSize); + page.setViewportSize(viewportSize); + RepaintRequestedRenderer r(&page, &painter); + + page.mainFrame()->setHtml("zalan loves trunk", QUrl()); + + QVERIFY(::waitForSignal(&r, SIGNAL(finished()))); +} + QTEST_MAIN(tst_QWebPage) #include "tst_qwebpage.moc" diff --git a/Source/WebKit/qt/tests/qwebview/tst_qwebview.cpp b/Source/WebKit/qt/tests/qwebview/tst_qwebview.cpp index 533d4e5..c7600fc 100644 --- a/Source/WebKit/qt/tests/qwebview/tst_qwebview.cpp +++ b/Source/WebKit/qt/tests/qwebview/tst_qwebview.cpp @@ -42,6 +42,7 @@ public slots: void cleanup(); private slots: + void renderingAfterMaxAndBack(); void renderHints(); void getWebKitVersion(); @@ -207,9 +208,9 @@ void tst_QWebView::microFocusCoordinates() page->mainFrame()->setHtml("<html><body>" \ "<input type='text' id='input1' style='font--family: serif' value='' maxlength='20'/><br>" \ - "<canvas id='canvas1' width='500' height='500'/>" \ + "<canvas id='canvas1' width='500' height='500'></canvas>" \ "<input type='password'/><br>" \ - "<canvas id='canvas2' width='500' height='500'/>" \ + "<canvas id='canvas2' width='500' height='500'></canvas>" \ "</body></html>"); page->mainFrame()->setFocus(); @@ -438,6 +439,63 @@ void tst_QWebView::setPalette() QVERIFY(img1 != img2); } +void tst_QWebView::renderingAfterMaxAndBack() +{ + QUrl url = QUrl("data:text/html,<html><head></head>" + "<body width=1024 height=768 bgcolor=red>" + "</body>" + "</html>"); + + QWebView view; + view.page()->mainFrame()->load(url); + QVERIFY(waitForSignal(&view, SIGNAL(loadFinished(bool)))); + view.show(); + + view.page()->settings()->setMaximumPagesInCache(3); + + QTest::qWaitForWindowShown(&view); + + QPixmap reference(view.page()->viewportSize()); + reference.fill(Qt::red); + + QPixmap image(view.page()->viewportSize()); + QPainter painter(&image); + view.page()->currentFrame()->render(&painter); + + QCOMPARE(image, reference); + + QUrl url2 = QUrl("data:text/html,<html><head></head>" + "<body width=1024 height=768 bgcolor=blue>" + "</body>" + "</html>"); + view.page()->mainFrame()->load(url2); + + QVERIFY(waitForSignal(&view, SIGNAL(loadFinished(bool)))); + + view.showMaximized(); + + QTest::qWaitForWindowShown(&view); + + QPixmap reference2(view.page()->viewportSize()); + reference2.fill(Qt::blue); + + QPixmap image2(view.page()->viewportSize()); + QPainter painter2(&image2); + view.page()->currentFrame()->render(&painter2); + + QCOMPARE(image2, reference2); + + view.back(); + + QPixmap reference3(view.page()->viewportSize()); + reference3.fill(Qt::red); + QPixmap image3(view.page()->viewportSize()); + QPainter painter3(&image3); + view.page()->currentFrame()->render(&painter3); + + QCOMPARE(image3, reference3); +} + QTEST_MAIN(tst_QWebView) #include "tst_qwebview.moc" diff --git a/Source/WebKit/qt/tests/tests.pri b/Source/WebKit/qt/tests/tests.pri index bb519eb..ebb6f8e 100644 --- a/Source/WebKit/qt/tests/tests.pri +++ b/Source/WebKit/qt/tests/tests.pri @@ -32,3 +32,5 @@ symbian { # This define is used by some tests to look up resources in the source tree !symbian: DEFINES += TESTS_SOURCE_DIR=\\\"$$PWD/\\\" +DEFINES -= QT_ASCII_CAST_WARNINGS + diff --git a/Source/WebKit/qt/tests/tests.pro b/Source/WebKit/qt/tests/tests.pro index e5b7408..529fa04 100644 --- a/Source/WebKit/qt/tests/tests.pro +++ b/Source/WebKit/qt/tests/tests.pro @@ -3,3 +3,6 @@ TEMPLATE = subdirs SUBDIRS = qwebframe qwebpage qwebelement qgraphicswebview qwebhistoryinterface qwebview qwebhistory qwebinspector hybridPixmap contains(QT_CONFIG, declarative): SUBDIRS += qdeclarativewebview SUBDIRS += benchmarks/painting benchmarks/loading +contains(DEFINES, ENABLE_WEBGL=1) { + SUBDIRS += benchmarks/webgl +} |