Fixed a problem that remember popup does not disappear
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_context_web_database.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_web_database.h
24  * @author SangYong Park <sy302.park@samsung.com>
25  * @date 2012-06-20
26  * @brief A header file to be used by ewk_context_web_database unit test cases
27  */
28
29 #define WEB_DATABASE_PROTOCOL "http"
30 #define WEB_DATABASE_HOST "unittest.com"
31 #define WEB_DATABASE_PORT 0
32
33 const char* webDatabaseURL = WEB_DATABASE_PROTOCOL "://" WEB_DATABASE_HOST "/";
34 const char* webDatabaseScript = "var db = openDatabase('test', '1.0', 'test db', 1024);"
35                                 "var result = 0;"
36                                 "db.transaction(function (tx) {"
37                                     "tx.executeSql('CREATE TABLE tbl(id INTEGER)');"
38                                     "tx.executeSql('INSERT INTO tbl(id) VALUES(1)')"
39                                 "}, function () { result = 1 }, function () { result = -1 });";
40 const char* webDatabaseResultScript = "result";
41
42 typedef void (*Web_Storage_Callback)();
43
44 Web_Storage_Callback finishedCallback;
45 Web_Storage_Callback errorCallback;
46
47 static void scriptExecuted(Evas_Object* o, const char* result, void* data)
48 {
49     int value = atoi(result);
50     if (!value) {
51         if (!ewk_view_script_execute(test_view.webview, webDatabaseResultScript, scriptExecuted, 0))
52             errorCallback();
53         return;
54     }
55
56     finishedCallback();
57 }
58
59 static void loadFinished(void* data, Evas_Object* webview, void* info)
60 {
61     if (!ewk_view_script_execute(test_view.webview, webDatabaseScript, scriptExecuted, 0))
62         errorCallback();
63 }
64
65 static void loadError(void* data, Evas_Object* webview, void* info)
66 {
67     errorCallback();
68 }
69
70 static Eina_Bool addWebDatabase(Web_Storage_Callback finished, Web_Storage_Callback error)
71 {
72     finishedCallback = finished;
73     errorCallback = error;
74
75     evas_object_smart_callback_add(test_view.webview, "load,finished", loadFinished, 0);
76     evas_object_smart_callback_add(test_view.webview, "load,error", loadError, 0);
77
78     return ewk_view_html_contents_set(test_view.webview, "", webDatabaseURL);
79 }