Missing ewk API tests
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_view_before_unload_confirm_panel_reply_func.c
1 /*
2  * WebKit2 EFL
3  *
4  * Copyright (c) 2013 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_view_before_unload_confirm_panel_reply_func.c
24  * @author Krzysztof Czech <k.czech@samsung.com>
25  * @date 2013-05-28
26  * @brief Tests EWK function ewk_view_before_unload_confirm_panel_reply
27  */
28
29 #define TESTED_FUN_NAME ewk_view_before_unload_confirm_panel_reply
30 #define POSITIVE_TEST_FUN_NUM 1
31 #define NEGATIVE_TEST_FUN_NUM 1
32
33 #include "utc_webkit2_ewk.h"
34
35 #define HTML_PAGE "/ewk_view/before_unload_test.html"
36
37 static Ecore_Timer* watchTimer;
38 static Eina_Bool result;
39
40 static void loadURL(const char* url)
41 {
42     char* full_path = generate_full_resource_path(url);
43     if (!full_path)
44         utc_fail();
45
46     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);
47     free(full_path);
48
49     if (!result)
50         utc_fail();
51 }
52
53 static Eina_Bool onWatchTimerCallback(void* data)
54 {
55     utc_message("====== onWatchTimerCallback ======\n");
56     utc_webkit2_main_loop_quit();
57     return ECORE_CALLBACK_CANCEL;
58 }
59
60 static void onLoadFinished(void* data, Evas_Object* webview, void* event_info)
61 {
62     utc_message("===== onLoadFinished ======\n");
63     watchTimer = ecore_timer_add(20, onWatchTimerCallback, 0);
64 }
65
66 static void startup(void)
67 {
68     utc_webkit2_ewk_test_init();
69     evas_object_smart_callback_add(test_view.webview, "load,finished", onLoadFinished, NULL);
70 }
71
72 static void cleanup(void)
73 {
74     utc_webkit2_ewk_test_end();
75     evas_object_smart_callback_del(test_view.webview, "load,finished", onLoadFinished);
76     ecore_timer_del(watchTimer);
77 }
78
79 static Eina_Bool beforeUnloadCallback(Evas_Object* o, const char* message, void* userData)
80 {
81     utc_message("===== beforeUnloadCallback =====\n");
82
83     ewk_view_before_unload_confirm_panel_reply(test_view.webview, EINA_TRUE);
84     result = EINA_TRUE;
85
86     utc_webkit2_main_loop_quit();
87 }
88
89 /**
90 * @brief Checks whether function works properly.
91 */
92 POS_TEST_FUN(1)
93 {
94     ewk_view_before_unload_confirm_panel_callback_set(test_view.webview, beforeUnloadCallback, 0);
95
96     loadURL(HTML_PAGE);
97     utc_webkit2_main_loop_begin();
98
99     utc_check_eq(result, EINA_TRUE);
100 }
101
102 /**
103 * @brief Checks whether function works correctly in case of null of a webview.
104 */
105 NEG_TEST_FUN(1)
106 {
107     ewk_view_before_unload_confirm_panel_reply(0, EINA_FALSE);
108     utc_pass();
109 }