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