From a708a0e447af81412599ec16e8d47e06dc584eb0 Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Tue, 20 Apr 2010 16:43:10 +0200 Subject: New (empty) urlbar test and improved protocolhandler test --- src/tests/CMakeLists.txt | 14 ++++++- src/tests/networkaccessmanager_test.cpp | 2 +- src/tests/protocolhandler_test.cpp | 56 +++++++++++++++---------- src/tests/urlbar_test.cpp | 74 +++++++++++++++++++++++++++++++++ src/urlbar/urlbar.h | 3 +- 5 files changed, 125 insertions(+), 24 deletions(-) create mode 100644 src/tests/urlbar_test.cpp (limited to 'src') diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index e05a056b..3bc9a27f 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -7,7 +7,6 @@ INCLUDE_DIRECTORIES ( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../adblock ${CMAKE_CURRENT_SOURCE_DIR}/../bookmarks ${CMAKE_CURRENT_SOURCE_DIR}/../history - ${CMAKE_CURRENT_SOURCE_DIR}/../rekonqpage ${CMAKE_CURRENT_SOURCE_DIR}/../settings ${CMAKE_CURRENT_SOURCE_DIR}/../urlbar ${KDE4_INCLUDES} @@ -68,6 +67,7 @@ target_link_libraries( protocolhandler_test ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KDEWEBKIT_LIBS} + ${QT_QTNETWORK_LIBRARY} ${QT_QTTEST_LIBRARY} ) @@ -153,4 +153,16 @@ target_link_libraries( webview_test ${QT_QTTEST_LIBRARY} ) +##### ------------- urlbar test + +kde4_add_unit_test( urlbar_test urlbar_test.cpp ) + +target_link_libraries( urlbar_test + kdeinit_rekonq + ${KDE4_KDECORE_LIBS} + ${KDE4_KDEUI_LIBS} + ${KDE4_KDEWEBKIT_LIBS} + ${QT_QTTEST_LIBRARY} +) + ############################################################ diff --git a/src/tests/networkaccessmanager_test.cpp b/src/tests/networkaccessmanager_test.cpp index 68ffc108..ac6cf89e 100644 --- a/src/tests/networkaccessmanager_test.cpp +++ b/src/tests/networkaccessmanager_test.cpp @@ -47,7 +47,7 @@ private: void NetworkAccessManagerTest::initTestCase() { - manager = new NetworkAccessManager; + manager = new NetworkAccessManager(this); } diff --git a/src/tests/protocolhandler_test.cpp b/src/tests/protocolhandler_test.cpp index 71d8d9ec..a3c78c2f 100644 --- a/src/tests/protocolhandler_test.cpp +++ b/src/tests/protocolhandler_test.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "protocolhandler.h" @@ -69,45 +70,58 @@ void ProtocolhandlerTest::cleanupTestCase() void ProtocolhandlerTest::preHandling_data() { QTest::addColumn("urlString"); + QTest::addColumn("result"); - QTest::newRow("mailto") << "mailto:me@here.com"; - QTest::newRow("relative") << "google.it"; - QTest::newRow("javascript") << "javascript:alertbox('hello')"; - QTest::newRow("aboutblank") << "about:blank"; - QTest::newRow("abouthome") << "about:home"; - QTest::newRow("ftp") << "ftp://ftp.kde.org"; - QTest::newRow("file") << "file:///home"; + QTest::newRow("mailto") << "mailto:me@here.com" << true ; + QTest::newRow("relative") << "google.it" << false ; + QTest::newRow("javascript") << "javascript:alertbox('hello')" << true ; + QTest::newRow("aboutblank") << "about:blank" << false ; + QTest::newRow("abouthome") << "about:home" << true ; + QTest::newRow("ftp") << "ftp://ftp.kde.org" << false ; + QTest::newRow("file") << "file:///home" << false ; } void ProtocolhandlerTest::preHandling() { -// QFETCH( QString, urlString ); -// -// QWebView *view = new QWebView; -// QWebFrame *frame = view->page()->mainFrame(); -// -// QNetworkRequest *request = new QNetworkRequest( QUrl(urlString) ); -// handler->preHandling( request, frame ); + QFETCH( QString, urlString ); + QFETCH( bool , result ); + + QWebView *view = new QWebView; + QWebFrame *frame = view->page()->mainFrame(); + + QNetworkRequest request = QNetworkRequest( QUrl(urlString) ); + + QCOMPARE( handler->preHandling( request, frame ) , result ); } void ProtocolhandlerTest::postHandling_data() { QTest::addColumn("urlString"); + QTest::addColumn("result"); - QTest::newRow("mailto") << "mailto:me@here.com"; - QTest::newRow("relative") << "google.it"; - QTest::newRow("javascript") << "javascript:alertbox('hello')"; - QTest::newRow("aboutblank") << "about:blank"; - QTest::newRow("abouthome") << "about:home"; - QTest::newRow("ftp") << "ftp://ftp.kde.org"; - QTest::newRow("file") << "file:///home"; + QTest::newRow("mailto") << "mailto:me@here.com" << true ; + QTest::newRow("relative") << "google.it" << false ; + QTest::newRow("javascript") << "javascript:alertbox('hello')" << false ; + QTest::newRow("aboutblank") << "about:blank" << false ; + QTest::newRow("abouthome") << "about:home" << false ; + QTest::newRow("ftp") << "ftp://ftp.kde.org" << true ; + QTest::newRow("file") << "file:///home" << true ; } void ProtocolhandlerTest::postHandling() { + QFETCH( QString, urlString ); + QFETCH( bool , result ); + + QWebView *view = new QWebView; + QWebFrame *frame = view->page()->mainFrame(); + + QNetworkRequest request = QNetworkRequest( QUrl(urlString) ); + + QCOMPARE( handler->postHandling( request, frame ) , result ); } // ------------------------------------------- diff --git a/src/tests/urlbar_test.cpp b/src/tests/urlbar_test.cpp new file mode 100644 index 00000000..7a1fb40b --- /dev/null +++ b/src/tests/urlbar_test.cpp @@ -0,0 +1,74 @@ +/* + * Copyright 2010 Andrea Diamantini + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + + + +#include + +#include +#include +#include + +#include "webpage.h" +#include "webview.h" +#include "webtab.h" + +#include "urlbar.h" + + +class UrlBarTest : public QObject +{ + Q_OBJECT + +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + +private: + UrlBar *bar; + WebTab *tab; +}; + + +// ------------------------------------------- + +void UrlBarTest::initTestCase() +{ + tab = new WebTab; + bar = new UrlBar(tab); +} + + +void UrlBarTest::cleanupTestCase() +{ + delete bar; + delete tab; +} + + +// ------------------------------------------- + + + +// ------------------------------------------- + +QTEST_KDEMAIN(UrlBarTest,GUI) +#include "urlbar_test.moc" diff --git a/src/urlbar/urlbar.h b/src/urlbar/urlbar.h index 9adc35a3..28afc21e 100644 --- a/src/urlbar/urlbar.h +++ b/src/urlbar/urlbar.h @@ -32,6 +32,7 @@ // Local Includes +#include "rekonqprivate_export.h" #include "lineedit.h" #include "application.h" @@ -48,7 +49,7 @@ class CompletionWidget; class WebTab; -class UrlBar : public LineEdit +class REKONQ_TESTS_EXPORT UrlBar : public LineEdit { Q_OBJECT -- cgit v1.2.1