1 /*
2  * Copyright (C) 2022 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 #define protected public
18 #include "ime_cfg_manager.h"
19 #include "input_method_ability.h"
20 #include "input_method_controller.h"
21 #include "input_method_system_ability.h"
22 #include "inputmethod_sysevent.h"
23 #include "task_manager.h"
24 #undef private
25 
26 #include <gtest/gtest.h>
27 #include <sys/time.h>
28 #include <unistd.h>
29 
30 #include <cstdint>
31 #include <string>
32 
33 #include "global.h"
34 #include "hisysevent_base_manager.h"
35 #include "hisysevent_listener.h"
36 #include "hisysevent_manager.h"
37 #include "hisysevent_query_callback.h"
38 #include "hisysevent_record.h"
39 #include "identity_checker_mock.h"
40 #include "input_method_ability.h"
41 #include "input_method_controller.h"
42 #include "input_method_engine_listener_impl.h"
43 #include "tdd_util.h"
44 #include "text_listener.h"
45 
46 using namespace testing::ext;
47 using namespace OHOS::HiviewDFX;
48 namespace OHOS {
49 namespace MiscServices {
50 using WindowMgr = TddUtil::WindowManager;
51 constexpr const char *CMD1 = "hidumper -s 3703 -a -a";
52 constexpr const char *CMD2 = "hidumper -s 3703 -a -h";
53 constexpr const char *CMD3 = "hidumper -s 3703 -a -test";
54 constexpr const char *PARAM_KEY = "OPERATE_INFO";
55 constexpr const char *STATE = "STATE";
56 constexpr const char *PID = "PID";
57 constexpr const char *BUNDLE_NAME = "BUNDLE_NAME";
58 constexpr const char *DOMAIN = "INPUTMETHOD";
59 constexpr const char *OPERATE_SOFTKEYBOARD_EVENT_NAME = "OPERATE_SOFTKEYBOARD";
60 constexpr const char *IME_STATE_CHANGED_EVENT_NAME = "IME_STATE_CHANGED";
61 
62 class Watcher : public HiSysEventListener {
63 public:
Watcher(const std::string &operateInfo)64     explicit Watcher(const std::string &operateInfo) : operateInfo_(operateInfo)
65     {
66     }
~Watcher()67     virtual ~Watcher()
68     {
69     }
70     void OnEvent(std::shared_ptr<HiSysEventRecord> sysEvent) final
71     {
72         if (sysEvent == nullptr) {
73             IMSA_HILOGE("sysEvent is nullptr!");
74             return;
75         }
76         std::string result;
77         sysEvent->GetParamValue(PARAM_KEY, result);
78         IMSA_HILOGI("result = %{public}s", result.c_str());
79         if (result != operateInfo_) {
80             IMSA_HILOGE("string is not matched.");
81             return;
82         }
83         std::unique_lock<std::mutex> lock(cvMutex_);
84         watcherCv_.notify_all();
85     }
86     void OnServiceDied() final
87     {
88         IMSA_HILOGE("Watcher::OnServiceDied");
89     }
90     std::mutex cvMutex_;
91     std::condition_variable watcherCv_;
92 
93 private:
94     std::string operateInfo_;
95 };
96 
97 class WatcherImeChange : public HiSysEventListener {
98 public:
WatcherImeChange(const std::string &state, const std::string &pid, const std::string &bundleName)99     explicit WatcherImeChange(const std::string &state, const std::string &pid, const std::string &bundleName)
100         : state_(state), pid_(pid), bundleName_(bundleName)
101     {
102     }
~WatcherImeChange()103     virtual ~WatcherImeChange()
104     {
105     }
106     void OnEvent(std::shared_ptr<HiSysEventRecord> sysEvent) final
107     {
108         if (sysEvent == nullptr) {
109             IMSA_HILOGE("sysEvent is nullptr!");
110             return;
111         }
112         std::string pid;
113         std::string state;
114         std::string bundleName;
115         sysEvent->GetParamValue(STATE, state);
116         sysEvent->GetParamValue(PID, pid);
117         sysEvent->GetParamValue(BUNDLE_NAME, bundleName);
118         IMSA_HILOGI("bundleName: %{public}s, state: %{public}s, pid: %{public}s", bundleName.c_str(), state.c_str(),
119             pid.c_str());
120         if (state != state_ || pid != pid_ || bundleName != bundleName_) {
121             IMSA_HILOGE("string is not matched.");
122             return;
123         }
124         std::unique_lock<std::mutex> lock(cvMutexImeChange_);
125         watcherCvImeChange_.notify_all();
126     }
127     void OnServiceDied() final
128     {
129         IMSA_HILOGE("WatcherImeChange::OnServiceDied");
130     }
131     std::mutex cvMutexImeChange_;
132     std::condition_variable watcherCvImeChange_;
133 
134 private:
135     std::string state_;
136     std::string pid_;
137     std::string bundleName_;
138 };
139 
140 class InputMethodDfxTest : public testing::Test {
141 public:
142     using ExecFunc = std::function<void()>;
143     static void SetUpTestCase(void);
144     static void TearDownTestCase(void);
145     static bool WriteAndWatch(const std::shared_ptr<Watcher> &watcher, const InputMethodDfxTest::ExecFunc &exec);
146     static bool WriteAndWatchImeChange(
147         const std::shared_ptr<WatcherImeChange> &watcher, const InputMethodDfxTest::ExecFunc &exec);
148     void SetUp();
149     void TearDown();
150     static sptr<InputMethodController> inputMethodController_;
151     static sptr<OnTextChangedListener> textListener_;
152     static sptr<InputMethodAbility> inputMethodAbility_;
153     static std::shared_ptr<InputMethodEngineListenerImpl> imeListener_;
154     static sptr<InputMethodSystemAbility> imsa_;
155 };
156 sptr<InputMethodController> InputMethodDfxTest::inputMethodController_;
157 sptr<OnTextChangedListener> InputMethodDfxTest::textListener_;
158 sptr<InputMethodAbility> InputMethodDfxTest::inputMethodAbility_;
159 std::shared_ptr<InputMethodEngineListenerImpl> InputMethodDfxTest::imeListener_;
160 sptr<InputMethodSystemAbility> InputMethodDfxTest::imsa_;
161 
WriteAndWatch( const std::shared_ptr<Watcher> &watcher, const InputMethodDfxTest::ExecFunc &exec)162 bool InputMethodDfxTest::WriteAndWatch(
163     const std::shared_ptr<Watcher> &watcher, const InputMethodDfxTest::ExecFunc &exec)
164 {
165     OHOS::HiviewDFX::ListenerRule listenerRule(
166         DOMAIN, OPERATE_SOFTKEYBOARD_EVENT_NAME, "", OHOS::HiviewDFX::RuleType::WHOLE_WORD);
167     std::vector<OHOS::HiviewDFX::ListenerRule> sysRules;
168     sysRules.emplace_back(listenerRule);
169     auto ret = OHOS::HiviewDFX::HiSysEventManager::AddListener(watcher, sysRules);
170     if (ret != SUCCESS) {
171         IMSA_HILOGE("AddListener failed! ret = %{public}d", ret);
172         return false;
173     }
174     std::unique_lock<std::mutex> lock(watcher->cvMutex_);
175     exec();
176     bool result = watcher->watcherCv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
177     ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher);
178     if (ret != SUCCESS || !result) {
179         IMSA_HILOGE("RemoveListener ret = %{public}d, wait_for result = %{public}s", ret, result ? "true" : "false");
180         return false;
181     }
182     return true;
183 }
184 
WriteAndWatchImeChange( const std::shared_ptr<WatcherImeChange> &watcher, const InputMethodDfxTest::ExecFunc &exec)185 bool InputMethodDfxTest::WriteAndWatchImeChange(
186     const std::shared_ptr<WatcherImeChange> &watcher, const InputMethodDfxTest::ExecFunc &exec)
187 {
188     OHOS::HiviewDFX::ListenerRule listenerRule(
189         DOMAIN, IME_STATE_CHANGED_EVENT_NAME, "", OHOS::HiviewDFX::RuleType::WHOLE_WORD);
190     std::vector<OHOS::HiviewDFX::ListenerRule> sysRules;
191     sysRules.emplace_back(listenerRule);
192     auto ret = OHOS::HiviewDFX::HiSysEventManager::AddListener(watcher, sysRules);
193     if (ret != SUCCESS) {
194         IMSA_HILOGE("AddListener failed! ret = %{public}d", ret);
195         return false;
196     }
197     std::unique_lock<std::mutex> lock(watcher->cvMutexImeChange_);
198     exec();
199     bool result = watcher->watcherCvImeChange_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
200     ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher);
201     if (ret != SUCCESS || !result) {
202         IMSA_HILOGE("RemoveListener ret = %{public}d, wait_for result = %{public}s", ret, result ? "true" : "false");
203         return false;
204     }
205     return true;
206 }
207 
SetUpTestCase(void)208 void InputMethodDfxTest::SetUpTestCase(void)
209 {
210     IMSA_HILOGI("InputMethodDfxTest::SetUpTestCase");
211     IdentityCheckerMock::ResetParam();
212     imsa_ = new (std::nothrow) InputMethodSystemAbility();
213     if (imsa_ == nullptr) {
214         return;
215     }
216     imsa_->OnStart();
217     imsa_->userId_ = TddUtil::GetCurrentUserId();
218     imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
219     IdentityCheckerMock::SetFocused(true);
220 
221     inputMethodAbility_ = InputMethodAbility::GetInstance();
222     imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
223     inputMethodAbility_->abilityManager_ = imsa_;
224     TddUtil::InitCurrentImePermissionInfo();
225     IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
226     inputMethodAbility_->SetCoreAndAgent();
227     inputMethodAbility_->SetImeListener(imeListener_);
228 
229     inputMethodController_ = InputMethodController::GetInstance();
230     inputMethodController_->abilityManager_ = imsa_;
231     textListener_ = new TextListener();
232 }
233 
TearDownTestCase(void)234 void InputMethodDfxTest::TearDownTestCase(void)
235 {
236     IMSA_HILOGI("InputMethodDfxTest::TearDownTestCase");
237     IdentityCheckerMock::ResetParam();
238     imsa_->OnStop();
239     ImeCfgManager::GetInstance().imeConfigs_.clear();
240 }
241 
SetUp(void)242 void InputMethodDfxTest::SetUp(void)
243 {
244     IMSA_HILOGI("InputMethodDfxTest::SetUp");
245     TaskManager::GetInstance().SetInited(true);
246 }
247 
TearDown(void)248 void InputMethodDfxTest::TearDown(void)
249 {
250     IMSA_HILOGI("InputMethodDfxTest::TearDown");
251     std::this_thread::sleep_for(std::chrono::seconds(1));
252     TaskManager::GetInstance().Reset();
253 }
254 
255 /**
256 * @tc.name: InputMethodDfxTest_DumpAllMethod_001
257 * @tc.desc: DumpAllMethod
258 * @tc.type: FUNC
259 * @tc.require: issueI61PMG
260 * @tc.author: chenyu
261 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_DumpAllMethod_001, TestSize.Level0)262 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_DumpAllMethod_001, TestSize.Level0)
263 {
264     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_DumpAllMethod_001");
265     std::string result;
266     auto ret = TddUtil::ExecuteCmd(CMD1, result);
267     EXPECT_TRUE(ret);
268     EXPECT_NE(result.find("imeList"), std::string::npos);
269     EXPECT_NE(result.find("com.example.testIme"), std::string::npos);
270 }
271 
272 /**
273 * @tc.name: InputMethodDfxTest_Dump_ShowHelp_001
274 * @tc.desc: Dump ShowHelp.
275 * @tc.type: FUNC
276 * @tc.require: issueI61PMG
277 * @tc.author: chenyu
278 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowHelp_001, TestSize.Level0)279 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowHelp_001, TestSize.Level0)
280 {
281     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Dump_ShowHelp_001");
282     std::string result;
283     auto ret = TddUtil::ExecuteCmd(CMD2, result);
284     EXPECT_TRUE(ret);
285     EXPECT_NE(result.find("Description:"), std::string::npos);
286     EXPECT_NE(result.find("-h show help"), std::string::npos);
287     EXPECT_NE(result.find("-a dump all input methods"), std::string::npos);
288 }
289 
290 /**
291 * @tc.name: InputMethodDfxTest_Dump_ShowIllealInformation_001
292 * @tc.desc: Dump ShowIllealInformation.
293 * @tc.type: FUNC
294 * @tc.require: issueI61PMG
295 * @tc.author: chenyu
296 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowIllealInformation_001, TestSize.Level0)297 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowIllealInformation_001, TestSize.Level0)
298 {
299     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Dump_ShowIllealInformation_001");
300     std::string result;
301     auto ret = TddUtil::ExecuteCmd(CMD3, result);
302     EXPECT_TRUE(ret);
303     EXPECT_NE(result.find("input dump parameter error,enter '-h' for usage."), std::string::npos);
304 }
305 
306 /**
307 * @tc.name: InputMethodDfxTest_Hisysevent_Attach
308 * @tc.desc: Hisysevent attach.
309 * @tc.type: FUNC
310 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Attach, TestSize.Level0)311 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Attach, TestSize.Level0)
312 {
313     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_Attach");
314     auto watcher = std::make_shared<Watcher>(
315         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ATTACH)));
316     auto attach = []() { inputMethodController_->Attach(textListener_, true); };
317     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, attach));
318 }
319 
320 /**
321 * @tc.name: InputMethodDfxTest_Hisysevent_HideTextInput
322 * @tc.desc: Hisysevent HideTextInput.
323 * @tc.type: FUNC
324 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideTextInput, TestSize.Level0)325 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideTextInput, TestSize.Level0)
326 {
327     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_HideTextInput");
328     auto ret = inputMethodController_->Attach(textListener_, true);
329     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
330     auto watcher = std::make_shared<Watcher>(InputMethodSysEvent::GetInstance().GetOperateInfo(
331         static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNEDITABLE)));
332     auto hideTextInput = []() { inputMethodController_->HideTextInput(); };
333     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, hideTextInput));
334 }
335 
336 /**
337 * @tc.name: InputMethodDfxTest_Hisysevent_ShowTextInput
338 * @tc.desc: Hisysevent ShowTextInput.
339 * @tc.type: FUNC
340 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowTextInput, TestSize.Level0)341 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowTextInput, TestSize.Level0)
342 {
343     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_ShowTextInput");
344     auto watcher = std::make_shared<Watcher>(InputMethodSysEvent::GetInstance().GetOperateInfo(
345         static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ENEDITABLE)));
346     auto showTextInput = []() { inputMethodController_->ShowTextInput(); };
347     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, showTextInput));
348 }
349 
350 /**
351 * @tc.name: InputMethodDfxTest_Hisysevent_HideCurrentInput
352 * @tc.desc: Hisysevent HideCurrentInput.
353 * @tc.type: FUNC
354 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideCurrentInput, TestSize.Level0)355 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideCurrentInput, TestSize.Level0)
356 {
357     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_HideCurrentInput");
358     auto watcher = std::make_shared<Watcher>(
359         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_NORMAL)));
360     auto hideCurrentInput = []() { inputMethodController_->HideCurrentInput(); };
361     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, hideCurrentInput));
362 }
363 
364 /**
365 * @tc.name: InputMethodDfxTest_Hisysevent_ShowCurrentInput
366 * @tc.desc: Hisysevent ShowCurrentInput.
367 * @tc.type: FUNC
368 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowCurrentInput, TestSize.Level0)369 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowCurrentInput, TestSize.Level0)
370 {
371     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_ShowCurrentInput");
372     auto watcher = std::make_shared<Watcher>(
373         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_NORMAL)));
374     auto showCurrentInput = []() { inputMethodController_->ShowCurrentInput(); };
375     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, showCurrentInput));
376 }
377 
378 /**
379 * @tc.name: InputMethodDfxTest_Hisysevent_HideSoftKeyboard
380 * @tc.desc: Hisysevent HideSoftKeyboard.
381 * @tc.type: FUNC
382 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideSoftKeyboard, TestSize.Level0)383 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideSoftKeyboard, TestSize.Level0)
384 {
385     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_HideSoftKeyboard");
386     auto watcher = std::make_shared<Watcher>(
387         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_NORMAL)));
388     auto hideSoftKeyboard = []() { inputMethodController_->HideSoftKeyboard(); };
389     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, hideSoftKeyboard));
390 }
391 
392 /**
393 * @tc.name: InputMethodDfxTest_Hisysevent_ShowSoftKeyboard
394 * @tc.desc: Hisysevent ShowSoftKeyboard.
395 * @tc.type: FUNC
396 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowSoftKeyboard, TestSize.Level0)397 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowSoftKeyboard, TestSize.Level0)
398 {
399     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_ShowSoftKeyboard");
400     auto watcher = std::make_shared<Watcher>(
401         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_NORMAL)));
402     auto showSoftKeyboard = []() { inputMethodController_->ShowSoftKeyboard(); };
403     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, showSoftKeyboard));
404 }
405 
406 /**
407 * @tc.name: InputMethodDfxTest_Hisysevent_HideKeyboardSelf
408 * @tc.desc: Hisysevent HideKeyboardSelf.
409 * @tc.type: FUNC
410 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideKeyboardSelf, TestSize.Level0)411 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideKeyboardSelf, TestSize.Level0)
412 {
413     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_HideKeyboardSelf");
414     auto watcher = std::make_shared<Watcher>(
415         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_SELF)));
416     auto hideKeyboardSelf = []() { inputMethodAbility_->HideKeyboardSelf(); };
417     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, hideKeyboardSelf));
418 }
419 
420 /**
421 * @tc.name: InputMethodDfxTest_Hisysevent_Close
422 * @tc.desc: Hisysevent Close.
423 * @tc.type: FUNC
424 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Close, TestSize.Level0)425 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Close, TestSize.Level0)
426 {
427     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_Close");
428     auto watcher = std::make_shared<Watcher>(
429         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_UNBIND)));
430     auto close = []() { inputMethodController_->Close(); };
431     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, close));
432 }
433 
434 /**
435 * @tc.name: InputMethodDfxTest_Hisysevent_UnBind
436 * @tc.desc: Hisysevent UnBind.
437 * @tc.type: FUNC
438 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_UnBind, TestSize.Level0)439 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_UnBind, TestSize.Level0)
440 {
441     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_UnBind");
442     auto watcherImeChange = std::make_shared<WatcherImeChange>(std::to_string(static_cast<int32_t>(ImeState::UNBIND)),
443         std::to_string(static_cast<int32_t>(getpid())), TddUtil::currentBundleNameMock_);
444     auto imeStateUnBind = []() {
445         inputMethodController_->Attach(textListener_, true);
446         inputMethodController_->Close();
447     };
448     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatchImeChange(watcherImeChange, imeStateUnBind));
449 }
450 
451 /**
452 * @tc.name: InputMethodDfxTest_Hisysevent_Bind
453 * @tc.desc: Hisysevent Bind.
454 * @tc.type: FUNC
455 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Bind, TestSize.Level0)456 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Bind, TestSize.Level0)
457 {
458     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_Bind");
459     auto watcherImeChange = std::make_shared<WatcherImeChange>(std::to_string(static_cast<int32_t>(ImeState::BIND)),
460         std::to_string(static_cast<int32_t>(getpid())), TddUtil::currentBundleNameMock_);
461     auto imeStateBind = []() { inputMethodController_->RequestShowInput(); };
462     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatchImeChange(watcherImeChange, imeStateBind));
463 }
464 
465 /**
466 * @tc.name: InputMethod_Dump_HELP
467 * @tc.desc: InputMethodDump.
468 * @tc.type: FUNC
469 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_HELP, TestSize.Level0)470 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_HELP, TestSize.Level0)
471 {
472     IMSA_HILOGI("InputMethodDump::InputMethod_Dump_HELP");
473     std::vector<std::string> args = {"-h"};
474     int fd = 1;
475     EXPECT_TRUE(InputmethodDump::GetInstance().Dump(fd, args));
476 }
477 
478 /**
479 * @tc.name: InputMethod_Dump_ALL
480 * @tc.desc: InputMethodDump.
481 * @tc.type: FUNC
482 */
HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ALL, TestSize.Level0)483 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ALL, TestSize.Level0)
484 {
485     IMSA_HILOGI("InputMethodDump::InputMethod_Dump_ALL");
486     std::vector<std::string> args = {"-a"};
487     int fd = 1;
488     EXPECT_FALSE(!InputmethodDump::GetInstance().Dump(fd, args));
489 }
490 } // namespace MiscServices
491 } // namespace OHOS
492