• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2023 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 #define private public
16 #define protected public
17 #include "input_method_ability.h"
18 
19 #include "input_method_controller.h"
20 #include "input_method_system_ability.h"
21 #include "task_manager.h"
22 #undef private
23 
24 #include <gtest/gtest.h>
25 #include <string_ex.h>
26 #include <unistd.h>
27 
28 #include <cstdint>
29 #include <functional>
30 #include <string>
31 #include <thread>
32 #include <vector>
33 
34 #include "global.h"
35 #include "i_input_data_channel.h"
36 #include "identity_checker_mock.h"
37 #include "input_attribute.h"
38 #include "input_control_channel_stub.h"
39 #include "input_data_channel_proxy.h"
40 #include "input_data_channel_stub.h"
41 #include "input_method_ability_interface.h"
42 #include "input_method_agent_stub.h"
43 #include "input_method_core_proxy.h"
44 #include "input_method_core_stub.h"
45 #include "input_method_panel.h"
46 #include "input_method_system_ability_proxy.h"
47 #include "inputmethod_message_handler.h"
48 #include "scope_utils.h"
49 #include "tdd_util.h"
50 #include "text_listener.h"
51 
52 using namespace testing::ext;
53 namespace OHOS {
54 namespace MiscServices {
55 constexpr uint32_t DEALY_TIME = 1;
56 class InputMethodAbilityTest : public testing::Test {
57 public:
58     static std::mutex imeListenerCallbackLock_;
59     static std::condition_variable imeListenerCv_;
60     static bool showKeyboard_;
61     static constexpr int CURSOR_DIRECTION_BASE_VALUE = 2011;
62     static sptr<InputMethodController> imc_;
63     static sptr<OnTextChangedListener> textListener_;
64     static sptr<InputMethodAbility> inputMethodAbility_;
65     static uint32_t windowId_;
66     static int32_t security_;
67     static uint64_t currentImeTokenId_;
68     static int32_t currentImeUid_;
69     static sptr<InputMethodSystemAbility> imsa_;
70     static sptr<InputMethodSystemAbilityProxy> imsaProxy_;
71 
72     class InputMethodEngineListenerImpl : public InputMethodEngineListener {
73     public:
74         InputMethodEngineListenerImpl() = default;
75         ~InputMethodEngineListenerImpl() = default;
76 
OnKeyboardStatus(bool isShow)77         void OnKeyboardStatus(bool isShow)
78         {
79             showKeyboard_ = isShow;
80             InputMethodAbilityTest::imeListenerCv_.notify_one();
81             IMSA_HILOGI("InputMethodEngineListenerImpl OnKeyboardStatus");
82         }
83 
OnInputStart()84         void OnInputStart()
85         {
86             IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStart");
87         }
88 
OnInputStop()89         int32_t OnInputStop()
90         {
91             IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStop");
92             return ErrorCode::NO_ERROR;
93         }
94 
OnSetCallingWindow(uint32_t windowId)95         void OnSetCallingWindow(uint32_t windowId)
96         {
97             windowId_ = windowId;
98             IMSA_HILOGI("InputMethodEngineListenerImpl OnSetCallingWindow");
99         }
100 
OnSetSubtype(const SubProperty & property)101         void OnSetSubtype(const SubProperty &property)
102         {
103             IMSA_HILOGI("InputMethodEngineListenerImpl OnSetSubtype");
104         }
105 
OnSecurityChange(int32_t security)106         void OnSecurityChange(int32_t security)
107         {
108             security_ = security;
109             IMSA_HILOGI("InputMethodEngineListenerImpl OnSecurityChange");
110         }
111 
ReceivePrivateCommand(const std::unordered_map<std::string,PrivateDataValue> & privateCommand)112         void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
113         {
114             IMSA_HILOGI("InputMethodEngineListenerImpl ReceivePrivateCommand");
115         }
116 
OnCallingDisplayIdChanged(uint64_t callingDisplayId)117         void OnCallingDisplayIdChanged(uint64_t callingDisplayId)
118         {
119             IMSA_HILOGI("InputMethodEngineListenerImpl OnCallingDisplayIdChanged displayId:%{public}" PRIu64"",
120                 callingDisplayId);
121         }
122     };
123 
SetUpTestCase(void)124     static void SetUpTestCase(void)
125     {
126         IdentityCheckerMock::ResetParam();
127         // Set the tokenID to the tokenID of the current ime
128         TddUtil::StorageSelfTokenID();
129         imsa_ = new (std::nothrow) InputMethodSystemAbility();
130         if (imsa_ == nullptr) {
131             return;
132         }
133         imsa_->OnStart();
134         imsa_->userId_ = TddUtil::GetCurrentUserId();
135         imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
136         sptr<InputMethodSystemAbilityStub> serviceStub = imsa_;
137         imsaProxy_ = new (std::nothrow) InputMethodSystemAbilityProxy(serviceStub->AsObject());
138         if (imsaProxy_ == nullptr) {
139             return;
140         }
141         IdentityCheckerMock::SetFocused(true);
142 
143         std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
144         auto currentIme = property != nullptr ? property->name : "default.inputmethod.unittest";
145         currentImeTokenId_ = TddUtil::GetTestTokenID(currentIme);
146         currentImeUid_ = TddUtil::GetUid(currentIme);
147 
148         inputMethodAbility_ = InputMethodAbility::GetInstance();
149         inputMethodAbility_->abilityManager_ = imsaProxy_;
150         TddUtil::InitCurrentImePermissionInfo();
151         IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
152         inputMethodAbility_->SetCoreAndAgent();
153         TaskManager::GetInstance().SetInited(true);
154 
155         TextListener::ResetParam();
156         imc_ = InputMethodController::GetInstance();
157         imc_->abilityManager_ = imsaProxy_;
158         textListener_ = new TextListener();
159     }
TearDownTestCase(void)160     static void TearDownTestCase(void)
161     {
162         IMSA_HILOGI("InputMethodAbilityTest::TearDownTestCase");
163         imc_->Close();
164         TextListener::ResetParam();
165         TddUtil::RestoreSelfTokenID();
166         IdentityCheckerMock::ResetParam();
167         imsa_->OnStop();
168     }
GetIMCAttachIMA()169     static void GetIMCAttachIMA()
170     {
171         imc_->SetTextListener(textListener_);
172         imc_->clientInfo_.state = ClientState::ACTIVE;
173         imc_->isBound_.store(true);
174         imc_->isEditable_.store(true);
175         auto agent = inputMethodAbility_->agentStub_->AsObject();
176         imc_->SetAgent(agent);
177 
178         sptr<IInputDataChannel> channel = iface_cast<IInputDataChannel>(imc_->clientInfo_.channel);
179         inputMethodAbility_->SetInputDataChannel(channel->AsObject());
180         IMSA_HILOGI("end");
181     }
GetIMCDetachIMA()182     static void GetIMCDetachIMA()
183     {
184         imc_->OnInputStop();
185         inputMethodAbility_->ClearDataChannel(inputMethodAbility_->dataChannelObject_);
186         IMSA_HILOGI("end");
187     }
SetUp()188     void SetUp()
189     {
190         IMSA_HILOGI("InputMethodAbilityTest::SetUp");
191         TaskManager::GetInstance().Reset();
192     }
TearDown()193     void TearDown()
194     {
195         IMSA_HILOGI("InputMethodAbilityTest::TearDown");
196     }
CheckPanelStatusInfo(const std::shared_ptr<InputMethodPanel> & panel,const PanelStatusInfo & info)197     void CheckPanelStatusInfo(const std::shared_ptr<InputMethodPanel> &panel, const PanelStatusInfo &info)
198     {
199         TextListener::ResetParam();
200         info.visible ? CheckPanelInfoInShow(panel, info) : CheckPanelInfoInHide(panel, info);
201     }
CheckPanelInfoInShow(const std::shared_ptr<InputMethodPanel> & panel,const PanelStatusInfo & info)202     void CheckPanelInfoInShow(const std::shared_ptr<InputMethodPanel> &panel, const PanelStatusInfo &info)
203     {
204         auto ret = inputMethodAbility_->ShowPanel(panel);
205         EXPECT_EQ(ret, ErrorCode::NO_ERROR);
206         if (info.panelInfo.panelFlag != FLG_CANDIDATE_COLUMN) {
207             if (info.panelInfo.panelType == SOFT_KEYBOARD) {
208                 EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
209             } else {
210                 EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
211             }
212             EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback({
213                 { info.panelInfo.panelType, info.panelInfo.panelFlag },
214                 info.visible, info.trigger
215             }));
216             return;
217         }
218         EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
219         EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback({
220             { info.panelInfo.panelType, info.panelInfo.panelFlag },
221             info.visible, info.trigger
222         }));
223     }
CheckPanelInfoInHide(const std::shared_ptr<InputMethodPanel> & panel,const PanelStatusInfo & info)224     void CheckPanelInfoInHide(const std::shared_ptr<InputMethodPanel> &panel, const PanelStatusInfo &info)
225     {
226         AccessScope scope(currentImeTokenId_, currentImeUid_);
227         auto ret = inputMethodAbility_->HidePanel(panel);
228         EXPECT_EQ(ret, ErrorCode::NO_ERROR);
229         if (info.panelInfo.panelFlag != FLG_CANDIDATE_COLUMN) {
230             if (info.panelInfo.panelType == SOFT_KEYBOARD) {
231                 EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
232             } else {
233                 EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
234             };
235             EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback({
236                 { info.panelInfo.panelType, info.panelInfo.panelFlag },
237                 info.visible, info.trigger
238             }));
239             return;
240         }
241         EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
242         EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback({
243             { info.panelInfo.panelType, info.panelInfo.panelFlag },
244             info.visible, info.trigger
245         }));
246     }
247 };
248 
249 std::mutex InputMethodAbilityTest::imeListenerCallbackLock_;
250 std::condition_variable InputMethodAbilityTest::imeListenerCv_;
251 bool InputMethodAbilityTest::showKeyboard_ = true;
252 sptr<InputMethodController> InputMethodAbilityTest::imc_;
253 sptr<OnTextChangedListener> InputMethodAbilityTest::textListener_;
254 sptr<InputMethodAbility> InputMethodAbilityTest::inputMethodAbility_;
255 uint32_t InputMethodAbilityTest::windowId_ = 0;
256 int32_t InputMethodAbilityTest::security_ = -1;
257 uint64_t InputMethodAbilityTest::currentImeTokenId_ = 0;
258 int32_t InputMethodAbilityTest::currentImeUid_ = 0;
259 sptr<InputMethodSystemAbility> InputMethodAbilityTest::imsa_;
260 sptr<InputMethodSystemAbilityProxy> InputMethodAbilityTest::imsaProxy_;
261 
262 /**
263  * @tc.name: testSerializedInputAttribute
264  * @tc.desc: Checkout the serialization of InputAttribute.
265  * @tc.type: FUNC
266  */
267 HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0)
268 {
269     InputAttribute inAttribute;
270     inAttribute.inputPattern = InputAttribute::PATTERN_PASSWORD;
271     MessageParcel data;
272     EXPECT_TRUE(InputAttribute::Marshalling(inAttribute, data));
273     InputAttribute outAttribute;
274     EXPECT_TRUE(InputAttribute::Unmarshalling(outAttribute, data));
275     EXPECT_TRUE(outAttribute.GetSecurityFlag());
276 }
277 
278 /**
279  * @tc.name: testSerializedInputAttribute
280  * @tc.desc: Checkout the serialization of InputAttribute.
281  * @tc.type: FUNC
282  */
283 HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute_WithSpecificBundleName, TestSize.Level0)
284 {
285     InputAttribute inAttribute;
286     inAttribute.bundleName = "com.example.inputmethod";
287     MessageParcel data;
288     EXPECT_TRUE(InputAttribute::Marshalling(inAttribute, data));
289     InputAttribute outAttribute;
290     EXPECT_TRUE(InputAttribute::Unmarshalling(outAttribute, data));
291     EXPECT_EQ(inAttribute.bundleName, outAttribute.bundleName);
292 }
293 
294 /**
295  * @tc.name: testShowKeyboardInputMethodCoreProxy
296  * @tc.desc: Test InputMethodCoreProxy ShowKeyboard
297  * @tc.type: FUNC
298  * @tc.require: issueI5NXHK
299  */
300 HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize.Level0)
301 {
302     IMSA_HILOGI("testShowKeyboardInputMethodCoreProxy start.");
303     sptr<InputMethodCoreStub> coreStub = new InputMethodCoreStub();
304     sptr<IInputMethodCore> core = coreStub;
305     sptr<InputDataChannelStub> channelStub = new InputDataChannelStub();
306     inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
307 
308     MessageParcel data;
309     data.WriteRemoteObject(core->AsObject());
310     data.WriteRemoteObject(channelStub->AsObject());
311     sptr<IRemoteObject> coreObject = data.ReadRemoteObject();
312     sptr<IRemoteObject> channelObject = data.ReadRemoteObject();
313 
314     sptr<InputMethodCoreProxy> coreProxy = new InputMethodCoreProxy(coreObject);
315     sptr<InputDataChannelProxy> channelProxy = new InputDataChannelProxy(channelObject);
316     auto ret = coreProxy->ShowKeyboard();
317     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
318 
319     ret = coreProxy->InitInputControlChannel(nullptr);
320     EXPECT_EQ(ErrorCode::ERROR_EX_NULL_POINTER, ret);
321 
322     std::this_thread::sleep_for(std::chrono::seconds(1));
323     EXPECT_EQ(showKeyboard_, true);
324 }
325 
326 /**
327  * @tc.name: testShowKeyboardWithoutImeListener
328  * @tc.desc: InputMethodAbility ShowKeyboard without imeListener
329  * @tc.type: FUNC
330  * @tc.require:
331  */
332 HWTEST_F(InputMethodAbilityTest, testShowKeyboardWithoutImeListener, TestSize.Level0)
333 {
334     IMSA_HILOGI("InputMethodAbilityTest testShowKeyboardWithoutImeListener start.");
335     auto ret = inputMethodAbility_->ShowKeyboard();
336     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
337 }
338 
339 /**
340  * @tc.name: testHideKeyboardWithoutImeListener
341  * @tc.desc: InputMethodAbility HideKeyboard without imeListener
342  * @tc.type: FUNC
343  * @tc.require:
344  */
345 HWTEST_F(InputMethodAbilityTest, testHideKeyboardWithoutImeListener, TestSize.Level0)
346 {
347     IMSA_HILOGI("InputMethodAbilityTest testHideKeyboardWithoutImeListener start.");
348     auto ret = inputMethodAbility_->HideKeyboard();
349     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
350 }
351 
352 /**
353  * @tc.name: testStartInputWithoutPanel
354  * @tc.desc: InputMethodAbility StartInput Without Panel
355  * @tc.type: FUNC
356  * @tc.require:
357  */
358 HWTEST_F(InputMethodAbilityTest, testStartInputWithoutPanel, TestSize.Level0)
359 {
360     IMSA_HILOGI("InputMethodAbilityTest testStartInputWithoutAttach start.");
361     inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
362     sptr<InputDataChannelStub> channelStub = new InputDataChannelStub();
363     InputClientInfo clientInfo;
364     clientInfo.channel = channelStub;
365     auto ret = inputMethodAbility_->StartInput(clientInfo, false);
366     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
367     clientInfo.isShowKeyboard = true;
368     ret = inputMethodAbility_->StartInput(clientInfo, false);
369     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
370 }
371 
372 /**
373  * @tc.name: testStartInputBeforeCreatePanel
374  * @tc.desc: InputMethodAbility StartInput before create panel
375  * @tc.type: FUNC
376  * @tc.require:
377  */
378 HWTEST_F(InputMethodAbilityTest, testStartInputBeforeCreatePanel, TestSize.Level0)
379 {
380     IMSA_HILOGI("InputMethodAbilityTest testStartInputBeforeCreatePanel start.");
381     inputMethodAbility_->panels_.Clear();
382     inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
383     auto ret = imc_->Attach(textListener_);
384     EXPECT_EQ(ErrorCode::NO_ERROR, ret);
385     {
386         std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
__anonc09676b10102null387         InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
388             return InputMethodAbilityTest::showKeyboard_;
389         });
390     }
391     InputMethodAbilityTest::showKeyboard_ = false;
392     std::shared_ptr<InputMethodPanel> softKeyboardPanel = nullptr;
393     {
394         AccessScope scope(currentImeTokenId_, currentImeUid_);
395         PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
396         ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, softKeyboardPanel);
397         EXPECT_EQ(ErrorCode::NO_ERROR, ret);
398     }
399     {
400         std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
__anonc09676b10202null401         InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
402             return InputMethodAbilityTest::showKeyboard_;
403         });
404         EXPECT_TRUE(InputMethodAbilityTest::showKeyboard_);
405     }
406     imc_->Close();
407     inputMethodAbility_->DestroyPanel(softKeyboardPanel);
408 }
409 
410 /**
411  * @tc.name: testHideKeyboardSelf
412  * @tc.desc: InputMethodAbility HideKeyboardSelf
413  * @tc.type: FUNC
414  * @tc.require:
415  * @tc.author: Hollokin
416  */
417 HWTEST_F(InputMethodAbilityTest, testHideKeyboardSelf, TestSize.Level0)
418 {
419     IMSA_HILOGI("InputMethodAbility testHideKeyboardSelf START");
420     imc_->Attach(textListener_);
421     std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
422     InputMethodAbilityTest::showKeyboard_ = true;
423     inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
424     auto ret = inputMethodAbility_->HideKeyboardSelf();
__anonc09676b10302null425     InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
426         return InputMethodAbilityTest::showKeyboard_ == false;
427     });
428     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
429     EXPECT_FALSE(InputMethodAbilityTest::showKeyboard_);
430 }
431 
432 /**
433  * @tc.name: testMoveCursor
434  * @tc.desc: InputMethodAbility MoveCursor
435  * @tc.type: FUNC
436  * @tc.require:
437  * @tc.author: Hollokin
438  */
439 HWTEST_F(InputMethodAbilityTest, testMoveCursor, TestSize.Level0)
440 {
441     IMSA_HILOGI("InputMethodAbility MoveCursor Test START");
442     constexpr int32_t keyCode = 4;
443     auto ret = inputMethodAbility_->MoveCursor(keyCode); // move cursor right });
444     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
445     EXPECT_TRUE(TextListener::WaitMoveCursor(keyCode));
446 
447     ret = InputMethodAbilityInterface::GetInstance().MoveCursor(keyCode);
448     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
449     EXPECT_TRUE(TextListener::WaitMoveCursor(keyCode));
450 }
451 
452 /**
453  * @tc.name: testInsertText
454  * @tc.desc: InputMethodAbility InsertText
455  * @tc.type: FUNC
456  * @tc.require:
457  * @tc.author: Hollokin
458  */
459 HWTEST_F(InputMethodAbilityTest, testInsertText, TestSize.Level0)
460 {
461     IMSA_HILOGI("InputMethodAbility InsertText Test START");
462     std::string text = "text";
463     std::u16string u16Text = Str8ToStr16(text);
464     auto ret = inputMethodAbility_->InsertText(text);
465     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
466     EXPECT_TRUE(TextListener::WaitInsertText(u16Text));
467 }
468 
469 /**
470  * @tc.name: testSendFunctionKey
471  * @tc.desc: InputMethodAbility SendFunctionKey
472  * @tc.type: FUNC
473  * @tc.require:
474  * @tc.author: Hollokin
475  */
476 HWTEST_F(InputMethodAbilityTest, testSendFunctionKey, TestSize.Level0)
477 {
478     IMSA_HILOGI("InputMethodAbility SendFunctionKey Test START");
479     constexpr int32_t funcKey = 1;
480     auto ret = inputMethodAbility_->SendFunctionKey(funcKey);
481     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
482     EXPECT_TRUE(TextListener::WaitSendFunctionKey(funcKey));
483 }
484 
485 /**
486  * @tc.name: testSendExtendAction
487  * @tc.desc: InputMethodAbility SendExtendAction
488  * @tc.type: FUNC
489  * @tc.require:
490  * @tc.author: chenyu
491  */
492 HWTEST_F(InputMethodAbilityTest, testSendExtendAction, TestSize.Level0)
493 {
494     IMSA_HILOGI("InputMethodAbility SendExtendAction Test START");
495     constexpr int32_t action = 1;
496     auto ret = inputMethodAbility_->SendExtendAction(action);
497     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
498     EXPECT_TRUE(TextListener::WaitHandleExtendAction(action));
499 }
500 
501 /**
502  * @tc.name: testDeleteText
503  * @tc.desc: InputMethodAbility DeleteForward & DeleteBackward
504  * @tc.type: FUNC
505  * @tc.require:
506  * @tc.author: Hollokin
507  */
508 HWTEST_F(InputMethodAbilityTest, testDeleteText, TestSize.Level0)
509 {
510     IMSA_HILOGI("InputMethodAbility testDelete Test START");
511     int32_t deleteForwardLenth = 1;
512     auto ret = inputMethodAbility_->DeleteForward(deleteForwardLenth);
513     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
514     EXPECT_TRUE(TextListener::WaitDeleteBackward(deleteForwardLenth));
515 
516     ret = InputMethodAbilityInterface::GetInstance().DeleteForward(deleteForwardLenth);
517     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
518     EXPECT_TRUE(TextListener::WaitDeleteBackward(deleteForwardLenth));
519 
520     int32_t deleteBackwardLenth = 2;
521     ret = InputMethodAbilityInterface::GetInstance().DeleteBackward(deleteBackwardLenth);
522     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
523     EXPECT_TRUE(TextListener::WaitDeleteForward(deleteBackwardLenth));
524     ret = inputMethodAbility_->DeleteBackward(deleteBackwardLenth);
525     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
526     EXPECT_TRUE(TextListener::WaitDeleteForward(deleteBackwardLenth));
527 }
528 
529 /**
530  * @tc.name: testGetEnterKeyType
531  * @tc.desc: InputMethodAbility GetEnterKeyType & GetInputPattern
532  * @tc.type: FUNC
533  * @tc.require:
534  * @tc.author: Hollokin
535  */
536 HWTEST_F(InputMethodAbilityTest, testGetEnterKeyType, TestSize.Level0)
537 {
538     IMSA_HILOGI("InputMethodAbility testGetEnterKeyType START");
539     Configuration config;
540     EnterKeyType keyType = EnterKeyType::NEXT;
541     config.SetEnterKeyType(keyType);
542     TextInputType textInputType = TextInputType::DATETIME;
543     config.SetTextInputType(textInputType);
544     imc_->OnConfigurationChange(config);
545     int32_t keyType2;
546     auto ret = inputMethodAbility_->GetEnterKeyType(keyType2);
547     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
548     EXPECT_EQ(keyType2, (int)keyType);
549     int32_t inputPattern;
550     ret = inputMethodAbility_->GetInputPattern(inputPattern);
551     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
552     EXPECT_EQ(inputPattern, (int)textInputType);
553 }
554 
555 /**
556  * @tc.name: testGetTextConfig
557  * @tc.desc: InputMethodAbility GetTextConfig
558  * @tc.type: FUNC
559  * @tc.require:
560  * @tc.author: Hollokin
561  */
562 HWTEST_F(InputMethodAbilityTest, testGetTextConfig, TestSize.Level0)
563 {
564     IMSA_HILOGI("InputMethodAbility testGetTextConfig START");
565     TextConfig textConfig;
566     textConfig.inputAttribute = { .inputPattern = 0, .enterKeyType = 1 };
567     auto ret = imc_->Attach(textListener_, false, textConfig);
568     TextTotalConfig textTotalConfig;
569     ret = inputMethodAbility_->GetTextConfig(textTotalConfig);
570     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
571     EXPECT_EQ(textTotalConfig.inputAttribute.inputPattern, textConfig.inputAttribute.inputPattern);
572     EXPECT_EQ(textTotalConfig.inputAttribute.enterKeyType, textConfig.inputAttribute.enterKeyType);
573 }
574 
575 /**
576  * @tc.name: testSelectByRange_001
577  * @tc.desc: InputMethodAbility SelectByRange
578  * @tc.type: FUNC
579  * @tc.require:
580  * @tc.author: Zhaolinglan
581  */
582 HWTEST_F(InputMethodAbilityTest, testSelectByRange_001, TestSize.Level0)
583 {
584     IMSA_HILOGI("InputMethodAbility testSelectByRange_001 START");
585     constexpr int32_t start = 1;
586     constexpr int32_t end = 2;
587     auto ret = inputMethodAbility_->SelectByRange(start, end);
588     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
589     EXPECT_TRUE(TextListener::WaitHandleSetSelection(start, end));
590 }
591 
592 /**
593  * @tc.name: testSelectByRange_002
594  * @tc.desc: InputMethodAbility SelectByRange
595  * @tc.type: FUNC
596  * @tc.require:
597  * @tc.author: chenyu
598  */
599 HWTEST_F(InputMethodAbilityTest, testSelectByRange_002, TestSize.Level0)
600 {
601     IMSA_HILOGI("InputMethodAbility testSelectByRange_002 START");
602     int32_t start = -2;
603     int32_t end = 2;
604     auto ret = inputMethodAbility_->SelectByRange(start, end);
605     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
606 
607     start = 2;
608     end = -2;
609     ret = inputMethodAbility_->SelectByRange(start, end);
610     EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
611 }
612 
613 /**
614  * @tc.name: testSelectByMovement
615  * @tc.desc: InputMethodAbility SelectByMovement
616  * @tc.type: FUNC
617  * @tc.require:
618  * @tc.author: Zhaolinglan
619  */
620 HWTEST_F(InputMethodAbilityTest, testSelectByMovement, TestSize.Level0)
621 {
622     IMSA_HILOGI("InputMethodAbility testSelectByMovement START");
623     constexpr int32_t direction = 1;
624     auto ret = inputMethodAbility_->SelectByMovement(direction);
625     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
626     EXPECT_TRUE(TextListener::WaitHandleSelect(direction + InputMethodAbilityTest::CURSOR_DIRECTION_BASE_VALUE, 0));
627 }
628 
629 /**
630  * @tc.name: testGetTextAfterCursor
631  * @tc.desc:
632  * @tc.type: FUNC
633  * @tc.require:
634  */
635 HWTEST_F(InputMethodAbilityTest, testGetTextAfterCursor, TestSize.Level0)
636 {
637     IMSA_HILOGI("InputMethodAbility testGetTextAfterCursor START");
638     int32_t number = 3;
639     std::u16string text;
640     auto ret = inputMethodAbility_->GetTextAfterCursor(number, text);
641     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
642     EXPECT_EQ(text, Str8ToStr16(TextListener::TEXT_AFTER_CURSOR));
643 }
644 
645 /**
646  * @tc.name: testGetTextBeforeCursor
647  * @tc.desc:
648  * @tc.type: FUNC
649  * @tc.require:
650  */
651 HWTEST_F(InputMethodAbilityTest, testGetTextBeforeCursor, TestSize.Level0)
652 {
653     IMSA_HILOGI("InputMethodAbility testGetTextBeforeCursor START");
654     int32_t number = 5;
655     std::u16string text;
656     auto ret = inputMethodAbility_->GetTextBeforeCursor(number, text);
657     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
658     EXPECT_EQ(text, Str8ToStr16(TextListener::TEXT_BEFORE_CURSOR));
659 }
660 
661 /**
662  * @tc.name: testGetTextIndexAtCursor
663  * @tc.desc:
664  * @tc.type: FUNC
665  * @tc.require:
666  */
667 HWTEST_F(InputMethodAbilityTest, testGetTextIndexAtCursor, TestSize.Level0)
668 {
669     IMSA_HILOGI("InputMethodAbility testGetTextIndexAtCursor START");
670     int32_t index;
671     auto ret = inputMethodAbility_->GetTextIndexAtCursor(index);
672     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
673     EXPECT_EQ(index, TextListener::TEXT_INDEX);
674 }
675 
676 /**
677  * @tc.name: testCreatePanel001
678  * @tc.desc: It's allowed to create one SOFT_KEYBOARD panel, but two is denied.
679  * @tc.type: FUNC
680  * @tc.require:
681  */
682 HWTEST_F(InputMethodAbilityTest, testCreatePanel001, TestSize.Level0)
683 {
684     IMSA_HILOGI("InputMethodAbilityTest testCreatePanel001 START. You can not create two SOFT_KEYBOARD panel.");
685     AccessScope scope(currentImeTokenId_, currentImeUid_);
686     std::shared_ptr<InputMethodPanel> softKeyboardPanel1 = nullptr;
687     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
688     auto ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, softKeyboardPanel1);
689     EXPECT_TRUE(softKeyboardPanel1 != nullptr);
690     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
691 
692     std::shared_ptr<InputMethodPanel> softKeyboardPanel2 = nullptr;
693     ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, softKeyboardPanel2);
694     EXPECT_TRUE(softKeyboardPanel2 == nullptr);
695     EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
696 
697     ret = inputMethodAbility_->DestroyPanel(softKeyboardPanel1);
698     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
699 
700     ret = inputMethodAbility_->DestroyPanel(softKeyboardPanel2);
701     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
702 }
703 
704 /**
705  * @tc.name: testCreatePanel002
706  * @tc.desc: It's allowed to create one STATUS_BAR panel, but two is denied.
707  * @tc.type: FUNC
708  * @tc.require:
709  */
710 HWTEST_F(InputMethodAbilityTest, testCreatePanel002, TestSize.Level0)
711 {
712     IMSA_HILOGI("InputMethodAbilityTest testCreatePanel002 START. You can not create two STATUS_BAR panel.");
713     AccessScope scope(currentImeTokenId_, currentImeUid_);
714     std::shared_ptr<InputMethodPanel> statusBar1 = nullptr;
715     PanelInfo panelInfo = { .panelType = STATUS_BAR };
716     auto ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, statusBar1);
717     EXPECT_TRUE(statusBar1 != nullptr);
718     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
719 
720     std::shared_ptr<InputMethodPanel> statusBar2 = nullptr;
721     ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, statusBar2);
722     EXPECT_TRUE(statusBar2 == nullptr);
723     EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
724 
725     ret = inputMethodAbility_->DestroyPanel(statusBar1);
726     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
727 
728     ret = inputMethodAbility_->DestroyPanel(statusBar2);
729     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
730 }
731 
732 /**
733  * @tc.name: testCreatePanel003
734  * @tc.desc: It's allowed to create one STATUS_BAR panel and one SOFT_KEYBOARD panel.
735  * @tc.type: FUNC
736  * @tc.require:
737  */
738 HWTEST_F(InputMethodAbilityTest, testCreatePanel003, TestSize.Level0)
739 {
740     IMSA_HILOGI("InputMethodAbilityTest testCreatePanel006 START. Allowed to create one SOFT_KEYBOARD panel and "
741                 "one STATUS_BAR panel.");
742     AccessScope scope(currentImeTokenId_, currentImeUid_);
743     std::shared_ptr<InputMethodPanel> softKeyboardPanel = nullptr;
744     PanelInfo panelInfo1 = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
745     auto ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo1, softKeyboardPanel);
746     EXPECT_TRUE(softKeyboardPanel != nullptr);
747     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
748 
749     PanelInfo panelInfo2 = { .panelType = STATUS_BAR };
750     std::shared_ptr<InputMethodPanel> statusBar = nullptr;
751     ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo2, statusBar);
752     EXPECT_TRUE(statusBar != nullptr);
753     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
754 
755     ret = inputMethodAbility_->DestroyPanel(softKeyboardPanel);
756     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
757 
758     ret = inputMethodAbility_->DestroyPanel(statusBar);
759     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
760 }
761 
762 /**
763  * @tc.name: testCreatePanel004
764  * @tc.desc: It's allowed to create one STATUS_BAR panel and one SOFT_KEYBOARD panel.
765  * @tc.type: FUNC
766  * @tc.require:
767  */
768 HWTEST_F(InputMethodAbilityTest, testCreatePanel004, TestSize.Level0)
769 {
770     IMSA_HILOGI("InputMethodAbilityTest testCreatePanel006 START. Allowed to create one SOFT_KEYBOARD panel and "
771                 "one STATUS_BAR panel.");
772     AccessScope scope(currentImeTokenId_, currentImeUid_);
773     std::shared_ptr<InputMethodPanel> inputMethodPanel = nullptr;
774     PanelInfo panelInfo1 = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
775     auto ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo1, inputMethodPanel);
776     EXPECT_TRUE(inputMethodPanel != nullptr);
777     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
778 
779     ret = inputMethodAbility_->DestroyPanel(inputMethodPanel);
780     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
781 
782     PanelInfo panelInfo2 = { .panelType = STATUS_BAR };
783     ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo2, inputMethodPanel);
784     EXPECT_TRUE(inputMethodPanel != nullptr);
785     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
786 
787     ret = inputMethodAbility_->DestroyPanel(inputMethodPanel);
788     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
789 
790     panelInfo1.panelFlag = FLG_FLOATING;
791     ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo1, inputMethodPanel);
792     EXPECT_TRUE(inputMethodPanel != nullptr);
793     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
794 
795     ret = inputMethodAbility_->DestroyPanel(inputMethodPanel);
796     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
797 }
798 
799 /**
800  * @tc.name: testCreatePanel005
801  * @tc.desc: It's allowed to create one SOFT_KEYBOARD panel, but two is denied.
802  * @tc.type: FUNC
803  * @tc.require:
804  */
805 HWTEST_F(InputMethodAbilityTest, testCreatePanel005, TestSize.Level0)
806 {
807     IMSA_HILOGI("InputMethodAbilityTest testCreatePanel005 START.");
808     AccessScope scope(currentImeTokenId_, currentImeUid_);
809     std::shared_ptr<InputMethodPanel> softKeyboardPanel1 = nullptr;
810     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
811     auto ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, softKeyboardPanel1);
812     EXPECT_TRUE(softKeyboardPanel1 != nullptr);
813     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
814 
815     ret = inputMethodAbility_->DestroyPanel(softKeyboardPanel1);
816     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
817 
818     std::shared_ptr<InputMethodPanel> softKeyboardPanel2 = nullptr;
819     ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, softKeyboardPanel2);
820     EXPECT_TRUE(softKeyboardPanel2 != nullptr);
821     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
822 
823     ret = inputMethodAbility_->DestroyPanel(softKeyboardPanel2);
824     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
825 }
826 
827 /**
828  * @tc.name: testCreatePanel006
829  * @tc.desc: It's allowed to create one SOFT_KEYBOARD panel, but two is denied.
830  * @tc.type: FUNC
831  * @tc.require:
832  */
833 HWTEST_F(InputMethodAbilityTest, testCreatePanel006, TestSize.Level0)
834 {
835     IMSA_HILOGI("InputMethodAbilityTest testCreatePanel006 START.");
836     AccessScope scope(currentImeTokenId_, currentImeUid_);
837     std::shared_ptr<InputMethodPanel> softKeyboardPanel1 = nullptr;
838     PanelInfo panelInfo = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
839     auto ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, softKeyboardPanel1);
840     EXPECT_TRUE(softKeyboardPanel1 != nullptr);
841     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
842 
843     std::shared_ptr<InputMethodPanel> softKeyboardPanel2 = nullptr;
844     ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, softKeyboardPanel2);
845     EXPECT_TRUE(softKeyboardPanel2 == nullptr);
846     EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
847 
848     ret = inputMethodAbility_->DestroyPanel(softKeyboardPanel1);
849     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
850 
851     std::shared_ptr<InputMethodPanel> softKeyboardPanel3 = nullptr;
852     ret = inputMethodAbility_->CreatePanel(nullptr, panelInfo, softKeyboardPanel3);
853     EXPECT_TRUE(softKeyboardPanel3 != nullptr);
854     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
855 
856     ret = inputMethodAbility_->DestroyPanel(softKeyboardPanel2);
857     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
858 
859     ret = inputMethodAbility_->DestroyPanel(softKeyboardPanel3);
860     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
861     std::this_thread::sleep_for(std::chrono::seconds(2));
862 }
863 
864 /**
865  * @tc.name: testSetCallingWindow001
866  * @tc.desc: InputMethodAbility SetCallingWindow
867  * @tc.type: FUNC
868  * @tc.require:
869  * @tc.author: Hollokin
870  */
871 HWTEST_F(InputMethodAbilityTest, testSetCallingWindow001, TestSize.Level0)
872 {
873     IMSA_HILOGI("InputMethodAbility testSetCallingWindow001 START");
874     std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
875     InputMethodAbilityTest::showKeyboard_ = true;
876     inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
877     uint32_t windowId = 10;
878     inputMethodAbility_->SetCallingWindow(windowId);
__anonc09676b10402null879     InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [windowId] {
880         return InputMethodAbilityTest::windowId_ == windowId;
881     });
882     EXPECT_EQ(InputMethodAbilityTest::windowId_, windowId);
883     std::this_thread::sleep_for(std::chrono::seconds(2));
884 }
885 
886 /**
887  * @tc.name: testNotifyPanelStatusInfo_001
888  * @tc.desc: ShowKeyboard HideKeyboard SOFT_KEYBOARD FLG_FIXED
889  * @tc.type: FUNC
890  * @tc.require:
891  * @tc.author: chenyu
892  */
893 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_001, TestSize.Level0)
894 {
895     IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_001 START");
896     imc_->Attach(textListener_);
897     PanelInfo info = { .panelType = STATUS_BAR };
898     auto panel = std::make_shared<InputMethodPanel>();
899     AccessScope scope(currentImeTokenId_, currentImeUid_);
900     auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
901     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
902     auto panel1 = std::make_shared<InputMethodPanel>();
903     PanelInfo info1 = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
904     ret = inputMethodAbility_->CreatePanel(nullptr, info1, panel1);
905     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
906 
907     TextListener::ResetParam();
908     ret = inputMethodAbility_->ShowKeyboard();
909     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
910     EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
911     EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback({ info1, true, Trigger::IMF }));
912 
913     TextListener::ResetParam();
914     ret = inputMethodAbility_->HideKeyboard();
915     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
916     EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
917     EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback({ info1, false, Trigger::IMF }));
918 
919     ret = inputMethodAbility_->DestroyPanel(panel);
920     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
921     ret = inputMethodAbility_->DestroyPanel(panel1);
922     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
923     std::this_thread::sleep_for(std::chrono::seconds(2));
924 }
925 
926 /**
927  * @tc.name: testNotifyPanelStatusInfo_002
928  * @tc.desc: ShowPanel HidePanel SOFT_KEYBOARD  FLG_FLOATING
929  * @tc.type: FUNC
930  * @tc.require:
931  * @tc.author: chenyu
932  */
933 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_002, TestSize.Level0)
934 {
935     IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_002 START");
936     imc_->Attach(textListener_);
937     PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
938     AccessScope scope(currentImeTokenId_, currentImeUid_);
939     auto panel = std::make_shared<InputMethodPanel>();
940     auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
941     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
942 
943     // ShowPanel
944     CheckPanelStatusInfo(panel, { info, true, Trigger::IME_APP });
945     // HidePanel
946     CheckPanelStatusInfo(panel, { info, false, Trigger::IME_APP });
947 
948     ret = inputMethodAbility_->DestroyPanel(panel);
949     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
950     std::this_thread::sleep_for(std::chrono::seconds(2));
951 }
952 
953 /**
954  * @tc.name: testNotifyPanelStatusInfo_003
955  * @tc.desc: ShowPanel HidePanel STATUS_BAR
956  * @tc.type: FUNC
957  * @tc.require:
958  * @tc.author: chenyu
959  */
960 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_003, TestSize.Level0)
961 {
962     IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_003 START");
963     imc_->Attach(textListener_, false);
964     PanelInfo info = { .panelType = STATUS_BAR };
965     auto panel = std::make_shared<InputMethodPanel>();
966     AccessScope scope(currentImeTokenId_, currentImeUid_);
967     auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
968     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
969     EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
970 
971     // ShowPanel
972     CheckPanelStatusInfo(panel, { info, true, Trigger::IME_APP });
973     // HidePanel
974     CheckPanelStatusInfo(panel, { info, false, Trigger::IME_APP });
975 
976     ret = inputMethodAbility_->DestroyPanel(panel);
977     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
978 }
979 
980 /**
981  * @tc.name: testNotifyPanelStatusInfo_004
982  * @tc.desc: ShowPanel HidePanel SOFT_KEYBOARD  FLG_CANDIDATE_COLUMN
983  * @tc.type: FUNC
984  * @tc.require:
985  * @tc.author: chenyu
986  */
987 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_004, TestSize.Level0)
988 {
989     IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_004 START");
990     imc_->Attach(textListener_);
991     PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_CANDIDATE_COLUMN };
992     auto panel = std::make_shared<InputMethodPanel>();
993     AccessScope scope(currentImeTokenId_, currentImeUid_);
994     auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
995     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
996 
997     // ShowPanel
998     CheckPanelStatusInfo(panel, { info, true, Trigger::IME_APP });
999     // HidePanel
1000     CheckPanelStatusInfo(panel, { info, false, Trigger::IME_APP });
1001 
1002     ret = inputMethodAbility_->DestroyPanel(panel);
1003     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1004 }
1005 
1006 /**
1007  * @tc.name: testNotifyPanelStatusInfo_005
1008  * @tc.desc: HideKeyboardSelf
1009  * @tc.type: FUNC
1010  * @tc.require:
1011  * @tc.author: chenyu
1012  */
1013 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_005, TestSize.Level0)
1014 {
1015     IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_005 START");
1016     PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FLOATING };
1017     imc_->Attach(textListener_);
1018 
1019     // has no panel
1020     TextListener::ResetParam();
1021     auto ret = inputMethodAbility_->HideKeyboardSelf();
1022     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1023     EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
1024     EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback({ info, false, Trigger::IME_APP }));
1025 
1026     AccessScope scope(currentImeTokenId_, currentImeUid_);
1027     auto panel = std::make_shared<InputMethodPanel>();
1028     ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
1029     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1030     ret = inputMethodAbility_->ShowPanel(panel);
1031     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1032     // has panel
1033     TextListener::ResetParam();
1034     ret = inputMethodAbility_->HideKeyboardSelf();
1035     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1036     EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
1037     EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback({ info, false, Trigger::IME_APP }));
1038 
1039     ret = inputMethodAbility_->DestroyPanel(panel);
1040     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1041 }
1042 
1043 /**
1044  * @tc.name: testNotifyKeyboardHeight_001
1045  * @tc.desc: NotifyKeyboardHeight SOFT_KEYBOARD  FLG_FIXED
1046  * @tc.type: FUNC
1047  * @tc.require:
1048  * @tc.author: mashaoyin
1049  */
1050 HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_001, TestSize.Level0)
1051 {
1052     IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_001 START");
1053     imc_->Attach(textListener_);
1054     AccessScope scope(currentImeTokenId_, currentImeUid_);
1055     TextListener::ResetParam();
1056     inputMethodAbility_->NotifyKeyboardHeight(1, FLG_FIXED);
1057     EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(1));
1058 }
1059 
1060 /**
1061  * @tc.name: testNotifyKeyboardHeight_002
1062  * @tc.desc: NotifyKeyboardHeight SOFT_KEYBOARD  FLG_CANDIDATE_COLUMN
1063  * @tc.type: FUNC
1064  * @tc.require:
1065  * @tc.author: mashaoyin
1066  */
1067 HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_002, TestSize.Level0)
1068 {
1069     IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_002 START");
1070     imc_->Attach(textListener_);
1071     AccessScope scope(currentImeTokenId_, currentImeUid_);
1072     TextListener::ResetParam();
1073     inputMethodAbility_->NotifyKeyboardHeight(1, FLG_CANDIDATE_COLUMN);
1074     EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(0));
1075 }
1076 
1077 /**
1078  * @tc.name: testNotifyKeyboardHeight_003
1079  * @tc.desc: NotifyKeyboardHeight Attach with hard keyboard
1080  * @tc.type: FUNC
1081  * @tc.require:
1082  * @tc.author: mashaoyin
1083  */
1084 HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_003, TestSize.Level0)
1085 {
1086     IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_003 START");
1087     TextListener::ResetParam();
1088     AccessScope scope(currentImeTokenId_, currentImeUid_);
1089     PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_CANDIDATE_COLUMN };
1090     auto panel = std::make_shared<InputMethodPanel>();
1091     auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
1092     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1093     panel->Resize(1, 1);
1094     imc_->Attach(textListener_);
1095     EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(0));
1096     ret = inputMethodAbility_->DestroyPanel(panel);
1097     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1098 }
1099 
1100 /**
1101  * @tc.name: testAdjustKeyboard_001
1102  * @tc.desc: adjust keyboard
1103  * @tc.type: FUNC
1104  * @tc.require:
1105  * @tc.author: guojin
1106  */
1107 HWTEST_F(InputMethodAbilityTest, testAdjustKeyboard_001, TestSize.Level0)
1108 {
1109     IMSA_HILOGI("InputMethodAbility testAdjustKeyboard_001 START");
1110     AccessScope scope(currentImeTokenId_, currentImeUid_);
1111     PanelInfo info = { .panelType = SOFT_KEYBOARD, .panelFlag = FLG_FIXED };
1112     auto panel = std::make_shared<InputMethodPanel>();
1113     auto ret = inputMethodAbility_->CreatePanel(nullptr, info, panel);
1114     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1115 
1116     ret = inputMethodAbility_->AdjustKeyboard();
1117     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1118 
1119     ret = inputMethodAbility_->DestroyPanel(panel);
1120     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1121 }
1122 
1123 /**
1124  * @tc.name: testOnSecurityChange
1125  * @tc.desc: OnSecurityChange
1126  * @tc.type: FUNC
1127  * @tc.require:
1128  * @tc.author: chenyu
1129  */
1130 HWTEST_F(InputMethodAbilityTest, testOnSecurityChange, TestSize.Level0)
1131 {
1132     IMSA_HILOGI("InputMethodAbility testOnSecurityChange START");
1133     int32_t security = 32;
1134     inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
1135     auto ret = inputMethodAbility_->OnSecurityChange(security);
1136     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1137     EXPECT_EQ(InputMethodAbilityTest::security_, security);
1138 }
1139 
1140 /**
1141  * @tc.name: testSendPrivateCommand_001
1142  * @tc.desc: IMA SendPrivateCommand current is not default ime.
1143  * @tc.type: FUNC
1144  * @tc.require:
1145  * @tc.author: mashaoyin
1146  */
1147 HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_001, TestSize.Level0)
1148 {
1149     IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_001 Test START");
1150     IdentityCheckerMock::SetBundleNameValid(false);
1151     TextListener::ResetParam();
1152     InputMethodAbilityTest::GetIMCDetachIMA();
1153     TddUtil::RestoreSelfTokenID();
1154     std::unordered_map<std::string, PrivateDataValue> privateCommand;
1155     auto ret = inputMethodAbility_->SendPrivateCommand(privateCommand);
1156     EXPECT_EQ(ret, ErrorCode::ERROR_NOT_DEFAULT_IME);
1157     IdentityCheckerMock::SetBundleNameValid(true);
1158 }
1159 
1160 /**
1161  * @tc.name: testSendPrivateCommand_002
1162  * @tc.desc: IMA SendPrivateCommand current data specification, default ime, not bound.
1163  * @tc.type: FUNC
1164  * @tc.require:
1165  * @tc.author: mashaoyin
1166  */
1167 HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_002, TestSize.Level0)
1168 {
1169     IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_002 Test START");
1170     InputMethodAbilityTest::GetIMCDetachIMA();
1171     IdentityCheckerMock::SetBundleNameValid(true);
1172     std::unordered_map<std::string, PrivateDataValue> privateCommand;
1173     PrivateDataValue privateDataValue1 = std::string("stringValue");
1174     privateCommand.insert({ "value1", privateDataValue1 });
1175     auto ret = inputMethodAbility_->SendPrivateCommand(privateCommand);
1176     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
1177     IdentityCheckerMock::SetBundleNameValid(false);
1178 }
1179 
1180 /**
1181  * @tc.name: testSendPrivateCommand_003
1182  * @tc.desc: IMA SendPrivateCommand with correct data specification and all data type.
1183  * @tc.type: FUNC
1184  * @tc.require:
1185  * @tc.author: mashaoyin
1186  */
1187 HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_003, TestSize.Level0)
1188 {
1189     IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_003 Test START");
1190     TextListener::ResetParam();
1191     InputMethodAbilityTest::GetIMCAttachIMA();
1192     IdentityCheckerMock::SetBundleNameValid(true);
1193     std::unordered_map<std::string, PrivateDataValue> privateCommand;
1194     PrivateDataValue privateDataValue1 = std::string("stringValue");
1195     PrivateDataValue privateDataValue2 = true;
1196     PrivateDataValue privateDataValue3 = 100;
1197     privateCommand.emplace("value1", privateDataValue1);
1198     privateCommand.emplace("value2", privateDataValue2);
1199     privateCommand.emplace("value3", privateDataValue3);
1200     auto ret = inputMethodAbility_->SendPrivateCommand(privateCommand);
1201     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1202     EXPECT_TRUE(TextListener::WaitSendPrivateCommandCallback(privateCommand));
1203     InputMethodAbilityTest::GetIMCDetachIMA();
1204     IdentityCheckerMock::SetBundleNameValid(false);
1205 }
1206 
1207 /**
1208  * @tc.name: testGetCallingWindowInfo_001
1209  * @tc.desc: GetCallingWindowInfo with IMC not bound
1210  * @tc.type: FUNC
1211  * @tc.require:
1212  * @tc.author: zhaolinglan
1213  */
1214 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_001, TestSize.Level0)
1215 {
1216     IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_001 Test START");
1217     InputMethodAbilityTest::GetIMCDetachIMA();
1218     CallingWindowInfo windowInfo;
1219     int32_t ret = InputMethodAbilityTest::inputMethodAbility_->GetCallingWindowInfo(windowInfo);
1220     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
1221 }
1222 
1223 /**
1224  * @tc.name: testGetCallingWindowInfo_002
1225  * @tc.desc: GetCallingWindowInfo with panel not created
1226  * @tc.type: FUNC
1227  * @tc.require:
1228  * @tc.author: zhaolinglan
1229  */
1230 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_002, TestSize.Level0)
1231 {
1232     IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_002 Test START");
1233     AccessScope accessScope(InputMethodAbilityTest::currentImeTokenId_, InputMethodAbilityTest::currentImeUid_);
1234     // bind IMC
1235     InputMethodAbilityTest::GetIMCAttachIMA();
1236     // no panel is created
1237     InputMethodAbilityTest::inputMethodAbility_->panels_.Clear();
1238     CallingWindowInfo windowInfo;
1239     int32_t ret = InputMethodAbilityTest::inputMethodAbility_->GetCallingWindowInfo(windowInfo);
1240     EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
1241     InputMethodAbilityTest::GetIMCDetachIMA();
1242 }
1243 
1244 /**
1245  * @tc.name: testGetCallingWindowInfo_003
1246  * @tc.desc: GetCallingWindowInfo with only status_bar created
1247  * @tc.type: FUNC
1248  * @tc.require:
1249  * @tc.author: zhaolinglan
1250  */
1251 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_003, TestSize.Level0)
1252 {
1253     IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_003 Test START");
1254     AccessScope accessScope(InputMethodAbilityTest::currentImeTokenId_, InputMethodAbilityTest::currentImeUid_);
1255     // bind IMC
1256     InputMethodAbilityTest::GetIMCAttachIMA();
1257     // only STATUS_BAR panel in IMA
1258     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1259     PanelInfo info = { PanelType::STATUS_BAR };
1260     InputMethodAbilityTest::inputMethodAbility_->CreatePanel(nullptr, info, inputMethodPanel);
1261     CallingWindowInfo windowInfo;
1262     int32_t ret = InputMethodAbilityTest::inputMethodAbility_->GetCallingWindowInfo(windowInfo);
1263     EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
1264     InputMethodAbilityTest::inputMethodAbility_->DestroyPanel(inputMethodPanel);
1265     InputMethodAbilityTest::GetIMCDetachIMA();
1266 }
1267 
1268 /**
1269  * @tc.name: testGetCallingWindowInfo_004
1270  * @tc.desc: GetCallingWindowInfo with invalid windowid
1271  * @tc.type: FUNC
1272  * @tc.require:
1273  * @tc.author: zhaolinglan
1274  */
1275 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_004, TestSize.Level0)
1276 {
1277     IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_004 Test START");
1278     AccessScope accessScope(InputMethodAbilityTest::currentImeTokenId_, InputMethodAbilityTest::currentImeUid_);
1279     // bind imc
1280     InputMethodAbilityTest::GetIMCAttachIMA();
1281     // SOFT_KEYBOARD panel exists
1282     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1283     PanelInfo info = { PanelType::SOFT_KEYBOARD, PanelFlag::FLG_FIXED };
1284     InputMethodAbilityTest::inputMethodAbility_->CreatePanel(nullptr, info, inputMethodPanel);
1285     // invalid window id
1286     InputMethodAbilityTest::imc_->clientInfo_.config.windowId = INVALID_WINDOW_ID;
1287     CallingWindowInfo windowInfo;
1288     int32_t ret = InputMethodAbilityTest::inputMethodAbility_->GetCallingWindowInfo(windowInfo);
1289     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1290     InputMethodAbilityTest::inputMethodAbility_->DestroyPanel(inputMethodPanel);
1291     InputMethodAbilityTest::GetIMCDetachIMA();
1292 }
1293 
1294 /**
1295  * @tc.name: testGetCallingWindowInfo_005
1296  * @tc.desc: GetCallingWindowInfo success
1297  * @tc.type: FUNC
1298  * @tc.require:
1299  * @tc.author: zhaolinglan
1300  */
1301 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_005, TestSize.Level0)
1302 {
1303     IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_005 Test START");
1304     AccessScope accessScope(InputMethodAbilityTest::currentImeTokenId_, InputMethodAbilityTest::currentImeUid_);
1305     // SOFT_KEYBOARD window is created
1306     InputMethodAbilityTest::inputMethodAbility_->panels_.Clear();
1307     auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1308     PanelInfo info = { PanelType::SOFT_KEYBOARD, PanelFlag::FLG_FIXED };
1309     InputMethodAbilityTest::inputMethodAbility_->CreatePanel(nullptr, info, inputMethodPanel);
1310     // bind IMC
1311     InputMethodAbilityTest::GetIMCAttachIMA();
1312     InputMethodAbilityTest::imc_->textConfig_.windowId = TddUtil::WindowManager::currentWindowId_;
1313     // get window info success
1314     CallingWindowInfo windowInfo;
1315     int32_t ret = InputMethodAbilityTest::inputMethodAbility_->GetCallingWindowInfo(windowInfo);
1316     EXPECT_TRUE(ret == ErrorCode::NO_ERROR || ret == ErrorCode::ERROR_WINDOW_MANAGER);
1317     InputMethodAbilityTest::GetIMCDetachIMA();
1318     InputMethodAbilityTest::inputMethodAbility_->DestroyPanel(inputMethodPanel);
1319 }
1320 
1321 /**
1322  * @tc.name: testSetPreviewText_001
1323  * @tc.desc: IMA
1324  * @tc.type: FUNC
1325  * @tc.require:
1326  * @tc.author: zhaolinglan
1327  */
1328 HWTEST_F(InputMethodAbilityTest, testSetPreviewText_001, TestSize.Level0)
1329 {
1330     IMSA_HILOGI("InputMethodAbilityTest testSetPreviewText_001 Test START");
1331     TextListener::ResetParam();
1332     std::string text = "test";
1333     Range range = { 1, 2 };
1334     InputMethodAbilityTest::GetIMCAttachIMA();
1335     InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = true;
1336     auto ret = InputMethodAbilityTest::inputMethodAbility_->SetPreviewText(text, range);
1337     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1338     EXPECT_EQ(TextListener::previewText_, text);
1339     EXPECT_EQ(TextListener::previewRange_, range);
1340     InputMethodAbilityTest::GetIMCDetachIMA();
1341 }
1342 
1343 /**
1344  * @tc.name: testSetPreviewText_002
1345  * @tc.desc: IMA
1346  * @tc.type: FUNC
1347  * @tc.require:
1348  * @tc.author: zhaolinglan
1349  */
1350 HWTEST_F(InputMethodAbilityTest, testSetPreviewText_002, TestSize.Level0)
1351 {
1352     IMSA_HILOGI("InputMethodAbilityTest testSetPreviewText_002 Test START");
1353     TextListener::ResetParam();
1354     std::string text = "test";
1355     Range range = { 1, 2 };
1356     InputMethodAbilityTest::inputMethodAbility_->ClearDataChannel(
1357         InputMethodAbilityTest::inputMethodAbility_->dataChannelObject_);
1358     auto ret = InputMethodAbilityTest::inputMethodAbility_->SetPreviewText(text, range);
1359     EXPECT_EQ(ret, ErrorCode::ERROR_IMA_CHANNEL_NULLPTR);
1360     EXPECT_NE(TextListener::previewText_, text);
1361     EXPECT_FALSE(TextListener::previewRange_ == range);
1362 }
1363 
1364 /**
1365  * @tc.name: testSetPreviewText_003
1366  * @tc.desc: IMA
1367  * @tc.type: FUNC
1368  * @tc.require:
1369  * @tc.author: zhaolinglan
1370  */
1371 HWTEST_F(InputMethodAbilityTest, testSetPreviewText_003, TestSize.Level0)
1372 {
1373     IMSA_HILOGI("InputMethodAbilityTest testSetPreviewText_003 Test START");
1374     TextListener::ResetParam();
1375     std::string text = "test";
1376     Range range = { 1, 2 };
1377     InputMethodAbilityTest::GetIMCAttachIMA();
1378     InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = false;
1379     auto ret = InputMethodAbilityTest::inputMethodAbility_->SetPreviewText(text, range);
1380     EXPECT_EQ(ret, ErrorCode::ERROR_TEXT_PREVIEW_NOT_SUPPORTED);
1381     EXPECT_NE(TextListener::previewText_, text);
1382     EXPECT_FALSE(TextListener::previewRange_ == range);
1383     InputMethodAbilityTest::GetIMCDetachIMA();
1384 }
1385 
1386 /**
1387  * @tc.name: testFinishTextPreview_001
1388  * @tc.desc: IMA
1389  * @tc.type: FUNC
1390  * @tc.require:
1391  * @tc.author: zhaolinglan
1392  */
1393 HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_001, TestSize.Level0)
1394 {
1395     IMSA_HILOGI("InputMethodAbilityTest testFinishTextPreview_001 Test START");
1396     TextListener::ResetParam();
1397     InputMethodAbilityTest::GetIMCAttachIMA();
1398     InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = true;
1399     auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview(false);
1400     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1401     EXPECT_TRUE(TextListener::isFinishTextPreviewCalled_);
1402     InputMethodAbilityTest::GetIMCDetachIMA();
1403 }
1404 
1405 /**
1406  * @tc.name: testFinishTextPreview_002
1407  * @tc.desc: IMA
1408  * @tc.type: FUNC
1409  * @tc.require:
1410  * @tc.author: zhaolinglan
1411  */
1412 HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_002, TestSize.Level0)
1413 {
1414     IMSA_HILOGI("InputMethodAbilityTest testFinishTextPreview_002 Test START");
1415     TextListener::ResetParam();
1416     InputMethodAbilityTest::inputMethodAbility_->ClearDataChannel(
1417         InputMethodAbilityTest::inputMethodAbility_->dataChannelObject_);
1418     auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview(false);
1419     EXPECT_EQ(ret, ErrorCode::ERROR_IMA_CHANNEL_NULLPTR);
1420     EXPECT_FALSE(TextListener::isFinishTextPreviewCalled_);
1421 }
1422 
1423 /**
1424  * @tc.name: testFinishTextPreview_003
1425  * @tc.desc: IMA
1426  * @tc.type: FUNC
1427  * @tc.require:
1428  * @tc.author: zhaolinglan
1429  */
1430 HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_003, TestSize.Level0)
1431 {
1432     IMSA_HILOGI("InputMethodAbilityTest testFinishTextPreview_003 Test START");
1433     TextListener::ResetParam();
1434     InputMethodAbilityTest::GetIMCAttachIMA();
1435     InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = false;
1436     auto ret = InputMethodAbilityTest::inputMethodAbility_->FinishTextPreview(false);
1437     EXPECT_EQ(ret, ErrorCode::ERROR_TEXT_PREVIEW_NOT_SUPPORTED);
1438     EXPECT_FALSE(TextListener::isFinishTextPreviewCalled_);
1439     InputMethodAbilityTest::GetIMCDetachIMA();
1440 }
1441 
1442 /**
1443  *@tc.name: testGetInputMethodState_001
1444  *@tc.desc: IMA
1445  *@tc.type: FUNC
1446  *@tc.require:
1447  */
1448 HWTEST_F(InputMethodAbilityTest, testGetInputMethodState_001, TestSize.Level0)
1449 {
1450     IMSA_HILOGI("InputMethodAbilityTest GetInputMethodState_001 Test START");
1451     EnabledStatus status = EnabledStatus::DISABLED;
1452     auto ret = InputMethodAbilityTest::imsa_->GetInputMethodState(status);
1453     EXPECT_EQ(ret, ErrorCode::ERROR_NOT_IME);
1454 }
1455 
1456 /**
1457  * @tc.name: BranchCoverage001
1458  * @tc.desc: BranchCoverage
1459  * @tc.type: FUNC
1460  */
1461 HWTEST_F(InputMethodAbilityTest, BranchCoverage001, TestSize.Level0)
1462 {
1463     IMSA_HILOGI("InputMethodAbilityTest BranchCoverage001 TEST START");
1464     auto ret = InputMethodAbilityTest::inputMethodAbility_->OnStopInputService(false);
1465     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1466 
1467     InputMethodAbilityTest::inputMethodAbility_->imeListener_ = nullptr;
1468     ret = InputMethodAbilityTest::inputMethodAbility_->OnStopInputService(false);
1469     EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED);
1470 
1471     ret = InputMethodAbilityTest::inputMethodAbility_->OnSecurityChange(INVALID_VALUE);
1472     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1473 
1474     ret = InputMethodAbilityTest::inputMethodAbility_->HideKeyboardImplWithoutLock(INVALID_VALUE);
1475     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1476 
1477     ret = InputMethodAbilityTest::inputMethodAbility_->ShowKeyboardImplWithoutLock(INVALID_VALUE);
1478     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1479 
1480     ret = InputMethodAbilityTest::inputMethodAbility_->ShowPanel(nullptr);
1481     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1482 
1483     PanelFlag flag = PanelFlag::FLG_FIXED;
1484     Trigger trigger = Trigger::IME_APP;
1485     ret = InputMethodAbilityTest::inputMethodAbility_->ShowPanel(nullptr, flag, trigger);
1486     EXPECT_EQ(ret, ErrorCode::ERROR_IMA_NULLPTR);
1487 
1488     ret = InputMethodAbilityTest::inputMethodAbility_->HidePanel(nullptr);
1489     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1490 
1491     ret = InputMethodAbilityTest::inputMethodAbility_->HidePanel(nullptr, flag, trigger);
1492     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1493 
1494     InputMethodAbilityTest::inputMethodAbility_->isCurrentIme_ = true;
1495     auto ret2 = InputMethodAbilityTest::inputMethodAbility_->IsCurrentIme();
1496     EXPECT_TRUE(ret2);
1497 
1498     ret2 = InputMethodAbilityTest::inputMethodAbility_->IsEnable();
1499     EXPECT_FALSE(ret2);
1500 }
1501 
1502 /**
1503  * @tc.name: BranchCoverage002
1504  * @tc.desc: BranchCoverage
1505  * @tc.type: FUNC
1506  */
1507 HWTEST_F(InputMethodAbilityTest, BranchCoverage002, TestSize.Level0)
1508 {
1509     IMSA_HILOGI("InputMethodAbilityTest BranchCoverage002 TEST START");
1510     int32_t vailidUserId = 100001;
1511     SwitchInfo switchInfo;
1512     std::string vailidString = "";
1513     std::shared_ptr<ImeInfo> info;
1514     bool needHide = false;
1515     auto ret = imsa_->OnStartInputType(vailidUserId, switchInfo, true);
1516     EXPECT_NE(ret, ErrorCode::NO_ERROR);
1517 
1518     ret = imsa_->Switch(vailidUserId, vailidString, info);
1519     EXPECT_NE(ret, ErrorCode::NO_ERROR);
1520     ret = imsa_->SwitchExtension(vailidUserId, info);
1521     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1522     ret = imsa_->SwitchSubType(vailidUserId, info);
1523     imsa_->NeedHideWhenSwitchInputType(vailidUserId, needHide);
1524     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1525     ret = imsa_->SwitchInputType(vailidUserId, switchInfo);
1526     EXPECT_EQ(ret, ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND);
1527     ret = imsa_->OnPackageRemoved(vailidUserId, vailidString);
1528     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1529 
1530     auto ret2 = imsa_->IsNeedSwitch(vailidUserId, vailidString, vailidString);
1531     EXPECT_FALSE(ret2);
1532     ret2 = imsa_->IsStartInputTypePermitted(vailidUserId);
1533     EXPECT_FALSE(ret2);
1534 }
1535 
1536 /**
1537  * @tc.name: testOnCallingDisplayIdChanged
1538  * @tc.desc: Test InputMethodCoreProxy OnCallingDisplayIdChanged
1539  * @tc.type: FUNC
1540  * @tc.require:
1541  */
1542 HWTEST_F(InputMethodAbilityTest, testOnCallingDisplayIdChanged, TestSize.Level0)
1543 {
1544     IMSA_HILOGI("testOnCallingDisplayIdChanged start.");
1545     sptr<InputMethodCoreStub> coreStub = new InputMethodCoreStub();
1546     sptr<IInputMethodCore> core = coreStub;
1547     inputMethodAbility_->SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
1548     MessageParcel data;
1549     data.WriteRemoteObject(core->AsObject());
1550     sptr<IRemoteObject> coreObject = data.ReadRemoteObject();
1551     sptr<InputMethodCoreProxy> coreProxy = new InputMethodCoreProxy(coreObject);
1552     if (coreProxy == nullptr) {
1553         IMSA_HILOGI("coreProxy is null");
1554         return;
1555     }
1556     coreProxy->OnCallingDisplayIdChanged(0);
1557     EXPECT_TRUE(coreProxy != nullptr);
1558 }
1559 } // namespace MiscServices
1560 } // namespace OHOS
1561