Commit f6a81788 authored by commit-queue@webkit.org's avatar commit-queue@webkit.org
Browse files

Source/WebKit: [EFL] Add file EWKTestEnvironment.cpp to build system.

https://bugs.webkit.org/show_bug.cgi?id=94925

Patch by Krzysztof Czech <k.czech@samsung.com> on 2012-10-02
Reviewed by Gyuyoung Kim.

Change is related to modifications in wk1 unit tests.

* PlatformEfl.cmake:

Source/WebKit/efl: [EFL][UT] Refactoring an implementation of testing framework for wk1.
https://bugs.webkit.org/show_bug.cgi?id=94925

Patch by Krzysztof Czech <k.czech@samsung.com> on 2012-10-02
Reviewed by Gyuyoung Kim.

The reason of changing, was to adjust current implementation to use gtest features
related to cleaning (SetUp, TearDown), cleaning code in terms of useless methods
and lastly to make framework easier to use.

* tests/UnitTestUtils/EWKTestBase.cpp:
(EWKUnitTests::EWKTestBase::EWKTestBase):
(EWKUnitTests::EWKTestBase::webView): Returns current webview.
(EWKUnitTests::EWKTestBase::SetUp):
Before test is started, SetUp is called.
Used this to initialize test view.
(EWKUnitTests::EWKTestBase::onLoadFinished):
(EWKUnitTests::EWKTestBase::waitUntilLoadFinished): It waits till test page will be properly loaded.
(EWKUnitTests::EWKTestBase::loadUrl): Starts loading test page.
* tests/UnitTestUtils/EWKTestBase.h:
* tests/UnitTestUtils/EWKTestEnvironment.cpp:
Used to have global SetUp and TearDown.
Global SetUp starts initialization of webkit wherease
global TearDown shuts it down. Generally we would like to have
only one initialization of webkit while tests are executed.
(EWKUnitTests):
(EWKUnitTests::EWKTestEnvironment::EWKTestEnvironment):
(EWKUnitTests::EWKTestEnvironment::SetUp): Starts initialization of webkit.
(EWKUnitTests::EWKTestEnvironment::TearDown): Shuts down of webkit.
* tests/UnitTestUtils/EWKTestEnvironment.h:
(EWKUnitTests):
(EWKTestEnvironment):
(EWKUnitTests::EWKTestEnvironment::useX11Window):
* tests/UnitTestUtils/EWKTestView.cpp:
(EWKUnitTests::EWKTestView::EWKTestView):
(EWKUnitTests::EWKTestView::init): Starts initialization of test view.
* tests/UnitTestUtils/EWKTestView.h:
(EWKTestView):
* tests/test_ewk_view.cpp: adjusted current unit tests to new implementation.
(TEST_F):
* tests/test_runner.cpp: entry point of all tests.
(parseCustomArguments):
(main):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@130175 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 537bec68
2012-10-02 Krzysztof Czech <k.czech@samsung.com>
[EFL] Add file EWKTestEnvironment.cpp to build system.
https://bugs.webkit.org/show_bug.cgi?id=94925
Reviewed by Gyuyoung Kim.
Change is related to modifications in wk1 unit tests.
* PlatformEfl.cmake:
2012-09-27 Anders Carlsson <andersca@apple.com>
Get rid of more unused WK1 plug-in code
......
......@@ -344,6 +344,7 @@ ADD_DEFINITIONS(-DDEFAULT_TEST_PAGE_DIR=\"${DEFAULT_TEST_PAGE_DIR}\"
ADD_LIBRARY(ewkTestUtils
${WEBKIT_DIR}/efl/tests/UnitTestUtils/EWKTestBase.cpp
${WEBKIT_DIR}/efl/tests/UnitTestUtils/EWKTestEnvironment.cpp
${WEBKIT_DIR}/efl/tests/UnitTestUtils/EWKTestView.cpp
)
TARGET_LINK_LIBRARIES(ewkTestUtils ${EWKUnitTests_LIBRARIES})
......
2012-10-02 Krzysztof Czech <k.czech@samsung.com>
[EFL][UT] Refactoring an implementation of testing framework for wk1.
https://bugs.webkit.org/show_bug.cgi?id=94925
Reviewed by Gyuyoung Kim.
The reason of changing, was to adjust current implementation to use gtest features
related to cleaning (SetUp, TearDown), cleaning code in terms of useless methods
and lastly to make framework easier to use.
* tests/UnitTestUtils/EWKTestBase.cpp:
(EWKUnitTests::EWKTestBase::EWKTestBase):
(EWKUnitTests::EWKTestBase::webView): Returns current webview.
(EWKUnitTests::EWKTestBase::SetUp):
Before test is started, SetUp is called.
Used this to initialize test view.
(EWKUnitTests::EWKTestBase::onLoadFinished):
(EWKUnitTests::EWKTestBase::waitUntilLoadFinished): It waits till test page will be properly loaded.
(EWKUnitTests::EWKTestBase::loadUrl): Starts loading test page.
* tests/UnitTestUtils/EWKTestBase.h:
* tests/UnitTestUtils/EWKTestEnvironment.cpp:
Used to have global SetUp and TearDown.
Global SetUp starts initialization of webkit wherease
global TearDown shuts it down. Generally we would like to have
only one initialization of webkit while tests are executed.
(EWKUnitTests):
(EWKUnitTests::EWKTestEnvironment::EWKTestEnvironment):
(EWKUnitTests::EWKTestEnvironment::SetUp): Starts initialization of webkit.
(EWKUnitTests::EWKTestEnvironment::TearDown): Shuts down of webkit.
* tests/UnitTestUtils/EWKTestEnvironment.h:
(EWKUnitTests):
(EWKTestEnvironment):
(EWKUnitTests::EWKTestEnvironment::useX11Window):
* tests/UnitTestUtils/EWKTestView.cpp:
(EWKUnitTests::EWKTestView::EWKTestView):
(EWKUnitTests::EWKTestView::init): Starts initialization of test view.
* tests/UnitTestUtils/EWKTestView.h:
(EWKTestView):
* tests/test_ewk_view.cpp: adjusted current unit tests to new implementation.
(TEST_F):
* tests/test_runner.cpp: entry point of all tests.
(parseCustomArguments):
(main):
2012-10-01 Brady Eidson <beidson@apple.com>
Remove the Safari 2 -> Safari 3 icon database import code.
......
......@@ -19,84 +19,45 @@
#include "config.h"
#include "EWKTestBase.h"
#include "EWKTestConfig.h"
#include "EWKTestView.h"
#include "EWKTestEnvironment.h"
#include <EWebKit.h>
#include <Ecore.h>
#include <Edje.h>
int EWKUnitTests::EWKTestBase::useX11Window;
extern EWKUnitTests::EWKTestEnvironment* environment;
namespace EWKUnitTests {
bool EWKTestBase::init()
EWKTestBase::EWKTestBase()
{
if (!ecore_evas_init())
return false;
if (!edje_init()) {
ecore_evas_shutdown();
return false;
}
int ret = ewk_init();
const char* proxyUri = getenv("http_proxy");
if (ret && proxyUri)
ewk_network_proxy_uri_set(proxyUri);
return ret;
}
void EWKTestBase::shutdownAll()
Evas_Object* EWKTestBase::webView()
{
int count = 0;
while ((count = ecore_evas_shutdown()) > 0) { }
while ((count = edje_shutdown()) > 0) { }
while ((count = ewk_shutdown()) > 0) { }
return m_ewkTestView.webView();
}
void EWKTestBase::startTest()
void EWKTestBase::SetUp()
{
ecore_main_loop_begin();
ASSERT_TRUE(m_ewkTestView.init(environment->useX11Window()));
}
void EWKTestBase::endTest()
void EWKTestBase::onLoadFinished(void* data, Evas_Object* webView, void* eventInfo)
{
ecore_main_loop_quit();
}
bool EWKTestBase::createTest(const char* url, void (*event_callback)(void*, Evas_Object*, void*), const char* event_name, void* event_data)
{
EFL_INIT_RET();
EWKTestEcoreEvas evas(useX11Window);
if (!evas.evas())
return false;
evas.show();
EWKTestView view(evas.evas(), url);
if (!view.init())
return false;
view.bindEvents(event_callback, event_name, event_data);
view.show();
START_TEST();
return true;
}
bool EWKTestBase::runTest(void (*event_callback)(void*, Evas_Object*, void*), const char* event_name, void* event_data)
void EWKTestBase::waitUntilLoadFinished()
{
return createTest(Config::defaultTestPage, event_callback, event_name, event_data);
evas_object_smart_callback_add(webView(), "load,finished", onLoadFinished, 0);
ecore_main_loop_begin();
evas_object_smart_callback_del(webView(), "load,finished", onLoadFinished);
}
bool EWKTestBase::runTest(const char* url, void (*event_callback)(void*, Evas_Object*, void*), const char* event_name, void* event_data)
void EWKTestBase::loadUrl(const char* url)
{
return createTest(url, event_callback, event_name, event_data);
ASSERT_TRUE(ewk_view_uri_set(webView(), url));
waitUntilLoadFinished();
}
}
......@@ -19,49 +19,25 @@
#ifndef EWKTestBase_h
#define EWKTestBase_h
#include <Evas.h>
#include "EWKTestConfig.h"
#include "EWKTestView.h"
#include <gtest/gtest.h>
#define RUN_TEST(args...) \
do { \
ASSERT_EQ(true, EWKTestBase::runTest(args)); \
} while (0)
#define START_TEST() \
do { \
EWKTestBase::startTest(); \
} while (0)
#define END_TEST() \
do { \
EWKTestBase::endTest(); \
} while (0)
#define EFL_INIT_RET() \
do { \
if (!EWKTestBase::init()) \
return false; \
} while (0)
#define EFL_INIT() \
do { \
EWKTestBase::init(); \
} while (0)
namespace EWKUnitTests {
class EWKTestBase {
static bool createTest(const char* url, void (*event_callback)(void*, Evas_Object*, void*), const char* event_name, void* event_data);
class EWKTestBase: public ::testing::Test {
public:
static bool init();
static void shutdownAll();
static void startTest();
static void endTest();
static void onLoadFinished(void* data, Evas_Object* webView, void* eventInfo);
Evas_Object* webView();
virtual void SetUp();
protected:
EWKTestBase();
static bool runTest(const char* url, void (*event_callback)(void*, Evas_Object*, void*), const char* event_name = "load,finished", void* event_data = 0);
static bool runTest(void (*event_callback)(void*, Evas_Object*, void*), const char* event_name = "load,finished", void* event_data = 0);
void loadUrl(const char* url = Config::defaultTestPage);
void waitUntilLoadFinished();
static int useX11Window;
EWKTestView m_ewkTestView;
};
}
......
/*
Copyright (C) 2012 Samsung Electronics
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 "EWKTestEnvironment.h"
#include <EWebKit.h>
#include <Ecore.h>
#include <Edje.h>
namespace EWKUnitTests {
EWKTestEnvironment::EWKTestEnvironment(bool useX11Window)
: m_useX11Window(useX11Window)
{
}
void EWKTestEnvironment::SetUp()
{
ASSERT_GT(ewk_init(), 0);
const char* proxyUrl = getenv("http_proxy");
if (proxyUrl)
ewk_network_proxy_uri_set(proxyUrl);
}
void EWKTestEnvironment::TearDown()
{
ewk_shutdown();
}
}
/*
Copyright (C) 2012 Samsung Electronics
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 EWKTestEnvironment_h
#define EWKTestEnvironment_h
#include <gtest/gtest.h>
namespace EWKUnitTests {
class EWKTestEnvironment : public ::testing::Environment {
public:
explicit EWKTestEnvironment(bool useX11Window);
bool useX11Window() const { return m_useX11Window; }
virtual void SetUp();
virtual void TearDown();
private:
bool m_useX11Window;
};
}
#endif
......@@ -19,131 +19,53 @@
#include "config.h"
#include "EWKTestView.h"
#include "EWKTestConfig.h"
#include <EWebKit.h>
#include <wtf/NullPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h>
namespace EWKUnitTests {
EWKTestEcoreEvas::EWKTestEcoreEvas(int useX11Window)
EWKTestView::EWKTestView()
{
if (useX11Window)
m_ecoreEvas = adoptPtr(ecore_evas_new(0, 0, 0, Config::defaultViewWidth, Config::defaultViewHeight, 0));
else
m_ecoreEvas = adoptPtr(ecore_evas_buffer_new(Config::defaultViewWidth, Config::defaultViewHeight));
}
EWKTestEcoreEvas::EWKTestEcoreEvas(const char* engine_name, int viewport_x, int viewport_y, int viewport_w, int viewport_h, const char* extra_options, int useX11Window)
bool EWKTestView::init(int useX11Window, EwkViewType testViewType, int width, int height)
{
m_webView = nullptr;
if (useX11Window)
m_ecoreEvas = adoptPtr(ecore_evas_new(engine_name, viewport_x, viewport_y, viewport_w, viewport_h, extra_options));
m_ecoreEvas = adoptPtr(ecore_evas_new(0, 0, 0, width, height, 0));
else
m_ecoreEvas = adoptPtr(ecore_evas_buffer_new(viewport_x, viewport_y));
}
Evas* EWKTestEcoreEvas::evas()
{
if (m_ecoreEvas.get())
return ecore_evas_get(m_ecoreEvas.get());
return 0;
}
void EWKTestEcoreEvas::show()
{
if (m_ecoreEvas.get())
ecore_evas_show(m_ecoreEvas.get());
}
EWKTestView::EWKTestView(Evas* evas)
: m_evas(evas)
, m_url(Config::defaultTestPage)
, m_defaultViewType(TiledView)
, m_width(Config::defaultViewWidth)
, m_height(Config::defaultViewHeight)
{
}
EWKTestView::EWKTestView(Evas* evas, const char* url)
: m_evas(evas)
, m_url(url)
, m_defaultViewType(TiledView)
, m_width(Config::defaultViewWidth)
, m_height(Config::defaultViewHeight)
{
}
EWKTestView::EWKTestView(Evas* evas, EwkViewType type, const char* url)
: m_evas(evas)
, m_url(url)
, m_defaultViewType(type)
, m_width(Config::defaultViewWidth)
, m_height(Config::defaultViewHeight)
{
}
m_ecoreEvas = adoptPtr(ecore_evas_buffer_new(width, height));
EWKTestView::EWKTestView(Evas* evas, EwkViewType type, const char* url, int width, int height)
: m_evas(evas)
, m_url(url)
, m_defaultViewType(type)
, m_width(width)
, m_height(height)
{
}
if (!m_ecoreEvas)
return false;
bool EWKTestView::init()
{
if (!m_evas || m_url.empty())
ecore_evas_show(m_ecoreEvas.get());
Evas* evas = ecore_evas_get(m_ecoreEvas.get());
if (!evas)
return false;
switch (m_defaultViewType) {
switch (testViewType) {
case SingleView:
m_webView = adoptRef(ewk_view_single_add(m_evas));
m_webView = adoptRef(ewk_view_single_add(evas));
break;
case TiledView:
m_webView = adoptRef(ewk_view_tiled_add(m_evas));
m_webView = adoptRef(ewk_view_tiled_add(evas));
break;
}
if (!m_webView.get())
if (!m_webView)
return false;
ewk_view_theme_set(m_webView.get(), Config::defaultThemePath);
ewk_view_uri_set(m_webView.get(), m_url.c_str());
}
void EWKTestView::show()
{
if (!m_webView.get())
return;
evas_object_resize(m_webView.get(), m_width, m_height);
evas_object_resize(m_webView.get(), width, height);
evas_object_show(m_webView.get());
evas_object_focus_set(m_webView.get(), EINA_TRUE);
}
Evas_Object* EWKTestView::mainFrame()
{
if (m_webView.get())
return ewk_view_frame_main_get(m_webView.get());
return 0;
}
Evas* EWKTestView::evas()
{
if (m_webView.get())
return evas_object_evas_get(m_webView.get());
return 0;
}
void EWKTestView::bindEvents(void (*callback)(void*, Evas_Object*, void*), const char* eventName, void* ptr)
{
if (!m_webView.get())
return;
evas_object_smart_callback_del(m_webView.get(), eventName, callback);
evas_object_smart_callback_add(m_webView.get(), eventName, callback, ptr);
return true;
}
}
......@@ -19,56 +19,32 @@
#ifndef EWKTestView_h
#define EWKTestView_h
#include "EWKTestConfig.h"
#include <Ecore_Evas.h>
#include <Evas.h>
#include <string>
#include <wtf/OwnPtr.h>
#include <wtf/efl/RefPtrEfl.h>
namespace EWKUnitTests {
class EWKTestEcoreEvas {
public:
EWKTestEcoreEvas(int useX11Window);
EWKTestEcoreEvas(const char* engine_name, int viewport_x, int viewport_y, int viewport_w, int viewport_h, const char* extra_options, int useX11Window);
Evas* evas();
void show();
private:
OwnPtr<Ecore_Evas> m_ecoreEvas;
};
class EWKTestView {
public:
enum EwkViewType {
SingleView = 0,
TiledView,
TiledView
};
explicit EWKTestView(Evas*);
EWKTestView(Evas*, const char* url);
EWKTestView(Evas*, EwkViewType, const char* url);
EWKTestView(Evas*, EwkViewType, const char* url, int width, int height);
EWKTestView();
Evas_Object* webView() { return m_webView.get(); }
Evas_Object* mainFrame();
Evas* evas();
void show();
bool init();
void bindEvents(void (*callback)(void*, Evas_Object*, void*), const char* eventName, void* ptr);
bool init(int useX11Window = 0, EwkViewType testViewType = TiledView, int width = Config::defaultViewWidth, int height = Config::defaultViewHeight);
private:
EWKTestView(const EWKTestView&);
EWKTestView operator=(const EWKTestView&);
EWKTestView& operator=(const EWKTestView&);
Evas* m_evas;
OwnPtr<Ecore_Evas> m_ecoreEvas;
RefPtr<Evas_Object> m_webView;
int m_width, m_height;
EwkViewType m_defaultViewType;
std::string m_url;
};
}
......
......@@ -19,66 +19,54 @@
#include "config.h"
#include "UnitTestUtils/EWKTestBase.h"
#include "UnitTestUtils/EWKTestConfig.h"
#include <EWebKit.h>
#include <gtest/gtest.h>
#include <Ecore.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
using namespace EWKUnitTests;
/**
* @brief Checking whether function properly returns correct value.
*/
static void ewkViewEditableGetCb(void* eventInfo, Evas_Object* o, void* data)
TEST_F(EWKTestBase, ewk_view_editable_get)
{
ewk_view_editable_set(o, EINA_FALSE);
EXPECT_EQ(EINA_FALSE, ewk_view_editable_get(o));
END_TEST();
}
TEST(test_ewk_view, ewk_view_editable_get)
{
RUN_TEST(ewkViewEditableGetCb);
loadUrl();
ewk_view_editable_set(webView(), true);
ASSERT_TRUE(ewk_view_editable_get(webView()));
}
/**
* @brief Checking whether function returns correct uri string.
*/
static void ewkViewUriGetCb(void* eventInfo, Evas_Object* o, void* data)
TEST_F(EWKTestBase, ewk_view_uri_get)
{
EXPECT_STREQ("http://www.webkit.org/", ewk_view_uri_get(o));
END_TEST();
}
TEST(test_ewk_view, ewk_view_uri_get)
{
RUN_TEST("http://www.webkit.org", ewkViewUriGetCb);
loadUrl();
ASSERT_STREQ(ewk_view_uri_get(webView()), Config::defaultTestPage);
}
/**
* @brief Checking whether function properly get/set fullscreen setting value.
*/