2 * Copyright (C) 2009 Holger Hans Peter Freyther
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.
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.
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.
20 #include <QtTest/QtTest>
22 #include <qwebelement.h>
23 #include <qwebframe.h>
28 * Starts an event loop that runs until the given signal is received.
29 Optionally the event loop
30 * can return earlier on a timeout.
32 * \return \p true if the requested signal was received
35 static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0)
38 QObject::connect(obj, signal, &loop, SLOT(quit()));
40 QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
42 QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
43 timer.setSingleShot(true);
47 return timeoutSpy.isEmpty();
50 class tst_Painting : public QObject
70 void tst_Painting::init()
72 m_view = new QWebView;
73 m_page = m_view->page();
75 QSize viewportSize(1024, 768);
76 m_view->setFixedSize(viewportSize);
77 m_page->setViewportSize(viewportSize);
80 void tst_Painting::cleanup()
85 void tst_Painting::paint_data()
87 QTest::addColumn<QUrl>("url");
88 QTest::newRow("amazon") << QUrl("http://www.amazon.com");
91 void tst_Painting::paint()
96 ::waitForSignal(m_view, SIGNAL(loadFinished(bool)));
99 QWebFrame* mainFrame = m_page->mainFrame();
100 mainFrame->toPlainText();
102 QPixmap pixmap(m_page->viewportSize());
104 QPainter painter(&pixmap);
105 mainFrame->render(&painter, QRect(QPoint(0, 0), m_page->viewportSize()));
110 void tst_Painting::textAreas()
112 m_view->load(QUrl("data:text/html;<html><body></body></html>"));
113 ::waitForSignal(m_view, SIGNAL(loadFinished(bool)));
115 QWebElement bodyElement = m_page->mainFrame()->findFirstElement("body");
119 QString markup("<textarea cols='1' rows='1'></textarea>");
120 bodyElement.appendInside(markup);
124 QWebFrame* mainFrame = m_page->mainFrame();
125 mainFrame->toPlainText();
127 QPixmap pixmap(mainFrame->contentsSize());
129 QPainter painter(&pixmap);
130 mainFrame->render(&painter, QRect(QPoint(0, 0), mainFrame->contentsSize()));
135 QTEST_MAIN(tst_Painting)
136 #include "tst_painting.moc"