• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 
16 #define private public
17 #include "input_method_ability.h"
18 #include "task_manager.h"
19 #undef private
20 
21 #include <gtest/gtest.h>
22 
23 #include "ability_manager_client.h"
24 #include "global.h"
25 #include "ime_event_monitor_manager_impl.h"
26 #include "ime_setting_listener_test_impl.h"
27 #include "input_method_ability_interface.h"
28 #include "input_method_controller.h"
29 #include "input_method_engine_listener_impl.h"
30 #include "input_method_types.h"
31 #include "keyboard_listener_test_impl.h"
32 #include "tdd_util.h"
33 #include "text_listener.h"
34 using namespace testing::ext;
35 namespace OHOS {
36 namespace MiscServices {
37 constexpr int32_t RETRY_INTERVAL = 100;
38 constexpr int32_t RETRY_TIME = 30;
39 constexpr int32_t WAIT_APP_START_COMPLETE = 1;
40 constexpr int32_t WAIT_BIND_COMPLETE = 1;
41 constexpr int32_t WAIT_CLICK_COMPLETE = 100;
42 constexpr const char *BUNDLENAME = "com.example.editorbox";
43 class ImeProxyTest : public testing::Test {
44 public:
45     static sptr<InputMethodController> imc_;
SetUpTestCase(void)46     static void SetUpTestCase(void)
47     {
48         TddUtil::StorageSelfTokenID();
49         TddUtil::InitWindow(false);
50         imc_ = InputMethodController::GetInstance();
51         RegisterImeSettingListener();
52         SwitchToTestIme();
53         // native sa permission
54         TddUtil::GrantNativePermission();
55     }
TearDownTestCase(void)56     static void TearDownTestCase(void)
57     {
58         TddUtil::DestroyWindow();
59         TddUtil::RestoreSelfTokenID();
60         TddUtil::KillImsaProcess();
61     }
SetUp()62     void SetUp()
63     {
64         IMSA_HILOGI("InputMethodAbilityTest::SetUp");
65         InputMethodAbilityInterface::GetInstance().SetImeListener(std::make_shared<InputMethodEngineListenerImpl>());
66         InputMethodAbilityInterface::GetInstance().SetKdListener(std::make_shared<KeyboardListenerTestImpl>());
67         TaskManager::GetInstance().SetInited(true);
68     }
TearDown()69     void TearDown()
70     {
71         IMSA_HILOGI("InputMethodAbilityTest::TearDown");
72         std::this_thread::sleep_for(std::chrono::seconds(1));
73         TaskManager::GetInstance().Reset();
74     }
75 
Attach(bool isPc)76     static int32_t Attach(bool isPc)
77     {
78         isPc ? InputMethodEngineListenerImpl::isEnable_ = true : InputMethodEngineListenerImpl::isEnable_ = false;
79         TextConfig config;
80         config.cursorInfo = { .left = 0, .top = 1, .width = 0.5, .height = 1.2 };
81         sptr<OnTextChangedListener> testListener = new TextListener();
82         auto ret = imc_->Attach(testListener, true, config);
83         return ret;
84     }
Close(bool isPc)85     static void Close(bool isPc)
86     {
87         isPc ? InputMethodEngineListenerImpl::isEnable_ = true : InputMethodEngineListenerImpl::isEnable_ = false;
88         imc_->Close();
89     }
90 
StartApp()91     static void StartApp() // bind client default, not show keyboard
92     {
93         static std::string cmd = "aa start ability -a EntryAbility -b com.example.editorbox";
94         std::string result;
95         auto ret = TddUtil::ExecuteCmd(cmd, result);
96         EXPECT_TRUE(ret);
97         BlockRetry(RETRY_INTERVAL, RETRY_TIME, []() {
98             return AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility().GetBundleName() == BUNDLENAME;
99         });
100         IMSA_HILOGI("start app success");
101         sleep(WAIT_APP_START_COMPLETE); // ensure app start complete
102     }
103 
ClickEditor(bool isPc)104     static void ClickEditor(bool isPc)
105     {
106         isPc ? InputMethodEngineListenerImpl::isEnable_ = true : InputMethodEngineListenerImpl::isEnable_ = false;
107         static std::string cmd = "uinput -T -d 200 200 -u 200 200";
108         std::string result;
109         auto ret = TddUtil::ExecuteCmd(cmd, result);
110         EXPECT_TRUE(ret);
111         usleep(WAIT_CLICK_COMPLETE); // ensure click complete
112     }
113 
StopApp()114     static void StopApp()
115     {
116         static std::string cmd = "aa force-stop com.example.editorbox";
117         std::string result;
118         auto ret = TddUtil::ExecuteCmd(cmd, result);
119         EXPECT_TRUE(ret);
120         BlockRetry(RETRY_INTERVAL, RETRY_TIME, []() {
121             return AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility().GetBundleName() != BUNDLENAME;
122         });
123         IMSA_HILOGI("stop app success");
124     }
125 
EnsureBindComplete()126     static void EnsureBindComplete()
127     {
128         sleep(WAIT_BIND_COMPLETE);
129     }
130 
SwitchToTestIme()131     static void SwitchToTestIme()
132     {
133         ImeSettingListenerTestImpl::ResetParam();
134         // ohos.permission.MANAGE_SECURE_SETTINGS ohos.permission.CONNECT_IME_ABILITY
135         TddUtil::GrantNativePermission();
136         std::string beforeValue;
137         TddUtil::GetEnableData(beforeValue);
138         std::string allEnableIme = "{\"enableImeList\" : {\"100\" : [ \"com.example.testIme\"]}}";
139         TddUtil::PushEnableImeValue("settings.inputmethod.enable_ime", allEnableIme);
140         SubProperty subProp = {
141             .name = "com.example.testIme",
142             .id = "InputMethodExtAbility",
143         };
144         auto ret = imc_->SwitchInputMethod(SwitchTrigger::CURRENT_IME, subProp.name, subProp.id);
145         EXPECT_EQ(ret, ErrorCode::NO_ERROR);
146         EXPECT_TRUE(ImeSettingListenerTestImpl::WaitImeChange(subProp));
147         TddUtil::RestoreSelfTokenID();
148         TddUtil::PushEnableImeValue("settings.inputmethod.enable_ime", beforeValue);
149     }
150 
151 private:
RegisterImeSettingListener()152     static void RegisterImeSettingListener()
153     {
154         TddUtil::StorageSelfTokenID();
155         TddUtil::SetTestTokenID(TddUtil::AllocTestTokenID(true, "ImeProxyTest"));
156         auto listener = std::make_shared<ImeSettingListenerTestImpl>();
157         ImeEventMonitorManagerImpl::GetInstance().RegisterImeEventListener(
158             EVENT_IME_HIDE_MASK | EVENT_IME_SHOW_MASK | EVENT_IME_CHANGE_MASK, listener);
159         TddUtil::RestoreSelfTokenID();
160     }
161 };
162 sptr<InputMethodController> ImeProxyTest::imc_;
163 
164 /**
165  * @tc.name: RegisteredProxyNotInEditor_001
166  * @tc.desc: not in editor
167  * @tc.type: FUNC
168  */
169 HWTEST_F(ImeProxyTest, RegisteredProxyNotInEditor_001, TestSize.Level0)
170 {
171     IMSA_HILOGI("ImeProxyTest::RegisteredProxyNotInEditor_001");
172     // RegisteredProxy not in ima bind
173     InputMethodEngineListenerImpl::ResetParam();
174     InputMethodEngineListenerImpl::isEnable_ = true;
175     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
176     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
177     EXPECT_FALSE(InputMethodEngineListenerImpl::WaitInputStart());
178 
179     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
180 }
181 
182 /**
183  * @tc.name: AttachInPcAfterRegisteredProxyNotInEditor_002
184  * @tc.desc: not in editor
185  * @tc.type: FUNC
186  */
187 HWTEST_F(ImeProxyTest, AttachInPcAfterRegisteredProxyNotInEditor_002, TestSize.Level0)
188 {
189     IMSA_HILOGI("ImeProxyTest::AttachInPcAfterRegisteredProxyNotInEditor_002");
190     TddUtil::GetFocused();
191     // RegisteredProxy not in ima bind
192     InputMethodEngineListenerImpl::isEnable_ = true;
193     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
194     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
195 
196     // mock click the edit box in pc, bind proxy
197     ImeSettingListenerTestImpl::ResetParam();
198     InputMethodEngineListenerImpl::ResetParam();
199     ret = Attach(true);
200     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
201     EXPECT_FALSE(ImeSettingListenerTestImpl::WaitPanelShow());
202     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
203     Close(false);
204     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
205     TddUtil::GetUnfocused();
206 }
207 
208 /**
209  * @tc.name: AttachInPeAfterRegisteredProxyNotInEditor_003
210  * @tc.desc: not in editor
211  * @tc.type: FUNC
212  */
213 HWTEST_F(ImeProxyTest, AttachInPeAfterRegisteredProxyNotInEditor_003, TestSize.Level0)
214 {
215     IMSA_HILOGI("ImeProxyTest::AttachInPeAfterRegisteredProxyNotInEditor_003");
216     TddUtil::GetFocused();
217     // RegisteredProxy not in ima bind
218     InputMethodEngineListenerImpl::isEnable_ = true;
219     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
220     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
221 
222     // mock click the edit box in pe, bind ima
223     ImeSettingListenerTestImpl::ResetParam();
224     InputMethodEngineListenerImpl::ResetParam();
225     ret = Attach(false);
226     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
227     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelShow());
228     EXPECT_FALSE(InputMethodEngineListenerImpl::WaitInputStart());
229     Close(false);
230     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
231     TddUtil::GetUnfocused();
232 }
233 
234 /**
235  * @tc.name: RegisteredProxyInImaEditor_004
236  * @tc.desc:
237  * @tc.type: FUNC
238  */
239 HWTEST_F(ImeProxyTest, RegisteredProxyInImaEditor_004, TestSize.Level0)
240 {
241     IMSA_HILOGI("ImeProxyTest::RegisteredProxyInImaEditor_004");
242     TddUtil::GetFocused();
243     // mock click the edit box in pe, bind ima
244     ImeSettingListenerTestImpl::ResetParam();
245     auto ret = Attach(false);
246     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
247     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelShow());
248 
249     // RegisteredProxy in ima bind, unbind ima, bind proxy
250     InputMethodEngineListenerImpl::ResetParam();
251     ImeSettingListenerTestImpl::ResetParam();
252     KeyboardListenerTestImpl::ResetParam();
253     InputMethodEngineListenerImpl::isEnable_ = true;
254     ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
255     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
256     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelHide());
257     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
258     EXPECT_TRUE(KeyboardListenerTestImpl::WaitCursorUpdate());
259     Close(false);
260     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
261     TddUtil::GetUnfocused();
262 }
263 
264 /**
265  * @tc.name: UnRegisteredAndRegisteredProxyInProxyBind_005
266  * @tc.desc:
267  * @tc.type: FUNC
268  */
269 HWTEST_F(ImeProxyTest, UnRegisteredAndRegisteredProxyInProxyBind_005, TestSize.Level0)
270 {
271     IMSA_HILOGI("ImeProxyTest::UnRegisteredAndRegisteredProxyInProxyBind_005");
272     TddUtil::GetFocused();
273     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
274     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
275 
276     // mock click the edit box in pc, bind proxy
277     InputMethodEngineListenerImpl::ResetParam();
278     ret = Attach(true);
279     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
280     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
281 
282     // UnRegisteredProxy in proxy bind
283     InputMethodEngineListenerImpl::ResetParam();
284     ret = InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
285     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
286     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
287     ret = InputMethodAbilityInterface::GetInstance().InsertText("b");
288     EXPECT_EQ(ret, ErrorCode::ERROR_IMA_CHANNEL_NULLPTR);
289 
290     // RegisteredProxy proxy, rebind proxy
291     InputMethodEngineListenerImpl::ResetParam();
292     InputMethodEngineListenerImpl::isEnable_ = true;
293     ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
294     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
295     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
296     Close(false);
297     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
298     TddUtil::GetUnfocused();
299 }
300 
301 /**
302  * @tc.name: UnRegisteredProxyNotInBind_stop_006
303  * @tc.desc:
304  * @tc.type: FUNC
305  */
306 HWTEST_F(ImeProxyTest, UnRegisteredProxyNotInBind_stop_006, TestSize.Level0)
307 {
308     IMSA_HILOGI("ImeProxyTest::UnRegisteredProxyNotInBind_stop_006");
309     InputMethodEngineListenerImpl::ResetParam();
310     InputMethodEngineListenerImpl::isEnable_ = true;
311     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
312     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
313     ret = InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
314     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
315     EXPECT_FALSE(InputMethodEngineListenerImpl::WaitInputFinish());
316 }
317 
318 /**
319  * @tc.name: UnRegisteredProxyInProxyBind_stop_007
320  * @tc.desc:
321  * @tc.type: FUNC
322  */
323 HWTEST_F(ImeProxyTest, UnRegisteredProxyInProxyBind_stop_007, TestSize.Level0)
324 {
325     IMSA_HILOGI("ImeProxyTest::UnRegisteredProxyInProxyBind_stop_007");
326     TddUtil::GetFocused();
327     InputMethodEngineListenerImpl::isEnable_ = true;
328     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
329     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
330     std::this_thread::sleep_for(std::chrono::seconds(2));
331 
332     // mock click the edit box in pc, bind proxy
333     InputMethodEngineListenerImpl::ResetParam();
334     ret = Attach(true);
335     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
336     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
337 
338     InputMethodEngineListenerImpl::ResetParam();
339     ImeSettingListenerTestImpl::ResetParam();
340     ret = InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
341     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
342     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
343     EXPECT_FALSE(ImeSettingListenerTestImpl::WaitPanelShow());
344     Close(false);
345     TddUtil::GetUnfocused();
346 }
347 
348 /**
349  * @tc.name: UnRegisteredProxyInImaBind_stop_008
350  * @tc.desc:
351  * @tc.type: FUNC
352  */
353 HWTEST_F(ImeProxyTest, UnRegisteredProxyInImaBind_stop_008, TestSize.Level0)
354 {
355     IMSA_HILOGI("ImeProxyTest::UnRegisteredProxyInImaBind_stop_008");
356     TddUtil::GetFocused();
357     InputMethodEngineListenerImpl::isEnable_ = true;
358     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
359     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
360 
361     // mock click the edit box in pe, bind ima
362     ImeSettingListenerTestImpl::ResetParam();
363     ret = Attach(false);
364     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
365     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelShow());
366 
367     InputMethodEngineListenerImpl::ResetParam();
368     ImeSettingListenerTestImpl::ResetParam();
369     ret = InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
370     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
371     EXPECT_FALSE(ImeSettingListenerTestImpl::WaitPanelHide());
372     EXPECT_FALSE(InputMethodEngineListenerImpl::WaitInputFinish());
373     Close(false);
374     TddUtil::GetUnfocused();
375 }
376 
377 /**
378  * @tc.name: UnRegisteredProxyNotInBind_switch_009
379  * @tc.desc:
380  * @tc.type: FUNC
381  */
382 HWTEST_F(ImeProxyTest, UnRegisteredProxyNotInBind_switch_009, TestSize.Level0)
383 {
384     IMSA_HILOGI("ImeProxyTest::UnRegisteredProxyNotInBind_switch_009");
385     InputMethodEngineListenerImpl::isEnable_ = true;
386     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
387     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
388     ret = InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::SWITCH_PROXY_IME_TO_IME);
389     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_BOUND);
390 }
391 
392 /**
393  * @tc.name: UnRegisteredProxyInProxyBind_switch_010
394  * @tc.desc:
395  * @tc.type: FUNC
396  */
397 HWTEST_F(ImeProxyTest, UnRegisteredProxyInProxyBind_switch_010, TestSize.Level0)
398 {
399     IMSA_HILOGI("ImeProxyTest::UnRegisteredProxyInProxyBind_switch_010");
400     TddUtil::GetFocused();
401     InputMethodEngineListenerImpl::isEnable_ = true;
402     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
403     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
404 
405     // mock click the edit box in pc, bind proxy
406     InputMethodEngineListenerImpl::ResetParam();
407     ret = Attach(true);
408     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
409     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
410 
411     ImeSettingListenerTestImpl::ResetParam();
412     InputMethodEngineListenerImpl::ResetParam();
413     ret = InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::SWITCH_PROXY_IME_TO_IME);
414     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
415     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
416     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelShow());
417     Close(false);
418     TddUtil::GetUnfocused();
419 }
420 
421 /**
422  * @tc.name: UnRegisteredProxyWithErrorType_011
423  * @tc.desc:
424  * @tc.type: FUNC
425  */
426 HWTEST_F(ImeProxyTest, UnRegisteredProxyWithErrorType_011, TestSize.Level0)
427 {
428     IMSA_HILOGI("ImeProxyTest::UnRegisteredProxyWithErrorType_011");
429     InputMethodEngineListenerImpl::isEnable_ = true;
430     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
431     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
432     ret = InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(static_cast<UnRegisteredType>(3));
433     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
434 }
435 
436 /**
437  * @tc.name: AppUnFocusInProxyBindInPe_012
438  * @tc.desc:
439  * @tc.type: FUNC
440  */
441 HWTEST_F(ImeProxyTest, AppUnFocusInProxyBindInPe_012, TestSize.Level0)
442 {
443     IMSA_HILOGI("ImeProxyTest::AppUnFocusInProxyBindInPe_012");
444     TddUtil::GetFocused();
445     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
446     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
447 
448     // mock click the edit box in pc, bind proxy
449     InputMethodEngineListenerImpl::ResetParam();
450     ret = Attach(true);
451     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
452     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
453 
454     // mock app unFocus in proxy bind in pe, unbind proxy
455     Close(false);
456     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
457     ret = InputMethodAbilityInterface::GetInstance().InsertText("d");
458     EXPECT_EQ(ret, ErrorCode::ERROR_IMA_CHANNEL_NULLPTR);
459 
460     ret = InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
461     TddUtil::GetUnfocused();
462 }
463 
464 /**
465  * @tc.name: AppUnFocusInProxyBindInPc_013
466  * @tc.desc:
467  * @tc.type: FUNC
468  */
469 HWTEST_F(ImeProxyTest, AppUnFocusInProxyBindInPc_013, TestSize.Level0)
470 {
471     IMSA_HILOGI("ImeProxyTest::AppUnFocusInProxyBindInPc_013");
472     TddUtil::GetFocused();
473     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
474     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
475 
476     // open the app, click the edit box in pc, bind proxy
477     InputMethodEngineListenerImpl::ResetParam();
478     ret = Attach(true);
479     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
480     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
481 
482     // mock app unFocus in proxy bind in pc, unbind proxy
483     Close(true);
484     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
485     ret = InputMethodAbilityInterface::GetInstance().InsertText("d");
486     EXPECT_EQ(ret, ErrorCode::ERROR_IMA_CHANNEL_NULLPTR);
487 
488     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
489     TddUtil::GetUnfocused();
490 }
491 
492 /**
493  * @tc.name: ProxyAndImaSwitchTest_014
494  * @tc.desc:
495  * @tc.type: FUNC
496  */
497 HWTEST_F(ImeProxyTest, ProxyAndImaSwitchTest_014, TestSize.Level0)
498 {
499     IMSA_HILOGI("ImeProxyTest::ProxyAndImaSwitchTest_014");
500     TddUtil::GetFocused();
501     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
502     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
503 
504     // mock click the edit box in pe, bind ima
505     ImeSettingListenerTestImpl::ResetParam();
506     ret = Attach(false);
507     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
508     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelShow());
509 
510     // mock click the edit box in pc, unbind ima, bind proxy
511     ImeSettingListenerTestImpl::ResetParam();
512     InputMethodEngineListenerImpl::ResetParam();
513     ret = Attach(true);
514     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
515     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
516     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelHide());
517 
518     // mock click the edit box in pe, unbind proxy, bind ima
519     ImeSettingListenerTestImpl::ResetParam();
520     InputMethodEngineListenerImpl::ResetParam();
521     ret = Attach(false);
522     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
523     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelShow());
524     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
525 
526     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
527     Close(false);
528     TddUtil::GetUnfocused();
529 }
530 
531 /**
532  * @tc.name: KeyboardListenerTest_015
533  * @tc.desc:
534  * @tc.type: FUNC
535  */
536 HWTEST_F(ImeProxyTest, KeyboardListenerTest_015, TestSize.Level0)
537 {
538     IMSA_HILOGI("ImeProxyTest::KeyboardListenerTest_015");
539     // 1:positionX, 2: positionY, 5: height
540     InputMethodAbility::GetInstance()->OnCursorUpdate(1, 2, 5);
541     EXPECT_TRUE(KeyboardListenerTestImpl::WaitCursorUpdate());
542 
543     InputMethodAbility::GetInstance()->OnSelectionChange(std::u16string(u"text"), 1, 2, 4, 6);
544     EXPECT_TRUE(KeyboardListenerTestImpl::WaitSelectionChange(4));
545     EXPECT_TRUE(KeyboardListenerTestImpl::WaitTextChange("text"));
546 }
547 
548 /**
549  * @tc.name: TextEditTest
550  * @tc.desc:
551  * @tc.type: FUNC
552  */
553 HWTEST_F(ImeProxyTest, TextEditTest, TestSize.Level0)
554 {
555     IMSA_HILOGI("ImeProxyTest::TextEditTest");
556     TddUtil::GetFocused();
557     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
558     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
559     InputMethodEngineListenerImpl::ResetParam();
560     ret = Attach(true);
561     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
562     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
563 
564     TextListener::ResetParam();
565     ret = InputMethodAbilityInterface::GetInstance().InsertText("b");
566     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
567     EXPECT_TRUE(TextListener::WaitInsertText(u"b"));
568     ret = InputMethodAbilityInterface::GetInstance().MoveCursor(1);
569     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
570     EXPECT_TRUE(TextListener::WaitMoveCursor(1));
571     ret = InputMethodAbilityInterface::GetInstance().DeleteBackward(1);
572     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
573     EXPECT_TRUE(TextListener::WaitDeleteForward(1));
574     ret = InputMethodAbilityInterface::GetInstance().DeleteForward(2);
575     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
576     EXPECT_TRUE(TextListener::WaitDeleteBackward(2));
577 
578     Close(true);
579     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
580     TddUtil::GetUnfocused();
581 }
582 
583 /**
584  * @tc.name: ClientDiedInImaBind_016
585  * @tc.desc:
586  * @tc.type: FUNC
587  */
588 HWTEST_F(ImeProxyTest, ClientDiedInImaBind_016, TestSize.Level0)
589 {
590     IMSA_HILOGI("ImeProxyTest::ClientDiedInImaBind_016");
591     // open the app, click the edit box in pe, bind ima
592     StartApp();
593     ImeSettingListenerTestImpl::ResetParam();
594     ClickEditor(false);
595     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelShow());
596     EnsureBindComplete();
597 
598     ImeSettingListenerTestImpl::ResetParam();
599     StopApp();
600     EXPECT_TRUE(ImeSettingListenerTestImpl::WaitPanelHide());
601 }
602 
603 /**
604  * @tc.name: ClientDiedInProxyBind_017
605  * @tc.desc:
606  * @tc.type: FUNC
607  */
608 HWTEST_F(ImeProxyTest, ClientDiedInProxyBind_017, TestSize.Level0)
609 {
610     IMSA_HILOGI("ImeProxyTest::ClientDiedInProxyBind_017");
611     // RegisteredProxy not in ima bind
612     InputMethodEngineListenerImpl::isEnable_ = true;
613     auto ret = InputMethodAbilityInterface::GetInstance().RegisteredProxy();
614     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
615 
616     StartApp();
617     InputMethodEngineListenerImpl::ResetParam();
618     ClickEditor(true);
619     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputStart());
620     EnsureBindComplete();
621 
622     InputMethodEngineListenerImpl::ResetParam();
623     StopApp();
624     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
625     InputMethodAbilityInterface::GetInstance().UnRegisteredProxy(UnRegisteredType::REMOVE_PROXY_IME);
626 }
627 
628 /**
629  * @tc.name: onInputFinishTest_StopInput
630  * @tc.desc: close
631  * @tc.type: FUNC
632  */
633 HWTEST_F(ImeProxyTest, onInputFinishTest_StopInput, TestSize.Level0)
634 {
635     IMSA_HILOGI("ImeProxyTest::onInputFinishTest_StopInput");
636     InputMethodAbility::GetInstance()->StopInput(nullptr);
637     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
638 }
639 /**
640  * @tc.name: onInputFinishTest_OnClientInactive
641  * @tc.desc: OnClientInactive
642  * @tc.type: FUNC
643  */
644 HWTEST_F(ImeProxyTest, onInputFinishTest_OnClientInactive, TestSize.Level0)
645 {
646     IMSA_HILOGI("ImeProxyTest::onInputFinishTest_OnClientInactive");
647     InputMethodAbility::GetInstance()->OnClientInactive(nullptr);
648     EXPECT_TRUE(InputMethodEngineListenerImpl::WaitInputFinish());
649 }
650 
651 /**
652  * @tc.name: testIsFromTs
653  * @tc.desc: ImeProxyTest testIsFromTs
654  * @tc.type: FUNC
655  * @tc.require:
656  */
657 HWTEST_F(ImeProxyTest, testIsFromTs, TestSize.Level0)
658 {
659     IMSA_HILOGI("ImeProxyTest testIsFromTs Test START");
660     sptr<OnTextChangedListener> testListener = new TextListener();
661     bool isFrom = testListener->IsFromTs();
662     EXPECT_FALSE(isFrom);
663 }
664 } // namespace MiscServices
665 } // namespace OHOS
666