1/* 2 * Copyright (C) 2009 Holger Hans Peter Freyther 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20#ifndef QT_NO_BEARERMANAGEMENT 21#include <QNetworkConfigurationManager> 22#endif 23 24#include <QtTest/QtTest> 25 26#include <qwebelement.h> 27#include <qwebframe.h> 28#include <qwebview.h> 29#include <qpainter.h> 30 31#include "util.h" 32 33class tst_Painting : public QObject 34{ 35 Q_OBJECT 36 37public: 38 39public Q_SLOTS: 40 void init(); 41 void cleanup(); 42 43private Q_SLOTS: 44 void paint_data(); 45 void paint(); 46 void textAreas(); 47 48private: 49#ifndef QT_NO_BEARERMANAGEMENT 50 QNetworkConfigurationManager m_manager; 51#endif 52 QWebView* m_view; 53 QWebPage* m_page; 54}; 55 56void tst_Painting::init() 57{ 58 m_view = new QWebView; 59 m_page = m_view->page(); 60 61 QSize viewportSize(1024, 768); 62 m_view->setFixedSize(viewportSize); 63 m_page->setViewportSize(viewportSize); 64} 65 66void tst_Painting::cleanup() 67{ 68 delete m_view; 69} 70 71void tst_Painting::paint_data() 72{ 73 QTest::addColumn<QUrl>("url"); 74 QTest::newRow("amazon") << QUrl("http://www.amazon.com"); 75} 76 77void tst_Painting::paint() 78{ 79 QFETCH(QUrl, url); 80 81#ifndef QT_NO_BEARERMANAGEMENT 82 if (!m_manager.isOnline()) 83 W_QSKIP("This test requires an active network connection", SkipSingle); 84#endif 85 86 m_view->load(url); 87 ::waitForSignal(m_view, SIGNAL(loadFinished(bool)), 0); 88 89 /* force a layout */ 90 QWebFrame* mainFrame = m_page->mainFrame(); 91 mainFrame->toPlainText(); 92 93 QPixmap pixmap(m_page->viewportSize()); 94 QBENCHMARK { 95 QPainter painter(&pixmap); 96 mainFrame->render(&painter, QRect(QPoint(0, 0), m_page->viewportSize())); 97 painter.end(); 98 } 99} 100 101void tst_Painting::textAreas() 102{ 103 m_view->load(QUrl("data:text/html;<html><body></body></html>")); 104 ::waitForSignal(m_view, SIGNAL(loadFinished(bool)), 0); 105 106 QWebElement bodyElement = m_page->mainFrame()->findFirstElement("body"); 107 108 int count = 100; 109 while (count--) { 110 QString markup("<textarea cols='1' rows='1'></textarea>"); 111 bodyElement.appendInside(markup); 112 } 113 114 /* force a layout */ 115 QWebFrame* mainFrame = m_page->mainFrame(); 116 mainFrame->toPlainText(); 117 118 QPixmap pixmap(mainFrame->contentsSize()); 119 QBENCHMARK { 120 QPainter painter(&pixmap); 121 mainFrame->render(&painter, QRect(QPoint(0, 0), mainFrame->contentsSize())); 122 painter.end(); 123 } 124} 125 126QTEST_MAIN(tst_Painting) 127#include "tst_painting.moc" 128