From 8634d204153e1c3e520c7f886d4250237434a64c Mon Sep 17 00:00:00 2001 From: "benjamin.poulain@nokia.com" Date: Tue, 1 Mar 2011 00:57:09 +0000 Subject: [PATCH] 2011-02-28 Benjamin Poulain Reviewed by Kenneth Rohde Christiansen. [Qt][WK2] Add a way to test the WebKit 2 APIs https://bugs.webkit.org/show_bug.cgi?id=55408 Add the build file for test to the build system. * Source/WebKit.pri: Add the include path for WebKit 2 APIs. * Source/WebKit.pro: Add the dependency to build the new test project. 2011-02-28 Benjamin Poulain Reviewed by Kenneth Rohde Christiansen. [Qt][WK2] Add a way to test the WebKit 2 APIs https://bugs.webkit.org/show_bug.cgi?id=55408 Add an initial test for the WebKit 2 APIs of Qt. * UIProcess/API/qt/tests/html/basic_page.html: Added. * UIProcess/API/qt/tests/qgraphicswkview/qgraphicswkview.pro: Added. * UIProcess/API/qt/tests/qgraphicswkview/tst_qgraphicswkview.cpp: Added. (View::View): (View::resizeEvent): (tst_QGraphicsWKView::init): (tst_QGraphicsWKView::cleanup): (tst_QGraphicsWKView::loadEmptyPage): * UIProcess/API/qt/tests/tests.pri: Added. * UIProcess/API/qt/tests/tests.pro: Added. * UIProcess/API/qt/tests/util.h: Added. (waitForSignal): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@79945 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- ChangeLog | 12 +++ Source/WebKit.pri | 6 ++ Source/WebKit.pro | 5 +- Source/WebKit2/ChangeLog | 22 +++++ .../API/qt/tests/html/basic_page.html | 1 + .../tests/qgraphicswkview/qgraphicswkview.pro | 1 + .../qgraphicswkview/tst_qgraphicswkview.cpp | 93 +++++++++++++++++++ .../WebKit2/UIProcess/API/qt/tests/tests.pri | 16 ++++ .../WebKit2/UIProcess/API/qt/tests/tests.pro | 2 + Source/WebKit2/UIProcess/API/qt/tests/util.h | 78 ++++++++++++++++ 10 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 Source/WebKit2/UIProcess/API/qt/tests/html/basic_page.html create mode 100644 Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/qgraphicswkview.pro create mode 100644 Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/tst_qgraphicswkview.cpp create mode 100644 Source/WebKit2/UIProcess/API/qt/tests/tests.pri create mode 100644 Source/WebKit2/UIProcess/API/qt/tests/tests.pro create mode 100644 Source/WebKit2/UIProcess/API/qt/tests/util.h diff --git a/ChangeLog b/ChangeLog index 99757e9d7c78..6f51843df541 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-02-28 Benjamin Poulain + + Reviewed by Kenneth Rohde Christiansen. + + [Qt][WK2] Add a way to test the WebKit 2 APIs + https://bugs.webkit.org/show_bug.cgi?id=55408 + + Add the build file for test to the build system. + + * Source/WebKit.pri: Add the include path for WebKit 2 APIs. + * Source/WebKit.pro: Add the dependency to build the new test project. + 2011-02-28 Balazs Kelemen Reviewed by Anders Carlsson. diff --git a/Source/WebKit.pri b/Source/WebKit.pri index 11d93336f2d6..3f0fa26c3363 100644 --- a/Source/WebKit.pri +++ b/Source/WebKit.pri @@ -56,6 +56,12 @@ INCLUDEPATH += \ $$OUTPUT_DIR/include INCLUDEPATH += $$QT.script.includes +webkit2 { + INCLUDEPATH += $$OUTPUT_DIR/include/WebKit2 + # FIXME: Once the public header are well defined for WebKit2, this must go away. + INCLUDEPATH += $$PWD/WebKit2/ +} + CONFIG -= warn_on *-g++*:QMAKE_CXXFLAGS += -Wall -Wextra -Wreturn-type -fno-strict-aliasing -Wcast-align -Wchar-subscripts -Wformat-security -Wreturn-type -Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-switch-enum -Wundef -Wmissing-noreturn -Winit-self diff --git a/Source/WebKit.pro b/Source/WebKit.pro index 10bd8cfa4484..063ded7a851d 100644 --- a/Source/WebKit.pro +++ b/Source/WebKit.pro @@ -13,7 +13,10 @@ webkit2:exists($$PWD/WebKit2/WebKit2.pro): SUBDIRS += WebKit2/WebKit2.pro SUBDIRS += WebCore SUBDIRS += WebKit/qt/QtWebKit.pro -webkit2:exists($$PWD/WebKit2/WebProcess.pro): SUBDIRS += WebKit2/WebProcess.pro +webkit2 { + exists($$PWD/WebKit2/WebProcess.pro): SUBDIRS += WebKit2/WebProcess.pro + exists($$PWD/WebKit2/UIProcess/API/qt/tests): SUBDIRS += WebKit2/UIProcess/API/qt/tests +} contains(QT_CONFIG, declarative) { exists($$PWD/WebKit/qt/declarative): SUBDIRS += WebKit/qt/declarative diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index f82c75595d22..f0034a53db70 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,25 @@ +2011-02-28 Benjamin Poulain + + Reviewed by Kenneth Rohde Christiansen. + + [Qt][WK2] Add a way to test the WebKit 2 APIs + https://bugs.webkit.org/show_bug.cgi?id=55408 + + Add an initial test for the WebKit 2 APIs of Qt. + + * UIProcess/API/qt/tests/html/basic_page.html: Added. + * UIProcess/API/qt/tests/qgraphicswkview/qgraphicswkview.pro: Added. + * UIProcess/API/qt/tests/qgraphicswkview/tst_qgraphicswkview.cpp: Added. + (View::View): + (View::resizeEvent): + (tst_QGraphicsWKView::init): + (tst_QGraphicsWKView::cleanup): + (tst_QGraphicsWKView::loadEmptyPage): + * UIProcess/API/qt/tests/tests.pri: Added. + * UIProcess/API/qt/tests/tests.pro: Added. + * UIProcess/API/qt/tests/util.h: Added. + (waitForSignal): + 2011-02-28 Anders Carlsson Fix clang build. diff --git a/Source/WebKit2/UIProcess/API/qt/tests/html/basic_page.html b/Source/WebKit2/UIProcess/API/qt/tests/html/basic_page.html new file mode 100644 index 000000000000..b4eea41bdbef --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/html/basic_page.html @@ -0,0 +1 @@ +

Basic page

diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/qgraphicswkview.pro b/Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/qgraphicswkview.pro new file mode 100644 index 000000000000..e99c7f4938cb --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/qgraphicswkview.pro @@ -0,0 +1 @@ +include(../tests.pri) diff --git a/Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/tst_qgraphicswkview.cpp b/Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/tst_qgraphicswkview.cpp new file mode 100644 index 000000000000..f26c69d541c6 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/tst_qgraphicswkview.cpp @@ -0,0 +1,93 @@ +/* + Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "../util.h" +#include +#include +#include +#include +#include +#include +#include + +class View; + +class tst_QGraphicsWKView : public QObject { + Q_OBJECT + +private slots: + void init(); + void cleanup(); + + void loadEmptyPage(); + +private: + View* m_view; +}; + +class View : public QGraphicsView { +public: + View(); + QGraphicsWKView* m_webView; + +protected: + void resizeEvent(QResizeEvent*); +}; + +View::View() +{ + QGraphicsScene* const scene = new QGraphicsScene(this); + setScene(scene); + + QWKContext* context = new QWKContext(this); + m_webView = new QGraphicsWKView(context); + scene->addItem(m_webView); +} + +void View::resizeEvent(QResizeEvent* event) +{ + QGraphicsView::resizeEvent(event); + QRectF rect(QPoint(0, 0), event->size()); + m_webView->setGeometry(rect); + scene()->setSceneRect(rect); +} + +void tst_QGraphicsWKView::init() +{ + m_view = new View; +} + +void tst_QGraphicsWKView::cleanup() +{ + delete m_view; + m_view = 0; +} + +void tst_QGraphicsWKView::loadEmptyPage() +{ + m_view->show(); + + m_view->m_webView-> load(QUrl::fromLocalFile(TESTDIR "/html/basic_page.html")); + QVERIFY(waitForSignal(m_view->m_webView, SIGNAL(loadFinished(bool)))); +} + +QTEST_MAIN(tst_QGraphicsWKView) + +#include "tst_qgraphicswkview.moc" + diff --git a/Source/WebKit2/UIProcess/API/qt/tests/tests.pri b/Source/WebKit2/UIProcess/API/qt/tests/tests.pri new file mode 100644 index 000000000000..3a2aac15a3e1 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/tests.pri @@ -0,0 +1,16 @@ +TEMPLATE = app +CONFIG -= app_bundle + +VPATH += $$_PRO_FILE_PWD_ +# Add the tst_ prefix, In QTDIR_build it's done by qttest_p4.prf +CONFIG(QTDIR_build) { load(qttest_p4) } +ELSE { TARGET = tst_$$TARGET } + +SOURCES += $${TARGET}.cpp +INCLUDEPATH += $$PWD + +include(../../../../../WebKit.pri) +QT += testlib + +QMAKE_RPATHDIR = $$OUTPUT_DIR/lib $$QMAKE_RPATHDIR +DEFINES += TESTDIR=\\\"$$PWD\\\" diff --git a/Source/WebKit2/UIProcess/API/qt/tests/tests.pro b/Source/WebKit2/UIProcess/API/qt/tests/tests.pro new file mode 100644 index 000000000000..eb850215182e --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/tests.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS = qgraphicswkview diff --git a/Source/WebKit2/UIProcess/API/qt/tests/util.h b/Source/WebKit2/UIProcess/API/qt/tests/util.h new file mode 100644 index 000000000000..08d23a97c913 --- /dev/null +++ b/Source/WebKit2/UIProcess/API/qt/tests/util.h @@ -0,0 +1,78 @@ +/* + Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +// Functions and macros that really need to be in QTestLib + +#include +#include +#include + +#if !defined(TESTS_SOURCE_DIR) +#define TESTS_SOURCE_DIR "" +#endif + +/** + * Starts an event loop that runs until the given signal is received. + * Optionally the event loop + * can return earlier on a timeout. + * + * \return \p true if the requested signal was received + * \p false on timeout + */ +static bool waitForSignal(QObject* obj, const char* signal, int timeout = 10000) +{ + QEventLoop loop; + QObject::connect(obj, signal, &loop, SLOT(quit())); + QTimer timer; + QSignalSpy timeoutSpy(&timer, SIGNAL(timeout())); + if (timeout > 0) { + QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + timer.setSingleShot(true); + timer.start(timeout); + } + loop.exec(); + return timeoutSpy.isEmpty(); +} + +// Will try to wait for the condition while allowing event processing +#define QTRY_VERIFY(__expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QVERIFY(__expr); \ + } while(0) + +// Will try to wait for the condition while allowing event processing +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) -- 2.36.0