Fixed a problem that remember popup does not disappear
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_view_string_find_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 /**\r
23  * @file utc_webkit2_ewk_view_string_find_func.c\r
24  * @author Nikhil Bansal <n.bansal@samsung.com>\r
25  * @date 2012-06-11\r
26  * @brief Tests EWK function ewk_view_string_find()\r
27  */\r
28 \r
29 /* Define those macros _before_ you include the utc_webkit2_ewk.h header file. */\r
30 #define TESTED_FUN_NAME ewk_view_string_find\r
31 #define POSITIVE_TEST_FUN_NUM 1\r
32 #define NEGATIVE_TEST_FUN_NUM 3\r
33 \r
34 #include "utc_webkit2_ewk.h"\r
35 \r
36 #define SAMPLE_HTML_FILE                ("/common/sample.html")\r
37 #define SEARCH_STRING                   ("test")\r
38 #define MAX_MATCH_COUNT                 2\r
39 \r
40 /* Load specified url */\r
41 static void loadURL(const char* url)\r
42 {\r
43     char* full_path = generate_full_resource_path(url);\r
44     if (!full_path)\r
45         utc_fail();\r
46 \r
47     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);\r
48     free(full_path);\r
49 \r
50     if (!result)\r
51         utc_fail();\r
52 }\r
53 \r
54 /* Callback for load finished */\r
55 static void loadFinished(void* data, Evas_Object* webview, void* event_info)\r
56 {\r
57     utc_message("[loadFinished] :: \n");\r
58     utc_webkit2_main_loop_quit();\r
59 }\r
60 \r
61 /* Callback for load error */\r
62 static void loadError(void* data, Evas_Object* webview, void* event_info)\r
63 {\r
64     utc_message("[load_error] :: \n");\r
65     utc_webkit2_main_loop_quit();\r
66 \r
67     utc_fail();\r
68 }\r
69 \r
70 /* Callback for find string operation */\r
71 static void findStringCallback(Evas_Object* webview, const char* searchString, int matchCount, void* data)\r
72 {\r
73     utc_message("[findStringCallback] :: \n");\r
74     utc_webkit2_main_loop_quit();\r
75 \r
76     if((strcmp(searchString, SEARCH_STRING)) || matchCount == 0)\r
77         utc_fail();\r
78 }\r
79 \r
80 /* Startup function */\r
81 static void startup(void)\r
82 {    \r
83     utc_webkit2_ewk_test_init();\r
84     evas_object_smart_callback_add(test_view.webview, "load,finished", loadFinished, NULL);\r
85     evas_object_smart_callback_add(test_view.webview, "load,error", loadError, NULL);\r
86 }\r
87 \r
88 /* Cleanup function */\r
89 static void cleanup(void)\r
90 {\r
91     evas_object_smart_callback_del(test_view.webview, "load,finished", loadFinished);\r
92     evas_object_smart_callback_del(test_view.webview, "load,error", loadError);\r
93     utc_webkit2_ewk_test_end();\r
94 }\r
95 \r
96 /**\r
97 * @brief Positive test case of ewk_view_string_find(). Search string and find options are set, and the result is returned in callback.\r
98 */\r
99 POS_TEST_FUN(1)\r
100 {\r
101     loadURL(SAMPLE_HTML_FILE);\r
102     utc_webkit2_main_loop_begin();\r
103 \r
104     Eina_Bool result = ewk_view_string_find(test_view.webview, SEARCH_STRING, EWK_FIND_OPTIONS_CASE_INSENSITIVE, MAX_MATCH_COUNT, findStringCallback, NULL);\r
105     utc_webkit2_main_loop_begin();\r
106 \r
107     utc_check_eq(result, EINA_TRUE);\r
108 }\r
109 \r
110 /**\r
111 * @brief Checking whether function works properly in case of NULL of a webview.\r
112 */\r
113 NEG_TEST_FUN(1)\r
114 {\r
115     Eina_Bool result = ewk_view_string_find(NULL, SEARCH_STRING, EWK_FIND_OPTIONS_CASE_INSENSITIVE, MAX_MATCH_COUNT, findStringCallback, NULL);\r
116     utc_check_eq(result, EINA_FALSE);\r
117 }\r
118 \r
119 \r
120 /**\r
121 * @brief Checking whether function works properly in case of NULL of search string.\r
122 */\r
123 NEG_TEST_FUN(2)\r
124 {\r
125     Eina_Bool result = ewk_view_string_find(test_view.webview, NULL, EWK_FIND_OPTIONS_CASE_INSENSITIVE, MAX_MATCH_COUNT, findStringCallback, NULL);\r
126     utc_check_eq(result, EINA_FALSE);\r
127 }\r
128 \r
129 /**\r
130 * @brief Checking whether function works properly in case of NULL of callback.\r
131 */\r
132 NEG_TEST_FUN(3)\r
133 {\r
134     Eina_Bool result = ewk_view_string_find(test_view.webview, SEARCH_STRING, EWK_FIND_OPTIONS_CASE_INSENSITIVE, MAX_MATCH_COUNT, NULL, NULL);\r
135     utc_check_eq(result, EINA_FALSE);\r
136 }\r