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 "key_event_util.h"
22 #include "task_manager.h"
23 #undef private
24
25 #include <gtest/gtest.h>
26 #include <gtest/hwext/gtest-multithread.h>
27 #include <string_ex.h>
28 #include <unistd.h>
29
30 #include <cstdint>
31 #include <functional>
32 #include <string>
33 #include <thread>
34 #include <vector>
35
36 #include "global.h"
37 #include "iinput_data_channel.h"
38 #include "identity_checker_mock.h"
39 #include "input_attribute.h"
40 #include "input_control_channel_stub.h"
41 #include "input_data_channel_proxy.h"
42 #include "input_data_channel_service_impl.h"
43 #include "input_method_core_proxy.h"
44 #include "input_method_ability_interface.h"
45 #include "input_method_agent_service_impl.h"
46 #include "input_method_core_service_impl.h"
47 #include "input_method_core_stub.h"
48 #include "input_method_panel.h"
49 #include "inputmethod_message_handler.h"
50 #include "scope_utils.h"
51 #include "input_method_system_ability_proxy.h"
52 #include "tdd_util.h"
53 #include "text_listener.h"
54
55 using namespace testing::ext;
56 using namespace testing::mt;
57 namespace OHOS {
58 namespace MiscServices {
59 constexpr uint32_t DEALY_TIME = 1;
60 class InputMethodAbilityTest : public testing::Test {
61 public:
62 static std::mutex imeListenerCallbackLock_;
63 static std::condition_variable imeListenerCv_;
64 static bool showKeyboard_;
65 static constexpr int CURSOR_DIRECTION_BASE_VALUE = 2011;
66 static sptr<InputMethodController> imc_;
67 static sptr<OnTextChangedListener> textListener_;
68 static InputMethodAbility &inputMethodAbility_;
69 static uint32_t windowId_;
70 static int32_t security_;
71 static uint64_t currentImeTokenId_;
72 static int32_t currentImeUid_;
73 static sptr<InputMethodSystemAbility> imsa_;
74 static sptr<InputMethodSystemAbilityProxy> imsaProxy_;
75 static constexpr int32_t MAXRUNCOUNT = 100;
76 static constexpr int32_t THREAD_NUM = 5;
77 static void TestOnConnectSystemCmd();
78 static std::atomic<int32_t> multiThreadExecTotalNum_;
79
80 class InputMethodEngineListenerImpl : public InputMethodEngineListener {
81 public:
82 InputMethodEngineListenerImpl() = default;
83 ~InputMethodEngineListenerImpl() = default;
84
OnKeyboardStatus(bool isShow)85 void OnKeyboardStatus(bool isShow)
86 {
87 showKeyboard_ = isShow;
88 InputMethodAbilityTest::imeListenerCv_.notify_one();
89 IMSA_HILOGI("InputMethodEngineListenerImpl OnKeyboardStatus");
90 }
91
OnInputStart()92 void OnInputStart()
93 {
94 IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStart");
95 }
96
OnInputStop()97 int32_t OnInputStop()
98 {
99 IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStop");
100 return ErrorCode::NO_ERROR;
101 }
102
OnSetCallingWindow(uint32_t windowId)103 void OnSetCallingWindow(uint32_t windowId)
104 {
105 windowId_ = windowId;
106 IMSA_HILOGI("InputMethodEngineListenerImpl OnSetCallingWindow");
107 }
108
OnSetSubtype(const SubProperty & property)109 void OnSetSubtype(const SubProperty &property)
110 {
111 IMSA_HILOGI("InputMethodEngineListenerImpl OnSetSubtype");
112 }
113
OnSecurityChange(int32_t security)114 void OnSecurityChange(int32_t security)
115 {
116 security_ = security;
117 IMSA_HILOGI("InputMethodEngineListenerImpl OnSecurityChange");
118 }
119
ReceivePrivateCommand(const std::unordered_map<std::string,PrivateDataValue> & privateCommand)120 void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
121 {
122 IMSA_HILOGI("InputMethodEngineListenerImpl ReceivePrivateCommand");
123 }
124
OnCallingDisplayIdChanged(uint64_t callingDisplayId)125 void OnCallingDisplayIdChanged(uint64_t callingDisplayId)
126 {
127 IMSA_HILOGI("InputMethodEngineListenerImpl OnCallingDisplayIdChanged displayId:%{public}" PRIu64"",
128 callingDisplayId);
129 }
130
PostTaskToEventHandler(std::function<void ()> task,const std::string & taskName)131 bool PostTaskToEventHandler(std::function<void()> task, const std::string &taskName)
132 {
133 task();
134 return true;
135 }
136 };
137
138 class TextInputClientListenerImpl : public TextInputClientListener {
139 public:
140 TextInputClientListenerImpl() = default;
141 ~TextInputClientListenerImpl() = default;
142
OnAttachOptionsChanged(const AttachOptions & options)143 void OnAttachOptionsChanged(const AttachOptions &options)
144 {
145 IMSA_HILOGI("TextInputClientListenerImpl OnAttachOptionsChanged");
146 }
147 };
148
SetUpTestCase(void)149 static void SetUpTestCase(void)
150 {
151 IdentityCheckerMock::ResetParam();
152 // Set the tokenID to the tokenID of the current ime
153 TddUtil::StorageSelfTokenID();
154 imsa_ = new (std::nothrow) InputMethodSystemAbility();
155 if (imsa_ == nullptr) {
156 return;
157 }
158 imsa_->OnStart();
159 imsa_->userId_ = TddUtil::GetCurrentUserId();
160 imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
161 sptr<InputMethodSystemAbilityStub> serviceStub = imsa_;
162 imsaProxy_ = new (std::nothrow) InputMethodSystemAbilityProxy(serviceStub->AsObject());
163 if (imsaProxy_ == nullptr) {
164 return;
165 }
166 IdentityCheckerMock::SetFocused(true);
167
168 std::shared_ptr<Property> property = InputMethodController::GetInstance()->GetCurrentInputMethod();
169 auto currentIme = property != nullptr ? property->name : "default.inputmethod.unittest";
170 currentImeTokenId_ = TddUtil::GetTestTokenID(currentIme);
171 currentImeUid_ = TddUtil::GetUid(currentIme);
172 {
173 TokenScope scope(currentImeTokenId_);
174 inputMethodAbility_.InitConnect();
175 }
176 inputMethodAbility_.abilityManager_ = imsaProxy_;
177 TddUtil::InitCurrentImePermissionInfo();
178 IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
179 inputMethodAbility_.SetCoreAndAgent();
180 TaskManager::GetInstance().SetInited(true);
181
182 TextListener::ResetParam();
183 imc_ = InputMethodController::GetInstance();
184 imc_->abilityManager_ = imsaProxy_;
185 textListener_ = new TextListener();
186 }
TearDownTestCase(void)187 static void TearDownTestCase(void)
188 {
189 IMSA_HILOGI("InputMethodAbilityTest::TearDownTestCase");
190 imc_->Close();
191 TextListener::ResetParam();
192 TddUtil::RestoreSelfTokenID();
193 IdentityCheckerMock::ResetParam();
194 imsa_->OnStop();
195 }
GetIMCAttachIMA()196 static void GetIMCAttachIMA()
197 {
198 imc_->SetTextListener(textListener_);
199 imc_->clientInfo_.state = ClientState::ACTIVE;
200 imc_->isBound_.store(true);
201 imc_->isEditable_.store(true);
202 auto agent = inputMethodAbility_.agentStub_->AsObject();
203 imc_->SetAgent(agent, "");
204
205 sptr<IInputDataChannel> channel = iface_cast<IInputDataChannel>(imc_->clientInfo_.channel);
206 inputMethodAbility_.SetInputDataChannel(channel->AsObject());
207 IMSA_HILOGI("end");
208 }
GetIMCDetachIMA()209 static void GetIMCDetachIMA()
210 {
211 imc_->OnInputStop();
212 inputMethodAbility_.ClearDataChannel(inputMethodAbility_.dataChannelObject_);
213 IMSA_HILOGI("end");
214 }
SetUp()215 void SetUp()
216 {
217 IMSA_HILOGI("InputMethodAbilityTest::SetUp");
218 TaskManager::GetInstance().Reset();
219 }
TearDown()220 void TearDown()
221 {
222 IMSA_HILOGI("InputMethodAbilityTest::TearDown");
223 }
CheckPanelStatusInfo(const std::shared_ptr<InputMethodPanel> & panel,const PanelStatusInfo & info)224 void CheckPanelStatusInfo(const std::shared_ptr<InputMethodPanel> &panel, const PanelStatusInfo &info)
225 {
226 TextListener::ResetParam();
227 info.visible ? CheckPanelInfoInShow(panel, info) : CheckPanelInfoInHide(panel, info);
228 }
CheckPanelInfoInShow(const std::shared_ptr<InputMethodPanel> & panel,const PanelStatusInfo & info)229 void CheckPanelInfoInShow(const std::shared_ptr<InputMethodPanel> &panel, const PanelStatusInfo &info)
230 {
231 auto ret = inputMethodAbility_.ShowPanel(panel);
232 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
233 if (info.panelInfo.panelFlag != FLG_CANDIDATE_COLUMN) {
234 if (info.panelInfo.panelType == SOFT_KEYBOARD) {
235 EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
236 } else {
237 EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
238 }
239 PanelStatusInfo statusInfo;
240 statusInfo.panelInfo.panelType = info.panelInfo.panelType;
241 statusInfo.panelInfo.panelFlag = info.panelInfo.panelFlag;
242 statusInfo.visible = info.visible;
243 statusInfo.trigger = info.trigger;
244
245 EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback(statusInfo));
246 return;
247 }
248 EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
249 PanelStatusInfo statusInfo1;
250 statusInfo1.panelInfo.panelType = info.panelInfo.panelType;
251 statusInfo1.panelInfo.panelFlag = info.panelInfo.panelFlag;
252 statusInfo1.visible = info.visible;
253 statusInfo1.trigger = info.trigger;
254
255 EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback(statusInfo1));
256 }
CheckPanelInfoInHide(const std::shared_ptr<InputMethodPanel> & panel,const PanelStatusInfo & info)257 void CheckPanelInfoInHide(const std::shared_ptr<InputMethodPanel> &panel, const PanelStatusInfo &info)
258 {
259 AccessScope scope(currentImeTokenId_, currentImeUid_);
260 auto ret = inputMethodAbility_.HidePanel(panel);
261 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
262 if (info.panelInfo.panelFlag != FLG_CANDIDATE_COLUMN) {
263 if (info.panelInfo.panelType == SOFT_KEYBOARD) {
264 EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
265 } else {
266 EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
267 };
268 PanelStatusInfo statusInfo1;
269 statusInfo1.panelInfo.panelType = info.panelInfo.panelType;
270 statusInfo1.panelInfo.panelFlag = info.panelInfo.panelFlag;
271 statusInfo1.visible = info.visible;
272 statusInfo1.trigger = info.trigger;
273
274 EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback(statusInfo1));
275 return;
276 }
277 EXPECT_FALSE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
278 PanelStatusInfo statusInfo;
279 statusInfo.panelInfo.panelType = info.panelInfo.panelType;
280 statusInfo.panelInfo.panelFlag = info.panelInfo.panelFlag;
281 statusInfo.visible = info.visible;
282 statusInfo.trigger = info.trigger;
283
284 EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback(statusInfo));
285 }
286 };
287
288 std::mutex InputMethodAbilityTest::imeListenerCallbackLock_;
289 std::condition_variable InputMethodAbilityTest::imeListenerCv_;
290 bool InputMethodAbilityTest::showKeyboard_ = true;
291 sptr<InputMethodController> InputMethodAbilityTest::imc_;
292 sptr<OnTextChangedListener> InputMethodAbilityTest::textListener_;
293 InputMethodAbility &InputMethodAbilityTest::inputMethodAbility_ = InputMethodAbility::GetInstance();
294 uint32_t InputMethodAbilityTest::windowId_ = 0;
295 int32_t InputMethodAbilityTest::security_ = -1;
296 uint64_t InputMethodAbilityTest::currentImeTokenId_ = 0;
297 int32_t InputMethodAbilityTest::currentImeUid_ = 0;
298 sptr<InputMethodSystemAbility> InputMethodAbilityTest::imsa_;
299 sptr<InputMethodSystemAbilityProxy> InputMethodAbilityTest::imsaProxy_;
300 std::atomic<int32_t> InputMethodAbilityTest::multiThreadExecTotalNum_{ 0 };
301
TestOnConnectSystemCmd()302 void InputMethodAbilityTest::TestOnConnectSystemCmd()
303 {
304 IMSA_HILOGI("TestOnConnectSystemCmd start!");
305 for (int32_t count = 0; count < MAXRUNCOUNT; count++) {
306 IMSA_HILOGI("TestOnConnectSystemCmd start %{public}d", count);
307 sptr<IInputDataChannel> channel = new (std::nothrow) InputDataChannelServiceImpl();
308 ASSERT_NE(channel, nullptr);
309 sptr<IRemoteObject> agent = nullptr;
310 auto ret = inputMethodAbility_.OnConnectSystemCmd(channel->AsObject(), agent);
311 multiThreadExecTotalNum_++;
312 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
313 }
314 IMSA_HILOGI("TestOnConnectSystemCmd finished!");
315 }
316
317 /**
318 * @tc.name: testSerializedInputAttribute
319 * @tc.desc: Checkout the serialization of InputAttribute.
320 * @tc.type: FUNC
321 */
322 HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute, TestSize.Level0)
323 {
324 InputAttributeInner inAttribute;
325 inAttribute.inputPattern = InputAttributeInner::PATTERN_PASSWORD;
326 MessageParcel data;
327 EXPECT_TRUE(inAttribute.Marshalling(data));
328 InputAttributeInner outAttribute;
329 auto attribute = InputAttributeInner::Unmarshalling(data);
330 EXPECT_TRUE(attribute->GetSecurityFlag());
331 }
332
333 /**
334 * @tc.name: testSerializedInputAttribute001
335 * @tc.desc: Checkout the serialization of InputAttribute.
336 * @tc.type: FUNC
337 */
338 HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute001, TestSize.Level0)
339 {
340 InputAttributeInner inAttribute;
341 inAttribute.inputPattern = InputAttribute::PATTERN_ONE_TIME_CODE;
342 Parcel data;
343 EXPECT_TRUE(inAttribute.Marshalling(data));
344 InputAttributeInner* outInnerAttribute = InputAttributeInner::Unmarshalling(data);
345 if (outInnerAttribute == nullptr) {
346 return;
347 }
348 InputAttribute outAttribute;
349 outAttribute.inputPattern = outInnerAttribute->inputPattern;
350 EXPECT_TRUE(outAttribute.IsOneTimeCodeFlag());
351 delete outInnerAttribute;
352 }
353
354 /**
355 * @tc.name: testSerializedInputAttribute
356 * @tc.desc: Checkout the serialization of InputAttribute.
357 * @tc.type: FUNC
358 */
359 HWTEST_F(InputMethodAbilityTest, testSerializedInputAttribute_WithSpecificBundleName, TestSize.Level0)
360 {
361 InputAttributeInner inAttribute;
362 inAttribute.bundleName = "com.example.inputmethod";
363 MessageParcel data;
364 EXPECT_TRUE(inAttribute.Marshalling(data));
365 auto ret = InputAttributeInner::Unmarshalling(data);
366 EXPECT_NE(ret, nullptr);
367 EXPECT_EQ(inAttribute.bundleName, ret->bundleName);
368 }
369
370 /**
371 * @tc.name: testShowKeyboardInputMethodCoreProxy
372 * @tc.desc: Test InputMethodCoreProxy ShowKeyboard
373 * @tc.type: FUNC
374 * @tc.require: issueI5NXHK
375 */
376 HWTEST_F(InputMethodAbilityTest, testShowKeyboardInputMethodCoreProxy, TestSize.Level0)
377 {
378 IMSA_HILOGI("testShowKeyboardInputMethodCoreProxy start.");
379 sptr<InputMethodCoreStub> coreStub = new InputMethodCoreServiceImpl();
380 sptr<IInputMethodCore> core = coreStub;
381 sptr<InputDataChannelStub> channelStub = new InputDataChannelServiceImpl();
382 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
383
384 MessageParcel data;
385 data.WriteRemoteObject(core->AsObject());
386 data.WriteRemoteObject(channelStub->AsObject());
387 sptr<IRemoteObject> coreObject = data.ReadRemoteObject();
388 sptr<IRemoteObject> channelObject = data.ReadRemoteObject();
389
390 sptr<InputMethodCoreProxy> coreProxy = new InputMethodCoreProxy(coreObject);
391 sptr<InputDataChannelProxy> channelProxy = new InputDataChannelProxy(channelObject);
392 auto ret = coreProxy->ShowKeyboard(static_cast<int32_t>(RequestKeyboardReason::NONE));
393 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
394
395 std::this_thread::sleep_for(std::chrono::seconds(1));
396 EXPECT_EQ(showKeyboard_, true);
397 }
398
399 /**
400 * @tc.name: testExitCurrentInputType
401 * @tc.desc: InputMethodAbility ExitCurrentInputType
402 * @tc.type: FUNC
403 * @tc.require:
404 */
405 HWTEST_F(InputMethodAbilityTest, testExitCurrentInputType, TestSize.Level0)
406 {
407 IMSA_HILOGI("InputMethodAbilityTest testExitCurrentInputType start.");
408 auto ret = inputMethodAbility_.ExitCurrentInputType();
409 EXPECT_EQ(ret, ErrorCode::ERROR_NOT_DEFAULT_IME);
410
411 InputMethodAbilityTest::GetIMCDetachIMA();
412 IdentityCheckerMock::SetBundleNameValid(true);
413 ret = inputMethodAbility_.ExitCurrentInputType();
414 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
415 IdentityCheckerMock::SetBundleNameValid(false);
416 }
417
418 /**
419 * @tc.name: testNotifyPanelStatus
420 * @tc.desc: InputMethodAbility NotifyPanelStatus
421 * @tc.type: FUNC
422 * @tc.require:
423 */
424 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatus1, TestSize.Level0)
425 {
426 IMSA_HILOGI("InputMethodAbilityTest testNotifyPanelStatus1 start.");
427 auto ret = inputMethodAbility_.NotifyPanelStatus(false);
428 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
429 }
430
431 /**
432 * @tc.name: testNotifyPanelStatus
433 * @tc.desc: InputMethodAbility NotifyPanelStatus
434 * @tc.type: FUNC
435 * @tc.require:
436 */
437 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatus2, TestSize.Level0)
438 {
439 IMSA_HILOGI("InputMethodAbilityTest testNotifyPanelStatus2 start.");
440 std::shared_ptr<InputMethodPanel> softKeyboardPanel1 = nullptr;
441 PanelInfo panelInfo = {};
442 panelInfo.panelType = SOFT_KEYBOARD;
443 panelInfo.panelFlag = FLG_FIXED;
444 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel1);
445 EXPECT_TRUE(softKeyboardPanel1 != nullptr);
446 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
447
448 ret = inputMethodAbility_.NotifyPanelStatus(false);
449 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
450
451 ret = inputMethodAbility_.NotifyPanelStatus(true, FLG_FIXED);
452 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
453
454 AttachOptions options;
455 options.isSimpleKeyboardEnabled = true;
456 inputMethodAbility_.SetAttachOptions(options);
457 InputAttribute inputAttribute;
458 inputAttribute.inputPattern = InputAttribute::PATTERN_ONE_TIME_CODE;
459 inputMethodAbility_.SetInputAttribute(inputAttribute);
460 ret = inputMethodAbility_.NotifyPanelStatus(false);
461 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
462
463 options.isSimpleKeyboardEnabled = true;
464 inputMethodAbility_.SetAttachOptions(options);
465 inputAttribute.inputPattern = InputAttribute::PATTERN_NEWPASSWORD;
466 inputMethodAbility_.SetInputAttribute(inputAttribute);
467 ret = inputMethodAbility_.NotifyPanelStatus(false);
468 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
469
470 options.isSimpleKeyboardEnabled = false;
471 inputMethodAbility_.SetAttachOptions(options);
472 inputAttribute.inputPattern = InputAttribute::PATTERN_ONE_TIME_CODE;
473 inputMethodAbility_.SetInputAttribute(inputAttribute);
474 ret = inputMethodAbility_.NotifyPanelStatus(false);
475 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
476
477 options.isSimpleKeyboardEnabled = false;
478 inputMethodAbility_.SetAttachOptions(options);
479 inputAttribute.inputPattern = InputAttribute::PATTERN_NEWPASSWORD;
480 inputMethodAbility_.SetInputAttribute(inputAttribute);
481 ret = inputMethodAbility_.NotifyPanelStatus(false);
482 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
483 }
484
485 /**
486 * @tc.name: testShowKeyboardWithoutImeListener
487 * @tc.desc: InputMethodAbility ShowKeyboard without imeListener
488 * @tc.type: FUNC
489 * @tc.require:
490 */
491 HWTEST_F(InputMethodAbilityTest, testShowKeyboardWithoutImeListener, TestSize.Level0)
492 {
493 IMSA_HILOGI("InputMethodAbilityTest testShowKeyboardWithoutImeListener start.");
494 auto ret = inputMethodAbility_.ShowKeyboard(static_cast<int32_t>(RequestKeyboardReason::NONE));
495 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
496 }
497
498 /**
499 * @tc.name: testHideKeyboardWithoutImeListener
500 * @tc.desc: InputMethodAbility HideKeyboard without imeListener
501 * @tc.type: FUNC
502 * @tc.require:
503 */
504 HWTEST_F(InputMethodAbilityTest, testHideKeyboardWithoutImeListener, TestSize.Level0)
505 {
506 IMSA_HILOGI("InputMethodAbilityTest testHideKeyboardWithoutImeListener start.");
507 auto ret = inputMethodAbility_.HideKeyboard();
508 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
509 }
510
511 /**
512 * @tc.name: testDiscardTypingTextWithoutImeListener
513 * @tc.desc: InputMethodAbility DiscardTypingText without imeListener
514 * @tc.type: FUNC
515 * @tc.require:
516 */
517 HWTEST_F(InputMethodAbilityTest, testDiscardTypingTextWithoutImeListener, TestSize.Level0)
518 {
519 IMSA_HILOGI("InputMethodAbilityTest testDiscardTypingTextWithoutImeListener start.");
520 auto ret = inputMethodAbility_.OnDiscardTypingText();
521 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
522 }
523
524 /**
525 * @tc.name: testStartInputWithoutPanel
526 * @tc.desc: InputMethodAbility StartInput Without Panel
527 * @tc.type: FUNC
528 * @tc.require:
529 */
530 HWTEST_F(InputMethodAbilityTest, testStartInputWithoutPanel, TestSize.Level0)
531 {
532 IMSA_HILOGI("InputMethodAbilityTest testStartInputWithoutAttach start.");
533 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
534 sptr<InputDataChannelStub> channelStub = new InputDataChannelServiceImpl();
535 InputClientInfo clientInfo;
536 clientInfo.channel = channelStub;
537 auto ret = inputMethodAbility_.StartInput(clientInfo, false);
538 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
539 clientInfo.isShowKeyboard = true;
540 ret = inputMethodAbility_.StartInput(clientInfo, false);
541 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
542 }
543
544 /**
545 * @tc.name: testStartInput
546 * @tc.desc: InputMethodAbility StartInput
547 * @tc.type: FUNC
548 * @tc.require:
549 */
550 HWTEST_F(InputMethodAbilityTest, testStartInput, TestSize.Level0)
551 {
552 IMSA_HILOGI("InputMethodAbilityTest testStartInput start.");
553 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
554 sptr<InputDataChannelStub> channelStub = new InputDataChannelServiceImpl();
555 InputClientInfo clientInfo;
556 clientInfo.channel = channelStub;
557 auto ret = inputMethodAbility_.StartInput(clientInfo, false);
558 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
559 EXPECT_TRUE(inputMethodAbility_.isInputStartNotified_);
560 }
561
562 /**
563 * @tc.name: testStartInputWithSimpleKeyBoard
564 * @tc.desc: InputMethodAbility StartInput
565 * @tc.type: FUNC
566 * @tc.require:
567 */
568 HWTEST_F(InputMethodAbilityTest, testStartInputWithSimpleKeyBoard, TestSize.Level0)
569 {
570 IMSA_HILOGI("InputMethodAbilityTest testStartInputWithSimpleKeyBoard start.");
571 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
572 sptr<InputDataChannelStub> channelStub = new InputDataChannelServiceImpl();
573 InputClientInfo clientInfo;
574 clientInfo.channel = channelStub;
575 clientInfo.config.isSimpleKeyboardEnabled = true;
576 auto ret = inputMethodAbility_.StartInput(clientInfo, false);
577 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
578 }
579
580 /**
581 * @tc.name: testStartInputBeforeCreatePanel
582 * @tc.desc: InputMethodAbility StartInput before create panel
583 * @tc.type: FUNC
584 * @tc.require:
585 */
586 HWTEST_F(InputMethodAbilityTest, testStartInputBeforeCreatePanel, TestSize.Level0)
587 {
588 IMSA_HILOGI("InputMethodAbilityTest testStartInputBeforeCreatePanel start.");
589 inputMethodAbility_.panels_.Clear();
590 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
591 auto ret = imc_->Attach(textListener_);
592 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
593 {
594 std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
__anon27a046d30102null595 InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
596 return InputMethodAbilityTest::showKeyboard_;
597 });
598 }
599 InputMethodAbilityTest::showKeyboard_ = false;
600 std::shared_ptr<InputMethodPanel> softKeyboardPanel = nullptr;
601 {
602 AccessScope scope(currentImeTokenId_, currentImeUid_);
603 PanelInfo panelInfo = {};
604 panelInfo.panelType = SOFT_KEYBOARD;
605 panelInfo.panelFlag = FLG_FIXED;
606 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel);
607 EXPECT_EQ(ErrorCode::NO_ERROR, ret);
608 }
609 {
610 std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
__anon27a046d30202null611 InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
612 return InputMethodAbilityTest::showKeyboard_;
613 });
614 EXPECT_TRUE(InputMethodAbilityTest::showKeyboard_);
615 }
616 imc_->Close();
617 inputMethodAbility_.DestroyPanel(softKeyboardPanel);
618 }
619
620 /**
621 * @tc.name: testHideKeyboardSelf
622 * @tc.desc: InputMethodAbility HideKeyboardSelf
623 * @tc.type: FUNC
624 * @tc.require:
625 * @tc.author: Hollokin
626 */
627 HWTEST_F(InputMethodAbilityTest, testHideKeyboardSelf, TestSize.Level0)
628 {
629 IMSA_HILOGI("InputMethodAbility testHideKeyboardSelf START");
630 imc_->Attach(textListener_);
631 std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
632 InputMethodAbilityTest::showKeyboard_ = true;
633 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
634 auto ret = inputMethodAbility_.HideKeyboardSelf();
__anon27a046d30302null635 InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [] {
636 return InputMethodAbilityTest::showKeyboard_ == false;
637 });
638 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
639 EXPECT_FALSE(InputMethodAbilityTest::showKeyboard_);
640 }
641
642 /**
643 * @tc.name: testMoveCursor
644 * @tc.desc: InputMethodAbility MoveCursor
645 * @tc.type: FUNC
646 * @tc.require:
647 * @tc.author: Hollokin
648 */
649 HWTEST_F(InputMethodAbilityTest, testMoveCursor, TestSize.Level0)
650 {
651 IMSA_HILOGI("InputMethodAbility MoveCursor Test START");
652 constexpr int32_t keyCode = 4;
653 auto ret = inputMethodAbility_.MoveCursor(keyCode); // move cursor right });
654 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
655 EXPECT_TRUE(TextListener::WaitMoveCursor(keyCode));
656 }
657
658 /**
659 * @tc.name: testInsertText
660 * @tc.desc: InputMethodAbility InsertText
661 * @tc.type: FUNC
662 * @tc.require:
663 * @tc.author: Hollokin
664 */
665 HWTEST_F(InputMethodAbilityTest, testInsertText, TestSize.Level0)
666 {
667 IMSA_HILOGI("InputMethodAbility InsertText Test START");
668 std::string text = "text";
669 std::u16string u16Text = Str8ToStr16(text);
670 auto ret = inputMethodAbility_.InsertText(text);
671 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
672 EXPECT_TRUE(TextListener::WaitInsertText(u16Text));
673 }
674
675 /**
676 * @tc.name: testSendFunctionKey
677 * @tc.desc: InputMethodAbility SendFunctionKey
678 * @tc.type: FUNC
679 * @tc.require:
680 * @tc.author: Hollokin
681 */
682 HWTEST_F(InputMethodAbilityTest, testSendFunctionKey, TestSize.Level0)
683 {
684 IMSA_HILOGI("InputMethodAbility SendFunctionKey Test START");
685 constexpr int32_t funcKey = 1;
686 auto ret = inputMethodAbility_.SendFunctionKey(funcKey);
687 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
688 EXPECT_TRUE(TextListener::WaitSendFunctionKey(funcKey));
689
690 TextListener::ResetParam();
691 ret = InputMethodAbilityInterface::GetInstance().SendFunctionKey(funcKey);
692 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
693 EXPECT_TRUE(TextListener::WaitSendFunctionKey(funcKey));
694 }
695
696 /**
697 * @tc.name: testSendExtendAction
698 * @tc.desc: InputMethodAbility SendExtendAction
699 * @tc.type: FUNC
700 * @tc.require:
701 * @tc.author: chenyu
702 */
703 HWTEST_F(InputMethodAbilityTest, testSendExtendAction, TestSize.Level0)
704 {
705 IMSA_HILOGI("InputMethodAbility SendExtendAction Test START");
706 constexpr int32_t action = 1;
707 auto ret = inputMethodAbility_.SendExtendAction(action);
708 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
709 EXPECT_TRUE(TextListener::WaitHandleExtendAction(action));
710 }
711
712 /**
713 * @tc.name: testDeleteText
714 * @tc.desc: InputMethodAbility DeleteForward & DeleteBackward
715 * @tc.type: FUNC
716 * @tc.require:
717 * @tc.author: Hollokin
718 */
719 HWTEST_F(InputMethodAbilityTest, testDeleteText, TestSize.Level0)
720 {
721 IMSA_HILOGI("InputMethodAbility testDelete Test START");
722 int32_t deleteForwardLenth = 1;
723 auto ret = inputMethodAbility_.DeleteForward(deleteForwardLenth);
724 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
725 EXPECT_TRUE(TextListener::WaitDeleteBackward(deleteForwardLenth));
726
727 int32_t deleteBackwardLenth = 2;
728 ret = inputMethodAbility_.DeleteBackward(deleteBackwardLenth);
729 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
730 EXPECT_TRUE(TextListener::WaitDeleteForward(deleteBackwardLenth));
731 }
732
733 /**
734 * @tc.name: testGetEnterKeyType
735 * @tc.desc: InputMethodAbility GetEnterKeyType & GetInputPattern
736 * @tc.type: FUNC
737 * @tc.require:
738 * @tc.author: Hollokin
739 */
740 HWTEST_F(InputMethodAbilityTest, testGetEnterKeyType, TestSize.Level0)
741 {
742 IMSA_HILOGI("InputMethodAbility testGetEnterKeyType START");
743 Configuration config;
744 EnterKeyType keyType = EnterKeyType::NEXT;
745 config.SetEnterKeyType(keyType);
746 TextInputType textInputType = TextInputType::DATETIME;
747 config.SetTextInputType(textInputType);
748 imc_->OnConfigurationChange(config);
749 int32_t keyType2;
750 auto ret = inputMethodAbility_.GetEnterKeyType(keyType2);
751 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
752 EXPECT_EQ(keyType2, (int)keyType);
753 int32_t inputPattern;
754 ret = inputMethodAbility_.GetInputPattern(inputPattern);
755 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
756 EXPECT_EQ(inputPattern, (int)textInputType);
757 }
758
759 /**
760 * @tc.name: testGetTextConfig
761 * @tc.desc: InputMethodAbility GetTextConfig
762 * @tc.type: FUNC
763 * @tc.require:
764 * @tc.author: Hollokin
765 */
766 HWTEST_F(InputMethodAbilityTest, testGetTextConfig, TestSize.Level0)
767 {
768 IMSA_HILOGI("InputMethodAbility testGetTextConfig START");
769 TextConfig textConfig;
770 textConfig.inputAttribute = { .inputPattern = 0, .enterKeyType = 1 };
771 auto ret = imc_->Attach(textListener_, false, textConfig);
772 TextTotalConfig textTotalConfig;
773 ret = inputMethodAbility_.GetTextConfig(textTotalConfig);
774 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
775 EXPECT_EQ(textTotalConfig.inputAttribute.inputPattern, textConfig.inputAttribute.inputPattern);
776 EXPECT_EQ(textTotalConfig.inputAttribute.enterKeyType, textConfig.inputAttribute.enterKeyType);
777
778 InputAttribute inputAttribute;
779 ret = InputMethodAbilityInterface::GetInstance().GetInputAttribute(inputAttribute);
780 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
781 EXPECT_EQ(inputAttribute, textConfig.inputAttribute);
782 }
783
784 /**
785 * @tc.name: testSelectByRange_001
786 * @tc.desc: InputMethodAbility SelectByRange
787 * @tc.type: FUNC
788 * @tc.require:
789 * @tc.author: Zhaolinglan
790 */
791 HWTEST_F(InputMethodAbilityTest, testSelectByRange_001, TestSize.Level0)
792 {
793 IMSA_HILOGI("InputMethodAbility testSelectByRange_001 START");
794 constexpr int32_t start = 1;
795 constexpr int32_t end = 2;
796 auto ret = inputMethodAbility_.SelectByRange(start, end);
797 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
798 EXPECT_TRUE(TextListener::WaitHandleSetSelection(start, end));
799 }
800
801 /**
802 * @tc.name: testSelectByRange_002
803 * @tc.desc: InputMethodAbility SelectByRange
804 * @tc.type: FUNC
805 * @tc.require:
806 * @tc.author: chenyu
807 */
808 HWTEST_F(InputMethodAbilityTest, testSelectByRange_002, TestSize.Level0)
809 {
810 IMSA_HILOGI("InputMethodAbility testSelectByRange_002 START");
811 int32_t start = -2;
812 int32_t end = 2;
813 auto ret = inputMethodAbility_.SelectByRange(start, end);
814 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
815
816 start = 2;
817 end = -2;
818 ret = inputMethodAbility_.SelectByRange(start, end);
819 EXPECT_EQ(ret, ErrorCode::ERROR_PARAMETER_CHECK_FAILED);
820 }
821
822 /**
823 * @tc.name: testSelectByMovement
824 * @tc.desc: InputMethodAbility SelectByMovement
825 * @tc.type: FUNC
826 * @tc.require:
827 * @tc.author: Zhaolinglan
828 */
829 HWTEST_F(InputMethodAbilityTest, testSelectByMovement, TestSize.Level0)
830 {
831 IMSA_HILOGI("InputMethodAbility testSelectByMovement START");
832 constexpr int32_t direction = 1;
833 auto ret = inputMethodAbility_.SelectByMovement(direction);
834 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
835 EXPECT_TRUE(TextListener::WaitHandleSelect(direction + InputMethodAbilityTest::CURSOR_DIRECTION_BASE_VALUE, 0));
836 }
837
838 /**
839 * @tc.name: testGetTextAfterCursor
840 * @tc.desc:
841 * @tc.type: FUNC
842 * @tc.require:
843 */
844 HWTEST_F(InputMethodAbilityTest, testGetTextAfterCursor, TestSize.Level0)
845 {
846 IMSA_HILOGI("InputMethodAbility testGetTextAfterCursor START");
847 int32_t number = 3;
848 std::u16string text;
849 auto ret = inputMethodAbility_.GetTextAfterCursor(number, text);
850 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
851 EXPECT_EQ(text, Str8ToStr16(TextListener::TEXT_AFTER_CURSOR));
852 }
853
854 /**
855 * @tc.name: testGetTextBeforeCursor
856 * @tc.desc:
857 * @tc.type: FUNC
858 * @tc.require:
859 */
860 HWTEST_F(InputMethodAbilityTest, testGetTextBeforeCursor, TestSize.Level0)
861 {
862 IMSA_HILOGI("InputMethodAbility testGetTextBeforeCursor START");
863 int32_t number = 5;
864 std::u16string text;
865 auto ret = inputMethodAbility_.GetTextBeforeCursor(number, text);
866 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
867 EXPECT_EQ(text, Str8ToStr16(TextListener::TEXT_BEFORE_CURSOR));
868 }
869
870 /**
871 * @tc.name: testGetTextIndexAtCursor
872 * @tc.desc:
873 * @tc.type: FUNC
874 * @tc.require:
875 */
876 HWTEST_F(InputMethodAbilityTest, testGetTextIndexAtCursor, TestSize.Level0)
877 {
878 IMSA_HILOGI("InputMethodAbility testGetTextIndexAtCursor START");
879 int32_t index;
880 auto ret = inputMethodAbility_.GetTextIndexAtCursor(index);
881 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
882 EXPECT_EQ(index, TextListener::TEXT_INDEX);
883 }
884
885 /**
886 * @tc.name: testCreatePanel001
887 * @tc.desc: It's allowed to create one SOFT_KEYBOARD panel, but two is denied.
888 * @tc.type: FUNC
889 * @tc.require:
890 */
891 HWTEST_F(InputMethodAbilityTest, testCreatePanel001, TestSize.Level0)
892 {
893 IMSA_HILOGI("InputMethodAbilityTest testCreatePanel001 START. You can not create two SOFT_KEYBOARD panel.");
894 AccessScope scope(currentImeTokenId_, currentImeUid_);
895 std::shared_ptr<InputMethodPanel> softKeyboardPanel1 = nullptr;
896 PanelInfo panelInfo = {};
897 panelInfo.panelType = SOFT_KEYBOARD;
898 panelInfo.panelFlag = FLG_FIXED;
899 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel1);
900 EXPECT_TRUE(softKeyboardPanel1 != nullptr);
901 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
902
903 std::shared_ptr<InputMethodPanel> softKeyboardPanel2 = nullptr;
904 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel2);
905 EXPECT_TRUE(softKeyboardPanel2 == nullptr);
906 EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
907
908 ret = inputMethodAbility_.DestroyPanel(softKeyboardPanel1);
909 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
910
911 ret = inputMethodAbility_.DestroyPanel(softKeyboardPanel2);
912 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
913 }
914
915 /**
916 * @tc.name: testCreatePanel002
917 * @tc.desc: It's allowed to create one STATUS_BAR panel, but two is denied.
918 * @tc.type: FUNC
919 * @tc.require:
920 */
921 HWTEST_F(InputMethodAbilityTest, testCreatePanel002, TestSize.Level0)
922 {
923 IMSA_HILOGI("InputMethodAbilityTest testCreatePanel002 START. You can not create two STATUS_BAR panel.");
924 AccessScope scope(currentImeTokenId_, currentImeUid_);
925 std::shared_ptr<InputMethodPanel> statusBar1 = nullptr;
926 PanelInfo panelInfo = {};
927 panelInfo.panelType = STATUS_BAR;
928 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, statusBar1);
929 EXPECT_TRUE(statusBar1 != nullptr);
930 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
931
932 std::shared_ptr<InputMethodPanel> statusBar2 = nullptr;
933 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, statusBar2);
934 EXPECT_TRUE(statusBar2 == nullptr);
935 EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
936
937 ret = inputMethodAbility_.DestroyPanel(statusBar1);
938 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
939
940 ret = inputMethodAbility_.DestroyPanel(statusBar2);
941 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
942 }
943
944 /**
945 * @tc.name: testCreatePanel003
946 * @tc.desc: It's allowed to create one STATUS_BAR panel and one SOFT_KEYBOARD panel.
947 * @tc.type: FUNC
948 * @tc.require:
949 */
950 HWTEST_F(InputMethodAbilityTest, testCreatePanel003, TestSize.Level0)
951 {
952 IMSA_HILOGI("InputMethodAbilityTest testCreatePanel006 START. Allowed to create one SOFT_KEYBOARD panel and "
953 "one STATUS_BAR panel.");
954 AccessScope scope(currentImeTokenId_, currentImeUid_);
955 std::shared_ptr<InputMethodPanel> softKeyboardPanel = nullptr;
956 PanelInfo panelInfo1;
957 panelInfo1.panelType = SOFT_KEYBOARD;
958 panelInfo1.panelFlag = FLG_FIXED;
959 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo1, softKeyboardPanel);
960 EXPECT_TRUE(softKeyboardPanel != nullptr);
961 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
962
963 PanelInfo panelInfo2;
964 panelInfo2.panelType = STATUS_BAR;
965 std::shared_ptr<InputMethodPanel> statusBar = nullptr;
966 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo2, statusBar);
967 EXPECT_TRUE(statusBar != nullptr);
968 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
969
970 ret = inputMethodAbility_.DestroyPanel(softKeyboardPanel);
971 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
972
973 ret = inputMethodAbility_.DestroyPanel(statusBar);
974 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
975 }
976
977 /**
978 * @tc.name: testCreatePanel004
979 * @tc.desc: It's allowed to create one STATUS_BAR panel and one SOFT_KEYBOARD panel.
980 * @tc.type: FUNC
981 * @tc.require:
982 */
983 HWTEST_F(InputMethodAbilityTest, testCreatePanel004, TestSize.Level0)
984 {
985 IMSA_HILOGI("InputMethodAbilityTest testCreatePanel006 START. Allowed to create one SOFT_KEYBOARD panel and "
986 "one STATUS_BAR panel.");
987 AccessScope scope(currentImeTokenId_, currentImeUid_);
988 std::shared_ptr<InputMethodPanel> inputMethodPanel = nullptr;
989 PanelInfo panelInfo = {};
990 panelInfo.panelType = SOFT_KEYBOARD;
991 panelInfo.panelFlag = FLG_FIXED;
992 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, inputMethodPanel);
993 EXPECT_TRUE(inputMethodPanel != nullptr);
994 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
995
996 ret = inputMethodAbility_.DestroyPanel(inputMethodPanel);
997 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
998
999 PanelInfo panelInfo1;
1000 panelInfo1.panelType = STATUS_BAR;
1001 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo1, inputMethodPanel);
1002 EXPECT_TRUE(inputMethodPanel != nullptr);
1003 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1004
1005 ret = inputMethodAbility_.DestroyPanel(inputMethodPanel);
1006 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1007
1008 PanelInfo panelInfo2;
1009 panelInfo2.panelFlag = FLG_FLOATING;
1010 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo2, inputMethodPanel);
1011 EXPECT_TRUE(inputMethodPanel != nullptr);
1012 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1013
1014 ret = inputMethodAbility_.DestroyPanel(inputMethodPanel);
1015 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1016 }
1017
1018 /**
1019 * @tc.name: testCreatePanel005
1020 * @tc.desc: It's allowed to create one SOFT_KEYBOARD panel, but two is denied.
1021 * @tc.type: FUNC
1022 * @tc.require:
1023 */
1024 HWTEST_F(InputMethodAbilityTest, testCreatePanel005, TestSize.Level0)
1025 {
1026 IMSA_HILOGI("InputMethodAbilityTest testCreatePanel005 START.");
1027 AccessScope scope(currentImeTokenId_, currentImeUid_);
1028 std::shared_ptr<InputMethodPanel> softKeyboardPanel1 = nullptr;
1029 PanelInfo panelInfo = {};
1030 panelInfo.panelType = SOFT_KEYBOARD;
1031 panelInfo.panelFlag = FLG_FIXED;
1032 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel1);
1033 EXPECT_TRUE(softKeyboardPanel1 != nullptr);
1034 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1035
1036 ret = inputMethodAbility_.DestroyPanel(softKeyboardPanel1);
1037 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1038
1039 std::shared_ptr<InputMethodPanel> softKeyboardPanel2 = nullptr;
1040 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel2);
1041 EXPECT_TRUE(softKeyboardPanel2 != nullptr);
1042 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1043
1044 ret = inputMethodAbility_.DestroyPanel(softKeyboardPanel2);
1045 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1046 }
1047
1048 /**
1049 * @tc.name: testCreatePanel006
1050 * @tc.desc: It's allowed to create one SOFT_KEYBOARD panel, but two is denied.
1051 * @tc.type: FUNC
1052 * @tc.require:
1053 */
1054 HWTEST_F(InputMethodAbilityTest, testCreatePanel006, TestSize.Level0)
1055 {
1056 IMSA_HILOGI("InputMethodAbilityTest testCreatePanel006 START.");
1057 AccessScope scope(currentImeTokenId_, currentImeUid_);
1058 std::shared_ptr<InputMethodPanel> softKeyboardPanel1 = nullptr;
1059 PanelInfo panelInfo = {};
1060 panelInfo.panelType = SOFT_KEYBOARD;
1061 panelInfo.panelFlag = FLG_FIXED;
1062 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel1);
1063 EXPECT_TRUE(softKeyboardPanel1 != nullptr);
1064 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1065
1066 std::shared_ptr<InputMethodPanel> softKeyboardPanel2 = nullptr;
1067 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel2);
1068 EXPECT_TRUE(softKeyboardPanel2 == nullptr);
1069 EXPECT_EQ(ret, ErrorCode::ERROR_OPERATE_PANEL);
1070
1071 ret = inputMethodAbility_.DestroyPanel(softKeyboardPanel1);
1072 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1073
1074 std::shared_ptr<InputMethodPanel> softKeyboardPanel3 = nullptr;
1075 ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, softKeyboardPanel3);
1076 EXPECT_TRUE(softKeyboardPanel3 != nullptr);
1077 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1078
1079 ret = inputMethodAbility_.DestroyPanel(softKeyboardPanel2);
1080 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1081
1082 ret = inputMethodAbility_.DestroyPanel(softKeyboardPanel3);
1083 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1084 std::this_thread::sleep_for(std::chrono::seconds(2));
1085 }
1086
1087 /**
1088 * @tc.name: testSetCallingWindow001
1089 * @tc.desc: InputMethodAbility SetCallingWindow
1090 * @tc.type: FUNC
1091 * @tc.require:
1092 * @tc.author: Hollokin
1093 */
1094 HWTEST_F(InputMethodAbilityTest, testSetCallingWindow001, TestSize.Level0)
1095 {
1096 IMSA_HILOGI("InputMethodAbility testSetCallingWindow001 START");
1097 std::unique_lock<std::mutex> lock(InputMethodAbilityTest::imeListenerCallbackLock_);
1098 InputMethodAbilityTest::showKeyboard_ = true;
1099 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
1100 uint32_t windowId = 10;
1101 inputMethodAbility_.SetCallingWindow(windowId);
__anon27a046d30402null1102 InputMethodAbilityTest::imeListenerCv_.wait_for(lock, std::chrono::seconds(DEALY_TIME), [windowId] {
1103 return InputMethodAbilityTest::windowId_ == windowId;
1104 });
1105 EXPECT_EQ(InputMethodAbilityTest::windowId_, windowId);
1106 std::this_thread::sleep_for(std::chrono::seconds(2));
1107 }
1108
1109 /**
1110 * @tc.name: testNotifyPanelStatusInfo_001
1111 * @tc.desc: ShowKeyboard HideKeyboard SOFT_KEYBOARD FLG_FIXED
1112 * @tc.type: FUNC
1113 * @tc.require:
1114 * @tc.author: chenyu
1115 */
1116 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_001, TestSize.Level0)
1117 {
1118 IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_001 START");
1119 imc_->Attach(textListener_);
1120 PanelInfo info;
1121 info.panelType = STATUS_BAR;
1122 auto panel = std::make_shared<InputMethodPanel>();
1123 AccessScope scope(currentImeTokenId_, currentImeUid_);
1124 auto ret = inputMethodAbility_.CreatePanel(nullptr, info, panel);
1125 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1126 auto panel1 = std::make_shared<InputMethodPanel>();
1127 PanelInfo info1;
1128 info1.panelType = SOFT_KEYBOARD;
1129 info1.panelFlag = FLG_FIXED;
1130 ret = inputMethodAbility_.CreatePanel(nullptr, info1, panel1);
1131 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1132
1133 TextListener::ResetParam();
1134 ret = inputMethodAbility_.ShowKeyboard(static_cast<int32_t>(RequestKeyboardReason::NONE));
1135 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1136 EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::SHOW));
1137 PanelStatusInfo statusInfo;
1138 statusInfo.panelInfo = info1;
1139 statusInfo.visible = true;
1140 statusInfo.trigger = Trigger::IMF;
1141 EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback(statusInfo));
1142
1143 TextListener::ResetParam();
1144 ret = inputMethodAbility_.HideKeyboard();
1145 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1146 EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
1147 PanelStatusInfo statusInfo1;
1148 statusInfo1.panelInfo = info1;
1149 statusInfo1.visible = false;
1150 statusInfo1.trigger = Trigger::IMF;
1151 EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback(statusInfo1));
1152
1153 ret = inputMethodAbility_.DestroyPanel(panel);
1154 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1155 ret = inputMethodAbility_.DestroyPanel(panel1);
1156 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1157 std::this_thread::sleep_for(std::chrono::seconds(2));
1158 }
1159
1160 /**
1161 * @tc.name: testNotifyPanelStatusInfo_002
1162 * @tc.desc: ShowPanel HidePanel SOFT_KEYBOARD FLG_FLOATING
1163 * @tc.type: FUNC
1164 * @tc.require:
1165 * @tc.author: chenyu
1166 */
1167 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_002, TestSize.Level0)
1168 {
1169 IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_002 START");
1170 imc_->Attach(textListener_);
1171 PanelInfo info1;
1172 info1.panelType = SOFT_KEYBOARD;
1173 info1.panelFlag = FLG_FLOATING;
1174 AccessScope scope(currentImeTokenId_, currentImeUid_);
1175 auto panel = std::make_shared<InputMethodPanel>();
1176 auto ret = inputMethodAbility_.CreatePanel(nullptr, info1, panel);
1177 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1178 PanelStatusInfo statusInfo;
1179 statusInfo.panelInfo = info1;
1180 statusInfo.visible = true;
1181 statusInfo.trigger = Trigger::IME_APP;
1182 // ShowPanel
1183 CheckPanelStatusInfo(panel, statusInfo);
1184 PanelStatusInfo statusInfo1;
1185 statusInfo1.panelInfo = info1;
1186 statusInfo1.visible = false;
1187 statusInfo1.trigger = Trigger::IME_APP;
1188 // HidePanel
1189 CheckPanelStatusInfo(panel, statusInfo1);
1190
1191 ret = inputMethodAbility_.DestroyPanel(panel);
1192 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1193 std::this_thread::sleep_for(std::chrono::seconds(2));
1194 }
1195
1196 /**
1197 * @tc.name: testNotifyPanelStatusInfo_003
1198 * @tc.desc: ShowPanel HidePanel STATUS_BAR
1199 * @tc.type: FUNC
1200 * @tc.require:
1201 * @tc.author: chenyu
1202 */
1203 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_003, TestSize.Level0)
1204 {
1205 IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_003 START");
1206 imc_->Attach(textListener_, false);
1207 PanelInfo panelInfo = {};
1208 panelInfo.panelType = STATUS_BAR;
1209 auto panel = std::make_shared<InputMethodPanel>();
1210 AccessScope scope(currentImeTokenId_, currentImeUid_);
1211 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, panel);
1212 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1213 PanelStatusInfo statusInfo;
1214 statusInfo.panelInfo = panelInfo;
1215 statusInfo.visible = true;
1216 statusInfo.trigger = Trigger::IME_APP;
1217 // ShowPanel
1218 CheckPanelStatusInfo(panel, statusInfo);
1219 PanelStatusInfo statusInfo1;
1220 statusInfo1.panelInfo = panelInfo;
1221 statusInfo1.visible = false;
1222 statusInfo1.trigger = Trigger::IME_APP;
1223 // HidePanel
1224 CheckPanelStatusInfo(panel, statusInfo1);
1225
1226 ret = inputMethodAbility_.DestroyPanel(panel);
1227 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1228 }
1229
1230 /**
1231 * @tc.name: testNotifyPanelStatusInfo_004
1232 * @tc.desc: ShowPanel HidePanel SOFT_KEYBOARD FLG_CANDIDATE_COLUMN
1233 * @tc.type: FUNC
1234 * @tc.require:
1235 * @tc.author: chenyu
1236 */
1237 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_004, TestSize.Level0)
1238 {
1239 IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_004 START");
1240 imc_->Attach(textListener_);
1241 PanelInfo info;
1242 info.panelType = SOFT_KEYBOARD;
1243 info.panelFlag = FLG_CANDIDATE_COLUMN;
1244 auto panel = std::make_shared<InputMethodPanel>();
1245 AccessScope scope(currentImeTokenId_, currentImeUid_);
1246 auto ret = inputMethodAbility_.CreatePanel(nullptr, info, panel);
1247 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1248 PanelStatusInfo statusInfo;
1249 statusInfo.panelInfo = info;
1250 statusInfo.visible = true;
1251 statusInfo.trigger = Trigger::IME_APP;
1252 // ShowPanel
1253 CheckPanelStatusInfo(panel, statusInfo);
1254 PanelStatusInfo statusInfo1;
1255 statusInfo1.panelInfo = info;
1256 statusInfo1.visible = false;
1257 statusInfo1.trigger = Trigger::IME_APP;
1258 // HidePanel
1259 CheckPanelStatusInfo(panel, statusInfo1);
1260
1261 ret = inputMethodAbility_.DestroyPanel(panel);
1262 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1263 }
1264
1265 /**
1266 * @tc.name: testNotifyPanelStatusInfo_005
1267 * @tc.desc: HideKeyboardSelf
1268 * @tc.type: FUNC
1269 * @tc.require:
1270 * @tc.author: chenyu
1271 */
1272 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_005, TestSize.Level0)
1273 {
1274 IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_005 START");
1275 PanelInfo info;
1276 info.panelType = SOFT_KEYBOARD;
1277 info.panelFlag = FLG_FLOATING;
1278 imc_->Attach(textListener_);
1279
1280 // has no panel
1281 TextListener::ResetParam();
1282 auto ret = inputMethodAbility_.HideKeyboardSelf();
1283 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1284 EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
1285 PanelStatusInfo statusInfo;
1286 statusInfo.panelInfo = info;
1287 statusInfo.visible = false;
1288 statusInfo.trigger = Trigger::IME_APP;
1289 EXPECT_FALSE(TextListener::WaitNotifyPanelStatusInfoCallback(statusInfo));
1290
1291 AccessScope scope(currentImeTokenId_, currentImeUid_);
1292 auto panel = std::make_shared<InputMethodPanel>();
1293 ret = inputMethodAbility_.CreatePanel(nullptr, info, panel);
1294 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1295 ret = inputMethodAbility_.ShowPanel(panel);
1296 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1297 // has panel
1298 TextListener::ResetParam();
1299 ret = inputMethodAbility_.HideKeyboardSelf();
1300 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1301 EXPECT_TRUE(TextListener::WaitSendKeyboardStatusCallback(KeyboardStatus::HIDE));
1302 EXPECT_TRUE(TextListener::WaitNotifyPanelStatusInfoCallback(statusInfo));
1303
1304 ret = inputMethodAbility_.DestroyPanel(panel);
1305 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1306 }
1307
1308 /**
1309 * @tc.name: testNotifyPanelStatusInfo_006
1310 * @tc.desc: HideKeyboardSelf
1311 * @tc.type: FUNC
1312 * @tc.require:
1313 * @tc.author: chenyu
1314 */
1315 HWTEST_F(InputMethodAbilityTest, testNotifyPanelStatusInfo_006, TestSize.Level0)
1316 {
1317 IMSA_HILOGI("InputMethodAbility testNotifyPanelStatusInfo_006 START");
1318 imc_->Attach(textListener_);
1319 PanelInfo info;
1320 info.panelType = SOFT_KEYBOARD;
1321 info.panelFlag = FLG_CANDIDATE_COLUMN;
1322 auto panel = std::make_shared<InputMethodPanel>();
1323 AccessScope scope(currentImeTokenId_, currentImeUid_);
1324 auto ret = inputMethodAbility_.CreatePanel(nullptr, info, panel);
1325 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1326 PanelStatusInfo statusInfo;
1327 statusInfo.panelInfo = info;
1328 statusInfo.visible = true;
1329 statusInfo.trigger = Trigger::IME_APP;
1330 // ShowPanel
1331 CheckPanelStatusInfo(panel, statusInfo);
1332 PanelStatusInfo statusInfo1;
1333 statusInfo1.panelInfo = info;
1334 statusInfo1.visible = false;
1335 statusInfo1.trigger = Trigger::IME_APP;
1336 InputMethodAbilityTest::inputMethodAbility_.isImeTerminating_ = false;
1337 // HidePanel
1338 CheckPanelStatusInfo(panel, statusInfo1);
1339
1340 ret = inputMethodAbility_.DestroyPanel(panel);
1341 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1342 }
1343
1344 /**
1345 * @tc.name: testNotifyKeyboardHeight_001
1346 * @tc.desc: NotifyKeyboardHeight SOFT_KEYBOARD FLG_FIXED
1347 * @tc.type: FUNC
1348 * @tc.require:
1349 * @tc.author: mashaoyin
1350 */
1351 HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_001, TestSize.Level0)
1352 {
1353 IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_001 START");
1354 imc_->Attach(textListener_);
1355 AccessScope scope(currentImeTokenId_, currentImeUid_);
1356 TextListener::ResetParam();
1357 inputMethodAbility_.NotifyKeyboardHeight(1, FLG_FIXED);
1358 EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(1));
1359 }
1360
1361 /**
1362 * @tc.name: testNotifyKeyboardHeight_002
1363 * @tc.desc: NotifyKeyboardHeight SOFT_KEYBOARD FLG_CANDIDATE_COLUMN
1364 * @tc.type: FUNC
1365 * @tc.require:
1366 * @tc.author: mashaoyin
1367 */
1368 HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_002, TestSize.Level0)
1369 {
1370 IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_002 START");
1371 imc_->Attach(textListener_);
1372 AccessScope scope(currentImeTokenId_, currentImeUid_);
1373 TextListener::ResetParam();
1374 inputMethodAbility_.NotifyKeyboardHeight(1, FLG_CANDIDATE_COLUMN);
1375 EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(0));
1376 }
1377
1378 /**
1379 * @tc.name: testNotifyKeyboardHeight_003
1380 * @tc.desc: NotifyKeyboardHeight Attach with hard keyboard
1381 * @tc.type: FUNC
1382 * @tc.require:
1383 * @tc.author: mashaoyin
1384 */
1385 HWTEST_F(InputMethodAbilityTest, testNotifyKeyboardHeight_003, TestSize.Level0)
1386 {
1387 IMSA_HILOGI("InputMethodAbility testNotifyKeyboardHeight_003 START");
1388 TextListener::ResetParam();
1389 AccessScope scope(currentImeTokenId_, currentImeUid_);
1390 PanelInfo info;
1391 info.panelType = SOFT_KEYBOARD;
1392 info.panelFlag = FLG_CANDIDATE_COLUMN;
1393 auto panel = std::make_shared<InputMethodPanel>();
1394 auto ret = inputMethodAbility_.CreatePanel(nullptr, info, panel);
1395 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1396 panel->Resize(1, 1);
1397 imc_->Attach(textListener_);
1398 EXPECT_TRUE(TextListener::WaitNotifyKeyboardHeightCallback(0));
1399 ret = inputMethodAbility_.DestroyPanel(panel);
1400 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1401 }
1402
1403 /**
1404 * @tc.name: testAdjustKeyboard_001
1405 * @tc.desc: adjust keyboard
1406 * @tc.type: FUNC
1407 * @tc.require:
1408 * @tc.author: guojin
1409 */
1410 HWTEST_F(InputMethodAbilityTest, testAdjustKeyboard_001, TestSize.Level0)
1411 {
1412 IMSA_HILOGI("InputMethodAbility testAdjustKeyboard_001 START");
1413 AccessScope scope(currentImeTokenId_, currentImeUid_);
1414 PanelInfo panelInfo = {};
1415 panelInfo.panelType = SOFT_KEYBOARD;
1416 panelInfo.panelFlag = FLG_FIXED;
1417 auto panel = std::make_shared<InputMethodPanel>();
1418 auto ret = inputMethodAbility_.CreatePanel(nullptr, panelInfo, panel);
1419 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1420
1421 ret = inputMethodAbility_.AdjustKeyboard();
1422 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1423
1424 ret = inputMethodAbility_.DestroyPanel(panel);
1425 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1426 }
1427
1428 /**
1429 * @tc.name: testGetInputType_001
1430 * @tc.desc: get inputType
1431 * @tc.type: FUNC
1432 * @tc.require:
1433 * @tc.author: guojin
1434 */
1435 HWTEST_F(InputMethodAbilityTest, testGetInputType_001, TestSize.Level0)
1436 {
1437 IMSA_HILOGI("InputMethodAbility testGetInputType_001 START");
1438 imc_->Attach(textListener_);
1439
1440 InputType inputType = inputMethodAbility_.GetInputType();
1441 EXPECT_EQ(inputType, InputType::NONE);
1442 }
1443
1444 /**
1445 * @tc.name: testOnSecurityChange
1446 * @tc.desc: OnSecurityChange
1447 * @tc.type: FUNC
1448 * @tc.require:
1449 * @tc.author: chenyu
1450 */
1451 HWTEST_F(InputMethodAbilityTest, testOnSecurityChange, TestSize.Level0)
1452 {
1453 IMSA_HILOGI("InputMethodAbility testOnSecurityChange START");
1454 int32_t security = 32;
1455 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
1456 auto ret = inputMethodAbility_.OnSecurityChange(security);
1457 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1458 EXPECT_EQ(InputMethodAbilityTest::security_, security);
1459 }
1460
1461 /**
1462 * @tc.name: testSendPrivateCommand_001
1463 * @tc.desc: IMA SendPrivateCommand current is not default ime.
1464 * @tc.type: FUNC
1465 * @tc.require:
1466 * @tc.author: mashaoyin
1467 */
1468 HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_001, TestSize.Level0)
1469 {
1470 IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_001 Test START");
1471 IdentityCheckerMock::SetBundleNameValid(false);
1472 TextListener::ResetParam();
1473 InputMethodAbilityTest::GetIMCDetachIMA();
1474 TddUtil::RestoreSelfTokenID();
1475 std::unordered_map<std::string, PrivateDataValue> privateCommand;
1476 auto ret = inputMethodAbility_.SendPrivateCommand(privateCommand);
1477 EXPECT_EQ(ret, ErrorCode::ERROR_NOT_DEFAULT_IME);
1478 IdentityCheckerMock::SetBundleNameValid(true);
1479 }
1480
1481 /**
1482 * @tc.name: testSendPrivateCommand_002
1483 * @tc.desc: IMA SendPrivateCommand current data specification, default ime, not bound.
1484 * @tc.type: FUNC
1485 * @tc.require:
1486 * @tc.author: mashaoyin
1487 */
1488 HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_002, TestSize.Level0)
1489 {
1490 IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_002 Test START");
1491 InputMethodAbilityTest::GetIMCDetachIMA();
1492 IdentityCheckerMock::SetBundleNameValid(true);
1493 std::unordered_map<std::string, PrivateDataValue> privateCommand;
1494 PrivateDataValue privateDataValue1 = std::string("stringValue");
1495 privateCommand.insert({ "value1", privateDataValue1 });
1496 auto ret = inputMethodAbility_.SendPrivateCommand(privateCommand);
1497 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
1498 IdentityCheckerMock::SetBundleNameValid(false);
1499 }
1500
1501 /**
1502 * @tc.name: testSendPrivateCommand_003
1503 * @tc.desc: IMA SendPrivateCommand with correct data specification and all data type.
1504 * @tc.type: FUNC
1505 * @tc.require:
1506 * @tc.author: mashaoyin
1507 */
1508 HWTEST_F(InputMethodAbilityTest, testSendPrivateCommand_003, TestSize.Level0)
1509 {
1510 IMSA_HILOGI("InputMethodAbility testSendPrivateCommand_003 Test START");
1511 TextListener::ResetParam();
1512 InputMethodAbilityTest::GetIMCAttachIMA();
1513 IdentityCheckerMock::SetBundleNameValid(true);
1514 std::unordered_map<std::string, PrivateDataValue> privateCommand;
1515 PrivateDataValue privateDataValue1 = std::string("stringValue");
1516 PrivateDataValue privateDataValue2 = true;
1517 PrivateDataValue privateDataValue3 = 100;
1518 privateCommand.emplace("value1", privateDataValue1);
1519 privateCommand.emplace("value2", privateDataValue2);
1520 privateCommand.emplace("value3", privateDataValue3);
1521 auto ret = inputMethodAbility_.SendPrivateCommand(privateCommand);
1522 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1523 EXPECT_TRUE(TextListener::WaitSendPrivateCommandCallback(privateCommand));
1524 InputMethodAbilityTest::GetIMCDetachIMA();
1525 IdentityCheckerMock::SetBundleNameValid(false);
1526 }
1527
1528 /**
1529 * @tc.name: testGetCallingWindowInfo_001
1530 * @tc.desc: GetCallingWindowInfo with IMC not bound
1531 * @tc.type: FUNC
1532 * @tc.require:
1533 * @tc.author: zhaolinglan
1534 */
1535 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_001, TestSize.Level0)
1536 {
1537 IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_001 Test START");
1538 InputMethodAbilityTest::GetIMCDetachIMA();
1539 CallingWindowInfo windowInfo;
1540 int32_t ret = InputMethodAbilityTest::inputMethodAbility_.GetCallingWindowInfo(windowInfo);
1541 EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
1542 }
1543
1544 /**
1545 * @tc.name: testGetCallingWindowInfo_002
1546 * @tc.desc: GetCallingWindowInfo with panel not created
1547 * @tc.type: FUNC
1548 * @tc.require:
1549 * @tc.author: zhaolinglan
1550 */
1551 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_002, TestSize.Level0)
1552 {
1553 IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_002 Test START");
1554 AccessScope accessScope(InputMethodAbilityTest::currentImeTokenId_, InputMethodAbilityTest::currentImeUid_);
1555 // bind IMC
1556 InputMethodAbilityTest::GetIMCAttachIMA();
1557 // no panel is created
1558 InputMethodAbilityTest::inputMethodAbility_.panels_.Clear();
1559 CallingWindowInfo windowInfo;
1560 int32_t ret = InputMethodAbilityTest::inputMethodAbility_.GetCallingWindowInfo(windowInfo);
1561 EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
1562 InputMethodAbilityTest::GetIMCDetachIMA();
1563 }
1564
1565 /**
1566 * @tc.name: testGetCallingWindowInfo_003
1567 * @tc.desc: GetCallingWindowInfo with only status_bar created
1568 * @tc.type: FUNC
1569 * @tc.require:
1570 * @tc.author: zhaolinglan
1571 */
1572 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_003, TestSize.Level0)
1573 {
1574 IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_003 Test START");
1575 AccessScope accessScope(InputMethodAbilityTest::currentImeTokenId_, InputMethodAbilityTest::currentImeUid_);
1576 // bind IMC
1577 InputMethodAbilityTest::GetIMCAttachIMA();
1578 // only STATUS_BAR panel in IMA
1579 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1580 PanelInfo info;
1581 info.panelType = STATUS_BAR;
1582 InputMethodAbilityTest::inputMethodAbility_.CreatePanel(nullptr, info, inputMethodPanel);
1583 CallingWindowInfo windowInfo;
1584 int32_t ret = InputMethodAbilityTest::inputMethodAbility_.GetCallingWindowInfo(windowInfo);
1585 EXPECT_EQ(ret, ErrorCode::ERROR_PANEL_NOT_FOUND);
1586 InputMethodAbilityTest::inputMethodAbility_.DestroyPanel(inputMethodPanel);
1587 InputMethodAbilityTest::GetIMCDetachIMA();
1588 }
1589
1590 /**
1591 * @tc.name: testGetCallingWindowInfo_004
1592 * @tc.desc: GetCallingWindowInfo with invalid windowid
1593 * @tc.type: FUNC
1594 * @tc.require:
1595 * @tc.author: zhaolinglan
1596 */
1597 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_004, TestSize.Level0)
1598 {
1599 IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_004 Test START");
1600 AccessScope accessScope(InputMethodAbilityTest::currentImeTokenId_, InputMethodAbilityTest::currentImeUid_);
1601 // bind imc
1602 InputMethodAbilityTest::GetIMCAttachIMA();
1603 // SOFT_KEYBOARD panel exists
1604 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1605 PanelInfo info;
1606 info.panelType = SOFT_KEYBOARD;
1607 info.panelFlag = FLG_FIXED;
1608 InputMethodAbilityTest::inputMethodAbility_.CreatePanel(nullptr, info, inputMethodPanel);
1609 // invalid window id
1610 InputMethodAbilityTest::imc_->clientInfo_.config.windowId = INVALID_WINDOW_ID;
1611 CallingWindowInfo windowInfo;
1612 int32_t ret = InputMethodAbilityTest::inputMethodAbility_.GetCallingWindowInfo(windowInfo);
1613 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1614 InputMethodAbilityTest::inputMethodAbility_.DestroyPanel(inputMethodPanel);
1615 InputMethodAbilityTest::GetIMCDetachIMA();
1616 }
1617
1618 /**
1619 * @tc.name: testGetCallingWindowInfo_005
1620 * @tc.desc: GetCallingWindowInfo success
1621 * @tc.type: FUNC
1622 * @tc.require:
1623 * @tc.author: zhaolinglan
1624 */
1625 HWTEST_F(InputMethodAbilityTest, testGetCallingWindowInfo_005, TestSize.Level0)
1626 {
1627 IMSA_HILOGI("InputMethodAbility testGetCallingWindowInfo_005 Test START");
1628 AccessScope accessScope(InputMethodAbilityTest::currentImeTokenId_, InputMethodAbilityTest::currentImeUid_);
1629 // SOFT_KEYBOARD window is created
1630 InputMethodAbilityTest::inputMethodAbility_.panels_.Clear();
1631 auto inputMethodPanel = std::make_shared<InputMethodPanel>();
1632 PanelInfo info;
1633 info.panelType = SOFT_KEYBOARD;
1634 info.panelFlag = FLG_FIXED;
1635 InputMethodAbilityTest::inputMethodAbility_.CreatePanel(nullptr, info, inputMethodPanel);
1636 // bind IMC
1637 InputMethodAbilityTest::GetIMCAttachIMA();
1638 InputMethodAbilityTest::imc_->textConfig_.windowId = TddUtil::WindowManager::currentWindowId_;
1639 // get window info success
1640 CallingWindowInfo windowInfo;
1641 int32_t ret = InputMethodAbilityTest::inputMethodAbility_.GetCallingWindowInfo(windowInfo);
1642 EXPECT_TRUE(ret == ErrorCode::NO_ERROR || ret == ErrorCode::ERROR_WINDOW_MANAGER);
1643 InputMethodAbilityTest::GetIMCDetachIMA();
1644 InputMethodAbilityTest::inputMethodAbility_.DestroyPanel(inputMethodPanel);
1645 }
1646
1647 /**
1648 * @tc.name: testSetPreviewText_001
1649 * @tc.desc: IMA
1650 * @tc.type: FUNC
1651 * @tc.require:
1652 * @tc.author: zhaolinglan
1653 */
1654 HWTEST_F(InputMethodAbilityTest, testSetPreviewText_001, TestSize.Level0)
1655 {
1656 IMSA_HILOGI("InputMethodAbilityTest testSetPreviewText_001 Test START");
1657 TextListener::ResetParam();
1658 std::string text = "test";
1659 Range range = { 1, 2 };
1660 InputMethodAbilityTest::GetIMCAttachIMA();
1661 InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = true;
1662 auto ret = InputMethodAbilityTest::inputMethodAbility_.SetPreviewText(text, range);
1663 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1664 EXPECT_EQ(TextListener::previewText_, text);
1665 EXPECT_EQ(TextListener::previewRange_, range);
1666 InputMethodAbilityTest::GetIMCDetachIMA();
1667 }
1668
1669 /**
1670 * @tc.name: testSetPreviewText_002
1671 * @tc.desc: IMA
1672 * @tc.type: FUNC
1673 * @tc.require:
1674 * @tc.author: zhaolinglan
1675 */
1676 HWTEST_F(InputMethodAbilityTest, testSetPreviewText_002, TestSize.Level0)
1677 {
1678 IMSA_HILOGI("InputMethodAbilityTest testSetPreviewText_002 Test START");
1679 TextListener::ResetParam();
1680 std::string text = "test";
1681 Range range = { 1, 2 };
1682 InputMethodAbilityTest::inputMethodAbility_.ClearDataChannel(
1683 InputMethodAbilityTest::inputMethodAbility_.dataChannelObject_);
1684 auto ret = InputMethodAbilityTest::inputMethodAbility_.SetPreviewText(text, range);
1685 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_CHANNEL_NULLPTR);
1686 EXPECT_NE(TextListener::previewText_, text);
1687 EXPECT_FALSE(TextListener::previewRange_ == range);
1688 }
1689
1690 /**
1691 * @tc.name: testSetPreviewText_003
1692 * @tc.desc: IMA
1693 * @tc.type: FUNC
1694 * @tc.require:
1695 * @tc.author: zhaolinglan
1696 */
1697 HWTEST_F(InputMethodAbilityTest, testSetPreviewText_003, TestSize.Level0)
1698 {
1699 IMSA_HILOGI("InputMethodAbilityTest testSetPreviewText_003 Test START");
1700 TextListener::ResetParam();
1701 std::string text = "test";
1702 Range range = { 1, 2 };
1703 InputMethodAbilityTest::GetIMCAttachIMA();
1704 InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = false;
1705 auto ret = InputMethodAbilityTest::inputMethodAbility_.SetPreviewText(text, range);
1706 EXPECT_EQ(ret, ErrorCode::ERROR_TEXT_PREVIEW_NOT_SUPPORTED);
1707 EXPECT_NE(TextListener::previewText_, text);
1708 EXPECT_FALSE(TextListener::previewRange_ == range);
1709 InputMethodAbilityTest::GetIMCDetachIMA();
1710 }
1711
1712 /**
1713 * @tc.name: testFinishTextPreview_001
1714 * @tc.desc: IMA
1715 * @tc.type: FUNC
1716 * @tc.require:
1717 * @tc.author: zhaolinglan
1718 */
1719 HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_001, TestSize.Level0)
1720 {
1721 IMSA_HILOGI("InputMethodAbilityTest testFinishTextPreview_001 Test START");
1722 TextListener::ResetParam();
1723 InputMethodAbilityTest::GetIMCAttachIMA();
1724 InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = true;
1725 auto ret = InputMethodAbilityTest::inputMethodAbility_.FinishTextPreview();
1726 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1727 EXPECT_TRUE(TextListener::isFinishTextPreviewCalled_);
1728 InputMethodAbilityTest::GetIMCDetachIMA();
1729 }
1730
1731 /**
1732 * @tc.name: testFinishTextPreview_002
1733 * @tc.desc: IMA
1734 * @tc.type: FUNC
1735 * @tc.require:
1736 * @tc.author: zhaolinglan
1737 */
1738 HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_002, TestSize.Level0)
1739 {
1740 IMSA_HILOGI("InputMethodAbilityTest testFinishTextPreview_002 Test START");
1741 TextListener::ResetParam();
1742 InputMethodAbilityTest::inputMethodAbility_.ClearDataChannel(
1743 InputMethodAbilityTest::inputMethodAbility_.dataChannelObject_);
1744 auto ret = InputMethodAbilityTest::inputMethodAbility_.FinishTextPreview();
1745 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_CHANNEL_NULLPTR);
1746 EXPECT_FALSE(TextListener::isFinishTextPreviewCalled_);
1747 }
1748
1749 /**
1750 * @tc.name: testFinishTextPreview_003
1751 * @tc.desc: IMA
1752 * @tc.type: FUNC
1753 * @tc.require:
1754 * @tc.author: zhaolinglan
1755 */
1756 HWTEST_F(InputMethodAbilityTest, testFinishTextPreview_003, TestSize.Level0)
1757 {
1758 IMSA_HILOGI("InputMethodAbilityTest testFinishTextPreview_003 Test START");
1759 TextListener::ResetParam();
1760 InputMethodAbilityTest::GetIMCAttachIMA();
1761 InputMethodAbilityTest::imc_->textConfig_.inputAttribute.isTextPreviewSupported = false;
1762 auto ret = InputMethodAbilityTest::inputMethodAbility_.FinishTextPreview();
1763 EXPECT_EQ(ret, ErrorCode::ERROR_TEXT_PREVIEW_NOT_SUPPORTED);
1764 EXPECT_FALSE(TextListener::isFinishTextPreviewCalled_);
1765 InputMethodAbilityTest::GetIMCDetachIMA();
1766 }
1767
1768 /**
1769 * @tc.name: testGetInputMethodState_001
1770 * @tc.desc: IMA
1771 * @tc.type: FUNC
1772 * @tc.require:
1773 */
1774 HWTEST_F(InputMethodAbilityTest, testGetInputMethodState_001, TestSize.Level0)
1775 {
1776 IMSA_HILOGI("InputMethodAbilityTest GetInputMethodState_001 Test START");
1777 int32_t status = 0;
1778 auto ret = InputMethodAbilityTest::imsa_->GetInputMethodState(status);
1779 EXPECT_EQ(ret, ErrorCode::ERROR_NOT_IME);
1780 }
1781
1782 /**
1783 * @tc.name: BranchCoverage001
1784 * @tc.desc: BranchCoverage
1785 * @tc.type: FUNC
1786 */
1787 HWTEST_F(InputMethodAbilityTest, BranchCoverage001, TestSize.Level0)
1788 {
1789 IMSA_HILOGI("InputMethodAbilityTest BranchCoverage001 TEST START");
1790 auto ret = InputMethodAbilityTest::inputMethodAbility_.OnStopInputService(false);
1791 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1792
1793 InputMethodAbilityTest::inputMethodAbility_.imeListener_ = nullptr;
1794 ret = InputMethodAbilityTest::inputMethodAbility_.OnStopInputService(false);
1795 EXPECT_EQ(ret, ErrorCode::ERROR_IME_NOT_STARTED);
1796
1797 ret = InputMethodAbilityTest::inputMethodAbility_.OnSecurityChange(INVALID_VALUE);
1798 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1799
1800 ret = InputMethodAbilityTest::inputMethodAbility_.HideKeyboardImplWithoutLock(INVALID_VALUE, 0);
1801 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1802
1803 ret = InputMethodAbilityTest::inputMethodAbility_.ShowKeyboardImplWithoutLock(INVALID_VALUE);
1804 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1805
1806 ret = InputMethodAbilityTest::inputMethodAbility_.ShowPanel(nullptr);
1807 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1808
1809 PanelFlag flag = PanelFlag::FLG_FIXED;
1810 Trigger trigger = Trigger::IME_APP;
1811 ret = InputMethodAbilityTest::inputMethodAbility_.ShowPanel(nullptr, flag, trigger);
1812 EXPECT_EQ(ret, ErrorCode::ERROR_IMA_NULLPTR);
1813
1814 ret = InputMethodAbilityTest::inputMethodAbility_.HidePanel(nullptr);
1815 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1816
1817 ret = InputMethodAbilityTest::inputMethodAbility_.HidePanel(nullptr, flag, trigger, 0);
1818 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
1819
1820 InputMethodAbilityTest::inputMethodAbility_.isCurrentIme_ = true;
1821 auto ret2 = InputMethodAbilityTest::inputMethodAbility_.IsCurrentIme();
1822 EXPECT_TRUE(ret2);
1823
1824 ret2 = InputMethodAbilityTest::inputMethodAbility_.IsEnable();
1825 EXPECT_FALSE(ret2);
1826 }
1827
1828 /**
1829 * @tc.name: BranchCoverage002
1830 * @tc.desc: BranchCoverage
1831 * @tc.type: FUNC
1832 */
1833 HWTEST_F(InputMethodAbilityTest, BranchCoverage002, TestSize.Level0)
1834 {
1835 IMSA_HILOGI("InputMethodAbilityTest BranchCoverage002 TEST START");
1836 int32_t vailidUserId = 100001;
1837 SwitchInfo switchInfo;
1838 std::string vailidString = "";
1839 std::shared_ptr<ImeInfo> info;
1840 bool needHide = false;
1841 InputType type = InputType::NONE;
1842 auto ret = imsa_->OnStartInputType(vailidUserId, switchInfo, true);
1843 EXPECT_NE(ret, ErrorCode::NO_ERROR);
1844
1845 ret = imsa_->Switch(vailidUserId, vailidString, info);
1846 EXPECT_NE(ret, ErrorCode::NO_ERROR);
1847 ret = imsa_->SwitchExtension(vailidUserId, info);
1848 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1849 ret = imsa_->SwitchSubType(vailidUserId, info);
1850 imsa_->IncreaseAttachCount();
1851 imsa_->NeedHideWhenSwitchInputType(vailidUserId, type, needHide);
1852 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
1853 ret = imsa_->SwitchInputType(vailidUserId, switchInfo);
1854 EXPECT_EQ(ret, ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND);
1855 ret = imsa_->OnPackageRemoved(vailidUserId, vailidString);
1856 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1857
1858 auto ret2 = imsa_->IsNeedSwitch(vailidUserId, vailidString, vailidString);
1859 EXPECT_FALSE(ret2);
1860 ret2 = imsa_->IsStartInputTypePermitted(vailidUserId);
1861 EXPECT_FALSE(ret2);
1862 }
1863
1864 /**
1865 * @tc.name: testOnCallingDisplayIdChanged
1866 * @tc.desc: Test InputMethodCoreProxy OnCallingDisplayIdChanged
1867 * @tc.type: FUNC
1868 * @tc.require:
1869 */
1870 HWTEST_F(InputMethodAbilityTest, testOnCallingDisplayIdChanged, TestSize.Level0)
1871 {
1872 IMSA_HILOGI("testOnCallingDisplayIdChanged start.");
1873 sptr<InputMethodCoreStub> coreStub = new InputMethodCoreServiceImpl();
1874 sptr<IInputMethodCore> core = coreStub;
1875 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
1876 MessageParcel data;
1877 data.WriteRemoteObject(core->AsObject());
1878 sptr<IRemoteObject> coreObject = data.ReadRemoteObject();
1879 sptr<InputMethodCoreProxy> coreProxy = new InputMethodCoreProxy(coreObject);
1880 if (coreProxy == nullptr) {
1881 IMSA_HILOGI("coreProxy is null");
1882 return;
1883 }
1884 coreProxy->OnCallingDisplayIdChanged(0);
1885 EXPECT_TRUE(coreProxy != nullptr);
1886 }
1887
1888 /**
1889 * @tc.name: testNotifyInfoToWmsInStartInput
1890 * @tc.desc: Test testNotifyInfoToWmsInStartInput
1891 * @tc.type: FUNC
1892 * @tc.require:
1893 */
1894 HWTEST_F(InputMethodAbilityTest, testNotifyInfoToWmsInStartInput, TestSize.Level0)
1895 {
1896 IMSA_HILOGI("testNotifyInfoToWmsInStartInput start.");
1897 auto oldImeListener = inputMethodAbility_.imeListener_;
1898 auto oldPanels = inputMethodAbility_.panels_;
1899
1900 inputMethodAbility_.imeListener_ = nullptr;
1901 TextTotalConfig textConfig;
1902 auto ret = inputMethodAbility_.NotifyInfoToWmsInStartInput(textConfig);
1903 EXPECT_FALSE(ret);
1904 inputMethodAbility_.imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
1905 ret = inputMethodAbility_.NotifyInfoToWmsInStartInput(textConfig);
1906 EXPECT_TRUE(ret);
1907 inputMethodAbility_.panels_.Clear();
1908 auto panel1 = std::make_shared<InputMethodPanel>();
1909 panel1->panelType_ = PanelType::SOFT_KEYBOARD;
1910 panel1->panelFlag_ = PanelFlag::FLG_FIXED;
1911 InputMethodAbilityTest::inputMethodAbility_.panels_.Insert(PanelType::SOFT_KEYBOARD, panel1);
1912 auto panel2 = std::make_shared<InputMethodPanel>();
1913 panel2->panelType_ = PanelType::SOFT_KEYBOARD;
1914 panel2->panelFlag_ = PanelFlag::FLG_FLOATING;
1915 InputMethodAbilityTest::inputMethodAbility_.panels_.Insert(PanelType::SOFT_KEYBOARD, panel2);
1916 auto panel3 = std::make_shared<InputMethodPanel>();
1917 panel3->panelType_ = PanelType::STATUS_BAR;
1918 panel3->panelFlag_ = PanelFlag::FLG_CANDIDATE_COLUMN;
1919 InputMethodAbilityTest::inputMethodAbility_.panels_.Insert(PanelType::STATUS_BAR, panel3);
1920 InputMethodAbilityTest::inputMethodAbility_.panels_.Insert(PanelType::SOFT_KEYBOARD, nullptr);
1921 ret = inputMethodAbility_.NotifyInfoToWmsInStartInput(textConfig);
1922 EXPECT_TRUE(ret);
1923
1924 inputMethodAbility_.imeListener_ = oldImeListener;
1925 inputMethodAbility_.panels_ = oldPanels;
1926 }
1927
1928 /**
1929 * @tc.name: testOnSendPrivateData_001
1930 * @tc.desc: IMA InputMethodCoreProxy OnSendPrivateData
1931 * @tc.type: FUNC
1932 * @tc.require:
1933 * @tc.author:
1934 */
1935 HWTEST_F(InputMethodAbilityTest, testOnSendPrivateData_001, TestSize.Level0)
1936 {
1937 IMSA_HILOGI("testOnSendPrivateData_001 start.");
1938 std::unordered_map<std::string, PrivateDataValue> privateCommand;
1939 PrivateDataValue privateDataValue = std::string("stringValue");
1940 privateCommand.insert({ "value", privateDataValue });
1941 auto ret = InputMethodAbilityTest::inputMethodAbility_.OnSendPrivateData(privateCommand);
1942 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
1943 }
1944
1945 /**
1946 * @tc.name: testOnSendPrivateData_002
1947 * @tc.desc: IMA InputMethodCoreProxy OnSendPrivateData
1948 * @tc.type: FUNC
1949 * @tc.require:
1950 * @tc.author:
1951 */
1952 HWTEST_F(InputMethodAbilityTest, testOnSendPrivateData_002, TestSize.Level0)
1953 {
1954 IMSA_HILOGI("testOnSendPrivateData_002 start.");
1955 std::unordered_map<std::string, PrivateDataValue> privateCommand;
1956 PrivateDataValue privateDataValue = std::string("stringValue");
1957 privateCommand.insert({ "value", privateDataValue });
1958 InputMethodAbilityTest::inputMethodAbility_.imeListener_ = nullptr;
1959 auto ret = InputMethodAbilityTest::inputMethodAbility_.OnSendPrivateData(privateCommand);
1960 EXPECT_NE(ret, ErrorCode::NO_ERROR);
1961 }
1962
1963 /**
1964 * @tc.name: testHandleUnconsumedKey_001
1965 * @tc.desc: Checkout keyEvent is nullptr.
1966 * @tc.type: FUNC
1967 */
1968 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_001, TestSize.Level0)
1969 {
1970 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_001 START");
1971 InputMethodAbilityTest::GetIMCAttachIMA();
1972 inputMethodAbility_.inputAttribute_.needAutoInputNumkey = true;
1973 bool ret = InputMethodAbilityTest::inputMethodAbility_.HandleUnconsumedKey(nullptr);
1974 EXPECT_FALSE(ret);
1975 InputMethodAbilityTest::GetIMCDetachIMA();
1976 }
1977
1978 /**
1979 * @tc.name: testHandleUnconsumedKey_002
1980 * @tc.desc: Checkout GetInputDataChannelProxy is nullptr.
1981 * @tc.type: FUNC
1982 */
1983 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_002, TestSize.Level0)
1984 {
1985 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_002 START");
1986
1987 InputMethodAbilityTest::inputMethodAbility_.ClearDataChannel(
1988 InputMethodAbilityTest::inputMethodAbility_.dataChannelObject_);
1989 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
1990 EXPECT_FALSE(inputMethodAbility_.HandleUnconsumedKey(keyEvent));
1991 }
1992
1993 /**
1994 * @tc.name: testHandleUnconsumedKey_003
1995 * @tc.desc: Checkout InputMethodAbility.needAutoInputNumkey is false.
1996 * @tc.type: FUNC
1997 */
1998 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_003, TestSize.Level0)
1999 {
2000 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_003 START");
2001 InputMethodAbilityTest::GetIMCAttachIMA();
2002 inputMethodAbility_.inputAttribute_.needAutoInputNumkey = false;
2003 std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
2004 EXPECT_FALSE(inputMethodAbility_.HandleUnconsumedKey(keyEvent));
2005 InputMethodAbilityTest::GetIMCDetachIMA();
2006 }
2007
2008 /**
2009 * @tc.name: testHandleUnconsumedKey_004
2010 * @tc.desc: Checkout the keyEvent is not down key.
2011 * @tc.type: FUNC
2012 */
2013 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_004, TestSize.Level0)
2014 {
2015 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_004 START");
2016 InputMethodAbilityTest::GetIMCAttachIMA();
2017 inputMethodAbility_.inputAttribute_.needAutoInputNumkey = true;
2018 auto keyEvent = KeyEventUtil::CreateKeyEvent(MMI::KeyEvent::KEYCODE_A, MMI::KeyEvent::KEY_ACTION_UP);
2019 EXPECT_FALSE(InputMethodAbility::GetInstance().HandleUnconsumedKey(keyEvent));
2020 InputMethodAbilityTest::GetIMCDetachIMA();
2021 }
2022
2023 /**
2024 * @tc.name: testHandleUnconsumedKey_005
2025 * @tc.desc: Checkout only handle single key.
2026 * @tc.type: FUNC
2027 */
2028 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_005, TestSize.Level0)
2029 {
2030 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_005 START");
2031 InputMethodAbilityTest::GetIMCAttachIMA();
2032 inputMethodAbility_.inputAttribute_.needAutoInputNumkey = true;
2033 auto keyEvent = KeyEventUtil::CreateKeyEvent(MMI::KeyEvent::KEYCODE_0, MMI::KeyEvent::KEY_ACTION_DOWN);
2034 ASSERT_TRUE(keyEvent != nullptr);
2035 MMI::KeyEvent::KeyItem keyItem;
2036 keyItem.SetKeyCode(MMI::KeyEvent::KEYCODE_A);
2037 keyItem.SetPressed(true);
2038 keyEvent->AddPressedKeyItems(keyItem);
2039 EXPECT_FALSE(inputMethodAbility_.HandleUnconsumedKey(keyEvent));
2040 InputMethodAbilityTest::GetIMCDetachIMA();
2041 }
2042
2043 /**
2044 * @tc.name: testHandleUnconsumedKey_006
2045 * @tc.desc: Checkout KEYCODE_0 to KEYCODE_9.
2046 * @tc.type: FUNC
2047 */
2048 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_006, TestSize.Level0)
2049 {
2050 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_006 START");
2051 InputMethodAbilityTest::GetIMCAttachIMA();
2052 inputMethodAbility_.inputAttribute_.needAutoInputNumkey = true;
2053 auto keyEvent = KeyEventUtil::CreateKeyEvent(MMI::KeyEvent::KEYCODE_6, MMI::KeyEvent::KEY_ACTION_DOWN);
2054 EXPECT_TRUE(InputMethodAbility::GetInstance().HandleUnconsumedKey(keyEvent));
2055 }
2056
2057 /**
2058 * @tc.name: testHandleUnconsumedKey_007
2059 * @tc.desc: Checkout the GetFunctionKey.
2060 * @tc.type: FUNC
2061 */
2062 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_007, TestSize.Level0)
2063 {
2064 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_007 START");
2065 InputMethodAbilityTest::GetIMCAttachIMA();
2066 inputMethodAbility_.inputAttribute_.needAutoInputNumkey = true;
2067
2068 auto keyEvent = KeyEventUtil::CreateKeyEvent(MMI::KeyEvent::KEYCODE_NUMPAD_0, MMI::KeyEvent::KEY_ACTION_DOWN);
2069 ASSERT_TRUE(keyEvent != nullptr);
2070 keyEvent->SetFunctionKey(MMI::KeyEvent::NUM_LOCK_FUNCTION_KEY, 0);
2071 EXPECT_FALSE(inputMethodAbility_.HandleUnconsumedKey(keyEvent));
2072 InputMethodAbilityTest::GetIMCDetachIMA();
2073 }
2074
2075 /**
2076 * @tc.name: testHandleUnconsumedKey_008
2077 * @tc.desc: Checkout KEYCODE_NUMPAD_0 to KEYCODE_NUMPAD_9.
2078 * @tc.type: FUNC
2079 */
2080 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_008, TestSize.Level0)
2081 {
2082 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_008 START");
2083
2084 sptr<InputDataChannelStub> channelObject = new InputDataChannelServiceImpl();
2085 auto channelProxy = std::make_shared<InputDataChannelProxy>(channelObject->AsObject());
2086 InputMethodAbility::GetInstance().dataChannelProxyWrap_ =
2087 std::make_shared<InputDataChannelProxyWrap>(channelProxy, nullptr);
2088 InputMethodAbility::GetInstance().inputAttribute_.needAutoInputNumkey = true;
2089
2090 auto keyEvent = KeyEventUtil::CreateKeyEvent(MMI::KeyEvent::KEYCODE_NUMPAD_0, MMI::KeyEvent::KEY_ACTION_DOWN);
2091 keyEvent->SetFunctionKey(MMI::KeyEvent::NUM_LOCK_FUNCTION_KEY, true);
2092 auto ret = InputMethodAbility::GetInstance().HandleUnconsumedKey(keyEvent);
2093 EXPECT_TRUE(ret);
2094 }
2095
2096 /**
2097 * @tc.name: testHandleUnconsumedKey_009
2098 * @tc.desc: Checkout the serialization of InputAttribute.
2099 * @tc.type: FUNC
2100 */
2101 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_009, TestSize.Level0)
2102 {
2103 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_009 START");
2104 sptr<InputDataChannelStub> channelObject = new InputDataChannelServiceImpl();
2105 auto channelProxy = std::make_shared<InputDataChannelProxy>(channelObject->AsObject());
2106 InputMethodAbility::GetInstance().dataChannelProxyWrap_ =
2107 std::make_shared<InputDataChannelProxyWrap>(channelProxy, nullptr);
2108 InputMethodAbility::GetInstance().inputAttribute_.needAutoInputNumkey = true;
2109
2110 auto keyEvent = KeyEventUtil::CreateKeyEvent(MMI::KeyEvent::KEYCODE_A, MMI::KeyEvent::KEY_ACTION_DOWN);
2111 EXPECT_FALSE(InputMethodAbility::GetInstance().HandleUnconsumedKey(keyEvent));
2112 }
2113
2114 /**
2115 * @tc.name: testHandleUnconsumedKey_010
2116 * @tc.desc: Checkout < KEYCODE_0 or > KEYCODE_9.
2117 * @tc.type: FUNC
2118 */
2119 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_010, TestSize.Level0)
2120 {
2121 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_010 START");
2122 InputMethodAbilityTest::GetIMCAttachIMA();
2123 inputMethodAbility_.inputAttribute_.needAutoInputNumkey = true;
2124
2125 int32_t keyCode = MMI::KeyEvent::KEYCODE_0 - 1;
2126 auto keyEvent = KeyEventUtil::CreateKeyEvent(keyCode, MMI::KeyEvent::KEY_ACTION_DOWN);
2127 EXPECT_FALSE(InputMethodAbility::GetInstance().HandleUnconsumedKey(keyEvent));
2128
2129 keyCode = MMI::KeyEvent::KEYCODE_9 + 1;
2130 keyEvent = KeyEventUtil::CreateKeyEvent(keyCode, MMI::KeyEvent::KEY_ACTION_DOWN);
2131 EXPECT_FALSE(InputMethodAbility::GetInstance().HandleUnconsumedKey(keyEvent));
2132 InputMethodAbilityTest::GetIMCDetachIMA();
2133 }
2134
2135 /**
2136 * @tc.name: testHandleUnconsumedKey_011
2137 * @tc.desc: Checkout < KEYCODE_NUMPAD_0 or > KEYCODE_NUMPAD_9.
2138 * @tc.type: FUNC
2139 */
2140 HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_011, TestSize.Level0)
2141 {
2142 IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_011 START");
2143 InputMethodAbilityTest::GetIMCAttachIMA();
2144 inputMethodAbility_.inputAttribute_.needAutoInputNumkey = true;
2145
2146 int32_t keyCode = MMI::KeyEvent::KEYCODE_NUMPAD_0 - 1;
2147 auto keyEvent = KeyEventUtil::CreateKeyEvent(keyCode, MMI::KeyEvent::KEY_ACTION_DOWN);
2148 EXPECT_FALSE(InputMethodAbility::GetInstance().HandleUnconsumedKey(keyEvent));
2149
2150 keyCode = MMI::KeyEvent::KEYCODE_NUMPAD_9 + 1;
2151 keyEvent = KeyEventUtil::CreateKeyEvent(keyCode, MMI::KeyEvent::KEY_ACTION_DOWN);
2152 EXPECT_FALSE(InputMethodAbility::GetInstance().HandleUnconsumedKey(keyEvent));
2153 InputMethodAbilityTest::GetIMCDetachIMA();
2154 }
2155
2156 /**
2157 * @tc.name: testInvokeAttachOptionsCallback
2158 * @tc.desc: testInvokeAttachOptionsCallback
2159 * @tc.type: FUNC
2160 */
2161 HWTEST_F(InputMethodAbilityTest, testInvokeAttachOptionsCallback, TestSize.Level0)
2162 {
2163 IMSA_HILOGI("InputMethodAbilityTest testInvokeAttachOptionsCallback START");
2164 AttachOptions options;
2165 auto textInputClientListener = std::make_shared<TextInputClientListenerImpl>();
2166 inputMethodAbility_.SetTextInputClientListener(textInputClientListener);
2167 inputMethodAbility_.SetAttachOptions(options);
2168 inputMethodAbility_.InvokeAttachOptionsCallback(options, true);
2169 options.isSimpleKeyboardEnabled = true;
2170 inputMethodAbility_.SetAttachOptions(options);
2171 inputMethodAbility_.InvokeAttachOptionsCallback(options, false);
2172 options.requestKeyboardReason = RequestKeyboardReason::TOUCH;
2173 inputMethodAbility_.SetAttachOptions(options);
2174 inputMethodAbility_.InvokeAttachOptionsCallback(options, false);
2175 uint64_t displayid = 0;
2176 uint64_t displayidNew = 1;
2177 auto ret = inputMethodAbility_.IsDisplayChanged(displayid, displayidNew);
2178 EXPECT_FALSE(ret);
2179 }
2180
2181 /**
2182 * @tc.name: testInitPasteBoardstart_001
2183 * @tc.desc: testInitPasteBoardstart_001
2184 * @tc.type: FUNC
2185 */
2186 HWTEST_F(InputMethodAbilityTest, testInitPasteBoardstart_001, TestSize.Level1)
2187 {
2188 IMSA_HILOGI("InputMethodAbilityTest testInitPasteBoardstart_001 START");
2189 ASSERT_NE(imsa_, nullptr);
2190 auto ret = imsa_->InitPasteboardMonitor();
2191 EXPECT_TRUE(ret);
2192 imsa_->HandlePasteboardStarted();
2193 }
2194
2195 /**
2196 * @tc.name: testClearBindInfo
2197 * @tc.desc: testClearBindInfo
2198 * @tc.type: FUNC
2199 */
2200 HWTEST_F(InputMethodAbilityTest, testClearBindInfo, TestSize.Level0)
2201 {
2202 IMSA_HILOGI("InputMethodAbilityTest testClearBindInfo START");
2203 TextListener::ResetParam();
2204 InputMethodAbilityTest::GetIMCAttachIMA();
2205 AttachOptions options;
2206 options.isSimpleKeyboardEnabled = true;
2207 inputMethodAbility_.SetAttachOptions(options);
2208 inputMethodAbility_.OnClientInactive(inputMethodAbility_.dataChannelObject_);
2209 EXPECT_TRUE(inputMethodAbility_.GetBindClientInfo().name.empty());
2210 EXPECT_TRUE(inputMethodAbility_.dataChannelObject_ == nullptr);
2211 InputMethodAbilityTest::GetIMCDetachIMA();
2212 }
2213
2214 /**
2215 * @tc.name: testServiceHandler_
2216 * @tc.desc: testServiceHandler_ is nullptr
2217 * @tc.type: FUNC
2218 */
2219 HWTEST_F(InputMethodAbilityTest, TestServiceHandler_, TestSize.Level0)
2220 {
2221 IMSA_HILOGI("InputMethodAbilityTest testServiceHandler_ START");
2222 int32_t userId = 100;
2223 string subName = "";
2224 auto temp = imsa_->serviceHandler_;
2225 imsa_->serviceHandler_ = nullptr;
2226
2227 imsa_->SubscribeCommonEvent();
2228
2229 imsa_->GetValidSubtype(subName, nullptr);
2230 auto info = std::make_shared<ImeInfo>();
2231 EXPECT_NE(info, nullptr);
2232 imsa_->GetValidSubtype(subName, info);
2233
2234 EXPECT_EQ(imsa_->serviceHandler_, nullptr);
2235 auto ret = imsa_->SwitchExtension(userId, nullptr);
2236 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
2237 ret = imsa_->SwitchExtension(userId, info);
2238 MessageParcel *parcel1 = new (std::nothrow) MessageParcel();
2239 auto msg = std::make_shared<Message>(MessageID::MSG_ID_USER_START, parcel1);
2240 ret = imsa_->OnUserStarted(msg.get());
2241 msg.reset();
2242 ret = imsa_->OnUserStarted(msg.get());
2243 EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
2244 imsa_->serviceHandler_ = temp;
2245 }
2246
2247 /**
2248 * @tc.name: TestOnConnectSystemCmd
2249 * @tc.desc: TestOnConnectSystemCmd in Multithreading
2250 * @tc.type: FUNC
2251 */
2252 HWTEST_F(InputMethodAbilityTest, TestOnConnectSystemCmd_001, TestSize.Level0)
2253 {
2254 IMSA_HILOGI("TestOnConnectSystemCmd_001 start.");
2255 multiThreadExecTotalNum_.store(0);
2256 SET_THREAD_NUM(THREAD_NUM);
2257 GTEST_RUN_TASK(TestOnConnectSystemCmd);
2258 EXPECT_EQ(multiThreadExecTotalNum_.load(), THREAD_NUM * MAXRUNCOUNT);
2259 }
2260
2261 /**
2262 *@tc.name: testOnStopInputService_001
2263 *@tc.desc: IMA
2264 *@tc.type: FUNC
2265 *@tc.require:
2266 */
2267 HWTEST_F(InputMethodAbilityTest, testOnStopInputService_001, TestSize.Level0)
2268 {
2269 IMSA_HILOGI("InputMethodAbilityTest OnStopInputService_001 Test START");
2270 InputMethodAbilityTest::inputMethodAbility_.isImeTerminating_ = false;
2271 inputMethodAbility_.SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
2272 auto ret = InputMethodAbilityTest::inputMethodAbility_.OnStopInputService(false);
2273 EXPECT_NE(true, InputMethodAbilityTest::inputMethodAbility_.isImeTerminating_);
2274 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
2275
2276 ret = InputMethodAbilityTest::inputMethodAbility_.OnStopInputService(true);
2277 EXPECT_EQ(true, InputMethodAbilityTest::inputMethodAbility_.isImeTerminating_);
2278 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
2279 }
2280
2281 /**
2282 * @tc.name: testHideKeyboardSelf_001
2283 * @tc.desc: InputMethodAbility HideKeyboardSelf
2284 * @tc.type: FUNC
2285 * @tc.require:
2286 * @tc.author: Hollokin
2287 */
2288 HWTEST_F(InputMethodAbilityTest, testHideKeyboardSelf_001, TestSize.Level0)
2289 {
2290 IMSA_HILOGI("InputMethodAbility testHideKeyboardSelf_001 START");
2291 InputMethodAbilityTest::inputMethodAbility_.isImeTerminating_ = true;
2292 auto ret = InputMethodAbilityTest::inputMethodAbility_.HideKeyboardSelf();
2293 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
2294 }
2295
2296 /**
2297 * @tc.name: testHidePanel
2298 * @tc.desc: InputMethodAbility HidePanel
2299 * @tc.type: FUNC
2300 * @tc.require:
2301 */
2302 HWTEST_F(InputMethodAbilityTest, testHidePanel, TestSize.Level0)
2303 {
2304 IMSA_HILOGI("InputMethodAbility testHidePanel START");
2305 imc_->Attach(textListener_);
2306 PanelInfo info1;
2307 info1.panelType = SOFT_KEYBOARD;
2308 info1.panelFlag = FLG_FLOATING;
2309 AccessScope scope(currentImeTokenId_, currentImeUid_);
2310 auto panel = std::make_shared<InputMethodPanel>();
2311 auto ret = inputMethodAbility_.CreatePanel(nullptr, info1, panel);
2312 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
2313 ret = InputMethodAbilityTest::inputMethodAbility_.HidePanel(nullptr);
2314 EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
2315
2316 InputMethodAbilityTest::inputMethodAbility_.isImeTerminating_ = true;
2317 ret = InputMethodAbilityTest::inputMethodAbility_.HidePanel(panel);
2318 EXPECT_EQ(ret, ErrorCode::NO_ERROR);
2319 }
2320 } // namespace MiscServices
2321 } // namespace OHOS
2322