summaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qmlgraphicswebview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qmlgraphicswebview')
-rw-r--r--tests/auto/declarative/qmlgraphicswebview/data/pixelCache.html10
-rw-r--r--tests/auto/declarative/qmlgraphicswebview/data/pixelCache.qml8
-rw-r--r--tests/auto/declarative/qmlgraphicswebview/qmlgraphicswebview.pro3
-rw-r--r--tests/auto/declarative/qmlgraphicswebview/testtypes.cpp49
-rw-r--r--tests/auto/declarative/qmlgraphicswebview/testtypes.h64
-rw-r--r--tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp31
6 files changed, 164 insertions, 1 deletions
diff --git a/tests/auto/declarative/qmlgraphicswebview/data/pixelCache.html b/tests/auto/declarative/qmlgraphicswebview/data/pixelCache.html
new file mode 100644
index 0000000..bf059b9
--- /dev/null
+++ b/tests/auto/declarative/qmlgraphicswebview/data/pixelCache.html
@@ -0,0 +1,10 @@
+<html>
+<body topmargin=0 leftmargin=0>
+<table width=120>
+<tr><td>
+<h1>Pixel Cache</h1>
+This test is for the pixel cache. Because this is a long document,
+as it scrolls, more of the document will need to be rendered.
+If the pixelCacheSize is small, the first parts of the document will
+no longer be in the cache when it returns.
+</table>
diff --git a/tests/auto/declarative/qmlgraphicswebview/data/pixelCache.qml b/tests/auto/declarative/qmlgraphicswebview/data/pixelCache.qml
new file mode 100644
index 0000000..3467c65
--- /dev/null
+++ b/tests/auto/declarative/qmlgraphicswebview/data/pixelCache.qml
@@ -0,0 +1,8 @@
+import Test 1.0
+
+MyWebView {
+ width: 100
+ height: 100
+ anchors.fill: parent
+ url: "pixelCache.html"
+}
diff --git a/tests/auto/declarative/qmlgraphicswebview/qmlgraphicswebview.pro b/tests/auto/declarative/qmlgraphicswebview/qmlgraphicswebview.pro
index cce3df2..c81912b 100644
--- a/tests/auto/declarative/qmlgraphicswebview/qmlgraphicswebview.pro
+++ b/tests/auto/declarative/qmlgraphicswebview/qmlgraphicswebview.pro
@@ -2,7 +2,8 @@ load(qttest_p4)
contains(QT_CONFIG,declarative): QT += declarative
macx:CONFIG -= app_bundle
-SOURCES += tst_qmlgraphicswebview.cpp
+SOURCES += tst_qmlgraphicswebview.cpp testtypes.cpp
+HEADERS += testtypes.h
# Define SRCDIR equal to test's source directory
DEFINES += SRCDIR=\\\"$$PWD\\\"
diff --git a/tests/auto/declarative/qmlgraphicswebview/testtypes.cpp b/tests/auto/declarative/qmlgraphicswebview/testtypes.cpp
new file mode 100644
index 0000000..e21f286
--- /dev/null
+++ b/tests/auto/declarative/qmlgraphicswebview/testtypes.cpp
@@ -0,0 +1,49 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include "testtypes.h"
+
+void MyWebView::drawContents(QPainter *p, const QRect &r)
+{
+ pp += r.width()*r.height();
+ QmlGraphicsWebView::drawContents(p,r);
+}
+
+QML_DEFINE_TYPE(Test,1,0,MyWebView,MyWebView);
diff --git a/tests/auto/declarative/qmlgraphicswebview/testtypes.h b/tests/auto/declarative/qmlgraphicswebview/testtypes.h
new file mode 100644
index 0000000..7ab7c78
--- /dev/null
+++ b/tests/auto/declarative/qmlgraphicswebview/testtypes.h
@@ -0,0 +1,64 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef TESTTYPES_H
+#define TESTTYPES_H
+
+#include <private/qmlgraphicswebview_p.h>
+
+class MyWebView : public QmlGraphicsWebView
+{
+ Q_OBJECT
+ Q_PROPERTY(int pixelsPainted READ pixelsPainted);
+
+public:
+ MyWebView() : pp(0) {}
+
+ int pixelsPainted() const { return pp; }
+
+ void drawContents(QPainter *p, const QRect &r);
+
+private:
+ int pp;
+};
+
+QML_DECLARE_TYPE(MyWebView);
+
+#endif // TESTTYPES_H
diff --git a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp
index da43e68..543ba3f 100644
--- a/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp
+++ b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp
@@ -49,6 +49,8 @@
#include <QtWebKit/qwebframe.h>
#include <QtCore/qdir.h>
#include <QtCore/qfile.h>
+#include <QtGui/qpainter.h>
+#include "testtypes.h"
class tst_qmlgraphicswebview : public QObject
{
@@ -66,6 +68,7 @@ private slots:
void setHtml();
void javaScript();
void cleanupTestCase();
+ void pixelCache();
private:
void checkNoErrors(const QmlComponent& component);
@@ -140,6 +143,7 @@ void tst_qmlgraphicswebview::basicProperties()
QCOMPARE(strippedHtml(fileContents(SRCDIR "/data/basic.html")), strippedHtml(wv->html()));
QCOMPARE(wv->width(), 123.0);
QCOMPARE(wv->preferredWidth(), 0);
+ QCOMPARE(wv->preferredHeight(), 0);
QCOMPARE(wv->zoomFactor(), 1.0);
QCOMPARE(wv->url(), QUrl::fromLocalFile(SRCDIR "/data/basic.html"));
QCOMPARE(wv->status(), QmlGraphicsWebView::Ready);
@@ -353,6 +357,33 @@ void tst_qmlgraphicswebview::javaScript()
QCOMPARE(wv->evaluateJavaScript("window.myjsname.qmlprop").toString(), QString("qmlvalue"));
}
+void tst_qmlgraphicswebview::pixelCache()
+{
+ QmlComponent component(&engine, QUrl::fromLocalFile(SRCDIR "/data/pixelCache.qml"));
+ checkNoErrors(component);
+ MyWebView *wv = qobject_cast<MyWebView*>(component.create());
+ QVERIFY(wv != 0);
+ QTRY_COMPARE(wv->progress(), 1.0);
+ QPixmap pm(150,150);
+ QPainter p(&pm);
+ wv->paint(&p,0,0);
+ const int expected = 120*(150+128); // 120 = width of HTML page, 150=pixmap height, 128=cache extra area
+ QCOMPARE(wv->pixelsPainted(), expected);
+ wv->paint(&p,0,0);
+ QCOMPARE(wv->pixelsPainted(), expected); // nothing new needed to be painted
+ wv->setPixelCacheSize(0); // clears the cache
+ wv->paint(&p,0,0);
+ QCOMPARE(wv->pixelsPainted(), expected*2); // everything needed to be painted
+ // Note that painted things always go into the cache (even if they don't "fit"),
+ // just that they will be removed if anything else needs to be painted.
+ wv->setPixelCacheSize(expected); // won't clear the cache
+ wv->paint(&p,0,0);
+ QCOMPARE(wv->pixelsPainted(), expected*2); // still there
+ wv->setPixelCacheSize(expected-1); // too small - will clear the cache
+ wv->paint(&p,0,0);
+ QCOMPARE(wv->pixelsPainted(), expected*3); // repainted
+}
+
QTEST_MAIN(tst_qmlgraphicswebview)
#include "tst_qmlgraphicswebview.moc"