2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3 Copyright (C) 2009 Torch Mobile Inc.
4 Copyright (C) 2009 Girish Ramakrishnan <girish@forwardbias.in>
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
28 #include <qnetworkrequest.h>
29 #include <qdiriterator.h>
30 #include <qwebkitversion.h>
31 #include <qwebframe.h>
33 class tst_QWebView : public QObject
39 void cleanupTestCase();
45 void getWebKitVersion();
47 void reusePage_data();
53 // This will be called before the first test function is executed.
54 // It is only called once.
55 void tst_QWebView::initTestCase()
59 // This will be called after the last test function is executed.
60 // It is only called once.
61 void tst_QWebView::cleanupTestCase()
65 // This will be called before each test function is executed.
66 void tst_QWebView::init()
70 // This will be called after every test function.
71 void tst_QWebView::cleanup()
75 void tst_QWebView::renderHints()
79 // default is only text antialiasing
80 QVERIFY(!(webView.renderHints() & QPainter::Antialiasing));
81 QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
82 QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform));
83 QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));
85 webView.setRenderHint(QPainter::Antialiasing, true);
86 QVERIFY(webView.renderHints() & QPainter::Antialiasing);
87 QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
88 QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform));
89 QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));
91 webView.setRenderHint(QPainter::Antialiasing, false);
92 QVERIFY(!(webView.renderHints() & QPainter::Antialiasing));
93 QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
94 QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform));
95 QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));
97 webView.setRenderHint(QPainter::SmoothPixmapTransform, true);
98 QVERIFY(!(webView.renderHints() & QPainter::Antialiasing));
99 QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
100 QVERIFY(webView.renderHints() & QPainter::SmoothPixmapTransform);
101 QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));
103 webView.setRenderHint(QPainter::SmoothPixmapTransform, false);
104 QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
105 QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform));
106 QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));
109 void tst_QWebView::getWebKitVersion()
111 QVERIFY(qWebKitVersion().toDouble() > 0);
114 void tst_QWebView::reusePage_data()
116 QTest::addColumn<QString>("html");
117 QTest::newRow("WithoutPlugin") << "<html><body id='b'>text</body></html>";
118 QTest::newRow("WindowedPlugin") << QString("<html><body id='b'>text<embed src='resources/test.swf'></embed></body></html>");
119 QTest::newRow("WindowlessPlugin") << QString("<html><body id='b'>text<embed src='resources/test.swf' wmode=\"transparent\"></embed></body></html>");
122 void tst_QWebView::reusePage()
124 QDir::setCurrent(SRCDIR);
126 QFETCH(QString, html);
127 QWebView* view1 = new QWebView;
128 QPointer<QWebPage> page = new QWebPage;
129 view1->setPage(page);
130 page->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
131 QWebFrame* mainFrame = page->mainFrame();
132 mainFrame->setHtml(html, QUrl::fromLocalFile(QDir::currentPath()));
133 if (html.contains("</embed>")) {
134 // some reasonable time for the PluginStream to feed test.swf to flash and start painting
141 QVERIFY(page != 0); // deleting view must not have deleted the page, since it's not a child of view
143 QWebView *view2 = new QWebView;
144 view2->setPage(page);
145 view2->show(); // in Windowless mode, you should still be able to see the plugin here
149 delete page; // must not crash
151 QDir::setCurrent(QApplication::applicationDirPath());
154 // Class used in crashTests
155 class WebViewCrashTest : public QObject {
162 WebViewCrashTest(QWebView* view)
166 view->connect(view, SIGNAL(loadProgress(int)), this, SLOT(loading(int)));
170 void loading(int progress)
172 if (progress >= 20 && progress < 90) {
173 QVERIFY(!m_executed);
182 void tst_QWebView::crashTests()
184 // Test if loading can be stopped in loadProgress handler without crash.
185 // Test page should have frames.
187 WebViewCrashTest tester(&view);
188 QUrl url("qrc:///data/index.html");
190 QTRY_VERIFY(tester.m_executed); // If fail it means that the test wasn't executed.
194 QTEST_MAIN(tst_QWebView)
195 #include "tst_qwebview.moc"