• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "input_method_controller.h"
16 
17 #include <event_handler.h>
18 #include <gtest/gtest.h>
19 #include <sys/time.h>
20 
21 #include <condition_variable>
22 #include <cstdint>
23 #include <functional>
24 #include <mutex>
25 #include <string>
26 #include <thread>
27 #include <vector>
28 
29 #include "accesstoken_kit.h"
30 #include "global.h"
31 #include "i_input_method_agent.h"
32 #include "i_input_method_system_ability.h"
33 #include "input_client_stub.h"
34 #include "input_data_channel_stub.h"
35 #include "input_method_ability.h"
36 #include "input_method_engine_listener.h"
37 #include "input_method_system_ability_proxy.h"
38 #include "input_method_utils.h"
39 #include "iservice_registry.h"
40 #include "keyboard_listener.h"
41 #include "message_parcel.h"
42 #include "nativetoken_kit.h"
43 #include "system_ability_definition.h"
44 #include "token_setproc.h"
45 #include "utils.h"
46 
47 using namespace testing::ext;
48 using namespace OHOS::Security::AccessToken;
49 namespace OHOS {
50 namespace MiscServices {
GrantNativePermission()51     void GrantNativePermission()
52     {
53         const char **perms = new const char *[1];
54         perms[0] = "ohos.permission.CONNECT_IME_ABILITY";
55         TokenInfoParams infoInstance = {
56             .dcapsNum = 0,
57             .permsNum = 1,
58             .aclsNum = 0,
59             .dcaps = nullptr,
60             .perms = perms,
61             .acls = nullptr,
62             .processName = "inputmethod_imf",
63             .aplStr = "system_core",
64         };
65         uint64_t tokenId = GetAccessTokenId(&infoInstance);
66         int res = SetSelfTokenID(tokenId);
67         if (res == 0) {
68             IMSA_HILOGI("SetSelfTokenID success!");
69         } else {
70             IMSA_HILOGE("SetSelfTokenID fail!");
71         }
72         AccessTokenKit::ReloadNativeTokenInfo();
73         delete[] perms;
74     }
75 
76     class TextListener : public OnTextChangedListener {
77     public:
TextListener()78         TextListener()
79         {
80             std::shared_ptr<AppExecFwk::EventRunner> runner = AppExecFwk::EventRunner::Create("TextListenerNotifier");
81             serviceHandler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
82         }
~TextListener()83         ~TextListener()
84         {
85         }
86         static KeyboardInfo keyboardInfo_;
87         static std::mutex cvMutex_;
88         static std::condition_variable cv_;
89         std::shared_ptr<AppExecFwk::EventHandler> serviceHandler_;
WaitIMACallback()90         static bool WaitIMACallback()
91         {
92             std::unique_lock<std::mutex> lock(TextListener::cvMutex_);
93             return TextListener::cv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
94         }
InsertText(const std::u16string & text)95         void InsertText(const std::u16string &text)
96         {
97             IMSA_HILOGI("IMC TEST TextListener InsertText: %{public}s", MiscServices::Utils::ToStr8(text).c_str());
98         }
99 
DeleteBackward(int32_t length)100         void DeleteBackward(int32_t length)
101         {
102             IMSA_HILOGI("IMC TEST TextListener DeleteBackward length: %{public}d", length);
103         }
104 
SetKeyboardStatus(bool status)105         void SetKeyboardStatus(bool status)
106         {
107             IMSA_HILOGI("IMC TEST TextListener SetKeyboardStatus %{public}d", status);
108         }
DeleteForward(int32_t length)109         void DeleteForward(int32_t length)
110         {
111             IMSA_HILOGI("IMC TEST TextListener DeleteForward length: %{public}d", length);
112         }
SendKeyEventFromInputMethod(const KeyEvent & event)113         void SendKeyEventFromInputMethod(const KeyEvent &event)
114         {
115             IMSA_HILOGI("IMC TEST TextListener sendKeyEventFromInputMethod");
116         }
SendKeyboardInfo(const KeyboardInfo & status)117         void SendKeyboardInfo(const KeyboardInfo &status)
118         {
119             IMSA_HILOGD("TextListener::SendKeyboardInfo %{public}d", status.GetKeyboardStatus());
120             constexpr int32_t INTERVAL = 20;
121             {
122                 std::unique_lock<std::mutex> lock(cvMutex_);
123                 IMSA_HILOGD("TextListener::SendKeyboardInfo lock");
124                 keyboardInfo_ = status;
125             }
126             serviceHandler_->PostTask([this]() { cv_.notify_all(); }, INTERVAL);
127             IMSA_HILOGD("TextListener::SendKeyboardInfo notify_all");
128         }
MoveCursor(const Direction direction)129         void MoveCursor(const Direction direction)
130         {
131             IMSA_HILOGI("IMC TEST TextListener MoveCursor");
132         }
HandleSetSelection(int32_t start,int32_t end)133         void HandleSetSelection(int32_t start, int32_t end)
134         {
135         }
HandleExtendAction(int32_t action)136         void HandleExtendAction(int32_t action)
137         {
138         }
HandleSelect(int32_t keyCode,int32_t cursorMoveSkip)139         void HandleSelect(int32_t keyCode, int32_t cursorMoveSkip)
140         {
141         }
142     };
143     KeyboardInfo TextListener::keyboardInfo_;
144     std::mutex TextListener::cvMutex_;
145     std::condition_variable TextListener::cv_;
146 
147     class KeyboardListenerImpl : public KeyboardListener {
148     public:
KeyboardListenerImpl()149         KeyboardListenerImpl(){};
~KeyboardListenerImpl()150         ~KeyboardListenerImpl(){};
151         static int32_t keyCode_;
152         static int32_t keyStatus_;
153         static CursorInfo cursorInfo_;
154         bool OnKeyEvent(int32_t keyCode, int32_t keyStatus) override;
155         void OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height) override;
156         void OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd) override;
157         void OnTextChange(const std::string &text) override;
158     };
159     int32_t KeyboardListenerImpl::keyCode_ = 0;
160     int32_t KeyboardListenerImpl::keyStatus_ = 0;
161     CursorInfo KeyboardListenerImpl::cursorInfo_ = {};
OnKeyEvent(int32_t keyCode,int32_t keyStatus)162     bool KeyboardListenerImpl::OnKeyEvent(int32_t keyCode, int32_t keyStatus)
163     {
164         IMSA_HILOGD("KeyboardListenerImpl::OnKeyEvent %{public}d %{public}d", keyCode, keyStatus);
165         keyCode_ = keyCode;
166         keyStatus_ = keyStatus;
167         return true;
168     }
OnCursorUpdate(int32_t positionX,int32_t positionY,int32_t height)169     void KeyboardListenerImpl::OnCursorUpdate(int32_t positionX, int32_t positionY, int32_t height)
170     {
171         IMSA_HILOGD(
172             "KeyboardListenerImpl::OnCursorUpdate %{public}d %{public}d %{public}d", positionX, positionY, height);
173         cursorInfo_ = { static_cast<double>(positionX), static_cast<double>(positionY), 0,
174             static_cast<double>(height) };
175     }
OnSelectionChange(int32_t oldBegin,int32_t oldEnd,int32_t newBegin,int32_t newEnd)176     void KeyboardListenerImpl::OnSelectionChange(int32_t oldBegin, int32_t oldEnd, int32_t newBegin, int32_t newEnd)
177     {
178     }
OnTextChange(const std::string & text)179     void KeyboardListenerImpl::OnTextChange(const std::string &text)
180     {
181     }
182 
183     class InputMethodEngineListenerImpl : public InputMethodEngineListener {
184     public:
InputMethodEngineListenerImpl()185         InputMethodEngineListenerImpl(){};
~InputMethodEngineListenerImpl()186         ~InputMethodEngineListenerImpl(){};
187         static bool keyboardState_;
188         static bool isInputStart_;
189         static uint32_t windowId_;
190         void OnKeyboardStatus(bool isShow) override;
191         void OnInputStart() override;
192         void OnInputStop(const std::string &imeId) override;
193         void OnSetCallingWindow(uint32_t windowId) override;
194         void OnSetSubtype(const SubProperty &property) override;
195     };
196     bool InputMethodEngineListenerImpl::keyboardState_ = false;
197     bool InputMethodEngineListenerImpl::isInputStart_ = false;
198     uint32_t InputMethodEngineListenerImpl::windowId_ = 0;
199 
OnKeyboardStatus(bool isShow)200     void InputMethodEngineListenerImpl::OnKeyboardStatus(bool isShow)
201     {
202         keyboardState_ = isShow;
203     }
OnInputStart()204     void InputMethodEngineListenerImpl::OnInputStart()
205     {
206         isInputStart_ = true;
207     }
OnInputStop(const std::string & imeId)208     void InputMethodEngineListenerImpl::OnInputStop(const std::string &imeId)
209     {
210         isInputStart_ = false;
211     }
OnSetCallingWindow(uint32_t windowId)212     void InputMethodEngineListenerImpl::OnSetCallingWindow(uint32_t windowId)
213     {
214         windowId_ = windowId;
215     }
OnSetSubtype(const SubProperty & property)216     void InputMethodEngineListenerImpl::OnSetSubtype(const SubProperty &property)
217     {
218         IMSA_HILOGD("InputMethodEngineListenerImpl::OnSetSubtype");
219     }
220 
221     class InputMethodControllerTest : public testing::Test {
222     public:
223         static void SetUpTestCase(void);
224         static void TearDownTestCase(void);
225         void SetUp();
226         void TearDown();
227         static sptr<InputMethodController> inputMethodController_;
228         static sptr<InputMethodAbility> inputMethodAbility_;
229         static std::shared_ptr<MMI::KeyEvent> keyEvent_;
230         static std::shared_ptr<KeyboardListenerImpl> kbListener_;
231         static std::shared_ptr<InputMethodEngineListenerImpl> imeListener_;
232         static sptr<OnTextChangedListener> textListener_;
233     };
234     sptr<InputMethodController> InputMethodControllerTest::inputMethodController_;
235     sptr<InputMethodAbility> InputMethodControllerTest::inputMethodAbility_;
236     std::shared_ptr<MMI::KeyEvent> InputMethodControllerTest::keyEvent_;
237     std::shared_ptr<KeyboardListenerImpl> InputMethodControllerTest::kbListener_;
238     std::shared_ptr<InputMethodEngineListenerImpl> InputMethodControllerTest::imeListener_;
239     sptr<OnTextChangedListener> InputMethodControllerTest::textListener_;
240 
SetUpTestCase(void)241     void InputMethodControllerTest::SetUpTestCase(void)
242     {
243         IMSA_HILOGI("InputMethodControllerTest::SetUpTestCase");
244         GrantNativePermission();
245         inputMethodAbility_ = InputMethodAbility::GetInstance();
246         inputMethodAbility_->OnImeReady();
247         kbListener_ = std::make_shared<KeyboardListenerImpl>();
248         imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
249         textListener_ = new TextListener();
250         inputMethodAbility_->setKdListener(kbListener_);
251         inputMethodAbility_->setImeListener(imeListener_);
252         inputMethodController_ = InputMethodController::GetInstance();
253 
254         keyEvent_ = MMI::KeyEvent::Create();
255         constexpr int32_t KEY_ACTION = 2;
256         constexpr int32_t KEY_CODE = 2001;
257         keyEvent_->SetKeyAction(KEY_ACTION);
258         keyEvent_->SetKeyCode(KEY_CODE);
259     }
260 
TearDownTestCase(void)261     void InputMethodControllerTest::TearDownTestCase(void)
262     {
263         IMSA_HILOGI("InputMethodControllerTest::TearDownTestCase");
264     }
265 
SetUp(void)266     void InputMethodControllerTest::SetUp(void)
267     {
268         IMSA_HILOGI("InputMethodControllerTest::SetUp");
269     }
270 
TearDown(void)271     void InputMethodControllerTest::TearDown(void)
272     {
273         IMSA_HILOGI("InputMethodControllerTest::TearDown");
274     }
275 
276     /**
277      * @tc.name: testIMCAttach
278      * @tc.desc: IMC Attach.
279      * @tc.type: FUNC
280      * @tc.require:
281      */
282     HWTEST_F(InputMethodControllerTest, testIMCAttach, TestSize.Level0)
283     {
284         IMSA_HILOGD("IMC Attach Test START");
285         imeListener_->isInputStart_ = false;
286         inputMethodController_->Attach(textListener_, false);
287         inputMethodController_->Attach(textListener_);
288         inputMethodController_->Attach(textListener_, true);
289         EXPECT_TRUE(TextListener::WaitIMACallback());
290         EXPECT_TRUE(imeListener_->isInputStart_ && imeListener_->keyboardState_);
291     }
292 
293     /**
294      * @tc.name: testIMCSetCallingWindow
295      * @tc.desc: IMC SetCallingWindow.
296      * @tc.type: FUNC
297      * @tc.require:
298      */
299     HWTEST_F(InputMethodControllerTest, testIMCSetCallingWindow, TestSize.Level0)
300     {
301         IMSA_HILOGD("IMC SetCallingWindow Test START");
302         uint32_t windowId = 3;
303         inputMethodController_->SetCallingWindow(windowId);
304         EXPECT_EQ(windowId, imeListener_->windowId_);
305     }
306 
307     /**
308      * @tc.name: testGetIMSAProxy
309      * @tc.desc: Get Imsa Proxy.
310      * @tc.type: FUNC
311      */
312     HWTEST_F(InputMethodControllerTest, testGetIMSAProxy, TestSize.Level0)
313     {
314         auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
315         EXPECT_TRUE(systemAbilityManager != nullptr);
316         auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, "");
317         EXPECT_TRUE(systemAbility != nullptr);
318     }
319 
320     /**
321      * @tc.name: testWriteReadIInputDataChannel
322      * @tc.desc: Checkout IInputDataChannel.
323      * @tc.type: FUNC
324      */
325     HWTEST_F(InputMethodControllerTest, testWriteReadIInputDataChannel, TestSize.Level0)
326     {
327         sptr<InputDataChannelStub> mInputDataChannel = new InputDataChannelStub();
328         MessageParcel data;
329         auto ret = data.WriteRemoteObject(mInputDataChannel->AsObject());
330         EXPECT_TRUE(ret);
331         auto remoteObject = data.ReadRemoteObject();
332         sptr<IInputDataChannel> iface = iface_cast<IInputDataChannel>(remoteObject);
333         EXPECT_TRUE(iface != nullptr);
334     }
335 
336     /**
337      * @tc.name: testIMCBindToIMSA
338      * @tc.desc: Bind IMSA.
339      * @tc.type: FUNC
340      */
341     HWTEST_F(InputMethodControllerTest, testIMCBindToIMSA, TestSize.Level0)
342     {
343         sptr<InputClientStub> mClient = new InputClientStub();
344         MessageParcel data;
345         auto ret = data.WriteRemoteObject(mClient->AsObject());
346         EXPECT_TRUE(ret);
347         auto remoteObject = data.ReadRemoteObject();
348         sptr<IInputClient> iface = iface_cast<IInputClient>(remoteObject);
349         EXPECT_TRUE(iface != nullptr);
350     }
351 
352     /**
353      * @tc.name: testIMCdispatchKeyEvent
354      * @tc.desc: IMC testdispatchKeyEvent.
355      * @tc.type: FUNC
356      * @tc.require:
357      */
358     HWTEST_F(InputMethodControllerTest, testIMCdispatchKeyEvent, TestSize.Level0)
359     {
360         IMSA_HILOGI("IMC dispatchKeyEvent Test START");
361         bool ret = inputMethodController_->dispatchKeyEvent(keyEvent_);
362         usleep(300);
363         ret = ret && kbListener_->keyCode_ == keyEvent_->GetKeyCode()
364               && kbListener_->keyStatus_ == keyEvent_->GetKeyAction();
365         EXPECT_TRUE(ret);
366     }
367 
368     /**
369      * @tc.name: testIMCOnCursorUpdate
370      * @tc.desc: IMC testOnCursorUpdate
371      * @tc.type: FUNC
372      * @tc.require:
373      */
374     HWTEST_F(InputMethodControllerTest, testIMCOnCursorUpdate, TestSize.Level0)
375     {
376         IMSA_HILOGI("IMC OnCursorUpdate Test START");
377         inputMethodController_->OnCursorUpdate({ 1, 2, 3, 4 });
378         usleep(300);
379         bool result = kbListener_->cursorInfo_.left == static_cast<double>(1)
380                       && kbListener_->cursorInfo_.top == static_cast<double>(2)
381                       && kbListener_->cursorInfo_.height == static_cast<double>(4);
382         EXPECT_TRUE(result);
383     }
384 
385     /**
386      * @tc.name: testShowTextInput
387      * @tc.desc: IMC ShowTextInput
388      * @tc.type: FUNC
389      */
390     HWTEST_F(InputMethodControllerTest, testShowTextInput, TestSize.Level0)
391     {
392         IMSA_HILOGI("IMC ShowTextInput Test START");
393         TextListener::keyboardInfo_.SetKeyboardStatus(static_cast<int32_t>(KeyboardStatus::NONE));
394         inputMethodController_->ShowTextInput();
395         EXPECT_TRUE(TextListener::WaitIMACallback());
396         EXPECT_TRUE(TextListener::keyboardInfo_.GetKeyboardStatus() == KeyboardStatus::SHOW);
397     }
398 
399     /**
400      * @tc.name: testShowSoftKeyboard
401      * @tc.desc: IMC ShowSoftKeyboard
402      * @tc.type: FUNC
403      */
404     HWTEST_F(InputMethodControllerTest, testShowSoftKeyboard, TestSize.Level0)
405     {
406         IMSA_HILOGI("IMC ShowSoftKeyboard Test START");
407         imeListener_->keyboardState_ = false;
408         TextListener::keyboardInfo_.SetKeyboardStatus(static_cast<int32_t>(KeyboardStatus::NONE));
409         int32_t ret = inputMethodController_->ShowSoftKeyboard();
410         EXPECT_TRUE(TextListener::WaitIMACallback());
411         EXPECT_EQ(ret, ErrorCode::NO_ERROR);
412         EXPECT_TRUE(
413             imeListener_->keyboardState_ && TextListener::keyboardInfo_.GetKeyboardStatus() == KeyboardStatus::SHOW);
414     }
415 
416     /**
417      * @tc.name: testShowCurrentInput
418      * @tc.desc: IMC ShowCurrentInput
419      * @tc.type: FUNC
420      */
421     HWTEST_F(InputMethodControllerTest, testShowCurrentInput, TestSize.Level0)
422     {
423         IMSA_HILOGI("IMC ShowCurrentInput Test START");
424         imeListener_->keyboardState_ = false;
425         TextListener::keyboardInfo_.SetKeyboardStatus(static_cast<int32_t>(KeyboardStatus::NONE));
426         int32_t ret = inputMethodController_->ShowCurrentInput();
427         EXPECT_TRUE(TextListener::WaitIMACallback());
428         EXPECT_EQ(ret, ErrorCode::NO_ERROR);
429         EXPECT_TRUE(
430             imeListener_->keyboardState_ && TextListener::keyboardInfo_.GetKeyboardStatus() == KeyboardStatus::SHOW);
431     }
432 
433 
434     /**
435      * @tc.name: testIMCGetTextBeforeCursor
436      * @tc.desc: IMC testGetTextBeforeCursor.
437      * @tc.type: FUNC
438      * @tc.require:
439      */
440     HWTEST_F(InputMethodControllerTest, testIMCGetTextBeforeCursor, TestSize.Level2)
441     {
442         IMSA_HILOGI("IMC GetTextBeforeCursor Test START");
443         constexpr int32_t TEXT_LENGTH = 1;
444         std::u16string text;
445         inputMethodController_->GetTextBeforeCursor(TEXT_LENGTH, text);
446         EXPECT_TRUE(text.size() == 0);
447     }
448 
449     /**
450      * @tc.name: testIMCGetTextAfterCursor
451      * @tc.desc: IMC testGetTextAfterCursor.
452      * @tc.type: FUNC
453      * @tc.require:
454      */
455     HWTEST_F(InputMethodControllerTest, testIMCGetTextAfterCursor, TestSize.Level2)
456     {
457         IMSA_HILOGI("IMC GetTextAfterCursor Test START");
458         constexpr int32_t TEXT_LENGTH = 1;
459         std::u16string text;
460         inputMethodController_->GetTextAfterCursor(TEXT_LENGTH, text);
461         EXPECT_TRUE(text.size() == 0);
462     }
463 
464     /**
465      * @tc.name: testIMCGetEnterKeyType
466      * @tc.desc: IMC testGetEnterKeyType.
467      * @tc.type: FUNC
468      * @tc.require:
469      */
470     HWTEST_F(InputMethodControllerTest, testIMCGetEnterKeyType, TestSize.Level0)
471     {
472         IMSA_HILOGI("IMC GetEnterKeyType Test START");
473         int32_t keyType;
474         inputMethodController_->GetEnterKeyType(keyType);
475         EXPECT_TRUE(keyType >= static_cast<int32_t>(EnterKeyType::UNSPECIFIED)
476                     && keyType <= static_cast<int32_t>(EnterKeyType::PREVIOUS));
477     }
478 
479     /**
480      * @tc.name: testIMCGetInputPattern
481      * @tc.desc: IMC testGetInputPattern.
482      * @tc.type: FUNC
483      * @tc.require:
484      */
485     HWTEST_F(InputMethodControllerTest, testIMCGetInputPattern, TestSize.Level0)
486     {
487         IMSA_HILOGI("IMC GetInputPattern Test START");
488         int32_t inputPattern;
489         inputMethodController_->GetInputPattern(inputPattern);
490         EXPECT_TRUE(inputPattern >= static_cast<int32_t>(TextInputType::NONE)
491                     && inputPattern <= static_cast<int32_t>(TextInputType::VISIBLE_PASSWORD));
492     }
493 
494     /**
495     * @tc.name: testIMCOnConfigurationChange
496     * @tc.desc: IMC testOnConfigurationChange.
497     * @tc.type: FUNC
498     * @tc.require:
499     */
500     HWTEST_F(InputMethodControllerTest, testIMCOnConfigurationChange, TestSize.Level0)
501     {
502         IMSA_HILOGI("IMC OnConfigurationChange Test START");
503         Configuration info;
504         info.SetEnterKeyType(EnterKeyType::GO);
505         info.SetTextInputType(TextInputType::TEXT);
506         inputMethodController_->OnConfigurationChange(info);
507 
508         auto keyType = static_cast<int32_t>(EnterKeyType::UNSPECIFIED);
509         auto inputPattern = static_cast<int32_t>(TextInputType::NONE);
510         inputMethodController_->GetEnterKeyType(keyType);
511         inputMethodController_->GetInputPattern(inputPattern);
512         EXPECT_TRUE(static_cast<OHOS::MiscServices::EnterKeyType>(keyType) == EnterKeyType::GO
513                     && static_cast<OHOS::MiscServices::TextInputType>(inputPattern) == TextInputType::TEXT);
514     }
515 
516     /**
517      * @tc.name: testHideSoftKeyboard
518      * @tc.desc: IMC HideSoftKeyboard
519      * @tc.type: FUNC
520      */
521     HWTEST_F(InputMethodControllerTest, testHideSoftKeyboard, TestSize.Level0)
522     {
523         IMSA_HILOGI("IMC HideSoftKeyboard Test START");
524         imeListener_->keyboardState_ = true;
525         TextListener::keyboardInfo_.SetKeyboardStatus(static_cast<int32_t>(KeyboardStatus::NONE));
526         int32_t ret = inputMethodController_->HideSoftKeyboard();
527         EXPECT_TRUE(TextListener::WaitIMACallback());
528         EXPECT_EQ(ret, ErrorCode::NO_ERROR);
529         EXPECT_TRUE(
530             !imeListener_->keyboardState_ && TextListener::keyboardInfo_.GetKeyboardStatus() == KeyboardStatus::HIDE);
531     }
532 
533     /**
534      * @tc.name: testIMCHideCurrentInput
535      * @tc.desc: IMC HideCurrentInput.
536      * @tc.type: FUNC
537      * @tc.require:
538      */
539     HWTEST_F(InputMethodControllerTest, testIMCHideCurrentInput, TestSize.Level0)
540     {
541         IMSA_HILOGI("IMC HideCurrentInput Test START");
542         imeListener_->keyboardState_ = true;
543         TextListener::keyboardInfo_.SetKeyboardStatus(static_cast<int32_t>(KeyboardStatus::NONE));
544         int32_t ret = inputMethodController_->HideCurrentInput();
545         EXPECT_TRUE(TextListener::WaitIMACallback());
546         EXPECT_EQ(ret, ErrorCode::NO_ERROR);
547         EXPECT_TRUE(
548             !imeListener_->keyboardState_ && TextListener::keyboardInfo_.GetKeyboardStatus() == KeyboardStatus::HIDE);
549     }
550 
551     /**
552     * @tc.name: testIMCInputStopSession
553     * @tc.desc: IMC testInputStopSession.
554     * @tc.type: FUNC
555     * @tc.require: issueI5U8FZ
556     * @tc.author: Hollokin
557     */
558     HWTEST_F(InputMethodControllerTest, testIMCInputStopSession, TestSize.Level0)
559     {
560         IMSA_HILOGI("IMC StopInputSession Test START");
561         imeListener_->keyboardState_ = true;
562         TextListener::keyboardInfo_.SetKeyboardStatus(static_cast<int32_t>(KeyboardStatus::NONE));
563         int32_t ret = inputMethodController_->StopInputSession();
564         EXPECT_TRUE(TextListener::WaitIMACallback());
565         EXPECT_EQ(ret, ErrorCode::NO_ERROR);
566         EXPECT_TRUE(
567             !imeListener_->keyboardState_ && TextListener::keyboardInfo_.GetKeyboardStatus() == KeyboardStatus::HIDE);
568     }
569 
570     /**
571      * @tc.name: testIMCHideTextInput.
572      * @tc.desc: IMC testHideTextInput.
573      * @tc.type: FUNC
574      */
575     HWTEST_F(InputMethodControllerTest, testIMCHideTextInput, TestSize.Level0)
576     {
577         IMSA_HILOGI("IMC InputStopSession Test START");
578         imeListener_->keyboardState_ = true;
579         TextListener::keyboardInfo_.SetKeyboardStatus(static_cast<int32_t>(KeyboardStatus::NONE));
580         inputMethodController_->HideTextInput();
581         EXPECT_TRUE(TextListener::WaitIMACallback());
582         EXPECT_TRUE(
583             !imeListener_->keyboardState_ && TextListener::keyboardInfo_.GetKeyboardStatus() == KeyboardStatus::HIDE);
584     }
585 
586     /**
587      * @tc.name: testIMCClose.
588      * @tc.desc: IMC Close.
589      * @tc.type: FUNC
590      */
591     HWTEST_F(InputMethodControllerTest, testIMCClose, TestSize.Level0)
592     {
593         IMSA_HILOGI("IMC Close Test START");
594         imeListener_->keyboardState_ = true;
595         TextListener::keyboardInfo_.SetKeyboardStatus(static_cast<int32_t>(KeyboardStatus::NONE));
596         inputMethodController_->Close();
597 
598         bool ret = inputMethodController_->dispatchKeyEvent(keyEvent_);
599         EXPECT_FALSE(ret);
600 
601         auto ret1 = inputMethodController_->ShowSoftKeyboard();
602         EXPECT_EQ(ret1, ErrorCode::ERROR_CLIENT_NOT_FOUND);
603 
604         ret1 = inputMethodController_->HideSoftKeyboard();
605         EXPECT_EQ(ret1, ErrorCode::ERROR_CLIENT_NOT_FOUND);
606 
607         ret1 = inputMethodController_->StopInputSession();
608         EXPECT_EQ(ret1, ErrorCode::ERROR_CLIENT_NOT_FOUND);
609     }
610 
611     /**
612      * @tc.name: testDeathRecipient
613      * @tc.desc: test DeathRecipient.
614      * @tc.type: FUNC
615      */
616     HWTEST_F(InputMethodControllerTest, testDeathRecipient, TestSize.Level0)
617     {
618         IMSA_HILOGI("IMC OnRemoteDied Test START");
619         auto deadObject = new ImsaDeathRecipient();
620         sptr<ISystemAbilityManager> systemAbilityManager =
621             SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
622         auto systemAbility = systemAbilityManager->GetSystemAbility(INPUT_METHOD_SYSTEM_ABILITY_ID, "");
623         deadObject->OnRemoteDied(systemAbility);
624         InputMethodController::GetInstance()->OnRemoteSaDied(systemAbility);
625         delete deadObject;
626     }
627 } // namespace MiscServices
628 } // namespace OHOS
629