From e71d967fc4698882fc9573d398f149610c3abb02 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Fri, 20 Nov 2009 17:06:19 +1000 Subject: Test pixelCache. --- .../qmlgraphicswebview/data/pixelCache.html | 10 ++++++++ .../qmlgraphicswebview/data/pixelCache.qml | 8 ++++++ .../qmlgraphicswebview/qmlgraphicswebview.pro | 3 ++- .../qmlgraphicswebview/tst_qmlgraphicswebview.cpp | 30 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qmlgraphicswebview/data/pixelCache.html create mode 100644 tests/auto/declarative/qmlgraphicswebview/data/pixelCache.qml 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 @@ + + + +
+

Pixel Cache

+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. +
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 #include #include +#include +#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(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" -- cgit v0.12