summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2009-11-20 07:06:19 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2009-11-20 07:06:19 (GMT)
commite71d967fc4698882fc9573d398f149610c3abb02 (patch)
tree258cabaa50d10f615b702125345a7a3bf4b2c77b
parent270ab71cc891b541f77176573c2db3e141aae938 (diff)
downloadQt-e71d967fc4698882fc9573d398f149610c3abb02.zip
Qt-e71d967fc4698882fc9573d398f149610c3abb02.tar.gz
Qt-e71d967fc4698882fc9573d398f149610c3abb02.tar.bz2
Test pixelCache.
-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/tst_qmlgraphicswebview.cpp30
4 files changed, 50 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/tst_qmlgraphicswebview.cpp b/tests/auto/declarative/qmlgraphicswebview/tst_qmlgraphicswebview.cpp
index da43e68..6bd28fb 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);
@@ -353,6 +356,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"