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