• 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 InputMethodAbility &inputMethodAbility_;
147     static std::shared_ptr<InputMethodEngineListenerImpl> imeListener_;
148     static sptr<InputMethodSystemAbility> imsa_;
149 private:
150     static uint32_t reportIntervalTime;
151 };
152 sptr<InputMethodController> InputMethodDfxTest::inputMethodController_;
153 sptr<OnTextChangedListener> InputMethodDfxTest::textListener_;
154 InputMethodAbility &InputMethodDfxTest::inputMethodAbility_ = InputMethodAbility::GetInstance();
155 std::shared_ptr<InputMethodEngineListenerImpl> InputMethodDfxTest::imeListener_;
156 sptr<InputMethodSystemAbility> InputMethodDfxTest::imsa_;
157 uint32_t InputMethodDfxTest::reportIntervalTime = 10; //10minutes
158 
WriteAndWatch(const std::shared_ptr<Watcher> & watcher,const InputMethodDfxTest::ExecFunc & exec)159 bool InputMethodDfxTest::WriteAndWatch(
160     const std::shared_ptr<Watcher> &watcher, const InputMethodDfxTest::ExecFunc &exec)
161 {
162     auto currentTime = std::chrono::steady_clock::now();
163     const auto& lastTime = InputMethodSysEvent::GetLastOperateTime();
164     // Check if the last trigger was more than 10 minutes ago
165     if (static_cast<uint32_t>(
166             std::chrono::duration_cast<std::chrono::minutes>(currentTime - lastTime).count()) <
167         reportIntervalTime) {
168         IMSA_HILOGI("Event triggered within 10 minutes, skipping report.");
169         return true;
170     }
171     OHOS::HiviewDFX::ListenerRule listenerRule(
172         DOMAIN, OPERATE_SOFTKEYBOARD_EVENT_NAME, "", OHOS::HiviewDFX::RuleType::WHOLE_WORD);
173     std::vector<OHOS::HiviewDFX::ListenerRule> sysRules;
174     sysRules.emplace_back(listenerRule);
175     auto ret = OHOS::HiviewDFX::HiSysEventManager::AddListener(watcher, sysRules);
176     if (ret != SUCCESS) {
177         IMSA_HILOGE("AddListener failed! ret = %{public}d", ret);
178         return false;
179     }
180     std::unique_lock<std::mutex> lock(watcher->cvMutex_);
181     exec();
182     bool result = watcher->watcherCv_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
183     ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher);
184     if (ret != SUCCESS || !result) {
185         IMSA_HILOGE("RemoveListener ret = %{public}d, wait_for result = %{public}s", ret, result ? "true" : "false");
186         return false;
187     }
188     return true;
189 }
190 
WriteAndWatchImeChange(const std::shared_ptr<WatcherImeChange> & watcher,const InputMethodDfxTest::ExecFunc & exec)191 bool InputMethodDfxTest::WriteAndWatchImeChange(
192     const std::shared_ptr<WatcherImeChange> &watcher, const InputMethodDfxTest::ExecFunc &exec)
193 {
194     auto currentTime = std::chrono::steady_clock::now();
195     const auto& lastTime = InputMethodSysEvent::GetLastOperateTime();
196     // Check if the last trigger was more than 10 minutes ago
197     if (static_cast<uint32_t>(
198             std::chrono::duration_cast<std::chrono::minutes>(currentTime - lastTime).count()) <
199         reportIntervalTime) {
200         IMSA_HILOGI("Event triggered within 10 minutes, skipping report.");
201         return true;
202     }
203     OHOS::HiviewDFX::ListenerRule listenerRule(
204         DOMAIN, IME_STATE_CHANGED_EVENT_NAME, "", OHOS::HiviewDFX::RuleType::WHOLE_WORD);
205     std::vector<OHOS::HiviewDFX::ListenerRule> sysRules;
206     sysRules.emplace_back(listenerRule);
207     auto ret = OHOS::HiviewDFX::HiSysEventManager::AddListener(watcher, sysRules);
208     if (ret != SUCCESS) {
209         IMSA_HILOGE("AddListener failed! ret = %{public}d", ret);
210         return false;
211     }
212     std::unique_lock<std::mutex> lock(watcher->cvMutexImeChange_);
213     exec();
214     bool result = watcher->watcherCvImeChange_.wait_for(lock, std::chrono::seconds(1)) != std::cv_status::timeout;
215     ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher);
216     if (ret != SUCCESS || !result) {
217         IMSA_HILOGE("RemoveListener ret = %{public}d, wait_for result = %{public}s", ret, result ? "true" : "false");
218         return false;
219     }
220     return true;
221 }
222 
SetUpTestCase(void)223 void InputMethodDfxTest::SetUpTestCase(void)
224 {
225     IMSA_HILOGI("InputMethodDfxTest::SetUpTestCase");
226     IdentityCheckerMock::ResetParam();
227     imsa_ = new (std::nothrow) InputMethodSystemAbility();
228     if (imsa_ == nullptr) {
229         return;
230     }
231     imsa_->OnStart();
232     imsa_->userId_ = TddUtil::GetCurrentUserId();
233     imsa_->identityChecker_ = std::make_shared<IdentityCheckerMock>();
234     IdentityCheckerMock::SetFocused(true);
235 
236     imeListener_ = std::make_shared<InputMethodEngineListenerImpl>();
237     inputMethodAbility_.abilityManager_ = imsa_;
238     TddUtil::InitCurrentImePermissionInfo();
239     IdentityCheckerMock::SetBundleName(TddUtil::currentBundleNameMock_);
240     inputMethodAbility_.SetCoreAndAgent();
241     inputMethodAbility_.SetImeListener(imeListener_);
242 
243     inputMethodController_ = InputMethodController::GetInstance();
244     inputMethodController_->abilityManager_ = imsa_;
245     textListener_ = new TextListener();
246 }
247 
TearDownTestCase(void)248 void InputMethodDfxTest::TearDownTestCase(void)
249 {
250     IMSA_HILOGI("InputMethodDfxTest::TearDownTestCase");
251     IdentityCheckerMock::ResetParam();
252     imsa_->OnStop();
253     ImeCfgManager::GetInstance().imeConfigs_.clear();
254 }
255 
SetUp(void)256 void InputMethodDfxTest::SetUp(void)
257 {
258     IMSA_HILOGI("InputMethodDfxTest::SetUp");
259     TaskManager::GetInstance().SetInited(true);
260 }
261 
TearDown(void)262 void InputMethodDfxTest::TearDown(void)
263 {
264     IMSA_HILOGI("InputMethodDfxTest::TearDown");
265     std::this_thread::sleep_for(std::chrono::seconds(1));
266     TaskManager::GetInstance().Reset();
267 }
268 
269 /**
270  * @tc.name: InputMethodDfxTest_DumpAllMethod_001
271  * @tc.desc: DumpAllMethod
272  * @tc.type: FUNC
273  * @tc.require: issueI61PMG
274  * @tc.author: chenyu
275  */
276 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_DumpAllMethod_001, TestSize.Level1)
277 {
278     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_DumpAllMethod_001");
279     std::string result;
280     auto ret = TddUtil::ExecuteCmd(CMD1, result);
281     EXPECT_TRUE(ret);
282     EXPECT_NE(result.find("imeList"), std::string::npos);
283     EXPECT_NE(result.find("com.example.testIme"), std::string::npos);
284 }
285 
286 /**
287  * @tc.name: InputMethodDfxTest_Dump_ShowHelp_001
288  * @tc.desc: Dump ShowHelp.
289  * @tc.type: FUNC
290  * @tc.require: issueI61PMG
291  * @tc.author: chenyu
292  */
293 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowHelp_001, TestSize.Level1)
294 {
295     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Dump_ShowHelp_001");
296     std::string result;
297     auto ret = TddUtil::ExecuteCmd(CMD2, result);
298     EXPECT_TRUE(ret);
299     EXPECT_NE(result.find("Description:"), std::string::npos);
300     EXPECT_NE(result.find("-h show help"), std::string::npos);
301     EXPECT_NE(result.find("-a dump all input methods"), std::string::npos);
302 }
303 
304 /**
305  * @tc.name: InputMethodDfxTest_Dump_ShowIllealInformation_001
306  * @tc.desc: Dump ShowIllealInformation.
307  * @tc.type: FUNC
308  * @tc.require: issueI61PMG
309  * @tc.author: chenyu
310  */
311 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ShowIllealInformation_001, TestSize.Level1)
312 {
313     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Dump_ShowIllealInformation_001");
314     std::string result;
315     auto ret = TddUtil::ExecuteCmd(CMD3, result);
316     EXPECT_TRUE(ret);
317     EXPECT_NE(result.find("input dump parameter error,enter '-h' for usage."), std::string::npos);
318 }
319 
320 /**
321  * @tc.name: InputMethodDfxTest_Hisysevent_Attach
322  * @tc.desc: Hisysevent attach.
323  * @tc.type: FUNC
324  */
325 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Attach, TestSize.Level1)
326 {
327     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_Attach");
328     auto watcher = std::make_shared<Watcher>(
329         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ATTACH)));
__anonf576e3270102() 330     auto attach = []() {
331         inputMethodController_->Attach(textListener_, true);
332     };
333     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, attach));
334 }
335 
336 /**
337  * @tc.name: InputMethodDfxTest_Hisysevent_HideTextInput
338  * @tc.desc: Hisysevent HideTextInput.
339  * @tc.type: FUNC
340  */
341 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideTextInput, TestSize.Level1)
342 {
343     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_HideTextInput");
344     auto ret = inputMethodController_->Attach(textListener_, true);
345     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
346     auto watcher = std::make_shared<Watcher>(InputMethodSysEvent::GetInstance().GetOperateInfo(
347         static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNEDITABLE)));
__anonf576e3270202() 348     auto hideTextInput = []() {
349         inputMethodController_->HideTextInput();
350     };
351     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, hideTextInput));
352 }
353 
354 /**
355  * @tc.name: InputMethodDfxTest_Hisysevent_ShowTextInput
356  * @tc.desc: Hisysevent ShowTextInput.
357  * @tc.type: FUNC
358  */
359 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowTextInput, TestSize.Level1)
360 {
361     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_ShowTextInput");
362     auto watcher = std::make_shared<Watcher>(InputMethodSysEvent::GetInstance().GetOperateInfo(
363         static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ENEDITABLE)));
__anonf576e3270302() 364     auto showTextInput = []() {
365         inputMethodController_->ShowTextInput();
366     };
367     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, showTextInput));
368 }
369 
370 /**
371  * @tc.name: InputMethodDfxTest_Hisysevent_HideCurrentInput
372  * @tc.desc: Hisysevent HideCurrentInput.
373  * @tc.type: FUNC
374  */
375 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideCurrentInput, TestSize.Level1)
376 {
377     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_HideCurrentInput");
378     auto watcher = std::make_shared<Watcher>(
379         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_NORMAL)));
__anonf576e3270402() 380     auto hideCurrentInput = []() {
381         inputMethodController_->HideCurrentInput();
382     };
383     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, hideCurrentInput));
384 }
385 
386 /**
387  * @tc.name: InputMethodDfxTest_Hisysevent_ShowCurrentInput
388  * @tc.desc: Hisysevent ShowCurrentInput.
389  * @tc.type: FUNC
390  */
391 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowCurrentInput, TestSize.Level1)
392 {
393     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_ShowCurrentInput");
394     auto watcher = std::make_shared<Watcher>(
395         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_NORMAL)));
__anonf576e3270502() 396     auto showCurrentInput = []() {
397         inputMethodController_->ShowCurrentInput();
398     };
399     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, showCurrentInput));
400 }
401 
402 /**
403  * @tc.name: InputMethodDfxTest_Hisysevent_HideSoftKeyboard
404  * @tc.desc: Hisysevent HideSoftKeyboard.
405  * @tc.type: FUNC
406  */
407 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideSoftKeyboard, TestSize.Level1)
408 {
409     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_HideSoftKeyboard");
410     auto watcher = std::make_shared<Watcher>(
411         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_NORMAL)));
__anonf576e3270602() 412     auto hideSoftKeyboard = []() {
413         inputMethodController_->HideSoftKeyboard();
414     };
415     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, hideSoftKeyboard));
416 }
417 
418 /**
419  * @tc.name: InputMethodDfxTest_Hisysevent_ShowSoftKeyboard
420  * @tc.desc: Hisysevent ShowSoftKeyboard.
421  * @tc.type: FUNC
422  */
423 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_ShowSoftKeyboard, TestSize.Level1)
424 {
425     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_ShowSoftKeyboard");
426     auto watcher = std::make_shared<Watcher>(
427         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_NORMAL)));
__anonf576e3270702() 428     auto showSoftKeyboard = []() {
429         inputMethodController_->ShowSoftKeyboard();
430     };
431     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, showSoftKeyboard));
432 }
433 
434 /**
435  * @tc.name: InputMethodDfxTest_Hisysevent_HideKeyboardSelf
436  * @tc.desc: Hisysevent HideKeyboardSelf.
437  * @tc.type: FUNC
438  */
439 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_HideKeyboardSelf, TestSize.Level1)
440 {
441     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_HideKeyboardSelf");
442     auto watcher = std::make_shared<Watcher>(
443         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_SELF)));
__anonf576e3270802() 444     auto hideKeyboardSelf = []() {
445         inputMethodAbility_.HideKeyboardSelf();
446     };
447     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, hideKeyboardSelf));
448 }
449 
450 /**
451  * @tc.name: InputMethodDfxTest_Hisysevent_Close
452  * @tc.desc: Hisysevent Close.
453  * @tc.type: FUNC
454  */
455 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Close, TestSize.Level1)
456 {
457     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_Close");
458     auto watcher = std::make_shared<Watcher>(
459         InputMethodSysEvent::GetInstance().GetOperateInfo(static_cast<int32_t>(OperateIMEInfoCode::IME_UNBIND)));
__anonf576e3270902() 460     auto close = []() {
461         inputMethodController_->Close();
462     };
463     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatch(watcher, close));
464 }
465 
466 /**
467  * @tc.name: InputMethodDfxTest_Hisysevent_UnBind
468  * @tc.desc: Hisysevent UnBind.
469  * @tc.type: FUNC
470  */
471 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_UnBind, TestSize.Level1)
472 {
473     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_UnBind");
474     auto watcherImeChange = std::make_shared<WatcherImeChange>(std::to_string(static_cast<int32_t>(ImeState::UNBIND)),
475         std::to_string(static_cast<int32_t>(getpid())), TddUtil::currentBundleNameMock_);
__anonf576e3270a02() 476     auto imeStateUnBind = []() {
477         inputMethodController_->Attach(textListener_, true);
478         inputMethodController_->Close();
479     };
480     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatchImeChange(watcherImeChange, imeStateUnBind));
481 }
482 
483 /**
484  * @tc.name: InputMethodDfxTest_Hisysevent_Bind
485  * @tc.desc: Hisysevent Bind.
486  * @tc.type: FUNC
487  */
488 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_Bind, TestSize.Level1)
489 {
490     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_Bind");
491     auto watcherImeChange = std::make_shared<WatcherImeChange>(std::to_string(static_cast<int32_t>(ImeState::BIND)),
492         std::to_string(static_cast<int32_t>(getpid())), TddUtil::currentBundleNameMock_);
__anonf576e3270b02() 493     auto imeStateBind = []() {
494         inputMethodController_->RequestShowInput();
495     };
496     EXPECT_TRUE(InputMethodDfxTest::WriteAndWatchImeChange(watcherImeChange, imeStateBind));
497 }
498 
499 /**
500  * @tc.name: InputMethod_Dump_HELP
501  * @tc.desc: InputMethodDump.
502  * @tc.type: FUNC
503  */
504 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_HELP, TestSize.Level1)
505 {
506     IMSA_HILOGI("InputMethodDump::InputMethod_Dump_HELP");
507     std::vector<std::string> args = { "-h" };
508     int fd = 1;
509     EXPECT_TRUE(InputmethodDump::GetInstance().Dump(fd, args));
510 }
511 
512 /**
513  * @tc.name: InputMethod_Dump_ALL
514  * @tc.desc: InputMethodDump.
515  * @tc.type: FUNC
516  */
517 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Dump_ALL, TestSize.Level1)
518 {
519     IMSA_HILOGI("InputMethodDump::InputMethod_Dump_ALL");
520     std::vector<std::string> args = { "-a" };
521     int fd = 1;
522     EXPECT_FALSE(!InputmethodDump::GetInstance().Dump(fd, args));
523 }
524 
525 /**
526  * @tc.name: InputMethodDfxTest_Hisysevent_GetOperateAction
527  * @tc.desc: Hisysevent GetOperateAction.
528  * @tc.type: FUNC
529  */
530 HWTEST_F(InputMethodDfxTest, InputMethodDfxTest_Hisysevent_GetOperateAction, TestSize.Level1)
531 {
532     IMSA_HILOGI("InputMethodDfxTest::InputMethodDfxTest_Hisysevent_GetOperateAction");
533     std::string ret = "";
534     ret = InputMethodSysEvent::GetInstance().GetOperateAction(
535         static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ATTACH));
536     ret = InputMethodSysEvent::GetInstance().GetOperateAction(
537         static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_ENEDITABLE));
538     ret = InputMethodSysEvent::GetInstance().GetOperateAction(
539         static_cast<int32_t>(OperateIMEInfoCode::IME_SHOW_NORMAL));
540     EXPECT_TRUE(ret == "show");
541 
542     ret = InputMethodSysEvent::GetInstance().GetOperateAction(static_cast<int32_t>(OperateIMEInfoCode::IME_UNBIND));
543     EXPECT_TRUE(ret == "unbind");
544     ret = InputMethodSysEvent::GetInstance().GetOperateAction(
545         static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNBIND));
546     EXPECT_TRUE(ret == "hide and unbind");
547 
548     ret = InputMethodSysEvent::GetInstance().GetOperateAction(
549         static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNEDITABLE));
550     ret = InputMethodSysEvent::GetInstance().GetOperateAction(
551         static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_NORMAL));
552     ret = InputMethodSysEvent::GetInstance().GetOperateAction(
553         static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_UNFOCUSED));
554     ret = InputMethodSysEvent::GetInstance().GetOperateAction(static_cast<int32_t>(OperateIMEInfoCode::IME_HIDE_SELF));
555     EXPECT_TRUE(ret == "hide");
556 
557     int32_t invalidNum = -1;
558     ret = InputMethodSysEvent::GetInstance().GetOperateAction(invalidNum);
559     EXPECT_TRUE(ret == "unknow action.");
560 }
561 } // namespace MiscServices
562 } // namespace OHOS
563