[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_cb_contextmenu_willshow.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_cb_contextmenu_willshow: public utc_blink_ewk_base
9 {
10 protected:
11   utc_blink_cb_contextmenu_willshow()
12   {
13     pos.x = -1;
14     pos.y = -1;
15   }
16
17   void LoadFinished(Evas_Object* webview) override {
18     feed_mouse_click(3, 50, 50, GetEwkEvas());
19   }
20
21   void PostSetUp() override {
22     evas_object_smart_callback_add(GetEwkWebView(), "contextmenu,willshow", ToSmartCallback(contextmenu_willshow_cb), this);
23   }
24
25   void PreTearDown() override {
26     evas_object_smart_callback_del(GetEwkWebView(), "contextmenu,willshow", ToSmartCallback(contextmenu_willshow_cb));
27   }
28
29   static void contextmenu_willshow_cb(utc_blink_cb_contextmenu_willshow* owner, Evas_Object* webview, Evas_Point* position)
30   {
31     ASSERT_TRUE(owner);
32
33     if (position) {
34       owner->pos.x = position->x;
35       owner->pos.y = position->y;
36     }
37
38     // callback has come, so we stop with success
39     owner->EventLoopStop(Success);
40   }
41
42 protected:
43   Evas_Point pos;
44 };
45
46 TEST_F(utc_blink_cb_contextmenu_willshow, callback)
47 {
48   // selecting text inside text area should invoke context menu
49
50   const char htmlBuff[] = "<html>"
51                           "<body>"
52                           "<textarea>Test context menu</textarea>"
53                           "</body>"
54                           "</html>";
55
56   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuff, NULL, NULL));
57
58   // Wait for context menu callback
59   ASSERT_EQ(Success, EventLoopStart());
60   // It's hard to calculate position of context menu that will appear so we check only if value was modified
61   ASSERT_NE(-1, pos.x);
62   ASSERT_NE(-1, pos.y);
63 }