[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_context_vibration_client_callbacks_set_func.cpp
1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "utc_blink_ewk_base.h"
6
7 class utc_blink_ewk_context_vibration_client_callbacks_set : public utc_blink_ewk_base
8 {
9 protected:
10   static void vibrateCallback(uint64_t vibration_time, void* user_data)
11   {
12     if(!user_data)
13       utc_fail();
14     static_cast<utc_blink_ewk_context_vibration_client_callbacks_set*>(user_data)->vibrateCalled = EINA_TRUE;
15   }
16
17   static void cancelVibrateCallback(void* user_data)
18   {
19     if(!user_data)
20       utc_fail();
21     static_cast<utc_blink_ewk_context_vibration_client_callbacks_set*>(user_data)->cancelCalled = EINA_TRUE;
22   }
23
24   static void title_changed(void* data, Evas_Object* webview, void* event)
25   {
26     if(!data)
27       utc_fail();
28     static_cast<utc_blink_ewk_context_vibration_client_callbacks_set*>(data)->EventLoopStop(Success);
29   }
30
31   /* Startup function */
32   void PostSetUp() override {
33     vibrateCalled = EINA_FALSE;
34     cancelCalled = EINA_FALSE;
35     evas_object_smart_callback_add(GetEwkWebView(), "title,changed", title_changed, this);
36   }
37
38   /* Cleanup function */
39   void PreTearDown() override {
40     evas_object_smart_callback_del(GetEwkWebView(), "title,changed", title_changed);
41   }
42
43 protected:
44   static const char*const sample;
45   Eina_Bool vibrateCalled;
46   Eina_Bool cancelCalled;
47 };
48
49 const char*const utc_blink_ewk_context_vibration_client_callbacks_set::sample="ewk_context_vibration/vibration.html";
50
51 /**
52  * @brief Tests if vibration callbacks are properly set
53  */
54 TEST_F(utc_blink_ewk_context_vibration_client_callbacks_set, POS_TEST)
55 {
56   ewk_context_vibration_client_callbacks_set(ewk_context_default_get(), vibrateCallback, cancelVibrateCallback, this);
57
58   if(!ewk_view_url_set(GetEwkWebView(), GetResourceUrl(sample).c_str()))
59      utc_fail();
60
61   if (Success!=EventLoopStart())
62     utc_fail();
63
64   utc_check_eq( vibrateCalled && cancelCalled, EINA_TRUE);
65 }
66
67 /**
68  * @brief Tests if ewk_context_vibration_client_callbacks_set crashes on null arguments and set context
69  */
70 TEST_F(utc_blink_ewk_context_vibration_client_callbacks_set, NEG_TEST1)
71 {
72   ewk_context_vibration_client_callbacks_set(ewk_context_default_get(), NULL, NULL, this);
73   /* If  NULL argument passing wont give segmentation fault negative test case will pass */
74   utc_pass();
75 }
76
77 /**
78  * @brief Tests if ewk_context_vibration_client_callbacks_set crashes on null arguments
79  */
80 TEST_F(utc_blink_ewk_context_vibration_client_callbacks_set, NEG_TEST2)
81 {
82   ewk_context_vibration_client_callbacks_set(NULL, NULL, NULL, this);
83   /* If  NULL argument passing wont give segmentation fault negative test case will pass */
84   utc_pass();
85 }