[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_context_menu_item_append_as_action_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 #include "utc_blink_ewk_context_menu.h"
7
8 class utc_blink_ewk_context_menu_item_append_as_action : public utc_blink_ewk_base {
9 protected:
10   utc_blink_ewk_context_menu_item_append_as_action()
11   : utc_blink_ewk_base()
12   , result(EINA_FALSE)
13   , is_failed(EINA_FALSE)
14   {
15   }
16
17   void LoadFinished(Evas_Object* webview) override {
18     feed_mouse_click(3, 100, 100, GetEwkEvas());
19   }
20
21   bool LoadError(Evas_Object* webview, Ewk_Error* error) override {
22     is_failed = EINA_TRUE;
23     EventLoopStop(utc_blink_ewk_base::Success);
24     return false;
25   }
26
27   void PostSetUp() override {
28     /* Enable mouse events to feed events directly. */
29     ewk_view_mouse_events_enabled_set(GetEwkWebView(), EINA_TRUE);
30
31     Eina_Bool result_set = ewk_view_url_set(GetEwkWebView(), GetResourceUrl("/ewk_context_menu/index.html").c_str());
32     if (!result_set) {
33       FAIL();
34     }
35     evas_object_smart_callback_add(GetEwkWebView(), "contextmenu,customize", contextmenu_customize_callback, this);
36   }
37
38   void PreTearDown() override {
39     evas_object_smart_callback_del(GetEwkWebView(), "contextmenu,customize", contextmenu_customize_callback);
40   }
41
42   static void contextmenu_customize_callback(void* data, Evas_Object* webview, void* event_info)
43   {
44     utc_message("[contextmenu_customize_callback] :: \n");
45     if (!data || !event_info) {
46       FAIL();
47     }
48     Ewk_Context_Menu* contextmenu = static_cast<Ewk_Context_Menu*>(event_info);
49     utc_blink_ewk_context_menu_item_append_as_action *owner = static_cast<utc_blink_ewk_context_menu_item_append_as_action*>(data);
50
51     owner->result = ewk_context_menu_item_append_as_action(contextmenu, CUSTOM_CONTEXT_MENU_ITEM_TEST_TAG, "test", EINA_TRUE);
52     owner->EventLoopStop(utc_blink_ewk_base::Success);
53   }
54
55 protected:
56   Eina_Bool result;
57   Eina_Bool is_failed;
58 };
59
60
61 /**
62  * @brief Tests whether the appending item to context menu is performed properly.
63  */
64 TEST_F(utc_blink_ewk_context_menu_item_append_as_action, POS_TEST)
65 {
66   if (!is_failed) {
67     utc_blink_ewk_base::MainLoopResult result_loop = EventLoopStart();
68     if (result_loop != utc_blink_ewk_base::Success) {
69       FAIL();
70     }
71   }
72
73   if (is_failed) {
74     FAIL();
75   }
76   EXPECT_EQ(result, EINA_TRUE);
77 }
78
79 /**
80  * @brief Tests whether the function works properly for case Ewk_Context_Menu object is NULL.
81  */
82 TEST_F(utc_blink_ewk_context_menu_item_append_as_action, NEG_TEST)
83 {
84   EXPECT_EQ(ewk_context_menu_item_append_as_action(NULL, CUSTOM_CONTEXT_MENU_ITEM_TEST_TAG, "test", EINA_TRUE), EINA_FALSE);
85 }