[M120 Migration][MM] Support W3C EME
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / unittest / utc_blink_cb_editorclient_ime_closed.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_closed : 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 LoadFinished(Evas_Object*)
17   {
18     EventLoopStop(utc_blink_ewk_base::Success);
19   }
20
21   static void editorclient_ime_closed_cb(utc_blink_cb_editorclient_ime_closed* owner, Evas_Object*, void*)
22   {
23     ASSERT_TRUE(owner);
24     owner->EventLoopStop(utc_blink_ewk_base::Success);
25   }
26 };
27
28 /**
29  * @brief Test "editorclient,ime,closed" callback
30  */
31 TEST_F(utc_blink_cb_editorclient_ime_closed, callback)
32 {
33   char htmlBuffer[] = "<html>"
34                         "<head></head>"
35                         "<body>"
36                           "<input id=\"e\" type=\"text\"/><br/>"
37                           "<a id=\"focus\" onclick=\"document.getElementById('e').focus();\">Focus</a><br/>"
38                           "<a id=\"unfocus\" onclick=\"document.getElementById('e').blur();\">Unfocus</a><br/>"
39                         "</body>"
40                       "</html>";
41
42
43   ASSERT_EQ(EINA_TRUE, ewk_view_html_string_load(GetEwkWebView(), htmlBuffer, NULL, NULL));
44   // This TC will timeout on desktop as there is no input method context
45   ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart());
46
47   // We need to focus on window
48   elm_object_focus_set(GetEwkWebView(), EINA_TRUE);
49
50   {
51     evas_object_smart_callback_auto ime(GetEwkWebView(), "editorclient,ime,opened", ToSmartCallback(editorclient_ime_closed_cb), this);
52     // This script execute should produce user gesture and should show software keyboard on mobile
53     ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "document.getElementById('focus').click();", NULL, NULL));
54     // Wait for keyboard
55     ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart()) << "editorclient,ime,opened smart callback timeout";
56   }
57
58   {
59     evas_object_smart_callback_auto ime(GetEwkWebView(), "editorclient,ime,closed", ToSmartCallback(editorclient_ime_closed_cb), this);
60     // This script execute should produce user gesture and should show software keyboard on mobile
61     ASSERT_EQ(EINA_TRUE, ewk_view_script_execute(GetEwkWebView(), "document.getElementById('unfocus').click();", NULL, NULL));
62     // Wait for keyboard
63     ASSERT_EQ(utc_blink_ewk_base::Success, EventLoopStart()) << "editorclient,ime,opened smart callback timeout";
64   }
65 }