[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_cb_inputmethod_changed.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_inputmethod_changed : public utc_blink_ewk_base
8 {
9 protected:
10   utc_blink_cb_inputmethod_changed()
11   {
12     memset(&panel_rect, 0, sizeof panel_rect);
13   }
14   void PreSetUp()
15   {
16     const char* default_context_id = ecore_imf_context_default_id_get();
17     ASSERT_TRUE(default_context_id) << "This TC can't be run without default imf context - it will fail anyway";
18   }
19
20   void PostSetUp()
21   {
22     evas_object_smart_callback_add(GetEwkWebView(), "inputmethod,changed", ToSmartCallback(inputmethod_changed_cb), this);
23   }
24
25   void PreTearDown()
26   {
27     evas_object_smart_callback_del(GetEwkWebView(), "inputmethod,changed", ToSmartCallback(inputmethod_changed_cb));
28   }
29
30   void LoadFinished(Evas_Object*)
31   {
32     EventLoopStop(utc_blink_ewk_base::Success);
33   }
34
35   static void inputmethod_changed_cb(utc_blink_cb_inputmethod_changed* owner, Evas_Object*, Eina_Rectangle* rect)
36   {
37     utc_message("%p", rect);
38     ASSERT_TRUE(owner);
39     if  (rect) {
40       owner->panel_rect = *rect;
41     }
42
43     owner->EventLoopStop(utc_blink_ewk_base::Success);
44   }
45
46 protected:
47   Eina_Rectangle panel_rect;
48 };
49
50 /**
51  * @brief Test "inputmethod,changed" callback
52  *
53  * The name of the callback may be misguiding - it doesn't mean that the way you input text has changed.
54  * It means that geometry of input panel has changed.
55  */
56 TEST_F(utc_blink_cb_inputmethod_changed, callback)
57 {
58   char htmlBuffer[] = "<html>"
59                         "<head></head>"
60                         "<body>"
61                           "<input id=\"e\" type=\"text\"/><br/>"
62                           "<a id=\"focus\" onclick=\"document.getElementById('e').focus();\">Focus</a><br/>"
63                           "<a id=\"unfocus\" onclick=\"document.getElementById('e').blur();\">Unfocus</a><br/>"
64                         "</body>"
65                       "</html>";
66
67
68   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
69   // This TC will timeout on desktop as there is no input method context
70   ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart());
71
72   // We need to focus on window
73   elm_object_focus_set(GetEwkWebView(), EINA_TRUE);
74
75   // This script execute should produce user gesture and should show software keyboard on mobile
76   ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "document.getElementById('focus').click();", NULL, NULL));
77   // Wait for keyboard
78
79   // When opening ime geometry is sent two times (by efl). First rect will be empty, second not
80   ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart()) << "inputmethod,changed smart callback timeout";
81   ASSERT_EQ(EINA_TRUE, eina_rectangle_is_empty(&panel_rect));
82
83   ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart()) << "inputmethod,changed smart callback timeout";
84   ASSERT_EQ(EINA_FALSE, eina_rectangle_is_empty(&panel_rect));
85
86   // This script execute should produce user gesture and should show software keyboard on mobile
87   ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "document.getElementById('unfocus').click();", NULL, NULL));
88   // Wait for keyboard
89   ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart()) << "inputmethod,changed smart callback timeout";
90   ASSERT_EQ(EINA_TRUE, eina_rectangle_is_empty(&panel_rect));
91 }