Fixed a problem that remember popup does not disappear
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_context_menu_item_image_url_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_context_menu_item_image_url_get_func.c
24  * @author Eunmi Lee <eunmi15.lee@samsung.com>
25  * @date 2012-06-20
26  * @brief Tests EWK function ewk_context_menu_item_image_url_get()
27  */
28
29 /* Define those macros _before_ you include the utc_webkit2_ewk.h header file. */
30 #define TESTED_FUN_NAME ewk_context_menu_item_image_url_get
31 #define POSITIVE_TEST_FUN_NUM 1
32 #define NEGATIVE_TEST_FUN_NUM 1
33
34 #include "utc_webkit2_ewk_context_menu.h"
35
36 static char* image_path = 0;
37 static char* url = 0;
38
39 static void contextmenu_customize_callback(void* data, Evas_Object* webview, void* event_info)
40 {
41     utc_message("[contextmenu_customize_callback] :: \n");
42     Ewk_Context_Menu* contextmenu = (Ewk_Context_Menu*)event_info;
43
44     Ewk_Context_Menu_Item* item = ewk_context_menu_nth_item_get(contextmenu, 0);
45     while (item) {
46         ewk_context_menu_item_remove(contextmenu, item);
47         item = ewk_context_menu_nth_item_get(contextmenu, 0);
48     }
49
50     ewk_context_menu_item_append_as_action(contextmenu, CUSTOM_CONTEXT_MENU_ITEM_TEST_TAG, "< Item for Test >", EINA_TRUE);
51     ewk_context_menu_item_append_as_action(contextmenu, CUSTOM_CONTEXT_MENU_ITEM_TEST_TAG, "< Item for Test >", EINA_TRUE);
52     ewk_context_menu_item_append_as_action(contextmenu, CUSTOM_CONTEXT_MENU_ITEM_TEST_TAG, "< Item for Test >", EINA_TRUE);
53
54     select_item();
55 }
56
57 static void contextmenu_selected_callback(void* data, Evas_Object* webview, void* event_info)
58 {
59     Ewk_Context_Menu_Item* item = (Ewk_Context_Menu_Item*)event_info;
60     const char* image_url = ewk_context_menu_item_image_url_get(item);
61     if (!image_url)
62         is_failed = EINA_TRUE;
63     else
64         url = strdup(image_url);
65
66     utc_webkit2_main_loop_quit();
67 }
68
69 /* Startup and cleanup functions */
70 static void startup(void)
71 {
72     utc_webkit2_ewk_context_menu_test_init();
73     evas_object_smart_callback_add(test_view.webview, "contextmenu,customize", contextmenu_customize_callback, 0);
74     evas_object_smart_callback_add(test_view.webview, "contextmenu,selected", contextmenu_selected_callback, 0);
75     image_path = generate_full_resource_path("/ewk_context_menu/webkit.png");
76 }
77
78 static void cleanup(void)
79 {
80     evas_object_smart_callback_del(test_view.webview, "contextmenu,customize", contextmenu_customize_callback);
81     evas_object_smart_callback_del(test_view.webview, "contextmenu,selected", contextmenu_selected_callback);
82     if (image_path)
83         free(image_path);
84     if (url)
85         free(url);
86     utc_webkit2_ewk_context_menu_test_end();
87 }
88
89 /**
90  * @brief Tests whether the getting image url from context menu item is performed properly.
91  */
92 POS_TEST_FUN(1)
93 {
94     if (!is_failed)
95         utc_webkit2_main_loop_begin();
96
97     if (is_failed)
98         utc_fail();
99
100     if (!url)
101        utc_fail();
102     utc_check_str_eq(url, image_path);
103 }
104
105 /**
106  * @brief Tests whether the function works properly for case Ewk_Context_Menu object is NULL.
107  */
108 NEG_TEST_FUN(1)
109 {
110     utc_check_eq(ewk_context_menu_item_image_url_get(NULL), 0);
111 }