[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_cb_editorclient_ime_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 #include "utc_blink_ewk_base.h"
6
7 class utc_blink_cb_editorclient_ime_opened : public utc_blink_ewk_base
8 {
9 protected:
10   void PreSetUp()
11   {
12     const char* default_context_id = ecore_imf_context_default_id_get();
13     ASSERT_TRUE(default_context_id) << "This TC can't be run without default imf context - it will fail anyway";
14   }
15
16   void PostSetUp()
17   {
18     evas_object_smart_callback_add(GetEwkWebView(), "editorclient,ime,opened", ToSmartCallback(editorclient_ime_opened_cb), this);
19   }
20
21   void PreTearDown()
22   {
23     evas_object_smart_callback_del(GetEwkWebView(), "editorclient,ime,opened", ToSmartCallback(editorclient_ime_opened_cb));
24   }
25
26   void LoadFinished(Evas_Object*)
27   {
28     EventLoopStop(utc_blink_ewk_base::Success);
29   }
30
31   static void editorclient_ime_opened_cb(utc_blink_cb_editorclient_ime_opened* owner, Evas_Object*, void*)
32   {
33     ASSERT_TRUE(owner);
34     owner->EventLoopStop(utc_blink_ewk_base::Success);
35   }
36 };
37
38 /**
39  * @brief Test "editorclient,ime,opened" callback
40  */
41 TEST_F(utc_blink_cb_editorclient_ime_opened, callback)
42 {
43   char htmlBuffer[] = "<html>"
44                         "<head></head>"
45                         "<body>"
46                           "<input id=\"e\" type=\"text\"><a id=\"b\" onclick=\"document.getElementById('e').focus(); console.log('asdf');\">Button</a>"
47                         "</body>"
48                       "</html>";
49
50
51   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
52   // This TC will timeout on desktop as there is no input method context
53   ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart());
54
55   // We need to focus on window
56   elm_object_focus_set(GetEwkWebView(), EINA_TRUE);
57
58   // This script execute should produce user gesture and should show software keyboard on mobile
59   ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "document.getElementById('b').click();", NULL, NULL));
60   // Wait for keyboard
61   ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart()) << "editorclient,ime,opened smart callback timeout";
62 }