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_menu.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_menu.h
24  * @author Eunmi Lee <eunmi15.lee@samsung.com>
25  * @date   2012-06-20
26  * @brief  A header file to be used by context menu's unit test cases for WebKit2 EFL API
27  *
28  * This header file contains a common content for unit test cases, i.e.:
29  * it includes useful header files for context menu.
30  */
31
32 #ifndef UTC_WEBKIT2_EWK_CONTEXT_MENU_H
33 #define UTC_WEBKIT2_EWK_CONTEXT_MENU_H
34
35 #include "ewk_context_menu.h"
36 #include "utc_webkit2_ewk.h"
37 #include <Ecore.h>
38 #include <Evas.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 enum {
45     CUSTOM_CONTEXT_MENU_ITEM_BASE_TAG = EWK_CONTEXT_MENU_ITEM_BASE_APPLICATION_TAG,
46     CUSTOM_CONTEXT_MENU_ITEM_TEST_TAG
47 };
48
49 static Eina_Bool is_failed = EINA_FALSE;
50 static Ecore_Timer* select_timer = 0;
51
52 static void feed_mouse_click(int button, int x, int y)
53 {
54     evas_event_feed_mouse_move(test_view.evas, x, y, ecore_time_get(), 0);
55     evas_event_feed_mouse_down(test_view.evas, button, EVAS_BUTTON_NONE, ecore_time_get(), 0);
56     evas_event_feed_mouse_up(test_view.evas, button, EVAS_BUTTON_NONE, ecore_time_get(), 0);
57 }
58
59 static Eina_Bool select_timer_callback(void* data)
60 {
61     utc_message("[select_timer_callback] :: \n");
62     feed_mouse_click(1, 50, 250);
63     return ECORE_CALLBACK_CANCEL;
64 }
65
66 static void select_item()
67 {
68     select_timer = ecore_timer_add(1, select_timer_callback, 0);
69 }
70
71 static void load_finished(void* data, Evas_Object* webview, void* event_info)
72 {
73     utc_message("[load_finished] :: \n");
74     feed_mouse_click(3, 100, 100);
75 }
76
77 static void load_error(void* data, Evas_Object* webview, void* event_info)
78 {
79     utc_message("[load_error] :: \n");
80     is_failed = EINA_TRUE;
81     utc_webkit2_main_loop_quit();
82 }
83
84 /**
85  * Initiates context menu used in the test.
86  *
87  * This function should be _always_ called before the actual context menu's test starts.
88  * @see utc_webkit2_ewk_context_menu_test_end()
89  */
90 static void utc_webkit2_ewk_context_menu_test_init()
91 {
92     utc_webkit2_ewk_test_init();
93
94     /* Enable mouse events to feed events directly. */
95     ewk_view_mouse_events_enabled_set(test_view.webview, EINA_TRUE);
96
97     evas_object_smart_callback_add(test_view.webview, "load,finished", load_finished, 0);
98     evas_object_smart_callback_add(test_view.webview, "load,error", load_error, 0);
99
100     char* full_path = generate_full_resource_path("/ewk_context_menu/index.html");
101     if (!full_path) {
102         is_failed = EINA_TRUE;
103         return;
104     }
105
106     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);
107     free(full_path);
108     if (!result) {
109         is_failed = EINA_TRUE;
110         return;
111     }
112 }
113
114 /**
115  * Frees context_menu's resources used during the test.
116  * This function should be _always_ called after the context menu's test is completed.
117  * @see utc_webkit2_ewk_context_menu_test_init()
118  */
119 static void utc_webkit2_ewk_context_menu_test_end()
120 {
121     evas_object_smart_callback_del(test_view.webview, "load,finished", load_finished);
122     evas_object_smart_callback_del(test_view.webview, "load,error", load_error);
123
124     if (select_timer)
125         ecore_timer_del(select_timer);
126
127     utc_webkit2_ewk_test_end();
128 }
129
130 #ifdef __cplusplus
131 }
132 #endif
133
134 #endif /* UTC_WEBKIT2_EWK_CONTEXT_MENU_H */