[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_ewk_context_menu_item_count_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_count : public utc_blink_ewk_base {
9 public:
10   utc_blink_ewk_context_menu_item_count()
11   : utc_blink_ewk_base()
12   , is_failed(EINA_FALSE)
13   , context_menu_item_count(0)
14   {
15   }
16
17 protected:
18  void LoadFinished(Evas_Object* webview) override {
19    feed_mouse_click(3, 100, 100, GetEwkEvas());
20   }
21
22   bool LoadError(Evas_Object* webview, Ewk_Error* error) override {
23     is_failed = EINA_TRUE;
24     EventLoopStop(utc_blink_ewk_base::Success);
25     return false;
26   }
27
28   void PostSetUp() override {
29     /* Enable mouse events to feed events directly. */
30     ewk_view_mouse_events_enabled_set(GetEwkWebView(), EINA_TRUE);
31
32     Eina_Bool result_set = ewk_view_url_set(GetEwkWebView(), GetResourceUrl("/ewk_context_menu/index.html").c_str());
33     if (!result_set) {
34       FAIL();
35     }
36     evas_object_smart_callback_add(GetEwkWebView(), "contextmenu,customize", contextmenu_customize_callback, this);
37   }
38
39   void PreTearDown() override {
40     evas_object_smart_callback_del(GetEwkWebView(), "contextmenu,customize", contextmenu_customize_callback);
41   }
42
43   static void contextmenu_customize_callback(void* data, Evas_Object* webview, void* event_info)
44   {
45     utc_message("[contextmenu_customize_callback] :: \n");
46     if (!data || !event_info) {
47       FAIL();
48     }
49     Ewk_Context_Menu* contextmenu = static_cast<Ewk_Context_Menu*>(event_info);
50     utc_blink_ewk_context_menu_item_count *owner = static_cast<utc_blink_ewk_context_menu_item_count*>(data);
51
52     owner->context_menu_item_count = ewk_context_menu_item_count(contextmenu);
53     owner->EventLoopStop(utc_blink_ewk_base::Success);
54   }
55
56 protected:
57   Eina_Bool is_failed;
58   int context_menu_item_count;
59 };
60
61 /**
62  * @brief Tests whether the count of item of context menu is returned properly.
63  */
64 TEST_F(utc_blink_ewk_context_menu_item_count, 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_GT(context_menu_item_count, 0);
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_count, NEG_TEST)
83 {
84   EXPECT_EQ(ewk_context_menu_item_count(NULL), 0);
85 }