Home | History | Annotate | Download | only in qgraphicswkview
      1 /*
      2     Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
      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 <QGraphicsScene>
     22 #include <QGraphicsView>
     23 #include <QResizeEvent>
     24 #include <QSignalSpy>
     25 #include <QtTest/QtTest>
     26 #include <qgraphicswkview.h>
     27 #include <qwkcontext.h>
     28 
     29 class View;
     30 
     31 class tst_QGraphicsWKView : public QObject {
     32     Q_OBJECT
     33 
     34 private slots:
     35     void init();
     36     void cleanup();
     37 
     38     void loadEmptyUrl();
     39     void loadEmptyPage();
     40 
     41 private:
     42     View* m_view;
     43 };
     44 
     45 class View : public QGraphicsView {
     46 public:
     47     View();
     48     QGraphicsWKView* m_webView;
     49 
     50 protected:
     51     void resizeEvent(QResizeEvent*);
     52 };
     53 
     54 View::View()
     55 {
     56     QGraphicsScene* const scene = new QGraphicsScene(this);
     57     setScene(scene);
     58 
     59     QWKContext* context = new QWKContext(this);
     60     m_webView = new QGraphicsWKView(context);
     61     scene->addItem(m_webView);
     62 }
     63 
     64 void View::resizeEvent(QResizeEvent* event)
     65 {
     66     QGraphicsView::resizeEvent(event);
     67     QRectF rect(QPoint(0, 0), event->size());
     68     m_webView->setGeometry(rect);
     69     scene()->setSceneRect(rect);
     70 }
     71 
     72 void tst_QGraphicsWKView::init()
     73 {
     74     m_view = new View;
     75 }
     76 
     77 void tst_QGraphicsWKView::cleanup()
     78 {
     79     delete m_view;
     80     m_view = 0;
     81 }
     82 
     83 void tst_QGraphicsWKView::loadEmptyPage()
     84 {
     85     m_view->show();
     86 
     87     m_view->m_webView-> load(QUrl::fromLocalFile(QLatin1String(TESTS_SOURCE_DIR "/html/basic_page.html")));
     88     QVERIFY(waitForSignal(m_view->m_webView, SIGNAL(loadFinished(bool))));
     89 }
     90 
     91 void tst_QGraphicsWKView::loadEmptyUrl()
     92 {
     93     // That should not crash.
     94     m_view->show();
     95     m_view->m_webView->load(QUrl());
     96     QVERIFY(!waitForSignal(m_view->m_webView->page(), SIGNAL(engineConnectionChanged(bool)), 50));
     97 
     98     m_view->m_webView->load(QUrl(QLatin1String("")));
     99     QVERIFY(!waitForSignal(m_view->m_webView->page(), SIGNAL(engineConnectionChanged(bool)), 50));
    100 }
    101 
    102 QTEST_MAIN(tst_QGraphicsWKView)
    103 
    104 #include "tst_qgraphicswkview.moc"
    105 
    106