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