Fixed a problem that remember popup does not disappear
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_view_javascript_prompt_callback_set_func.c
1 /*\r
2  * WebKit2 EFL\r
3  *\r
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
5  *\r
6  * This library is free software; you can redistribute it and/or modify it under\r
7  * the terms of the GNU Lesser General Public License as published by the\r
8  * Free Software Foundation; either version 2.1 of the License, or (at your option)\r
9  * any later version.\r
10  *\r
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY\r
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public\r
14  * License for more details.\r
15  *\r
16  * You should have received a copy of the GNU Lesser General Public License\r
17  * along with this library; if not, write to the Free Software Foundation, Inc., 51\r
18  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\r
19  *\r
20  */\r
21 \r
22 /* Define those macros _before_ you include the utc_webkit2_ewk.h header file. */\r
23 \r
24 #define TESTED_FUN_NAME ewk_view_javascript_prompt_callback_set\r
25 #define POSITIVE_TEST_FUN_NUM 1\r
26 #define NEGATIVE_TEST_FUN_NUM 2\r
27 \r
28 #include "utc_webkit2_ewk.h"\r
29 \r
30 #ifndef NULL\r
31 #define NULL    0x0\r
32 #endif\r
33 \r
34 Eina_Bool g_result = EINA_FALSE;\r
35 \r
36 #define SAMPLE_HTML_FILE        ("/ewk_view/prompt_test.html")\r
37 \r
38 /* Load specified url */\r
39 static void loadURL(const char* url)\r
40 {\r
41     char* full_path = generate_full_resource_path(url);\r
42     if (!full_path)\r
43         utc_fail();\r
44 \r
45     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);\r
46     free(full_path);\r
47 \r
48     if (!result)\r
49         utc_fail();\r
50 }\r
51 \r
52 /* Callback for load finished */\r
53 static void loadFinished(void* data, Evas_Object* webview, void* event_info)\r
54 {\r
55     utc_message("[loadFinished] :: \n");\r
56     utc_webkit2_main_loop_quit();\r
57 }\r
58 \r
59 /* Callback for load error */\r
60 static void loadError(void* data, Evas_Object* webview, void* event_info)\r
61 {\r
62     utc_message("[loadError] :: \n");\r
63     utc_webkit2_main_loop_quit();\r
64 }\r
65 \r
66 /* Callback for script prompt */\r
67 static Eina_Bool promptCallback(Evas_Object* webview ,const char* message,const char* default_value ,void* user_data)\r
68 {\r
69     utc_message("[promptCallback] :: xc\n");\r
70 \r
71     g_result = EINA_TRUE;\r
72     utc_webkit2_main_loop_quit();\r
73 }\r
74 \r
75 /* Startup function */\r
76 static void startup(void)\r
77 {\r
78     utc_webkit2_ewk_test_init();\r
79 \r
80     evas_object_smart_callback_add(test_view.webview, "load,finished", loadFinished, NULL);\r
81     evas_object_smart_callback_add(test_view.webview, "load,error", loadError, NULL);\r
82 }\r
83 \r
84 /* Cleanup function */\r
85 static void cleanup(void)\r
86 {\r
87     evas_object_smart_callback_del(test_view.webview, "load,finished", loadFinished);\r
88     evas_object_smart_callback_del(test_view.webview, "load,error", loadError);\r
89 \r
90     utc_webkit2_ewk_test_end();\r
91 }\r
92 \r
93 \r
94 /**\r
95  * @brief Positive  test case of ewk_view_javascript_prompt_callback()\r
96  * ewk_view_javascript_prompt_callback() should be set if the page content triggers a alert callback\r
97  */\r
98 POS_TEST_FUN(1)\r
99 {\r
100     ewk_view_javascript_prompt_callback_set(test_view.webview, promptCallback, 0);\r
101 \r
102     loadURL(SAMPLE_HTML_FILE);\r
103     utc_webkit2_main_loop_begin();\r
104 \r
105     utc_check_eq(g_result, EINA_TRUE);\r
106 }\r
107 \r
108 /**\r
109 * @brief Checking whether function works properly in case of NULL of a webview.\r
110 */\r
111 NEG_TEST_FUN(1)\r
112 {\r
113     ewk_view_javascript_prompt_callback_set(NULL, promptCallback, 0);\r
114     utc_pass();\r
115 }\r
116 \r
117 /**\r
118 * @brief Checking whether function works properly in case of NULL of a callback for javascript prompt.\r
119 */\r
120 NEG_TEST_FUN(2)\r
121 {\r
122     ewk_view_javascript_prompt_callback_set(test_view.webview, NULL, 0);\r
123     utc_pass();\r
124 }\r