[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_cb_geolocation_valid.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 /* Define those macros _before_ you include the utc_blink_ewk.h header file. */
6
7 #include "utc_blink_ewk_base.h"
8
9 #define SAMPLE_HTML_FILE                 ("/common/sample_js_geolocation.html")
10
11 class utc_blink_cb_geolocation_valid : public utc_blink_ewk_base {
12
13 protected:
14   static void geolocation_valid_allow_cb(utc_blink_cb_geolocation_valid* owner, Evas_Object* webview, Eina_Bool* allow)
15   {
16     ASSERT_TRUE(owner);
17     if (allow) {
18       *allow = EINA_TRUE;
19     } else {
20       owner->EventLoopStop(Failure);
21     }
22   }
23
24   static void geolocation_valid_deny_cb(utc_blink_cb_geolocation_valid* owner, Evas_Object* webview, Eina_Bool* allow)
25   {
26     ASSERT_TRUE(owner);
27     if (allow) {
28       *allow = EINA_FALSE;
29     } else {
30       owner->EventLoopStop(Failure);
31     }
32   }
33
34   static void geolocation_valid_cb(utc_blink_cb_geolocation_valid* owner, Evas_Object* webview, Eina_Bool* allow)
35   {
36     ASSERT_TRUE(owner);
37     owner->EventLoopStop(Success);
38   }
39
40   static void request_geolocation_permisson_success(utc_blink_cb_geolocation_valid* owner, Evas_Object* webview, void* event_info)
41   {
42     ASSERT_TRUE(owner);
43     owner->EventLoopStop(Success);
44   }
45
46   static void request_geolocation_permisson_fail(utc_blink_cb_geolocation_valid* owner, Evas_Object* webview, void* event_info)
47   {
48     ASSERT_TRUE(owner);
49     owner->EventLoopStop(Failure);
50   }
51
52 };
53
54 /**
55  * @brief Test "geolocation,valid" callback
56  */
57 TEST_F(utc_blink_cb_geolocation_valid, callback)
58 {
59   // Simply check if callback is fired, if load,finished comes first then something went wrong
60   evas_object_smart_callback_auto gv(GetEwkWebView(), "geolocation,valid", ToSmartCallback(geolocation_valid_cb), this);
61
62   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_HTML_FILE).c_str()));
63   ASSERT_EQ(Success, EventLoopStart());
64 }
65
66 /**
67  * @brief check if control param of "geolocation,valid" callback works as it suposed to.
68  *
69  * If we block geolocation module initialization in geolocation,valid callback then no geolocation,permission,request should be triggered.
70  */
71 TEST_F(utc_blink_cb_geolocation_valid, callback_param_to_false)
72 {
73   evas_object_smart_callback_auto gp(GetEwkWebView(), "geolocation,permission,request", ToSmartCallback(request_geolocation_permisson_fail), this);
74   evas_object_smart_callback_auto gv(GetEwkWebView(), "geolocation,valid", ToSmartCallback(geolocation_valid_deny_cb), this);
75
76   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_HTML_FILE).c_str()));
77   ASSERT_EQ(Timeout, EventLoopStart(5.0));
78 }
79
80 /**
81  * @brief check if control param of "geolocation,valid" callback works as it suposed to.
82  *
83  * If we allow geolocation module initialization in geolocation,valid callback then geolocation,permission,request should be triggered.
84  */
85 TEST_F(utc_blink_cb_geolocation_valid, callback_param_to_true)
86 {
87   evas_object_smart_callback_auto gp(GetEwkWebView(), "geolocation,permission,request", ToSmartCallback(request_geolocation_permisson_success), this);
88   evas_object_smart_callback_auto gv(GetEwkWebView(), "geolocation,valid", ToSmartCallback(geolocation_valid_allow_cb), this);
89
90   ASSERT_EQ(EINA_TRUE, ewk_view_url_set(GetEwkWebView(), GetResourceUrl(SAMPLE_HTML_FILE).c_str()));
91   ASSERT_EQ(Timeout, EventLoopStart(5.0));
92 }