0526da848bfcb72e1cff9e8e9b6ede562e61317b
[framework/web/webkit-efl.git] / TC / unit_test / webkit2 / utc_webkit2_ewk_view_top_of_contents_go_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 #define TESTED_FUN_NAME ewk_view_top_of_contents_go\r
24 #define POSITIVE_TEST_FUN_NUM 1\r
25 #define NEGATIVE_TEST_FUN_NUM 1\r
26 \r
27 #include "utc_webkit2_ewk.h"\r
28 \r
29 #ifndef NULL\r
30 #define NULL    0x0\r
31 #endif\r
32 \r
33 #define RESOURCE_PATH "/ewk_view/index_big_red_square.html"\r
34 \r
35 static const int cScrollBy_1 = 10;\r
36 \r
37 static void loadFinished(void* data, Evas_Object* eObject, void* dataFinished)\r
38 {\r
39     utc_message("[loadFinished] :: \n");\r
40 }\r
41 \r
42 /* Callback for load error */\r
43 static void loadError(void* data, Evas_Object* webview, void* event_info)\r
44 {\r
45     utc_message("[load_error] :: \n");\r
46     utc_webkit2_main_loop_quit();\r
47 \r
48     utc_fail();\r
49 }\r
50 \r
51 static void frameRendered(void* data, Evas_Object* eObject, void* dataFinished)\r
52 {\r
53     utc_message("[frameRendered] :: \n");\r
54     utc_webkit2_main_loop_quit();\r
55 }\r
56 \r
57 static void startup(void)\r
58 {\r
59     utc_webkit2_ewk_test_init();\r
60     evas_object_smart_callback_add(test_view.webview, "load,finished", loadFinished, NULL);\r
61     evas_object_smart_callback_add(test_view.webview, "load,error", loadError, NULL);\r
62         evas_object_smart_callback_add(test_view.webview, "frame,rendered", frameRendered, NULL);\r
63 }\r
64 \r
65 static void cleanup(void)\r
66 {\r
67     evas_object_smart_callback_del(test_view.webview, "load,finished", loadFinished);\r
68     evas_object_smart_callback_del(test_view.webview, "load,error", loadError);\r
69         evas_object_smart_callback_del(test_view.webview, "frame,rendered", frameRendered);  \r
70     utc_webkit2_ewk_test_end();\r
71 }\r
72 \r
73 static void loadURL(const char* url)\r
74 {\r
75     char* full_path = generate_full_resource_path(url);\r
76     if (!full_path)\r
77         utc_fail();\r
78 \r
79     Eina_Bool result = ewk_view_url_set(test_view.webview, full_path);\r
80     free(full_path);\r
81 \r
82     if (!result)\r
83         utc_fail();\r
84 }\r
85 \r
86 /**\r
87  * @brief Positive test case of ewk_view_top_of_contents_go(), tseting scroll postion for testing API\r
88  */\r
89 POS_TEST_FUN(1)\r
90 {\r
91     loadURL(RESOURCE_PATH);\r
92     utc_webkit2_main_loop_begin();    \r
93     ewk_view_scroll_set(test_view.webview, 0, 0);\r
94 \r
95     int x,y;\r
96     Eina_Bool result = EINA_FALSE;\r
97 \r
98     ewk_view_scroll_set(test_view.webview, 0, 0);\r
99     \r
100     ewk_view_scroll_by(test_view.webview, cScrollBy_1, cScrollBy_1);   \r
101     ewk_view_scroll_by(test_view.webview, cScrollBy_1, cScrollBy_1);    \r
102     ewk_view_top_of_contents_go(test_view.webview);    \r
103     ewk_view_scroll_pos_get(test_view.webview, &x, &y);\r
104 \r
105     if (x == 0 && y == 0)\r
106         result = EINA_TRUE;\r
107 \r
108     utc_check_eq(result, EINA_TRUE);\r
109 }\r
110 \r
111 \r
112 /**\r
113  * @brief Negative test case of ewk_view_top_of_contents_go(), testing for null, API should not crash when NULL is passed as a value\r
114  */\r
115 NEG_TEST_FUN(1)\r
116 {   \r
117     ewk_view_top_of_contents_go(NULL);   \r
118     utc_pass();\r
119 }\r