2011-02-28 Benjamin Poulain <benjamin.poulain@nokia.com>
authorbenjamin.poulain@nokia.com <benjamin.poulain@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Mar 2011 00:57:09 +0000 (00:57 +0000)
committerbenjamin.poulain@nokia.com <benjamin.poulain@nokia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Mar 2011 00:57:09 +0000 (00:57 +0000)
        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  <benjamin.poulain@nokia.com>

        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
Source/WebKit.pri
Source/WebKit.pro
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/qt/tests/html/basic_page.html [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/qgraphicswkview.pro [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/qgraphicswkview/tst_qgraphicswkview.cpp [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/tests.pri [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/tests.pro [new file with mode: 0644]
Source/WebKit2/UIProcess/API/qt/tests/util.h [new file with mode: 0644]

index 99757e9..6f51843 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2011-02-28  Benjamin Poulain  <benjamin.poulain@nokia.com>
+
+        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  <kbalazs@webkit.org>
 
         Reviewed by Anders Carlsson.
index 11d9333..3f0fa26 100644 (file)
@@ -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
 
index 10bd8cf..063ded7 100644 (file)
@@ -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
index f82c755..f0034a5 100644 (file)
@@ -1,3 +1,25 @@
+2011-02-28  Benjamin Poulain  <benjamin.poulain@nokia.com>
+
+        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  <andersca@apple.com>
 
         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 (file)
index 0000000..b4eea41
--- /dev/null
@@ -0,0 +1 @@
+<h1>Basic page</h1>
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 (file)
index 0000000..e99c7f4
--- /dev/null
@@ -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 (file)
index 0000000..f26c69d
--- /dev/null
@@ -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 <QGraphicsScene>
+#include <QGraphicsView>
+#include <QResizeEvent>
+#include <QSignalSpy>
+#include <QtTest/QtTest>
+#include <qgraphicswkview.h>
+#include <qwkcontext.h>
+
+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 (file)
index 0000000..3a2aac1
--- /dev/null
@@ -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 (file)
index 0000000..eb85021
--- /dev/null
@@ -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 (file)
index 0000000..08d23a9
--- /dev/null
@@ -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 <QEventLoop>
+#include <QSignalSpy>
+#include <QTimer>
+
+#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)