Merge "[Cherry-pick] Refactor WrapShape classes to BasicShape" into tizen_2.1
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_context_application_cache.h
1 /*
2  * WebKit2 EFL
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by the
8  * Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc., 51
18  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  */
21
22 /**
23  * @file utc_webkit2_ewk_context_application_cache.h
24  * @author SangYong Park <sy302.park@samsung.com>
25  * @date 2012-06-12
26  * @brief A header file to be used by ewk_context_application_cache unit test cases
27  */
28
29 #define APP_CACHE_PROTOCOL "http"
30 #define APP_CACHE_HOST "html5demos.com"
31 #define APP_CACHE_PORT 0
32
33 const char* appCacheURL = APP_CACHE_PROTOCOL "://" APP_CACHE_HOST "/offlineapp";
34 const char* checkStatusScript = "window.applicationCache.status";
35
36 typedef void (*App_Cache_Callback)();
37
38 App_Cache_Callback finishedCallback;
39 App_Cache_Callback errorCallback;
40
41 static void scriptExecuted(Evas_Object* o, const char* result, void* data)
42 {
43     int status = atoi(result);
44     if (status == 3) {
45         if (!ewk_view_script_execute(test_view.webview, checkStatusScript, scriptExecuted, 0))
46             errorCallback();
47         return;
48     }
49
50     finishedCallback();
51 }
52
53 static void loadFinished(void* data, Evas_Object* webview, void* info)
54 {
55     if (!ewk_view_script_execute(test_view.webview, checkStatusScript, scriptExecuted, 0))
56         errorCallback();
57 }
58
59 static void loadError(void* data, Evas_Object* webview, void* event)
60 {
61     errorCallback();
62 }
63
64 static Eina_Bool addApplicationCache(App_Cache_Callback finished, App_Cache_Callback error)
65 {
66     finishedCallback = finished;
67     errorCallback = error;
68
69     evas_object_smart_callback_add(test_view.webview, "load,finished", loadFinished, 0);
70     evas_object_smart_callback_add(test_view.webview, "load,error", loadError, 0);
71
72     return ewk_view_url_set(test_view.webview, appCacheURL);
73 }