Merge "[Cherry-pick] Refactor WrapShape classes to BasicShape" into tizen_2.1
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_custom_handlers_data_target_get_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_custom_handlers_data_target_get_func.c
24  * @author Yuni Jeong <yhnet.jung@samsung.com>
25  * @date 2012-06-21
26  * @brief Tests EWK function ewk_custom_handlers_data_target_get()
27  */
28
29 /* Define those macros _before_ you include the utc_webkit2_ewk.h header file. */
30 #define TESTED_FUN_NAME ewk_custom_handlers_data_target_get
31 #define POSITIVE_TEST_FUN_NUM 1
32 #define NEGATIVE_TEST_FUN_NUM 1
33
34 #include "utc_webkit2_ewk.h"
35 #include "ewk_custom_handlers.h"
36
37 static Eina_Bool is_load_failed = EINA_FALSE;
38 static Eina_Bool g_result = EINA_FALSE;
39
40 static void load_finished(void* data, Evas_Object* webview, void* event_info)
41 {
42     utc_message("[load_finished] :: \n");
43     is_load_failed = EINA_FALSE;
44     utc_webkit2_main_loop_quit();
45 }
46
47 static void load_error(void* data, Evas_Object* webview, void* event_info)
48 {
49     utc_message("[load_error] :: \n");
50     is_load_failed = EINA_TRUE;
51     utc_webkit2_main_loop_quit();
52 }
53
54 static void contenthandlers_regster(void* data, Evas_Object* webview, void* event_info)
55 {
56     utc_message("[contenthandlers_regster] :: \n");
57     Ewk_Custom_Handlers_Data* custom_handlers_data = (Ewk_Custom_Handlers_Data*)event_info;
58     if (custom_handlers_data && ewk_custom_handlers_data_target_get(custom_handlers_data))
59         g_result = EINA_TRUE;
60 }
61
62 /* Startup and cleanup functions */
63 static void startup(void)
64 {
65     utc_webkit2_ewk_test_init();
66
67     evas_object_smart_callback_add(test_view.webview, "load,finished", load_finished, NULL);
68     evas_object_smart_callback_add(test_view.webview, "load,error", load_error, NULL);
69     evas_object_smart_callback_add(test_view.webview, "contenthandlers,register", contenthandlers_regster, NULL);
70 }
71
72 static void cleanup(void)
73 {
74     evas_object_smart_callback_del(test_view.webview, "load,finished", load_finished);
75     evas_object_smart_callback_del(test_view.webview, "load,error", load_error);
76     evas_object_smart_callback_del(test_view.webview, "contenthandlers,register", contenthandlers_regster);
77
78     utc_webkit2_ewk_test_end();
79 }
80
81 /**
82  * @brief Checking whether the target(scheme or mime type) of custom handlers data is returned properly.
83  */
84 POS_TEST_FUN(1)
85 {
86     char* full_path = generate_full_resource_path("/ewk_custom_handlers/registerContentHandler.html");
87     if (!full_path)
88         utc_fail();
89
90     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);
91     if (!result)
92         utc_fail();
93     free(full_path);
94     utc_webkit2_main_loop_begin();
95
96     if (g_result && !is_load_failed)
97         result = EINA_TRUE;
98     else
99         result = EINA_FALSE;
100
101     utc_check_eq(result, EINA_TRUE);
102 }
103
104 /**
105  * @brief Checking whether function works properly in case of NULL of a custom handlers data.
106  */
107 NEG_TEST_FUN(1)
108 {
109     utc_check_eq(ewk_custom_handlers_data_target_get(NULL), 0);
110 }