Title: [122512] trunk/Source/WebKit2
Revision
122512
Author
[email protected]
Date
2012-07-12 14:46:04 -0700 (Thu, 12 Jul 2012)

Log Message

[EFL] Port the test framework to WebKit 2
https://bugs.webkit.org/show_bug.cgi?id=90606

Patch by Thiago Marcos P. Santos <[email protected]> on 2012-07-12
Reviewed by Kenneth Rohde Christiansen.

This port of EFL's WebKit 1 test framework uses a more gtest-ish
way of writing tests and it is based on a test fixture that loads a
page synchronously as convenience (if needed). This base fixture can be
easily extended by just inheriting from it.

* PlatformEfl.cmake:
* UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp: Added.
(EWK2UnitTest):
(EWK2UnitTest::onLoadProgress):
(EWK2UnitTest::EWK2UnitTestBase::EWK2UnitTestBase):
(EWK2UnitTest::EWK2UnitTestBase::SetUp):
(EWK2UnitTest::EWK2UnitTestBase::TearDown):
(EWK2UnitTest::EWK2UnitTestBase::loadUrlSync):
* UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h: Added.
(EWK2UnitTest):
(EWK2UnitTestBase):
(EWK2UnitTest::EWK2UnitTestBase::setLoadProgress):
(EWK2UnitTest::EWK2UnitTestBase::webView):
* UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp: Added.
(EWK2UnitTest):
(EWK2UnitTest::EWK2UnitTestEnvironment::EWK2UnitTestEnvironment):
(EWK2UnitTest::EWK2UnitTestEnvironment::defaultTestPageUrl):
* UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h: Added.
(EWK2UnitTest):
(EWK2UnitTestEnvironment):
(EWK2UnitTest::EWK2UnitTestEnvironment::useX11Window):
(EWK2UnitTest::EWK2UnitTestEnvironment::defaultWidth):
(EWK2UnitTest::EWK2UnitTestEnvironment::defaultHeight):
* UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp: Added.
(parseArguments):
(main):
* UIProcess/API/efl/tests/resources/default_test_page.html: Added.
* UIProcess/API/efl/tests/test_ewk2_view.cpp: Added.
(TEST_F):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (122511 => 122512)


--- trunk/Source/WebKit2/ChangeLog	2012-07-12 21:42:31 UTC (rev 122511)
+++ trunk/Source/WebKit2/ChangeLog	2012-07-12 21:46:04 UTC (rev 122512)
@@ -1,3 +1,45 @@
+2012-07-12  Thiago Marcos P. Santos  <[email protected]>
+
+        [EFL] Port the test framework to WebKit 2
+        https://bugs.webkit.org/show_bug.cgi?id=90606
+
+        Reviewed by Kenneth Rohde Christiansen.
+
+        This port of EFL's WebKit 1 test framework uses a more gtest-ish
+        way of writing tests and it is based on a test fixture that loads a
+        page synchronously as convenience (if needed). This base fixture can be
+        easily extended by just inheriting from it.
+
+        * PlatformEfl.cmake:
+        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp: Added.
+        (EWK2UnitTest):
+        (EWK2UnitTest::onLoadProgress):
+        (EWK2UnitTest::EWK2UnitTestBase::EWK2UnitTestBase):
+        (EWK2UnitTest::EWK2UnitTestBase::SetUp):
+        (EWK2UnitTest::EWK2UnitTestBase::TearDown):
+        (EWK2UnitTest::EWK2UnitTestBase::loadUrlSync):
+        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h: Added.
+        (EWK2UnitTest):
+        (EWK2UnitTestBase):
+        (EWK2UnitTest::EWK2UnitTestBase::setLoadProgress):
+        (EWK2UnitTest::EWK2UnitTestBase::webView):
+        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp: Added.
+        (EWK2UnitTest):
+        (EWK2UnitTest::EWK2UnitTestEnvironment::EWK2UnitTestEnvironment):
+        (EWK2UnitTest::EWK2UnitTestEnvironment::defaultTestPageUrl):
+        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h: Added.
+        (EWK2UnitTest):
+        (EWK2UnitTestEnvironment):
+        (EWK2UnitTest::EWK2UnitTestEnvironment::useX11Window):
+        (EWK2UnitTest::EWK2UnitTestEnvironment::defaultWidth):
+        (EWK2UnitTest::EWK2UnitTestEnvironment::defaultHeight):
+        * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp: Added.
+        (parseArguments):
+        (main):
+        * UIProcess/API/efl/tests/resources/default_test_page.html: Added.
+        * UIProcess/API/efl/tests/test_ewk2_view.cpp: Added.
+        (TEST_F):
+
 2012-07-12  Christophe Dumez  <[email protected]>
 
         [WK2] Add missing Network Information API integration to WebContext and WebPage

Modified: trunk/Source/WebKit2/PlatformEfl.cmake (122511 => 122512)


--- trunk/Source/WebKit2/PlatformEfl.cmake	2012-07-12 21:42:31 UTC (rev 122511)
+++ trunk/Source/WebKit2/PlatformEfl.cmake	2012-07-12 21:46:04 UTC (rev 122512)
@@ -173,3 +173,47 @@
 
 INSTALL(FILES ${CMAKE_BINARY_DIR}/WebKit2/efl/ewebkit2.pc DESTINATION lib/pkgconfig)
 INSTALL(FILES ${EWebKit2_HEADERS} DESTINATION include/${WebKit2_LIBRARY_NAME}-${PROJECT_VERSION_MAJOR})
+
+INCLUDE_DIRECTORIES(${THIRDPARTY_DIR}/gtest/include)
+
+SET(EWK2UnitTests_LIBRARIES
+    ${_javascript_Core_LIBRARY_NAME}
+    ${WebCore_LIBRARY_NAME}
+    ${WebKit2_LIBRARY_NAME}
+    ${ECORE_LIBRARIES}
+    ${ECORE_EVAS_LIBRARIES}
+    ${EVAS_LIBRARIES}
+)
+
+IF (ENABLE_GLIB_SUPPORT)
+    LIST(APPEND EWK2UnitTests_LIBRARIES
+        ${Glib_LIBRARIES}
+        ${Gthread_LIBRARIES}
+    )
+ENDIF()
+
+SET(WEBKIT2_EFL_TEST_DIR "${WEBKIT2_DIR}/UIProcess/API/efl/tests")
+SET(TEST_RESOURCES_DIR ${WEBKIT2_EFL_TEST_DIR}/resources)
+
+ADD_DEFINITIONS(-DTEST_RESOURCES_DIR=\"${TEST_RESOURCES_DIR}\")
+
+ADD_LIBRARY(ewk2UnitTestUtils
+    ${WEBKIT2_EFL_TEST_DIR}/UnitTestUtils/EWK2UnitTestBase.cpp
+    ${WEBKIT2_EFL_TEST_DIR}/UnitTestUtils/EWK2UnitTestEnvironment.cpp
+    ${WEBKIT2_EFL_TEST_DIR}/UnitTestUtils/EWK2UnitTestMain.cpp
+)
+
+TARGET_LINK_LIBRARIES(ewk2UnitTestUtils ${EWK2UnitTests_LIBRARIES})
+
+# The "ewk" on the test name needs to be suffixed with "2", otherwise it
+# will clash with tests from the WebKit 1 test suite.
+SET(EWK2UnitTests_BINARIES
+    test_ewk2_view
+)
+
+FOREACH(testName ${EWK2UnitTests_BINARIES})
+    ADD_EXECUTABLE(${testName} ${WEBKIT2_EFL_TEST_DIR}/${testName}.cpp)
+    ADD_TEST(${testName} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${testName})
+    SET_TESTS_PROPERTIES(${testName} PROPERTIES TIMEOUT 60)
+    TARGET_LINK_LIBRARIES(${testName} ${EWK2UnitTests_LIBRARIES} ewk2UnitTestUtils gtest pthread)
+ENDFOREACH()

Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp (0 => 122512)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.cpp	2012-07-12 21:46:04 UTC (rev 122512)
@@ -0,0 +1,90 @@
+/*
+    Copyright (C) 2012 Samsung Electronics
+    Copyright (C) 2012 Intel Corporation. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this library; if not, write to the Free Software Foundation,
+    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "config.h"
+#include "EWK2UnitTestBase.h"
+
+#include "EWK2UnitTestEnvironment.h"
+#include <EWebKit2.h>
+#include <Ecore.h>
+#include <wtf/UnusedParam.h>
+
+extern EWK2UnitTest::EWK2UnitTestEnvironment* environment;
+
+namespace EWK2UnitTest {
+
+static void onLoadProgress(void* userData, Evas_Object* webView, void* eventInfo)
+{
+    UNUSED_PARAM(webView);
+
+    EWK2UnitTestBase* test = static_cast<EWK2UnitTestBase*>(userData);
+    double progress = *static_cast<double*>(eventInfo);
+
+    test->setLoadProgress(progress);
+}
+
+EWK2UnitTestBase::EWK2UnitTestBase()
+    : m_loadProgress(0)
+    , m_ecoreEvas(0)
+    , m_webView(0)
+{
+}
+
+void EWK2UnitTestBase::SetUp()
+{
+    ASSERT_GT(ecore_evas_init(), 0);
+
+    unsigned int width = environment->defaultWidth();
+    unsigned int height = environment->defaultHeight();
+
+    if (environment->useX11Window())
+        m_ecoreEvas = ecore_evas_new(0, 0, 0, width, height, 0);
+    else
+        m_ecoreEvas = ecore_evas_buffer_new(width, height);
+
+    ecore_evas_show(m_ecoreEvas);
+    Evas* evas = ecore_evas_get(m_ecoreEvas);
+
+    m_webView = ewk_view_add(evas);
+    evas_object_resize(m_webView, width, height);
+    evas_object_show(m_webView);
+    evas_object_focus_set(m_webView, true);
+}
+
+void EWK2UnitTestBase::TearDown()
+{
+    evas_object_del(m_webView);
+    ecore_evas_free(m_ecoreEvas);
+    ecore_evas_shutdown();
+}
+
+void EWK2UnitTestBase::loadUrlSync(const char* url)
+{
+    m_loadProgress = 0;
+
+    evas_object_smart_callback_add(m_webView, "load,progress", onLoadProgress, this);
+    ewk_view_uri_set(m_webView, url);
+
+    while (m_loadProgress != 1)
+        ecore_main_loop_iterate();
+
+    evas_object_smart_callback_del(m_webView, "load,progress", onLoadProgress);
+}
+
+} // namespace EWK2UnitTest

Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h (0 => 122512)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestBase.h	2012-07-12 21:46:04 UTC (rev 122512)
@@ -0,0 +1,51 @@
+/*
+    Copyright (C) 2012 Samsung Electronics
+    Copyright (C) 2012 Intel Corporation. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this library; if not, write to the Free Software Foundation,
+    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef EWK2UnitTestBase_h
+#define EWK2UnitTestBase_h
+
+#include <Ecore_Evas.h>
+#include <Evas.h>
+#include <gtest/gtest.h>
+
+namespace EWK2UnitTest {
+
+class EWK2UnitTestBase : public ::testing::Test {
+public:
+    void setLoadProgress(float progress) { m_loadProgress = progress; }
+    Evas_Object* webView() { return m_webView; }
+
+protected:
+    EWK2UnitTestBase();
+
+    virtual void SetUp();
+    virtual void TearDown();
+
+    void loadUrlSync(const char* url);
+
+private:
+    Evas_Object* m_webView;
+    Ecore_Evas* m_ecoreEvas;
+
+    float m_loadProgress;
+};
+
+} // namespace EWK2UnitTest
+
+#endif // EWK2UnitTestBase_h

Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp (0 => 122512)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.cpp	2012-07-12 21:46:04 UTC (rev 122512)
@@ -0,0 +1,37 @@
+/*
+    Copyright (C) 2012 Samsung Electronics
+    Copyright (C) 2012 Intel Corporation. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this library; if not, write to the Free Software Foundation,
+    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "config.h"
+#include "EWK2UnitTestEnvironment.h"
+
+namespace EWK2UnitTest {
+
+EWK2UnitTestEnvironment::EWK2UnitTestEnvironment(bool useX11Window)
+    : m_defaultWidth(800)
+    , m_defaultHeight(600)
+    , m_useX11Window(useX11Window)
+{
+}
+
+const char* EWK2UnitTestEnvironment::defaultTestPageUrl() const
+{
+    return "file://"TEST_RESOURCES_DIR"/default_test_page.html";
+}
+
+} // namespace EWK2UnitTest

Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h (0 => 122512)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestEnvironment.h	2012-07-12 21:46:04 UTC (rev 122512)
@@ -0,0 +1,45 @@
+/*
+    Copyright (C) 2012 Intel Corporation. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this library; if not, write to the Free Software Foundation,
+    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef EWK2UnitTestEnvironment_h
+#define EWK2UnitTestEnvironment_h
+
+#include <gtest/gtest.h>
+
+namespace EWK2UnitTest {
+
+class EWK2UnitTestEnvironment : public ::testing::Environment {
+public:
+    EWK2UnitTestEnvironment(bool useX11Window);
+
+    bool useX11Window() const { return m_useX11Window; }
+    const char* defaultTestPageUrl() const;
+
+    virtual unsigned int defaultWidth() const { return m_defaultWidth; }
+    virtual unsigned int defaultHeight() const { return m_defaultHeight; }
+
+private:
+    unsigned int m_defaultWidth;
+    unsigned int m_defaultHeight;
+
+    bool m_useX11Window;
+};
+
+} // namespace EWK2UnitTest
+
+#endif // EWK2UnitTestEnvironment_h

Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp (0 => 122512)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestMain.cpp	2012-07-12 21:46:04 UTC (rev 122512)
@@ -0,0 +1,53 @@
+/*
+    Copyright (C) 2012 Samsung Electronics
+    Copyright (C) 2012 Intel Corporation. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this library; if not, write to the Free Software Foundation,
+    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "EWK2UnitTestBase.h"
+#include "EWK2UnitTestEnvironment.h"
+#include <getopt.h>
+#include <gtest/gtest.h>
+
+using namespace EWK2UnitTest;
+
+EWK2UnitTestEnvironment* environment = 0;
+
+static bool parseArguments(int argc, char** argv)
+{
+    int useX11Window = 0;
+
+    static const option options[] = {
+        {"useX11Window", no_argument, &useX11Window, 1},
+        {0, 0, 0, 0}
+    };
+
+    while (getopt_long(argc, argv, "", options, 0) != -1) { }
+
+    return useX11Window;
+}
+
+int main(int argc, char** argv)
+{
+    bool useX11Window = parseArguments(argc, argv);
+
+    ::testing::InitGoogleTest(&argc, argv);
+
+    environment = new EWK2UnitTestEnvironment(useX11Window);
+    testing::AddGlobalTestEnvironment(environment);
+
+    return RUN_ALL_TESTS();
+}

Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/default_test_page.html (0 => 122512)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/default_test_page.html	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/resources/default_test_page.html	2012-07-12 21:46:04 UTC (rev 122512)
@@ -0,0 +1,6 @@
+<HTML>
+<BODY>
+<H2 align="center">EFL Unit Tests</H2>
+<H2 align="center">Default Testing Web Page</H2>
+</BODY>
+</HTML>

Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp (0 => 122512)


--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp	2012-07-12 21:46:04 UTC (rev 122512)
@@ -0,0 +1,35 @@
+/*
+    Copyright (C) 2012 Samsung Electronics
+    Copyright (C) 2012 Intel Corporation. All rights reserved.
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 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
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this library; if not, write to the Free Software Foundation,
+    Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "config.h"
+
+#include "UnitTestUtils/EWK2UnitTestBase.h"
+#include "UnitTestUtils/EWK2UnitTestEnvironment.h"
+#include <EWebKit2.h>
+#include <gtest/gtest.h>
+
+using namespace EWK2UnitTest;
+
+extern EWK2UnitTestEnvironment* environment;
+
+TEST_F(EWK2UnitTestBase, ewk_view_uri_get)
+{
+    loadUrlSync(environment->defaultTestPageUrl());
+    EXPECT_STREQ(ewk_view_uri_get(webView()), environment->defaultTestPageUrl());
+}
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to