Merge "[Cherry-pick] Refactor WrapShape classes to BasicShape" into tizen_2.1
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_auth_challenge_credential_cancel_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_auth_challenge_credential_cancel_func.c
24  * @author Yuni Jeong <yhnet.jung@samsung.com>
25  * @date 2012-06-07
26  * @brief Tests EWK function ewk_auth_challenge_credential_cancel()
27  */
28
29 /* Define those macros _before_ you include the utc_webkit2_ewk.h header file. */
30 #define TESTED_FUN_NAME ewk_auth_challenge_credential_cancel
31 #define POSITIVE_TEST_FUN_NUM 1
32 #define NEGATIVE_TEST_FUN_NUM 1
33
34 #include "utc_webkit2_ewk.h"
35 static Eina_Bool is_failed;
36 static Eina_Bool is_Authenticated;
37
38 #define URL "http://reference.vodafone.com/widgets/"
39
40 static void load_finished(void* data, Evas_Object* webview, void* event_info)
41 {
42     utc_message("[load_finished] :: \n");
43     if (!is_Authenticated)
44         is_failed = EINA_TRUE;
45
46     utc_webkit2_main_loop_quit();
47 }
48
49 static void load_error(void* data, Evas_Object* webview, void* event_info)
50 {
51     utc_message("[load_error] :: \n");
52     is_failed = EINA_TRUE;
53     utc_webkit2_main_loop_quit();
54 }
55
56 static void authentication_challenge(void* data, Evas_Object* webview, void* event_info)
57 {
58     utc_message("[authentication_challenge] :: \n");
59     is_Authenticated = EINA_TRUE;
60
61     Ewk_Auth_Challenge* auth_challenge = (Ewk_Auth_Challenge*)event_info;
62     if (!auth_challenge) {
63         is_failed = EINA_TRUE;
64         utc_webkit2_main_loop_quit();
65         return;
66     }
67
68     char* realm = ewk_auth_challenge_realm_get(auth_challenge);
69     char* url = ewk_auth_challenge_url_get(auth_challenge);
70     if (!realm || !url) {
71         is_failed = EINA_TRUE;
72         utc_webkit2_main_loop_quit();
73         return;
74     }
75
76     ewk_auth_challenge_credential_cancel(auth_challenge);
77 }
78
79 /* Startup and cleanup functions */
80 static void startup(void)
81 {
82     utc_webkit2_ewk_test_init();
83
84     evas_object_smart_callback_add(test_view.webview, "load,finished", load_finished, NULL);
85     evas_object_smart_callback_add(test_view.webview, "load,error", load_error, NULL);
86     evas_object_smart_callback_add(test_view.webview, "authentication,challenge", authentication_challenge, NULL);
87 }
88
89 static void cleanup(void)
90 {
91     evas_object_smart_callback_del(test_view.webview, "load,finished", load_finished);
92     evas_object_smart_callback_del(test_view.webview, "load,error", load_error);
93     evas_object_smart_callback_del(test_view.webview, "authentication,challenge", authentication_challenge);
94
95     utc_webkit2_ewk_test_end();
96 }
97
98 /**
99  * @brief Checking whether sending cancellation notification for authentication challenge works properly.
100  */
101 POS_TEST_FUN(1)
102 {
103     is_failed = EINA_FALSE;
104     is_Authenticated = EINA_FALSE;
105
106     Eina_Bool result = ewk_view_url_set(test_view.webview, URL);
107     if (!result)
108         utc_fail();
109     utc_webkit2_main_loop_begin();
110
111     if (is_failed)
112         utc_fail();
113
114     result = is_Authenticated;
115
116     evas_object_show(test_view.webview);
117     evas_object_show(test_view.window);
118     utc_check_eq(result, EINA_TRUE);
119 }
120
121 /**
122  * @brief Checking whether function works properly in case of NULL of a webview.
123  */
124 NEG_TEST_FUN(1)
125 {
126     is_failed = EINA_FALSE;
127     is_Authenticated = EINA_FALSE;
128
129     Eina_Bool result = ewk_view_url_set(NULL, URL);
130     if (result)
131         utc_fail();
132
133     result = is_Authenticated;
134
135     evas_object_show(test_view.webview);
136     evas_object_show(test_view.window);
137     utc_check_ne(result, EINA_TRUE);
138 }