1 /* 2 Copyright (C) 2009 Jakub Wieczorek <faw217 (at) gmail.com> 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 "../util.h" 21 #include <QtTest/QtTest> 22 #include <QGraphicsView> 23 #include <qgraphicswebview.h> 24 #include <qwebpage.h> 25 #include <qwebframe.h> 26 27 class tst_QGraphicsWebView : public QObject 28 { 29 Q_OBJECT 30 31 private slots: 32 void qgraphicswebview(); 33 void crashOnViewlessWebPages(); 34 }; 35 36 void tst_QGraphicsWebView::qgraphicswebview() 37 { 38 QGraphicsWebView item; 39 item.url(); 40 item.title(); 41 item.icon(); 42 item.zoomFactor(); 43 item.history(); 44 item.settings(); 45 item.page(); 46 item.setPage(0); 47 item.page(); 48 item.setUrl(QUrl()); 49 item.setZoomFactor(0); 50 item.load(QUrl()); 51 item.setHtml(QString()); 52 item.setContent(QByteArray()); 53 item.isModified(); 54 } 55 56 class WebPage : public QWebPage 57 { 58 Q_OBJECT 59 60 public: 61 WebPage(QObject* parent = 0): QWebPage(parent) 62 { 63 } 64 65 QGraphicsWebView* webView; 66 67 private slots: 68 // Force a webview deletion during the load. 69 // It should not cause WebPage to crash due to 70 // it accessing invalid pageClient pointer. 71 void aborting() 72 { 73 delete webView; 74 } 75 }; 76 77 void tst_QGraphicsWebView::crashOnViewlessWebPages() 78 { 79 QGraphicsScene scene; 80 QGraphicsView view(&scene); 81 82 QGraphicsWebView* webView = new QGraphicsWebView; 83 WebPage* page = new WebPage; 84 webView->setPage(page); 85 page->webView = webView; 86 connect(page->mainFrame(), SIGNAL(initialLayoutCompleted()), page, SLOT(aborting())); 87 88 scene.addItem(webView); 89 90 view.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); 91 view.resize(600, 480); 92 webView->resize(view.geometry().size()); 93 QCoreApplication::processEvents(); 94 view.show(); 95 96 page->mainFrame()->setHtml(QString("data:text/html," 97 "<frameset cols=\"25%,75%\">" 98 "<frame src=\"data:text/html,foo \">" 99 "<frame src=\"data:text/html,bar\">" 100 "</frameset>")); 101 102 QVERIFY(waitForSignal(page, SIGNAL(loadFinished(bool)))); 103 } 104 105 QTEST_MAIN(tst_QGraphicsWebView) 106 107 #include "tst_qgraphicswebview.moc" 108