[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_cb_editorclient_candidate_opened.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 #if BUILDFLAG(IS_TIZEN)
6 #include "ecore_x_wayland_wrapper.h"
7 // using scim to simulate keyboard typing
8 #include <scim.h>
9 #include <scim_event.h>
10 #include <scim_attribute.h>
11 #include <scim_lookup_table.h>
12 #include <scim_socket.h>
13 #include <scim_property.h>
14 #include <scim_transaction.h>
15 #include <scim_helper.h>
16 #include <scim_helper_manager.h>
17 #endif
18
19 #include "utc_blink_ewk_base.h"
20
21 #include <X11/Xlib.h>
22 #undef Success // conflicts with utc_blink_ewk_base enum
23
24 class utc_blink_cb_editorclient_candidate_opened : public utc_blink_ewk_base
25 {
26 protected:
27   void PreSetUp()
28   {
29     const char* default_context_id = ecore_imf_context_default_id_get();
30     ASSERT_TRUE(default_context_id) << "This TC can't be run without default imf context - it will fail anyway";
31   }
32
33   void LoadFinished(Evas_Object*)
34   {
35     EventLoopStop(utc_blink_ewk_base::Success);
36   }
37
38   static void editorclient_candidate_opened_cb(utc_blink_cb_editorclient_candidate_opened* owner, Evas_Object*, void*)
39   {
40     ASSERT_TRUE(owner);
41     owner->EventLoopStop(utc_blink_ewk_base::Success);
42   }
43 };
44
45 /**
46  * @brief Tests "editorclient,candidate,opened" callback
47  *
48  * We use Tizen ISF API to open candidate window on current input method panel
49  */
50 TEST_F(utc_blink_cb_editorclient_candidate_opened, callback)
51 {
52   char htmlBuffer[] = "<html>"
53                         "<head></head>"
54                         "<body>"
55                           "<input id=\"e\" type=\"text\"><a id=\"b\" onclick=\"document.getElementById('e').focus();\">Button</a>"
56                         "</body>"
57                       "</html>";
58
59
60   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
61   // This TC will timeout on desktop as there is no input method context
62   ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart());
63
64   // We need to focus on window
65   elm_object_focus_set(GetEwkWebView(), EINA_TRUE);
66
67   // We scope this callback as it is only needed once
68   {
69     evas_object_smart_callback_auto ime(GetEwkWebView(), "editorclient,ime,opened", ToSmartCallback(editorclient_candidate_opened_cb), this);
70     // This script execute should produce user gesture and should show software keyboard on mobile
71     ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "document.getElementById('b').click();", NULL, NULL));
72     // Wait for keyboard
73     ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart()) << "editorclient,ime,opened smart callback timeout";
74   }
75
76 #if BUILDFLAG(IS_TIZEN)
77   {
78     Display* display = static_cast<Display*>(ecore_x_display_get());
79     ASSERT_TRUE(display) << "No X11 display available!";
80
81     evas_object_smart_callback_auto candidate(GetEwkWebView(), "editorclient,candidate,opened", ToSmartCallback(editorclient_candidate_opened_cb), this);
82
83     scim::HelperAgent agent;
84     scim::HelperManager manager;
85
86     int count = manager.number_of_helpers();
87
88     scim::HelperInfo info;
89
90     for (int i = 0; i < count; ++i) {
91       if (manager.get_helper_info(i, info)) {
92         agent.open_connection(info, XDisplayString(display));
93       }
94     }
95
96     ASSERT_TRUE(agent.is_connected()) << "Could not connect to SCIM - can't send proper events to virtual keyboard";
97
98     scim::WideString content = scim::utf8_mbstowcs("a");
99     agent.commit_string(-1, scim::String(), content);
100     agent.show_candidate_string();
101
102     agent.close_connection();
103
104     // wait for candidate to show
105     ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart()) << "editorclient,candidate,opened smart callback timeout";
106   }
107 #else   // IS_TIZEN
108   ASSERT_TRUE(false) << "This TC won't work outside Tizen OS";
109 #endif  // IS_TIZEN
110 }