Missing ewk API tests
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_view_popup_menu_multiple_select_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_popup_menu_multiple_select_func.c
24  * @author Krzysztof Czech <k.czech@samsung.com>
25  * @date 2013-05-29
26  * @brief Tests EWK function ewk_view_popup_menu_multiple_select()
27  */
28
29 #include <EWebKit2.h>
30 #include <Ecore.h>
31 #include <Ecore_Evas.h>
32 #include <Elementary.h>
33 #include <tet_api.h>
34
35 #define TESTED_FUN_NAME "ewk_view_popup_menu_multiple_select"
36 #define POS_STRING_FAIL "failed in positive test case"
37 #define NEG_STRING_FAIL "failed in negative test case"
38
39 static Evas_Object* webview;
40 static Evas_Object* window;
41 static Evas_Smart* evasSmartClass;
42 static Ewk_View_Smart_Class ewkViewSmartClass;
43
44 static void startup(void);
45 static void cleanup(void);
46
47 void (*tet_startup)(void) = startup;
48 void (*tet_cleanup)(void) = cleanup;
49
50 static void utc_webkit2_ewk_view_popup_menu_multiple_select_positive(void);
51 static void utc_webkit2_ewk_view_popup_menu_multiple_select_negative(void);
52
53 enum {
54     POSITIVE_TC_IDX = 1,
55     NEGATIVE_TC_IDX
56 };
57
58 struct tet_testlist tet_testlist[] = {
59     {utc_webkit2_ewk_view_popup_menu_multiple_select_positive, POSITIVE_TC_IDX},
60     {utc_webkit2_ewk_view_popup_menu_multiple_select_negative, NEGATIVE_TC_IDX},
61     {NULL, 0}
62 };
63
64 static Ewk_View_Smart_Class smartClass()
65 {
66     static Ewk_View_Smart_Class smart = EWK_VIEW_SMART_CLASS_INIT_NAME_VERSION("tcwebkit2");
67     return smart;
68 }
69
70 static void onLoadFinished(void* data, Evas_Object* obj, void* eventInfo)
71 {
72     tet_infoline("====== onLoadFinished ======\n");
73     ecore_main_loop_quit();
74 }
75
76 static void startup(void)
77 {
78     tet_infoline("====== startup ======\n");
79
80     g_type_init();
81     elm_init(0, NULL);
82
83     elm_config_preferred_engine_set("opengl_x11");
84
85     eina_init();
86
87     window = elm_win_add(NULL, "TC Launcher", ELM_WIN_BASIC);
88     elm_win_title_set(window, "TC Launcher");
89     evas_object_show(window);
90
91     Evas *evas = evas_object_evas_get(window);
92
93     ewkViewSmartClass = smartClass();
94     ewk_view_smart_class_set(&ewkViewSmartClass);
95     evasSmartClass = evas_smart_class_new(&ewkViewSmartClass.sc);
96     Ewk_Context *context = ewk_context_default_get();
97     webview = ewk_view_smart_add(evas, evasSmartClass, context);
98
99     /*elements = eina_list_append(elements, eina_stringshare_add("one"));
100     elements = eina_list_append(elements, eina_stringshare_add("two"));
101     elements = eina_list_append(elements, eina_stringshare_add("three"));*/
102
103     evas_object_resize(webview, 800, 600);
104     evas_object_show(webview);
105
106     evas_object_smart_callback_add(webview, "load,finished", onLoadFinished, 0);
107 }
108
109 static void cleanup(void)
110 {
111     evas_object_smart_callback_del(webview, "load,finished", onLoadFinished);
112     evas_smart_free(evasSmartClass);
113     evas_object_del(webview);
114     eina_shutdown();
115 }
116
117 static void mouseClick(int x, int y)
118 {
119     Evas *evas = evas_object_evas_get(window);
120     evas_event_feed_mouse_move(evas, x, y, 0, 0);
121     evas_event_feed_mouse_down(evas, 1, EVAS_BUTTON_NONE, 0, 0);
122     evas_event_feed_mouse_up(evas, 1, EVAS_BUTTON_NONE, 0, 0);
123 }
124
125 static Eina_Bool onTimeout(void* data)
126 {
127     ecore_main_loop_quit();
128     return ECORE_CALLBACK_CANCEL;
129 }
130
131 static Eina_Bool multiplePopupMenuShow(Ewk_View_Smart_Data* smartData, Eina_Rectangle rect, Ewk_Text_Direction text_direction, double page_scale_factor, Eina_List* items)
132 {
133     tet_infoline("====== multiple_popup_menu_show ======\n");
134
135     Eina_Inarray *inarr = eina_inarray_new(sizeof(int), 0);
136     int index = 0;
137     eina_inarray_push(inarr, &index);
138     index = 1;
139     eina_inarray_push(inarr, &index);
140
141     Eina_Bool result = ewk_view_popup_menu_multiple_select(webview, inarr);
142
143     eina_inarray_free(inarr);
144
145     dts_check_eq(TESTED_FUN_NAME, result, EINA_TRUE, POS_STRING_FAIL);
146
147     return EINA_TRUE;
148 }
149
150 /**
151 * @brief Checking whether function works properly.
152 */
153 static void utc_webkit2_ewk_view_popup_menu_multiple_select_positive(void)
154 {
155     static const char selectHTML[] =
156         "<body>"
157         "<select multiple>"
158         "<option>one</option>"
159         "<option>two</option>"
160         "<option>three</option>"
161         "</select>"
162         "</body>";
163
164     ewkViewSmartClass.multiple_popup_menu_show = multiplePopupMenuShow;
165     ewk_view_html_string_load(webview, selectHTML, 0, 0);
166
167     ecore_main_loop_begin();
168
169     static const unsigned x = 46;
170     static const unsigned y = 19;
171     mouseClick(x, y);
172
173     static const double timeout = 2;
174     Ecore_Timer *timer = ecore_timer_add(timeout, onTimeout, 0);
175     ecore_main_loop_begin();
176 }
177
178 /**
179 * @brief Checking whether function works properly.
180 */
181 static void utc_webkit2_ewk_view_popup_menu_multiple_select_negative(void)
182 {
183     dts_check_eq(TESTED_FUN_NAME, ewk_view_popup_menu_multiple_select(0, 0), EINA_FALSE, POS_STRING_FAIL);
184 }