Diff
Modified: trunk/Source/WebKit2/ChangeLog (133691 => 133692)
--- trunk/Source/WebKit2/ChangeLog 2012-11-07 00:29:48 UTC (rev 133691)
+++ trunk/Source/WebKit2/ChangeLog 2012-11-07 00:32:54 UTC (rev 133692)
@@ -1,3 +1,43 @@
+2012-11-06 Jihye Kang <[email protected]>
+
+ [EFL][WK2] Add ewk_database_manager APIs
+ https://bugs.webkit.org/show_bug.cgi?id=101193
+
+ Reviewed by Gyuyoung Kim.
+
+ Add ewk_database_manager to manage web database and
+ ewk_database_manaager_origins_get to get origins list of web storage.
+ Add unit tests for ewk_database_manager APIs.
+
+ * PlatformEfl.cmake:
+ * UIProcess/API/efl/ewk_context.cpp:
+ (Ewk_Context::Ewk_Context):
+ (Ewk_Context::databaseManager):
+ (ewk_context_database_manager_get):
+ * UIProcess/API/efl/ewk_context.h:
+ * UIProcess/API/efl/ewk_context_private.h:
+ (Ewk_Context):
+ * UIProcess/API/efl/ewk_database_manager.cpp: Added.
+ (Ewk_Database_Manager::Ewk_Database_Manager):
+ (Ewk_Database_Manager::getDatabaseOrigins):
+ (Ewk_Database_Manager::createOriginList):
+ (Ewk_Database_Origins_Async_Get_Context):
+ (Ewk_Database_Origins_Async_Get_Context::Ewk_Database_Origins_Async_Get_Context):
+ (getDatabaseOriginsCallback):
+ (ewk_database_manager_origins_get):
+ * UIProcess/API/efl/ewk_database_manager.h: Added.
+ * UIProcess/API/efl/ewk_database_manager_private.h: Added.
+ (Ewk_Database_Manager):
+ (Ewk_Database_Manager::create):
+ * UIProcess/API/efl/tests/test_ewk2_context.cpp:
+ (TEST_F):
+ * UIProcess/API/efl/tests/test_ewk2_database_manager.cpp: Added.
+ (OriginData):
+ (OriginData::OriginData):
+ (getDatabaseOriginsCallback):
+ (timerCallback):
+ (TEST_F):
+
2012-11-06 Mikhail Pozdnyakov <[email protected]>
[EFL][WK2] Refactor Ewk_Auth_Request, Ewk_Url_Scheme_Request and Ewk_Download_Job to be Ewk_Objects
Modified: trunk/Source/WebKit2/PlatformEfl.cmake (133691 => 133692)
--- trunk/Source/WebKit2/PlatformEfl.cmake 2012-11-07 00:29:48 UTC (rev 133691)
+++ trunk/Source/WebKit2/PlatformEfl.cmake 2012-11-07 00:32:54 UTC (rev 133692)
@@ -50,6 +50,7 @@
UIProcess/API/efl/ewk_color_picker.cpp
UIProcess/API/efl/ewk_context.cpp
UIProcess/API/efl/ewk_cookie_manager.cpp
+ UIProcess/API/efl/ewk_database_manager.cpp
UIProcess/API/efl/ewk_download_job.cpp
UIProcess/API/efl/ewk_error.cpp
UIProcess/API/efl/ewk_favicon_database.cpp
@@ -254,6 +255,7 @@
"${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_color_picker.h"
"${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_context.h"
"${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_cookie_manager.h"
+ "${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_database_manager.h"
"${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_download_job.h"
"${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_error.h"
"${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_favicon_database.h"
@@ -361,6 +363,7 @@
test_ewk2_context
test_ewk2_context_history_callbacks
test_ewk2_cookie_manager
+ test_ewk2_database_manager
test_ewk2_download_job
test_ewk2_eina_shared_string
test_ewk2_favicon_database
Modified: trunk/Source/WebKit2/UIProcess/API/efl/EWebKit2.h (133691 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/EWebKit2.h 2012-11-07 00:29:48 UTC (rev 133691)
+++ trunk/Source/WebKit2/UIProcess/API/efl/EWebKit2.h 2012-11-07 00:32:54 UTC (rev 133692)
@@ -34,6 +34,7 @@
#include "ewk_color_picker.h"
#include "ewk_context.h"
#include "ewk_cookie_manager.h"
+#include "ewk_database_manager.h"
#include "ewk_download_job.h"
#include "ewk_error.h"
#include "ewk_favicon_database.h"
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp (133691 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp 2012-11-07 00:29:48 UTC (rev 133691)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.cpp 2012-11-07 00:32:54 UTC (rev 133692)
@@ -36,6 +36,7 @@
#include "WebSoupRequestManagerProxy.h"
#include "ewk_context_private.h"
#include "ewk_cookie_manager_private.h"
+#include "ewk_database_manager_private.h"
#include "ewk_favicon_database_private.h"
#include "ewk_private.h"
#include "ewk_storage_manager_private.h"
@@ -63,6 +64,7 @@
EwkContext::EwkContext(WKContextRef context)
: m_context(context)
+ , m_databaseManager(Ewk_Database_Manager::create(WKContextGetDatabaseManager(m_context.get())))
, m_storageManager(Ewk_Storage_Manager::create(WKContextGetKeyValueStorageManager(m_context.get())))
#if ENABLE(BATTERY_STATUS)
, m_batteryProvider(BatteryProvider::create(context))
@@ -145,6 +147,11 @@
return m_cookieManager.get();
}
+Ewk_Database_Manager* EwkContext::databaseManager()
+{
+ return m_databaseManager.get();
+}
+
void EwkContext::ensureFaviconDatabase()
{
if (m_faviconDatabase)
@@ -218,6 +225,13 @@
return const_cast<EwkContext*>(impl)->cookieManager();
}
+Ewk_Database_Manager* ewk_context_database_manager_get(const Ewk_Context* ewkContext)
+{
+ EWK_OBJ_GET_IMPL_OR_RETURN(const EwkContext, ewkContext, impl, 0);
+
+ return const_cast<EwkContext*>(impl)->databaseManager();
+}
+
Eina_Bool ewk_context_favicon_database_directory_set(Ewk_Context* ewkContext, const char* directoryPath)
{
EWK_OBJ_GET_IMPL_OR_RETURN(EwkContext, ewkContext, impl, false);
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.h (133691 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.h 2012-11-07 00:29:48 UTC (rev 133691)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_context.h 2012-11-07 00:32:54 UTC (rev 133692)
@@ -38,6 +38,7 @@
#define ewk_context_h
#include "ewk_cookie_manager.h"
+#include "ewk_database_manager.h"
#include "ewk_favicon_database.h"
#include "ewk_navigation_data.h"
#include "ewk_storage_manager.h"
@@ -170,6 +171,15 @@
EAPI Ewk_Cookie_Manager *ewk_context_cookie_manager_get(const Ewk_Context *context);
/**
+ * Gets the database manager instance for this @a context.
+ *
+ * @param context context object to query
+ *
+ * @return Ewk_Database_Manager object instance or @c NULL in case of failure
+ */
+EAPI Ewk_Database_Manager *ewk_context_database_manager_get(const Ewk_Context *context);
+
+/**
* Sets the favicon database directory for this @a context.
*
* Sets the directory path to be used to store the favicons database
Modified: trunk/Source/WebKit2/UIProcess/API/efl/ewk_context_private.h (133691 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_context_private.h 2012-11-07 00:29:48 UTC (rev 133691)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_context_private.h 2012-11-07 00:32:54 UTC (rev 133692)
@@ -57,6 +57,8 @@
Ewk_Cookie_Manager* cookieManager();
+ Ewk_Database_Manager* databaseManager();
+
bool setFaviconDatabaseDirectoryPath(const String& databaseDirectory);
Ewk_Favicon_Database* faviconDatabase();
@@ -88,6 +90,7 @@
WKRetainPtr<WKContextRef> m_context;
OwnPtr<Ewk_Cookie_Manager> m_cookieManager;
+ OwnPtr<Ewk_Database_Manager> m_databaseManager;
OwnPtr<Ewk_Favicon_Database> m_faviconDatabase;
OwnPtr<Ewk_Storage_Manager> m_storageManager;
#if ENABLE(BATTERY_STATUS)
Added: trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager.cpp (0 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager.cpp (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager.cpp 2012-11-07 00:32:54 UTC (rev 133692)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ewk_database_manager.h"
+
+#include "WKAPICast.h"
+#include "WKArray.h"
+#include "WKDatabaseManager.h"
+#include "ewk_database_manager_private.h"
+#include "ewk_error_private.h"
+#include "ewk_security_origin.h"
+#include "ewk_security_origin_private.h"
+#include <wtf/RefCounted.h>
+
+using namespace WebKit;
+
+Ewk_Database_Manager::Ewk_Database_Manager(WKDatabaseManagerRef databaseManagerRef)
+ : m_databaseManager(databaseManagerRef)
+{ }
+
+void Ewk_Database_Manager::getDatabaseOrigins(WKDatabaseManagerGetDatabaseOriginsFunction callback, void* context) const
+{
+ WKDatabaseManagerGetDatabaseOrigins(m_databaseManager.get(), context, callback);
+}
+
+Eina_List* Ewk_Database_Manager::createOriginList(WKArrayRef origins) const
+{
+ Eina_List* originList = 0;
+ const size_t length = WKArrayGetSize(origins);
+
+ for (size_t i = 0; i < length; ++i) {
+ WKSecurityOriginRef wkOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
+ RefPtr<Ewk_Security_Origin> origin = m_wrapperCache.get(wkOriginRef);
+ if (!origin) {
+ origin = Ewk_Security_Origin::create(wkOriginRef);
+ m_wrapperCache.set(wkOriginRef, origin);
+ }
+ originList = eina_list_append(originList, origin.release().leakRef());
+ }
+
+ return originList;
+}
+
+struct Ewk_Database_Origins_Async_Get_Context {
+ const Ewk_Database_Manager* manager;
+ Ewk_Database_Origins_Get_Cb callback;
+ void* userData;
+
+ Ewk_Database_Origins_Async_Get_Context(const Ewk_Database_Manager* manager, Ewk_Database_Origins_Get_Cb callback, void* userData)
+ : manager(manager)
+ , callback(callback)
+ , userData(userData)
+ { }
+};
+
+static void getDatabaseOriginsCallback(WKArrayRef origins, WKErrorRef wkError, void* context)
+{
+ OwnPtr<Ewk_Database_Origins_Async_Get_Context*> webDatabaseContext = adoptPtr(static_cast<Ewk_Database_Origins_Async_Get_Context*>(context));
+ Eina_List* originList = webDatabaseContext->manager->createOriginList(origins);
+ OwnPtr<Ewk_Error> ewkError = Ewk_Error::create(wkError);
+ webDatabaseContext->callback(originList, ewkError.get(), webDatabaseContext->userData);
+}
+
+Eina_Bool ewk_database_manager_origins_get(const Ewk_Database_Manager* ewkDatabaseManager, Ewk_Database_Origins_Get_Cb callback, void* userData)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(ewkDatabaseManager, false);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
+
+ Ewk_Database_Origins_Async_Get_Context* context = new Ewk_Database_Origins_Async_Get_Context(ewkDatabaseManager, callback, userData);
+ ewkDatabaseManager->getDatabaseOrigins(getDatabaseOriginsCallback, context);
+
+ return true;
+}
Added: trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager.h (0 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager.h 2012-11-07 00:32:54 UTC (rev 133692)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @file ewk_database_manager.h
+ * @brief Describes the Ewk Database Manager API.
+ *
+ * Ewk Database Manager manages web database.
+ */
+
+#ifndef ewk_database_manager_h
+#define ewk_database_manager_h
+
+#include "ewk_error.h"
+#include <Eina.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/** Creates a type name for Ewk_Database_Manager. */
+typedef struct Ewk_Database_Manager Ewk_Database_Manager;
+
+/**
+ * @typedef Ewk_Database_Origins_Get_Cb Ewk_Database_Origins_Get_Cb
+ * @brief Callback type for use with ewk_database_manager_origins_get()
+ *
+ * @param origins @c Eina_List containing @c Ewk_Security_Origin elements or @c NULL in case of error,
+ * the Eina_List and its items should be freed after use. Use ewk_security_origin_unref()
+ * to free the items
+ */
+typedef void (*Ewk_Database_Origins_Get_Cb)(Eina_List *origins, Ewk_Error *error, void *user_data);
+
+/**
+ * Gets list of origins using web database asynchronously.
+ *
+ * This function allocates memory for context structure made from callback and user_data.
+ *
+ * @param manager Ewk_Database_Manager object
+ * @param callback callback to get database origins
+ * @param user_data user_data will be passed when result_callback is called,
+ * -i.e., user data will be kept until callback is called
+ *
+ * @return @c EINA_TRUE on success, @c EINA_FALSE on failure
+ */
+EAPI Eina_Bool ewk_database_manager_origins_get(const Ewk_Database_Manager *manager, Ewk_Database_Origins_Get_Cb callback, void *user_data);
+
+#ifdef __cplusplus
+}
+#endif
+#endif // ewk_database_manager_h
Added: trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager_private.h (0 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager_private.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/ewk_database_manager_private.h 2012-11-07 00:32:54 UTC (rev 133692)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef ewk_database_manager_private_h
+#define ewk_database_manager_private_h
+
+#include "WKDatabaseManager.h"
+#include "WKRetainPtr.h"
+#include "ewk_security_origin_private.h"
+#include <WebKit2/WKBase.h>
+#include <wtf/PassOwnPtr.h>
+
+class Ewk_Database_Manager {
+public:
+ static PassOwnPtr<Ewk_Database_Manager> create(WKDatabaseManagerRef databaseManagerRef)
+ {
+ return adoptPtr(new Ewk_Database_Manager(databaseManagerRef));
+ }
+
+ Eina_List* createOriginList(WKArrayRef wkList) const;
+ void getDatabaseOrigins(WKDatabaseManagerGetDatabaseOriginsFunction callback, void* context) const;
+
+private:
+ explicit Ewk_Database_Manager(WKDatabaseManagerRef);
+
+ WKRetainPtr<WKDatabaseManagerRef> m_databaseManager;
+ mutable HashMap<WKSecurityOriginRef, RefPtr<Ewk_Security_Origin> > m_wrapperCache;
+};
+#endif // ewk_database_manager_private_h
Modified: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp (133691 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp 2012-11-07 00:29:48 UTC (rev 133691)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp 2012-11-07 00:32:54 UTC (rev 133692)
@@ -53,6 +53,14 @@
ASSERT_EQ(cookieManager, ewk_context_cookie_manager_get(context));
}
+TEST_F(EWK2UnitTestBase, ewk_context_database_manager_get)
+{
+ Ewk_Context* context = ewk_view_context_get(webView());
+ Ewk_Database_Manager* databaseManager = ewk_context_database_manager_get(context);
+ ASSERT_TRUE(databaseManager);
+ ASSERT_EQ(databaseManager, ewk_context_database_manager_get(context));
+}
+
TEST_F(EWK2UnitTestBase, ewk_context_favicon_database_get)
{
Ewk_Context* context = ewk_view_context_get(webView());
Added: trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_database_manager.cpp (0 => 133692)
--- trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_database_manager.cpp (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_database_manager.cpp 2012-11-07 00:32:54 UTC (rev 133692)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2012 Samsung Electronics
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "UnitTestUtils/EWK2UnitTestBase.h"
+#include <EWebKit2.h>
+#include <Ecore.h>
+
+using namespace EWK2UnitTest;
+
+struct OriginData {
+ Eina_List* originList;
+ Ewk_Database_Manager* manager;
+ bool didReceiveOriginsCallback;
+ bool isSynchronized;
+ unsigned timeoutSeconds;
+
+ OriginData()
+ : originList(0)
+ , manager(0)
+ , didReceiveOriginsCallback(false)
+ , isSynchronized(false)
+ , timeoutSeconds(10)
+ { }
+};
+
+static void getDatabaseOriginsCallback(Eina_List* origins, Ewk_Error* error, void* userData)
+{
+ ASSERT_FALSE(error);
+
+ OriginData* originData = static_cast<OriginData*>(userData);
+ originData->didReceiveOriginsCallback = true;
+
+ Eina_List* l;
+ void* data;
+ EINA_LIST_FOREACH(origins, l, data) {
+ originData->originList = eina_list_append(originData->originList, data);
+ Ewk_Security_Origin* origin = static_cast<Ewk_Security_Origin*>(data);
+ if (!strcmp(ewk_security_origin_protocol_get(origin), "http")
+ && !strcmp(ewk_security_origin_host_get(origin), "www.databasetest.com")
+ && !ewk_security_origin_port_get(origin)) {
+ originData->isSynchronized = true;
+ ecore_main_loop_quit();
+ }
+ }
+}
+
+static bool timerCallback(void* userData)
+{
+ OriginData* originData = static_cast<OriginData*>(userData);
+
+ if (originData->isSynchronized || !--(originData->timeoutSeconds)) {
+ ecore_main_loop_quit();
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ if (originData->didReceiveOriginsCallback) {
+ originData->didReceiveOriginsCallback = false;
+ ewk_database_manager_origins_get(originData->manager, getDatabaseOriginsCallback, originData);
+ }
+
+ return ECORE_CALLBACK_RENEW;
+}
+
+TEST_F(EWK2UnitTestBase, ewk_database_manager_origins_get)
+{
+ Evas_Object* view = webView();
+ const char* databaseHTML =
+ "<html><head><title>original title</title></head>"
+ "<body>"
+ "<script type='text/_javascript_'>"
+ " var db = openDatabase(\"DBTest\", \"1.0\", \"HTML5 Database example\", 200000);"
+ "</script>"
+ "</body></html>";
+
+ ASSERT_TRUE(ewk_view_html_string_load(view, databaseHTML, "http://www.databasetest.com", 0));
+ ASSERT_TRUE(waitUntilLoadFinished());
+
+ OriginData originData;
+ originData.manager = ewk_context_database_manager_get(ewk_view_context_get(view));
+ ASSERT_TRUE(ewk_database_manager_origins_get(originData.manager, getDatabaseOriginsCallback, &originData));
+ Ecore_Timer* database_timer = ecore_timer_add(1, reinterpret_cast<Ecore_Task_Cb>(timerCallback), &originData);
+
+ ecore_main_loop_begin();
+ if (database_timer)
+ ecore_timer_del(database_timer);
+
+ ASSERT_TRUE(originData.isSynchronized);
+ ASSERT_LE(1, eina_list_count(originData.originList));
+}