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 #include <QtTest/QtTest>
21
22 #include <qwebframe.h>
23 #include <qwebview.h>
24 #include <qpainter.h>
25
26 /**
27 * Starts an event loop that runs until the given signal is received.
28 Optionally the event loop
29 * can return earlier on a timeout.
30 *
31 * \return \p true if the requested signal was received
32 * \p false on timeout
33 */
waitForSignal(QObject * obj,const char * signal,int timeout=0)34 static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0)
35 {
36 QEventLoop loop;
37 QObject::connect(obj, signal, &loop, SLOT(quit()));
38 QTimer timer;
39 QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
40 if (timeout > 0) {
41 QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
42 timer.setSingleShot(true);
43 timer.start(timeout);
44 }
45 loop.exec();
46 return timeoutSpy.isEmpty();
47 }
48
49 class tst_Loading : public QObject
50 {
51 Q_OBJECT
52
53 public:
54
55 public Q_SLOTS:
56 void init();
57 void cleanup();
58
59 private Q_SLOTS:
60 void load_data();
61 void load();
62
63 private:
64 QWebView* m_view;
65 QWebPage* m_page;
66 };
67
init()68 void tst_Loading::init()
69 {
70 m_view = new QWebView;
71 m_page = m_view->page();
72
73 QSize viewportSize(1024, 768);
74 m_view->setFixedSize(viewportSize);
75 m_page->setViewportSize(viewportSize);
76 }
77
cleanup()78 void tst_Loading::cleanup()
79 {
80 delete m_view;
81 }
82
load_data()83 void tst_Loading::load_data()
84 {
85 QTest::addColumn<QUrl>("url");
86 QTest::newRow("amazon") << QUrl("http://www.amazon.com");
87 QTest::newRow("kde") << QUrl("http://www.kde.org");
88 QTest::newRow("apple") << QUrl("http://www.apple.com");
89 }
90
load()91 void tst_Loading::load()
92 {
93 QFETCH(QUrl, url);
94
95
96 QBENCHMARK {
97 m_view->load(url);
98
99 // really wait for loading, painting is in another test
100 ::waitForSignal(m_view, SIGNAL(loadFinished(bool)));
101 }
102 }
103
104 QTEST_MAIN(tst_Loading)
105 #include "tst_loading.moc"
106