Fixed a problem that remember popup does not disappear
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_view_popup_menu_close_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_popup_menu_close_func.c
24  * @author Lukasz Gajowy <l.gajowy@samsung.com>
25  * @date 2013-03-27
26  * @brief Tests EWK function ewk_view_popup_menu_close(Evas_Object *o)
27  */
28
29 #define TESTED_FUN_NAME "ewk_view_popup_menu_close"
30 #define POS_STRING_FAIL "failed in positive test case"
31 #define NEG_STRING_FAIL "failed in negative test case"
32
33 #include <Ecore_Evas.h>
34 #include <Ecore.h>
35 #include <Elementary.h>
36 #include <EWebKit2.h>
37 #include <tet_api.h>
38
39 static Evas_Object* webview;
40 static Evas_Object* window;
41 static Evas_Smart* evasSmartClass;
42 static Ewk_View_Smart_Class ewkViewSmartClass;
43 static Ecore_Timer* timer;
44
45 static const unsigned xClick = 46;
46 static const unsigned yClick = 19;
47 static const double timeout = 2;
48 static const char selectHTML[] =
49         "<body>"
50         "<select>"
51         "<option>one</option>"
52         "</select>"
53         "</body>";
54
55 static void startup(void);
56 static void cleanup(void);
57
58 void (*tet_startup)(void) = startup;
59 void (*tet_cleanup)(void) = cleanup;
60
61 static void utcWebkit2EwkWiewPopupMenuClosePositive(void);
62 static void utcWebkit2EwkWiewPopupMenuCloseNegative(void);
63
64 enum {
65     POSITIVE_TC_IDX = 1,
66     NEGATIVE_TC_IDX
67 };
68
69 struct tet_testlist tet_testlist[] = {
70     {utcWebkit2EwkWiewPopupMenuClosePositive, POSITIVE_TC_IDX},
71     {utcWebkit2EwkWiewPopupMenuCloseNegative, NEGATIVE_TC_IDX},
72     {NULL, 0}
73 };
74
75 static Ewk_View_Smart_Class smartClass()
76 {
77     static Ewk_View_Smart_Class smart = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("tcwebkit2");
78     return smart;
79 }
80
81 static void onLoadFinished(void* data, Evas_Object* obj, void* eventInfo)
82 {
83     tet_infoline("====== onLoadFinished ======\n");
84     ecore_main_loop_quit();
85 }
86
87 static void startup(void)
88 {
89     tet_infoline("====== startup ======\n");
90
91     g_type_init();
92     elm_init(0, NULL);
93
94     elm_config_preferred_engine_set("opengl_x11");
95
96     window = elm_win_add(NULL, "TC Launcher", ELM_WIN_BASIC);
97     elm_win_title_set(window, "TC Launcher");
98     evas_object_show(window);
99
100     Evas *evas = evas_object_evas_get(window);
101
102     ewkViewSmartClass = smartClass();
103     ewk_view_smart_class_set(&ewkViewSmartClass);
104     evasSmartClass = evas_smart_class_new(&ewkViewSmartClass.sc);
105     Ewk_Context *context = ewk_context_default_get();
106     webview = ewk_view_smart_add(evas, evasSmartClass, context);
107
108     evas_object_resize(webview, 800, 600);
109     evas_object_show(webview);
110
111     evas_object_smart_callback_add(webview, "load,finished", onLoadFinished, 0);
112 }
113
114 static void cleanup(void)
115 {
116     evas_object_smart_callback_del(webview, "load,finished", onLoadFinished);
117     evas_smart_free(evasSmartClass);
118     evas_object_del(webview);
119 }
120
121 static void mouseClick(int x, int y)
122 {
123     Evas *evas = evas_object_evas_get(window);
124     evas_event_feed_mouse_move(evas, x, y, 0, 0);
125     evas_event_feed_mouse_down(evas, 1, EVAS_BUTTON_NONE, 0, 0);
126     evas_event_feed_mouse_up(evas, 1, EVAS_BUTTON_NONE, 0, 0);
127 }
128
129 static Eina_Bool onTimeout(void* data)
130 {
131     ecore_main_loop_quit();
132     return ECORE_CALLBACK_CANCEL;
133 }
134
135 static Eina_Bool popupMenuShow(Ewk_View_Smart_Data *sd, Eina_Rectangle rect, Ewk_Text_Direction text_direction, double page_scale_factor, Eina_List* items, int selected_index)
136 {
137     tet_infoline("====== popup_menu_show ======\n");
138     Eina_Bool result = ewk_view_popup_menu_close(webview);
139     dts_check_eq(TESTED_FUN_NAME, result, EINA_TRUE, POS_STRING_FAIL);
140     ecore_main_loop_quit();
141     ecore_timer_delete(timer);
142     return EINA_TRUE;
143 }
144
145 /*
146  * @brief Checking whether popup menu is closed properly.
147  */
148 static void utcWebkit2EwkWiewPopupMenuClosePositive(void)
149 {
150     ewkViewSmartClass.popup_menu_show = popupMenuShow;
151     ewk_view_html_string_load(webview, selectHTML, 0, 0);
152     ecore_main_loop_begin();
153     mouseClick(xClick, yClick);
154     timer = ecore_timer_add(timeout, onTimeout, 0);
155     ecore_main_loop_begin();
156 }
157
158 /**
159 * @brief Checking whether function works properly in case of a null Evas_Object given as an argument.
160 */
161 static void utcWebkit2EwkWiewPopupMenuCloseNegative(void)
162 {
163     dts_check_eq(TESTED_FUN_NAME, ewk_view_popup_menu_close(0), EINA_FALSE, NEG_STRING_FAIL);
164 }