Disable the pagecache/cache to get more stable loading results
[qtwebkit:performance.git] / tests / cycler / tst_cycler.cpp
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 "common_init.h"
23
24 #include <qwebframe.h>
25 #include <qwebview.h>
26 #include <qpainter.h>
27
28 /**
29  * Starts an event loop that runs until the given signal is received.
30  Optionally the event loop
31  * can return earlier on a timeout.
32  *
33  * \return \p true if the requested signal was received
34  *         \p false on timeout
35  */
36 static bool waitForSignal(QObject* obj, const char* signal, int timeout = 0)
37 {
38     QEventLoop loop;
39     QObject::connect(obj, signal, &loop, SLOT(quit()));
40     QTimer timer;
41     QSignalSpy timeoutSpy(&timer, SIGNAL(timeout()));
42     if (timeout > 0) {
43         QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
44         timer.setSingleShot(true);
45         timer.start(timeout);
46     }
47     loop.exec();
48     return timeoutSpy.isEmpty();
49 }
50
51 class tst_Loading : public QObject
52 {
53     Q_OBJECT
54
55 public:
56
57 public Q_SLOTS:
58     void init();
59     void cleanup();
60
61 private Q_SLOTS:
62     void load();
63
64 private:
65     QWebView* m_view;
66     QWebPage* m_page;
67 };
68
69 void tst_Loading::init()
70 {
71     QWebSettings::globalSettings()->setMaximumPagesInCache(0);
72     QWebSettings::globalSettings()->setObjectCacheCapacities(0, 0, 0);
73
74     m_view = new QWebView;
75     m_page = m_view->page();
76
77     QSize viewportSize(1024, 768);
78     m_view->setFixedSize(viewportSize);
79     m_page->setViewportSize(viewportSize);
80
81     // this makes us different to the loading test...
82     m_view->show();
83 }
84
85 void tst_Loading::cleanup()
86 {
87     delete m_view;
88 }
89
90 void tst_Loading::load()
91 {
92     const QList<QUrl> urls = test_urls();
93
94     QBENCHMARK {
95         foreach(const QUrl& url, urls) {
96             m_view->load(url);
97             // really wait for loading..
98             ::waitForSignal(m_view, SIGNAL(loadFinished(bool)));
99         }
100
101         m_view->load(QUrl("about:blank"));
102         QWebSettings::clearMemoryCaches();
103     }
104 }
105
106 QTEST_MAIN(tst_Loading)
107 #include "tst_cycler.moc"