Fixed a problem that remember popup does not disappear
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_view_orientation_send_func.c
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_view_orientation_send_func.c
24  * @author Yuni Jeong <yhnet.jung@samsung.com>
25  * @date 2012-06-23
26  * @brief Tests EWK function ewk_view_orientation_send()
27  */
28
29 /* Define those macros _before_ you include the utc_webkit2_ewk.h header file. */
30 #define TESTED_FUN_NAME ewk_view_orientation_send
31 #define POSITIVE_TEST_FUN_NUM 4
32 #define NEGATIVE_TEST_FUN_NUM 1
33
34 #include "utc_webkit2_ewk.h"
35
36 static Eina_Bool is_load_failed = EINA_FALSE;
37 static Ewk_Screen_Orientation g_orientation = EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY;
38
39 static void load_finished(void* data, Evas_Object* webview, void* event_info)
40 {
41     utc_message("[load_finished] :: \n");
42     is_load_failed = EINA_FALSE;
43     utc_webkit2_main_loop_quit();
44 }
45
46 static void load_error(void* data, Evas_Object* webview, void* event_info)
47 {
48     utc_message("[load_error] :: \n");
49     is_load_failed = EINA_TRUE;
50     utc_webkit2_main_loop_quit();
51 }
52
53 static Eina_Bool alert_callback(Evas_Object* webview ,const char* alert_text, void* user_data)
54 {
55     utc_message("[alert_callback] :: \n");
56     switch (atoi(alert_text)) {
57     case 0:
58         g_orientation = EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY;
59         break;
60     case 180:
61         g_orientation = EWK_SCREEN_ORIENTATION_PORTRAIT_SECONDARY;
62         break;
63     case 90:
64         g_orientation = EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY;
65         break;
66     case -90:
67         g_orientation = EWK_SCREEN_ORIENTATION_LANDSCAPE_SECONDARY;
68         break;
69     default:
70         g_orientation = -1;
71         break;
72     }
73     utc_webkit2_main_loop_quit();
74 }
75
76 /* Startup and cleanup functions */
77 static void startup(void)
78 {
79     utc_webkit2_ewk_test_init();
80
81     evas_object_smart_callback_add(test_view.webview, "load,finished", load_finished, NULL);
82     evas_object_smart_callback_add(test_view.webview, "load,error", load_error, NULL);
83
84     ewk_view_javascript_alert_callback_set(test_view.webview, alert_callback, 0);
85 }
86
87 static void cleanup(void)
88 {
89     evas_object_smart_callback_del(test_view.webview, "load,finished", load_finished);
90     evas_object_smart_callback_del(test_view.webview, "load,error", load_error);
91
92     utc_webkit2_ewk_test_end();
93 }
94
95 /**
96  * @brief Checking whether orientation is set to EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY properly.
97  */
98 POS_TEST_FUN(1)
99 {
100     char* full_path = generate_full_resource_path("/ewk_view/orientation_test.html");
101     if (!full_path)
102         utc_fail();
103
104     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);
105     if (!result)
106         utc_fail();
107     free(full_path);
108     utc_webkit2_main_loop_begin();
109
110     if (is_load_failed)
111         utc_fail();
112
113     Ewk_Screen_Orientation orientation = EWK_SCREEN_ORIENTATION_LANDSCAPE_PRIMARY;
114     ewk_view_orientation_send(test_view.webview, orientation);
115     utc_webkit2_main_loop_begin();
116     utc_check_eq(orientation, g_orientation);
117 }
118
119 /**
120  * @brief Checking whether orientation is set to EWK_SCREEN_ORIENTATION_LANDSCAPE_SECONDARY properly.
121  */
122 POS_TEST_FUN(2)
123 {
124     char* full_path = generate_full_resource_path("/ewk_view/orientation_test1.html");
125     if (!full_path)
126         utc_fail();
127
128     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);
129     if (!result)
130         utc_fail();
131     free(full_path);
132     utc_webkit2_main_loop_begin();
133
134     if (is_load_failed)
135         utc_fail();
136
137     Ewk_Screen_Orientation orientation = EWK_SCREEN_ORIENTATION_LANDSCAPE_SECONDARY;
138     ewk_view_orientation_send(test_view.webview, orientation);
139     utc_webkit2_main_loop_begin();
140     utc_check_eq(orientation, g_orientation);
141 }
142
143 /**
144  * @brief Checking whether orientation is set to EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY properly.
145  */
146 POS_TEST_FUN(3)
147 {
148     char* full_path = generate_full_resource_path("/ewk_view/orientation_test2.html");
149     if (!full_path)
150         utc_fail();
151
152     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);
153     if (!result)
154         utc_fail();
155     free(full_path);
156     utc_webkit2_main_loop_begin();
157
158     if (is_load_failed)
159         utc_fail();
160
161     Ewk_Screen_Orientation orientation = EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY;
162     ewk_view_orientation_send(test_view.webview, orientation);
163     utc_webkit2_main_loop_begin();
164     utc_check_eq(orientation, g_orientation);
165 }
166
167 /**
168  * @brief Checking whether orientation is set to EWK_SCREEN_ORIENTATION_PORTRAIT_SECONDARY properly.
169  */
170 POS_TEST_FUN(4)
171 {
172     char* full_path = generate_full_resource_path("/ewk_view/orientation_test3.html");
173     if (!full_path)
174         utc_fail();
175
176     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);
177     if (!result)
178         utc_fail();
179     free(full_path);
180     utc_webkit2_main_loop_begin();
181
182     if (is_load_failed)
183         utc_fail();
184
185     Ewk_Screen_Orientation orientation = EWK_SCREEN_ORIENTATION_PORTRAIT_SECONDARY;
186     ewk_view_orientation_send(test_view.webview, orientation);
187     utc_webkit2_main_loop_begin();
188     utc_check_eq(orientation, g_orientation);
189 }
190
191 /**
192  * @brief Checking whether function works properly in case of NULL of a webview.
193  */
194 NEG_TEST_FUN(1)
195 {
196     ewk_view_orientation_send(NULL, EWK_SCREEN_ORIENTATION_PORTRAIT_PRIMARY);
197     utc_pass();
198 }