Source/WebKit2/ChangeLog

 12012-12-04 Jiyeon Kim <jiyeon0402.kim@samsung.com>
 2
 3 [EFL][WK2] Add ewk_application_cache_manager APIs
 4 https://bugs.webkit.org/show_bug.cgi?id=102853
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Add EwkApplicationCacheManager to manage offline application cache and
 9 ewk_application_cache_manager_origins_get to origins list of application cache.
 10 Add unit tests for EwkApplicationCacheManager APIs.
 11
 12 * PlatformEfl.cmake:
 13 * UIProcess/API/efl/EWebKit2.h:
 14 * UIProcess/API/efl/ewk_application_cache_manager.cpp: Added.
 15 (EwkApplicationCacheManager::EwkApplicationCacheManager):
 16 (EwkApplicationCacheManager::getApplicationCacheOrigins):
 17 (EwkApplicationCacheManager::createOriginList):
 18 (getApplicationCacheOriginsCallback):
 19 (ewk_application_cache_manager_origins_get):
 20 * UIProcess/API/efl/ewk_application_cache_manager.h: Added.
 21 * UIProcess/API/efl/ewk_application_cache_manager_private.h: Added.
 22 (Ewk_Application_Cache_Origins_Async_Get_Context):
 23 (Ewk_Application_Cache_Origins_Async_Get_Context::Ewk_Application_Cache_Origins_Async_Get_Context):
 24 (EwkApplicationCacheManager):
 25 (EwkApplicationCacheManager::create):
 26 * UIProcess/API/efl/ewk_context.cpp:
 27 (EwkContext::EwkContext):
 28 (ewk_context_application_cache_manager_get):
 29 * UIProcess/API/efl/ewk_context.h:
 30 * UIProcess/API/efl/ewk_context_private.h:
 31 (EwkContext::applicationCacheManager):
 32 (EwkContext):
 33 * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.cpp:
 34 (EWK2UnitTestServer::getPort):
 35 * UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.h:
 36 (EWK2UnitTestServer):
 37 * UIProcess/API/efl/tests/test_ewk2_application_cache_manager.cpp: Added.
 38 (OriginData):
 39 (OriginData::OriginData):
 40 (getApplicationCacheOriginsCallback):
 41 (serverCallback):
 42 (timerCallback):
 43 (TEST_F):
 44 * UIProcess/API/efl/tests/test_ewk2_context.cpp:
 45 (TEST_F):
 46
1472012-12-04 Andy Estes <aestes@apple.com>
248
349 [WebKit2] WKWebProcessPlugInBrowserContextControllers should be treated as type WKBrowsingContextControllerType for encoding purposes

Source/WebKit2/PlatformEfl.cmake

@@LIST(APPEND WebKit2_SOURCES
4545 UIProcess/API/efl/EvasGLContext.cpp
4646 UIProcess/API/efl/EvasGLSurface.cpp
4747 UIProcess/API/efl/SnapshotImageGL.cpp
 48 UIProcess/API/efl/ewk_application_cache_manager.cpp
4849 UIProcess/API/efl/ewk_auth_request.cpp
4950 UIProcess/API/efl/ewk_back_forward_list.cpp
5051 UIProcess/API/efl/ewk_back_forward_list_item.cpp

@@SET(ForwardingNetworkHeaders_NAME forwarding-headerSoup)
255256CONFIGURE_FILE(efl/ewebkit2.pc.in ${CMAKE_BINARY_DIR}/WebKit2/efl/ewebkit2.pc @ONLY)
256257SET (EWebKit2_HEADERS
257258 "${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/EWebKit2.h"
 259 "${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_application_cache_manager.h"
258260 "${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_auth_request.h"
259261 "${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_back_forward_list.h"
260262 "${CMAKE_CURRENT_SOURCE_DIR}/UIProcess/API/efl/ewk_back_forward_list_item.h"

@@TARGET_LINK_LIBRARIES(ewk2UnitTestUtils ${EWK2UnitTests_LIBRARIES})
365367# The "ewk" on the test name needs to be suffixed with "2", otherwise it
366368# will clash with tests from the WebKit 1 test suite.
367369SET(EWK2UnitTests_BINARIES
 370 test_ewk2_application_cache_manager
368371 test_ewk2_auth_request
369372 test_ewk2_back_forward_list
370373 test_ewk2_color_picker

Source/WebKit2/UIProcess/API/efl/EWebKit2.h

2828#ifndef EWebKit2_h
2929#define EWebKit2_h
3030
 31#include "ewk_application_cache_manager.h"
3132#include "ewk_auth_request.h"
3233#include "ewk_back_forward_list.h"
3334#include "ewk_back_forward_list_item.h"

Source/WebKit2/UIProcess/API/efl/ewk_application_cache_manager.cpp

 1/*
 2 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27#include "ewk_application_cache_manager.h"
 28
 29#include "WKAPICast.h"
 30#include "WKApplicationCacheManager.h"
 31#include "WKArray.h"
 32#include "WebApplicationCacheManagerProxy.h"
 33#include "ewk_application_cache_manager_private.h"
 34#include "ewk_error_private.h"
 35#include "ewk_object.h"
 36#include "ewk_security_origin.h"
 37#include "ewk_security_origin_private.h"
 38#include <wtf/RefCounted.h>
 39
 40using namespace WebKit;
 41
 42EwkApplicationCacheManager::EwkApplicationCacheManager(WebApplicationCacheManagerProxy* applicationCacheManager)
 43 : m_applicationCacheManager(applicationCacheManager)
 44{ }
 45
 46void EwkApplicationCacheManager::getApplicationCacheOrigins(WKApplicationCacheManagerGetApplicationCacheOriginsFunction callback, void* context) const
 47{
 48 m_applicationCacheManager->getApplicationCacheOrigins(ArrayCallback::create(context, callback));
 49}
 50
 51Eina_List* EwkApplicationCacheManager::createOriginList(WKArrayRef origins) const
 52{
 53 Eina_List* originList = 0;
 54 const size_t length = WKArrayGetSize(origins);
 55
 56 for (size_t i = 0; i < length; ++i) {
 57 WKSecurityOriginRef wkOriginRef = static_cast<WKSecurityOriginRef>(WKArrayGetItemAtIndex(origins, i));
 58 RefPtr<Ewk_Security_Origin> origin = m_wrapperCache.get(wkOriginRef);
 59 if (!origin) {
 60 origin = EwkSecurityOrigin::create(wkOriginRef);
 61 m_wrapperCache.set(wkOriginRef, origin);
 62 }
 63 originList = eina_list_append(originList, ewk_object_ref(origin.get()));
 64 }
 65
 66 return originList;
 67}
 68
 69static void getApplicationCacheOriginsCallback(WKArrayRef origins, WKErrorRef wkError, void* context)
 70{
 71 Ewk_Application_Cache_Origins_Async_Get_Context* webApplicationCacheContext = static_cast<Ewk_Application_Cache_Origins_Async_Get_Context*>(context);
 72 Eina_List* originList = webApplicationCacheContext->manager->createOriginList(origins);
 73 OwnPtr<EwkError> ewkError = EwkError::create(wkError);
 74 webApplicationCacheContext->callback(originList, ewkError.get(), webApplicationCacheContext->userData);
 75
 76 void* item;
 77 EINA_LIST_FREE(originList, item)
 78 ewk_object_unref(static_cast<Ewk_Security_Origin*>(item));
 79
 80 delete webApplicationCacheContext;
 81}
 82
 83Eina_Bool ewk_application_cache_manager_origins_get(const Ewk_Application_Cache_Manager* ewkApplicationCacheManager, Ewk_Application_Cache_Origins_Get_Cb callback, void* userData)
 84{
 85 EINA_SAFETY_ON_NULL_RETURN_VAL(ewkApplicationCacheManager, false);
 86 EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
 87
 88 Ewk_Application_Cache_Origins_Async_Get_Context* context = new Ewk_Application_Cache_Origins_Async_Get_Context(ewkApplicationCacheManager, callback, userData);
 89 ewkApplicationCacheManager->getApplicationCacheOrigins(getApplicationCacheOriginsCallback, context);
 90
 91 return true;
 92}

Source/WebKit2/UIProcess/API/efl/ewk_application_cache_manager.h

 1/*
 2 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26/**
 27 * @file ewk_application_cache_manager.h
 28 * @brief Describes the Ewk Application Cache Manager API.
 29 *
 30 * Ewk Application Cache Manager manages web application cache.
 31 */
 32
 33#ifndef ewk_application_cache_manager_h
 34#define ewk_application_cache_manager_h
 35
 36#include "ewk_error.h"
 37#include <Eina.h>
 38
 39#ifdef __cplusplus
 40extern "C" {
 41#endif
 42
 43/** Creates a type name for Ewk_Application_Cache_Manager. */
 44typedef struct EwkApplicationCacheManager Ewk_Application_Cache_Manager;
 45
 46/**
 47 * @typedef Ewk_Application_Cache_Origins_Get_Cb Ewk_Application_Cache_Origins_Get_Cb
 48 * @brief Callback type for use with ewk_application_cache_manager_origins_get()
 49 *
 50 * @param origins @c Eina_List containing @c Ewk_Security_Origin elements or @c NULL in case of error,
 51 * the Eina_List and its items should be freed after use. Use ewk_object_unref()
 52 * to free the items
 53 */
 54typedef void (*Ewk_Application_Cache_Origins_Get_Cb)(Eina_List *origins, Ewk_Error *error, void *user_data);
 55
 56/**
 57 * Gets list of origins using application cache asynchronously.
 58 *
 59 * This function allocates memory for context structure made from callback and user_data.
 60 *
 61 * @param manager Ewk_Application_Cache_Manager object
 62 * @param callback callback to get application cache origins
 63 * @param user_data user_data will be passed when result_callback is called,
 64 * -i.e., user data will be kept until callback is called
 65 *
 66 * @return @c EINA_TRUE on success, @c EINA_FALSE on failure
 67 */
 68EAPI Eina_Bool ewk_application_cache_manager_origins_get(const Ewk_Application_Cache_Manager *manager, Ewk_Application_Cache_Origins_Get_Cb callback, void *user_data);
 69
 70#ifdef __cplusplus
 71}
 72#endif
 73#endif // ewk_application_cache_manager_h

Source/WebKit2/UIProcess/API/efl/ewk_application_cache_manager_private.h

 1/*
 2 * Copyright (C) 2012 Samsung Electronics. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 14 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 22 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 23 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef ewk_application_cache_manager_private_h
 27#define ewk_application_cache_manager_private_h
 28
 29#include "WKApplicationCacheManager.h"
 30#include "WebApplicationCacheManagerProxy.h"
 31#include "WebContext.h"
 32#include "ewk_security_origin.h"
 33#include <WebKit2/WKBase.h>
 34#include <wtf/PassOwnPtr.h>
 35
 36using namespace WebKit;
 37
 38struct Ewk_Application_Cache_Origins_Async_Get_Context {
 39 const Ewk_Application_Cache_Manager* manager;
 40 Ewk_Application_Cache_Origins_Get_Cb callback;
 41 void* userData;
 42
 43 Ewk_Application_Cache_Origins_Async_Get_Context(const Ewk_Application_Cache_Manager* manager, Ewk_Application_Cache_Origins_Get_Cb callback, void* userData)
 44 : manager(manager)
 45 , callback(callback)
 46 , userData(userData)
 47 { }
 48};
 49
 50class EwkApplicationCacheManager {
 51public:
 52 static PassOwnPtr<EwkApplicationCacheManager> create(PassRefPtr<WebContext> context)
 53 {
 54 ASSERT(context);
 55 return adoptPtr(new EwkApplicationCacheManager(context->applicationCacheManagerProxy()));
 56 }
 57
 58 Eina_List* createOriginList(WKArrayRef wkList) const;
 59 void getApplicationCacheOrigins(WKApplicationCacheManagerGetApplicationCacheOriginsFunction callback, void* context) const;
 60
 61private:
 62 explicit EwkApplicationCacheManager(WebApplicationCacheManagerProxy*);
 63
 64 RefPtr<WebApplicationCacheManagerProxy> m_applicationCacheManager;
 65 mutable HashMap<WKSecurityOriginRef, RefPtr<Ewk_Security_Origin> > m_wrapperCache;
 66};
 67#endif // ewk_application_cache_manager_private_h

Source/WebKit2/UIProcess/API/efl/ewk_context.cpp

3333#include "WebContext.h"
3434#include "WebIconDatabase.h"
3535#include "WebSoupRequestManagerProxy.h"
 36#include "ewk_application_cache_manager_private.h"
3637#include "ewk_context_private.h"
3738#include "ewk_cookie_manager_private.h"
3839#include "ewk_database_manager_private.h"

@@static inline ContextMap& contextMap()
6364
6465EwkContext::EwkContext(PassRefPtr<WebContext> context)
6566 : m_context(context)
 67 , m_applicationCacheManager(EwkApplicationCacheManager::create(m_context))
6668 , m_databaseManager(EwkDatabaseManager::create(m_context))
6769 , m_storageManager(EwkStorageManager::create(m_context))
6870#if ENABLE(BATTERY_STATUS)

@@void EwkContext::setAdditionalPluginPath(const String& path)
208210}
209211#endif
210212
 213Ewk_Application_Cache_Manager* ewk_context_application_cache_manager_get(const Ewk_Context* ewkContext)
 214{
 215 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkContext, ewkContext, impl, 0);
 216
 217 return const_cast<EwkContext*>(impl)->applicationCacheManager();
 218}
 219
211220Ewk_Cookie_Manager* ewk_context_cookie_manager_get(const Ewk_Context* ewkContext)
212221{
213222 EWK_OBJ_GET_IMPL_OR_RETURN(const EwkContext, ewkContext, impl, 0);

Source/WebKit2/UIProcess/API/efl/ewk_context.h

3737#ifndef ewk_context_h
3838#define ewk_context_h
3939
 40#include "ewk_application_cache_manager.h"
4041#include "ewk_cookie_manager.h"
4142#include "ewk_database_manager.h"
4243#include "ewk_favicon_database.h"

@@EAPI Ewk_Context *ewk_context_new(void);
148149EAPI Ewk_Context *ewk_context_new_with_injected_bundle_path(const char *path);
149150
150151/**
 152 * Gets the application cache manager instance for this @a context.
 153 *
 154 * @param context context object to query.
 155 *
 156 * @return Ewk_Application_Cache_Manager object instance or @c NULL in case of failure.
 157 */
 158EAPI Ewk_Application_Cache_Manager *ewk_context_application_cache_manager_get(const Ewk_Context *context);
 159
 160/**
151161 * Gets the cookie manager instance for this @a context.
152162 *
153163 * @param context context object to query.

Source/WebKit2/UIProcess/API/efl/ewk_context_private.h

@@public:
5555
5656 ~EwkContext();
5757
 58 inline EwkApplicationCacheManager* applicationCacheManager() const { return m_applicationCacheManager.get(); }
 59
5860 EwkCookieManager* cookieManager();
5961
6062 EwkDatabaseManager* databaseManager();

@@private:
8991
9092 RefPtr<WebContext> m_context;
9193
 94 OwnPtr<EwkApplicationCacheManager> m_applicationCacheManager;
9295 OwnPtr<EwkCookieManager> m_cookieManager;
9396 OwnPtr<EwkDatabaseManager> m_databaseManager;
9497 OwnPtr<EwkFaviconDatabase> m_faviconDatabase;

Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.cpp

@@CString EWK2UnitTestServer::getURLForPath(const char* path) const
5454
5555 return urlString;
5656}
 57
 58unsigned EWK2UnitTestServer::getPort() const
 59{
 60 return soup_server_get_port(m_soupServer);
 61}

Source/WebKit2/UIProcess/API/efl/tests/UnitTestUtils/EWK2UnitTestServer.h

@@public:
3131
3232 CString getURLForPath(const char* path) const;
3333 void run(SoupServerCallback);
 34 unsigned getPort() const;
3435
3536private:
3637 SoupServer* m_soupServer;

Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_application_cache_manager.cpp

 1/*
 2 * Copyright (C) 2012 Samsung Electronics
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 23 * THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#include "config.h"
 27
 28#include "UnitTestUtils/EWK2UnitTestBase.h"
 29#include "UnitTestUtils/EWK2UnitTestEnvironment.h"
 30#include "UnitTestUtils/EWK2UnitTestServer.h"
 31#include "ewk_security_origin_private.h"
 32#include <EWebKit2.h>
 33#include <Ecore.h>
 34#include <wtf/PassOwnPtr.h>
 35
 36using namespace EWK2UnitTest;
 37
 38extern EWK2UnitTestEnvironment* environment;
 39
 40struct OriginData {
 41 Eina_List* originList;
 42 Ewk_Application_Cache_Manager* manager;
 43 bool didReceiveOriginsCallback;
 44 bool isSynchronized;
 45 unsigned timeoutSeconds;
 46 const char* expectedProtocol;
 47 const char* expectedHost;
 48 const unsigned expectedPort;
 49
 50 OriginData(Ewk_Application_Cache_Manager* manager, const char* protocol, const char* host, const unsigned port)
 51 : originList(0)
 52 , manager(manager)
 53 , didReceiveOriginsCallback(false)
 54 , isSynchronized(false)
 55 , timeoutSeconds(10)
 56 , expectedProtocol(protocol)
 57 , expectedHost(host)
 58 , expectedPort(port)
 59 { }
 60};
 61
 62const char* applicationCacheHtml =
 63 "<html manifest='test.appcache'>"
 64 "<head>"
 65 "<title>application cache test</title>"
 66 "<script type='text/javascript'>"
 67 "setTimeout(function() { document.getElementById('clock').value = new Date(); }, 1000);"
 68 "</script>"
 69 "<link rel='stylesheet' href='clock.css'>"
 70 "</head>"
 71 "<body>"
 72 "<p> The time is: <output id='clock'></output></p>"
 73 "</body>"
 74 "</html>";
 75const char* applicationCacheManifest = "CACHE MANIFEST\n"
 76 "application_cache.html\n"
 77 "clock.css";
 78const char* applicationCacheCss = "output { font:2em sans-serif; }";
 79static const char applicationCacheHtmlFile[] = "/application_cache.html";
 80static const char applicationCacheManifestFile[] = "/test.appcache";
 81static const char applicationCacheCssFile[] = "/clock.css";
 82
 83static void getApplicationCacheOriginsCallback(Eina_List* origins, Ewk_Error* error, void* userData)
 84{
 85 ASSERT_FALSE(error);
 86
 87 OriginData* originData = static_cast<OriginData*>(userData);
 88 originData->didReceiveOriginsCallback = true;
 89
 90 Eina_List* l;
 91 void* data;
 92 EINA_LIST_FOREACH(origins, l, data) {
 93 originData->originList = eina_list_append(originData->originList, data);
 94 Ewk_Security_Origin* origin = static_cast<Ewk_Security_Origin*>(data);
 95 if (!strcmp(ewk_security_origin_protocol_get(origin), originData->expectedProtocol)
 96 && !strcmp(ewk_security_origin_host_get(origin), originData->expectedHost)
 97 && ewk_security_origin_port_get(origin) == originData->expectedPort) {
 98 originData->isSynchronized = true;
 99 ecore_main_loop_quit();
 100 }
 101 }
 102}
 103static void serverCallback(SoupServer*, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
 104{
 105 if (message->method != SOUP_METHOD_GET) {
 106 soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
 107 return;
 108 }
 109
 110 soup_message_set_status(message, SOUP_STATUS_OK);
 111 Eina_Strbuf* body = eina_strbuf_new();
 112
 113 if (!strcmp(path, applicationCacheHtmlFile)) {
 114 eina_strbuf_append_printf(body, applicationCacheHtml, 0);
 115 const size_t bodyLength = eina_strbuf_length_get(body);
 116 soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, eina_strbuf_string_steal(body), bodyLength);
 117 } else if (!strcmp(path, applicationCacheManifestFile)) {
 118 eina_strbuf_append_printf(body, applicationCacheManifest, 0);
 119 const size_t bodyLength = eina_strbuf_length_get(body);
 120 soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, eina_strbuf_string_steal(body), bodyLength);
 121 } else if (!strcmp(path, applicationCacheCssFile)) {
 122 eina_strbuf_append_printf(body, applicationCacheCss, 0);
 123 const size_t bodyLength = eina_strbuf_length_get(body);
 124 soup_message_body_append(message->response_body, SOUP_MEMORY_TAKE, eina_strbuf_string_steal(body), bodyLength);
 125 } else
 126 soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
 127
 128 eina_strbuf_free(body);
 129 soup_message_body_complete(message->response_body);
 130}
 131
 132static bool timerCallback(void* userData)
 133{
 134 OriginData* originData = static_cast<OriginData*>(userData);
 135
 136 if (originData->isSynchronized || !--(originData->timeoutSeconds)) {
 137 ecore_main_loop_quit();
 138
 139 return ECORE_CALLBACK_CANCEL;
 140 }
 141
 142 if (originData->didReceiveOriginsCallback) {
 143 originData->didReceiveOriginsCallback = false;
 144 ewk_application_cache_manager_origins_get(originData->manager, getApplicationCacheOriginsCallback, originData);
 145 }
 146
 147 return ECORE_CALLBACK_RENEW;
 148}
 149
 150TEST_F(EWK2UnitTestBase, ewk_application_cache_manager_origins_get)
 151{
 152 Evas_Object* view = webView();
 153 OwnPtr<EWK2UnitTestServer> httpServer = adoptPtr(new EWK2UnitTestServer);
 154 httpServer->run(serverCallback);
 155
 156 ASSERT_TRUE(loadUrlSync(httpServer->getURLForPath(applicationCacheHtmlFile).data()));
 157
 158 OriginData originData(ewk_context_application_cache_manager_get(ewk_view_context_get(view)), "http", "127.0.0.1", httpServer->getPort());
 159 ASSERT_TRUE(ewk_application_cache_manager_origins_get(originData.manager, getApplicationCacheOriginsCallback, &originData));
 160 Ecore_Timer* application_cache_timer = ecore_timer_add(1, reinterpret_cast<Ecore_Task_Cb>(timerCallback), &originData);
 161
 162 ecore_main_loop_begin();
 163 if (application_cache_timer)
 164 ecore_timer_del(application_cache_timer);
 165
 166 ASSERT_TRUE(originData.isSynchronized);
 167 ASSERT_LE(1, eina_list_count(originData.originList));
 168}

Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp

@@TEST_F(EWK2UnitTestBase, ewk_context_default_get)
4141 ASSERT_EQ(defaultContext, ewk_context_default_get());
4242}
4343
 44TEST_F(EWK2UnitTestBase, ewk_context_application_cache_manager_get)
 45{
 46 Ewk_Context* context = ewk_view_context_get(webView());
 47 Ewk_Application_Cache_Manager* applicationCacheManager = ewk_context_application_cache_manager_get(context);
 48 ASSERT_TRUE(applicationCacheManager);
 49 ASSERT_EQ(applicationCacheManager, ewk_context_application_cache_manager_get(context));
 50}
 51
4452TEST_F(EWK2UnitTestBase, ewk_context_cookie_manager_get)
4553{
4654 Ewk_Context* context = ewk_view_context_get(webView());