• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-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 #define protected public
18 #include "ime_cfg_manager.h"
19 #include "input_method_system_ability.h"
20 #undef private
21 
22 #include <gtest/gtest.h>
23 #include <sys/time.h>
24 #include <unistd.h>
25 
26 #include <cstdint>
27 #include <regex>
28 #include <sstream>
29 #include <string>
30 
31 #include "global.h"
32 using namespace testing;
33 using namespace testing::ext;
34 namespace OHOS {
35 namespace MiscServices {
36 class IdentityCheckerTest : public testing::Test {
37 public:
38     class IdentityCheckerMock : public IdentityChecker {
39     public:
40         IdentityCheckerMock() = default;
41         virtual ~IdentityCheckerMock() = default;
IsFocused(int64_t callingPid,uint32_t callingTokenId,int64_t focusedPid=INVALID_PID)42         bool IsFocused(int64_t callingPid, uint32_t callingTokenId, int64_t focusedPid = INVALID_PID) override
43         {
44             return isFocused_;
45         }
IsSystemApp(uint64_t fullTokenId)46         bool IsSystemApp(uint64_t fullTokenId) override
47         {
48             return isSystemApp_;
49         }
IsBundleNameValid(uint32_t tokenId,const std::string & validBundleName)50         bool IsBundleNameValid(uint32_t tokenId, const std::string &validBundleName) override
51         {
52             return isBundleNameValid_;
53         }
HasPermission(uint32_t tokenId,const std::string & permission)54         bool HasPermission(uint32_t tokenId, const std::string &permission) override
55         {
56             return hasPermission_;
57         }
IsBroker(Security::AccessToken::AccessTokenID tokenId)58         bool IsBroker(Security::AccessToken::AccessTokenID tokenId) override
59         {
60             return isBroker_;
61         }
IsNativeSa(Security::AccessToken::AccessTokenID tokenId)62         bool IsNativeSa(Security::AccessToken::AccessTokenID tokenId) override
63         {
64             return isNativeSa_;
65         }
GetBundleNameByToken(uint32_t tokenId)66         std::string GetBundleNameByToken(uint32_t tokenId) override
67         {
68             return "";
69         }
70         static bool isFocused_;
71         static bool isSystemApp_;
72         static bool isBundleNameValid_;
73         static bool hasPermission_;
74         static bool isBroker_;
75         static bool isNativeSa_;
76     };
77     static constexpr uint32_t CURRENT_USERID = 101;
78     static const constexpr char *CURRENT_IME = "testBundleName/testExtname";
79     static const constexpr char *CURRENT_SUBNAME = "testSubName";
80     static const constexpr char *CURRENT_BUNDLENAME = "testBundleName";
81     static void SetUpTestCase(void);
82     static void TearDownTestCase(void);
83     void SetUp();
84     void TearDown();
85     static sptr<InputMethodSystemAbility> service_;
86     static std::shared_ptr<IdentityCheckerMock> identityCheckerMock_;
87     static std::shared_ptr<IdentityCheckerImpl> identityCheckerImpl_;
88 };
89 bool IdentityCheckerTest::IdentityCheckerMock::isFocused_ = false;
90 bool IdentityCheckerTest::IdentityCheckerMock::isSystemApp_ = false;
91 bool IdentityCheckerTest::IdentityCheckerMock::isBundleNameValid_ = false;
92 bool IdentityCheckerTest::IdentityCheckerMock::hasPermission_ = false;
93 bool IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
94 bool IdentityCheckerTest::IdentityCheckerMock::isNativeSa_ = false;
95 
SetUpTestCase(void)96 void IdentityCheckerTest::SetUpTestCase(void)
97 {
98     IMSA_HILOGI("IdentityCheckerTest::SetUpTestCase");
99     service_ = new InputMethodSystemAbility();
100     service_->OnStart();
101     service_->userId_ = CURRENT_USERID;
102     ImeCfgManager::GetInstance().imeConfigs_ = { { CURRENT_USERID, CURRENT_IME, CURRENT_SUBNAME } };
103     identityCheckerImpl_ = std::make_shared<IdentityCheckerImpl>();
104 }
105 
TearDownTestCase(void)106 void IdentityCheckerTest::TearDownTestCase(void)
107 {
108     IMSA_HILOGI("IdentityCheckerTest::TearDownTestCase");
109     service_->OnStop();
110 }
111 
SetUp(void)112 void IdentityCheckerTest::SetUp(void)
113 {
114     identityCheckerMock_ = std::make_shared<IdentityCheckerMock>();
115     service_->identityChecker_ = identityCheckerMock_;
116     IMSA_HILOGI("IdentityCheckerTest::SetUp");
117 }
118 
TearDown(void)119 void IdentityCheckerTest::TearDown(void)
120 {
121     service_->identityChecker_ = identityCheckerImpl_;
122     identityCheckerMock_ = nullptr;
123     IMSA_HILOGI("IdentityCheckerTest::TearDown");
124 }
125 
126 sptr<InputMethodSystemAbility> IdentityCheckerTest::service_;
127 std::shared_ptr<IdentityCheckerTest::IdentityCheckerMock> IdentityCheckerTest::identityCheckerMock_;
128 std::shared_ptr<IdentityCheckerImpl> IdentityCheckerTest::identityCheckerImpl_;
129 
130 /**
131  * @tc.name: testPrepareInput_001
132  * @tc.desc: not broker, not focused app
133  * @tc.type: FUNC
134  * @tc.require:
135  * @tc.author:
136 */
137 HWTEST_F(IdentityCheckerTest, testPrepareInput_001, TestSize.Level0)
138 {
139     IMSA_HILOGI("IdentityCheckerTest testPrepareInput_001 start");
140     service_->identityChecker_ = identityCheckerImpl_;
141     InputClientInfo clientInfo{};
142     if (IdentityCheckerTest::service_ == nullptr) {
143         IMSA_HILOGI("service_ is nullptr");
144     }
145     int32_t ret = IdentityCheckerTest::service_->PrepareInput(clientInfo);
146     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
147 }
148 
149 /**
150  * @tc.name: testStartInput_001
151  * @tc.desc: not broker, not focused app
152  * @tc.type: FUNC
153  * @tc.require:
154  * @tc.author:
155 */
156 HWTEST_F(IdentityCheckerTest, testStartInput_001, TestSize.Level0)
157 {
158     IMSA_HILOGI("IdentityCheckerTest testStartInput_001 start");
159     service_->identityChecker_ = identityCheckerImpl_;
160     sptr<IRemoteObject> agent = nullptr;
161     InputClientInfo inputClientInfo;
162     int32_t ret = IdentityCheckerTest::service_->StartInput(inputClientInfo, agent);
163     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
164 }
165 
166 /**
167  * @tc.name: testStartInput_002
168  * @tc.desc: is broker, not focused app
169  * @tc.type: FUNC
170  * @tc.require:
171  * @tc.author:
172 */
173 HWTEST_F(IdentityCheckerTest, testStartInput_002, TestSize.Level0)
174 {
175     IMSA_HILOGI("IdentityCheckerTest testStartInput_002 start");
176     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
177     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = false;
178     sptr<IRemoteObject> agent = nullptr;
179     InputClientInfo inputClientInfo;
180     int32_t ret = IdentityCheckerTest::service_->StartInput(inputClientInfo, agent);
181     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
182 }
183 
184 /**
185  * @tc.name: testStartInput_003
186  * @tc.desc: is broker, is focused app
187  * @tc.type: FUNC
188  * @tc.require:
189  * @tc.author:
190 */
191 HWTEST_F(IdentityCheckerTest, testStartInput_003, TestSize.Level0)
192 {
193     IMSA_HILOGI("IdentityCheckerTest testStartInput_003 start");
194     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
195     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = true;
196     sptr<IRemoteObject> agent = nullptr;
197     InputClientInfo inputClientInfo;
198     int32_t ret = IdentityCheckerTest::service_->StartInput(inputClientInfo, agent);
199     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
200 }
201 
202 /**
203  * @tc.name: testStartInput_004
204  * @tc.desc: not broker, is focused app
205  * @tc.type: FUNC
206  * @tc.require:
207  * @tc.author:
208 */
209 HWTEST_F(IdentityCheckerTest, testStartInput_004, TestSize.Level0)
210 {
211     IMSA_HILOGI("IdentityCheckerTest testStartInput_004 start");
212     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
213     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = true;
214     sptr<IRemoteObject> agent = nullptr;
215     InputClientInfo inputClientInfo;
216     int32_t ret = IdentityCheckerTest::service_->StartInput(inputClientInfo, agent);
217     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
218 }
219 
220 /**
221  * @tc.name: testStopInput_001
222  * @tc.desc: not broker, not focused app
223  * @tc.type: FUNC
224  * @tc.require:
225  * @tc.author:
226 */
227 HWTEST_F(IdentityCheckerTest, testStopInput_001, TestSize.Level0)
228 {
229     IMSA_HILOGI("IdentityCheckerTest testStopInput_001 start");
230     service_->identityChecker_ = identityCheckerImpl_;
231     int32_t ret = IdentityCheckerTest::service_->HideInput(nullptr);
232     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
233 }
234 
235 /**
236  * @tc.name: testStopInput_002
237  * @tc.desc: is broker, not focused app
238  * @tc.type: FUNC
239  * @tc.require:
240  * @tc.author:
241 */
242 HWTEST_F(IdentityCheckerTest, testStopInput_002, TestSize.Level0)
243 {
244     IMSA_HILOGI("IdentityCheckerTest testStopInput_002 start");
245     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
246     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = false;
247     int32_t ret = IdentityCheckerTest::service_->HideInput(nullptr);
248     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
249 }
250 
251 /**
252  * @tc.name: testStopInput_003
253  * @tc.desc: is broker, is focused app
254  * @tc.type: FUNC
255  * @tc.require:
256  * @tc.author:
257 */
258 HWTEST_F(IdentityCheckerTest, testStopInput_003, TestSize.Level0)
259 {
260     IMSA_HILOGI("IdentityCheckerTest testStopInput_003 start");
261     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
262     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = true;
263     InputClientInfo clientInfo{};
264     int32_t ret = IdentityCheckerTest::service_->HideInput(nullptr);
265     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
266 }
267 
268 /**
269  * @tc.name: testStopInput_004
270  * @tc.desc: not broker, is focused app
271  * @tc.type: FUNC
272  * @tc.require:
273  * @tc.author:
274 */
275 HWTEST_F(IdentityCheckerTest, testStopInput_004, TestSize.Level0)
276 {
277     IMSA_HILOGI("IdentityCheckerTest testStopInput_004 start");
278     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
279     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = true;
280     InputClientInfo clientInfo{};
281     int32_t ret = IdentityCheckerTest::service_->HideInput(nullptr);
282     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NULL_POINTER);
283 }
284 
285 /**
286  * @tc.name: testStopInputSession_001
287  * @tc.desc: not broker, not focused app
288  * @tc.type: FUNC
289  * @tc.require:
290  * @tc.author:
291 */
292 HWTEST_F(IdentityCheckerTest, testStopInputSession_001, TestSize.Level0)
293 {
294     IMSA_HILOGI("IdentityCheckerTest testStopInputSession_001 start");
295     service_->identityChecker_ = identityCheckerImpl_;
296     int32_t ret = IdentityCheckerTest::service_->StopInputSession();
297     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
298 }
299 
300 /**
301  * @tc.name: testStopInputSession_002
302  * @tc.desc: is broker, not focused app
303  * @tc.type: FUNC
304  * @tc.require:
305  * @tc.author:
306 */
307 HWTEST_F(IdentityCheckerTest, testStopInputSession_002, TestSize.Level0)
308 {
309     IMSA_HILOGI("IdentityCheckerTest testStopInputSession_002 start");
310     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
311     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = false;
312     int32_t ret = IdentityCheckerTest::service_->StopInputSession();
313     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
314 }
315 
316 /**
317  * @tc.name: testStopInputSession_003
318  * @tc.desc: is broker, is focused app
319  * @tc.type: FUNC
320  * @tc.require:
321  * @tc.author:
322 */
323 HWTEST_F(IdentityCheckerTest, testStopInputSession_003, TestSize.Level0)
324 {
325     IMSA_HILOGI("IdentityCheckerTest testStopInputSession_003 start");
326     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
327     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = true;
328     InputClientInfo clientInfo{};
329     int32_t ret = IdentityCheckerTest::service_->StopInputSession();
330     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
331 }
332 
333 /**
334  * @tc.name: testStopInputSession_004
335  * @tc.desc: not broker, is focused app
336  * @tc.type: FUNC
337  * @tc.require:
338  * @tc.author:
339 */
340 HWTEST_F(IdentityCheckerTest, testStopInputSession_004, TestSize.Level0)
341 {
342     IMSA_HILOGI("IdentityCheckerTest testStopInputSession_004 start");
343     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
344     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = true;
345     InputClientInfo clientInfo{};
346     int32_t ret = IdentityCheckerTest::service_->StopInputSession();
347     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
348 }
349 
350 /**
351  * @tc.name: testSetCoreAndAgent_001
352  * @tc.desc: not current ime
353  * @tc.type: FUNC
354  * @tc.require:
355  * @tc.author:
356 */
357 HWTEST_F(IdentityCheckerTest, testSetCoreAndAgent_001, TestSize.Level0)
358 {
359     IMSA_HILOGI("IdentityCheckerTest testSetCoreAndAgent_001 start");
360     service_->identityChecker_ = identityCheckerImpl_;
361     int32_t ret = IdentityCheckerTest::service_->SetCoreAndAgent(nullptr, nullptr);
362     EXPECT_EQ(ret, ErrorCode::ERROR_NOT_CURRENT_IME);
363 }
364 
365 /**
366  * @tc.name: testSetCoreAndAgent_002
367  * @tc.desc: current ime
368  * @tc.type: FUNC
369  * @tc.require:
370  * @tc.author:
371 */
372 HWTEST_F(IdentityCheckerTest, testSetCoreAndAgent_002, TestSize.Level0)
373 {
374     IMSA_HILOGI("IdentityCheckerTest testSetCoreAndAgent_002 start");
375     IdentityCheckerTest::IdentityCheckerMock::isBundleNameValid_ = true;
376     int32_t ret = IdentityCheckerTest::service_->SetCoreAndAgent(nullptr, nullptr);
377     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
378 }
379 
380 /**
381  * @tc.name: testSetCoreAndAgent_003
382  * @tc.desc: not current ime, is a sys_basic native sa
383  * @tc.type: FUNC
384  * @tc.require:
385  * @tc.author:
386 */
387 HWTEST_F(IdentityCheckerTest, testSetCoreAndAgent_003, TestSize.Level0)
388 {
389     IMSA_HILOGI("IdentityCheckerTest testSetCoreAndAgent_003 start");
390     IdentityCheckerTest::IdentityCheckerMock::isBundleNameValid_ = false;
391     IdentityCheckerTest::IdentityCheckerMock::isNativeSa_ = true;
392     int32_t ret = IdentityCheckerTest::service_->SetCoreAndAgent(nullptr, nullptr);
393     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
394 }
395 
396 /**
397  * @tc.name: testUnRegisteredProxyIme_001
398  * @tc.desc: not a sys_basic native sa
399  * @tc.type: FUNC
400  * @tc.require:
401  * @tc.author:
402 */
403 HWTEST_F(IdentityCheckerTest, testUnRegisteredProxyIme_001, TestSize.Level0)
404 {
405     IMSA_HILOGI("IdentityCheckerTest testUnRegisteredProxyIme_001 start");
406     IdentityCheckerTest::IdentityCheckerMock::isNativeSa_ = false;
407     int32_t ret = IdentityCheckerTest::service_->UnRegisteredProxyIme(UnRegisteredType::REMOVE_PROXY_IME, nullptr);
408     EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
409 }
410 
411 /**
412  * @tc.name: testUnRegisteredProxyIme_002
413  * @tc.desc: a sys_basic native sa
414  * @tc.type: FUNC
415  * @tc.require:
416  * @tc.author:
417 */
418 HWTEST_F(IdentityCheckerTest, testUnRegisteredProxyIme_002, TestSize.Level0)
419 {
420     IMSA_HILOGI("IdentityCheckerTest testUnRegisteredProxyIme_002 start");
421     IdentityCheckerTest::IdentityCheckerMock::isNativeSa_ = true;
422     int32_t ret = IdentityCheckerTest::service_->UnRegisteredProxyIme(UnRegisteredType::NONE, nullptr);
423     EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
424 }
425 
426 /**
427  * @tc.name: testIsCurrentIme_001
428  * @tc.desc: not current ime
429  * @tc.type: FUNC
430  * @tc.require:
431  * @tc.author:
432 */
433 HWTEST_F(IdentityCheckerTest, testIsCurrentIme_001, TestSize.Level0)
434 {
435     IMSA_HILOGI("IdentityCheckerTest testIsCurrentIme_001 start");
436     service_->identityChecker_ = identityCheckerImpl_;
437     bool ret = IdentityCheckerTest::service_->IsCurrentIme();
438     EXPECT_FALSE(ret);
439 }
440 
441 /**
442  * @tc.name: testIsCurrentIme_002
443  * @tc.desc: current ime
444  * @tc.type: FUNC
445  * @tc.require:
446  * @tc.author:
447 */
448 HWTEST_F(IdentityCheckerTest, testIsCurrentIme_002, TestSize.Level0)
449 {
450     IMSA_HILOGI("IdentityCheckerTest testIsCurrentIme_002 start");
451     IdentityCheckerTest::IdentityCheckerMock::isBundleNameValid_ = true;
452     bool ret = IdentityCheckerTest::service_->IsCurrentIme();
453     EXPECT_TRUE(ret);
454 }
455 
456 /**
457  * @tc.name: testHideCurrentInput_001
458  * @tc.desc: is broker
459  * @tc.type: FUNC
460  * @tc.require:
461  * @tc.author:
462 */
463 HWTEST_F(IdentityCheckerTest, testHideCurrentInput_001, TestSize.Level0)
464 {
465     IMSA_HILOGI("IdentityCheckerTest testHideCurrentInput_001 start");
466     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
467     int32_t ret = IdentityCheckerTest::service_->HideCurrentInput();
468     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
469 }
470 
471 /**
472  * @tc.name: testHideCurrentInput_002
473  * @tc.desc: is not broker, has no PERMISSION_CONNECT_IME_ABILITY
474  * @tc.type: FUNC
475  * @tc.require:
476  * @tc.author:
477 */
478 HWTEST_F(IdentityCheckerTest, testHideCurrentInput_002, TestSize.Level0)
479 {
480     IMSA_HILOGI("IdentityCheckerTest testHideCurrentInput_002 start");
481     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
482     IdentityCheckerTest::IdentityCheckerMock::hasPermission_ = false;
483     int32_t ret = IdentityCheckerTest::service_->HideCurrentInput();
484     EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
485 }
486 
487 /**
488  * @tc.name: testHideCurrentInput_003
489  * @tc.desc: is not broker, has PERMISSION_CONNECT_IME_ABILITY, not focused app
490  * @tc.type: FUNC
491  * @tc.require:
492  * @tc.author:
493 */
494 HWTEST_F(IdentityCheckerTest, testHideCurrentInput_003, TestSize.Level0)
495 {
496     IMSA_HILOGI("IdentityCheckerTest testHideCurrentInput_003 start");
497     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
498     IdentityCheckerTest::IdentityCheckerMock::hasPermission_ = true;
499     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = false;
500     int32_t ret = IdentityCheckerTest::service_->HideCurrentInput();
501     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
502 }
503 
504 /**
505  * @tc.name: testShowCurrentInput_001
506  * @tc.desc: is broker
507  * @tc.type: FUNC
508  * @tc.require:
509  * @tc.author:
510 */
511 HWTEST_F(IdentityCheckerTest, testShowCurrentInput_001, TestSize.Level0)
512 {
513     IMSA_HILOGI("IdentityCheckerTest testShowCurrentInput_001 start");
514     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
515     int32_t ret = IdentityCheckerTest::service_->ShowCurrentInput();
516     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
517 }
518 
519 /**
520  * @tc.name: testShowCurrentInput_002
521  * @tc.desc: is not broker, has no PERMISSION_CONNECT_IME_ABILITY
522  * @tc.type: FUNC
523  * @tc.require:
524  * @tc.author:
525 */
526 HWTEST_F(IdentityCheckerTest, testShowCurrentInput_002, TestSize.Level0)
527 {
528     IMSA_HILOGI("IdentityCheckerTest testShowCurrentInput_002 start");
529     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
530     IdentityCheckerTest::IdentityCheckerMock::hasPermission_ = false;
531     int32_t ret = IdentityCheckerTest::service_->ShowCurrentInput();
532     EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
533 }
534 
535 /**
536  * @tc.name: testShowCurrentInput_003
537  * @tc.desc: is not broker, has PERMISSION_CONNECT_IME_ABILITY, not focused app
538  * @tc.type: FUNC
539  * @tc.require:
540  * @tc.author:
541 */
542 HWTEST_F(IdentityCheckerTest, testShowCurrentInput_003, TestSize.Level0)
543 {
544     IMSA_HILOGI("IdentityCheckerTest testShowCurrentInput_003 start");
545     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
546     IdentityCheckerTest::IdentityCheckerMock::hasPermission_ = true;
547     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = false;
548     int32_t ret = IdentityCheckerTest::service_->ShowCurrentInput();
549     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
550 }
551 
552 /**
553  * @tc.name: testPanelStatusChange_001
554  * @tc.desc: not current ime
555  * @tc.type: FUNC
556  * @tc.require:
557  * @tc.author:
558 */
559 HWTEST_F(IdentityCheckerTest, testPanelStatusChange_001, TestSize.Level0)
560 {
561     IMSA_HILOGI("IdentityCheckerTest testPanelStatusChange_001 start");
562     service_->identityChecker_ = identityCheckerImpl_;
563     InputWindowStatus status = InputWindowStatus::SHOW;
564     InputWindowInfo windowInfo{};
565     int32_t ret = IdentityCheckerTest::service_->PanelStatusChange(status, windowInfo);
566     EXPECT_EQ(ret, ErrorCode::ERROR_NOT_CURRENT_IME);
567 }
568 
569 /**
570  * @tc.name: testPanelStatusChange_002
571  * @tc.desc: current ime
572  * @tc.type: FUNC
573  * @tc.require:
574  * @tc.author:
575 */
576 HWTEST_F(IdentityCheckerTest, testPanelStatusChange_002, TestSize.Level0)
577 {
578     IMSA_HILOGI("IdentityCheckerTest testPanelStatusChange_002 start");
579     IdentityCheckerTest::IdentityCheckerMock::isBundleNameValid_ = true;
580     InputWindowStatus status = InputWindowStatus::SHOW;
581     InputWindowInfo windowInfo{};
582     int32_t ret = IdentityCheckerTest::service_->PanelStatusChange(status, windowInfo);
583     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
584 }
585 
586 /**
587  * @tc.name: testUpdateListenEventFlag_001
588  * @tc.desc: not system app
589  * @tc.type: FUNC
590  * @tc.require:
591  * @tc.author:
592 */
593 HWTEST_F(IdentityCheckerTest, testUpdateListenEventFlag_001, TestSize.Level0)
594 {
595     IMSA_HILOGI("IdentityCheckerTest testUpdateListenEventFlag_001 start");
596     service_->identityChecker_ = identityCheckerImpl_;
597     InputClientInfo clientInfo{};
598     EventType eventType = IME_SHOW;
599     int32_t ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType);
600     EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION);
601 
602     eventType = IME_HIDE;
603     ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType);
604     EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_SYSTEM_PERMISSION);
605 
606     eventType = IME_CHANGE;
607     ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType);
608     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
609 }
610 
611 /**
612  * @tc.name: testUpdateListenEventFlag_002
613  * @tc.desc: is system app
614  * @tc.type: FUNC
615  * @tc.require:
616  * @tc.author:
617 */
618 HWTEST_F(IdentityCheckerTest, testUpdateListenEventFlag_002, TestSize.Level0)
619 {
620     IMSA_HILOGI("IdentityCheckerTest testUpdateListenEventFlag_002 start");
621     IdentityCheckerTest::IdentityCheckerMock::isSystemApp_ = true;
622     InputClientInfo clientInfo{};
623     EventType eventType = IME_SHOW;
624     int32_t ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType);
625     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
626 
627     eventType = IME_HIDE;
628     ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType);
629     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
630 
631     eventType = IME_CHANGE;
632     ret = IdentityCheckerTest::service_->UpdateListenEventFlag(clientInfo, eventType);
633     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
634 }
635 
636 /**
637  * @tc.name: testDisplayOptionalInputMethod_001
638  * @tc.desc: has no PERMISSION
639  * @tc.type: FUNC
640  * @tc.require:
641  * @tc.author:
642 */
643 HWTEST_F(IdentityCheckerTest, testDisplayOptionalInputMethod_001, TestSize.Level0)
644 {
645     IMSA_HILOGI("IdentityCheckerTest testDisplayOptionalInputMethod_001 start");
646     service_->identityChecker_ = identityCheckerImpl_;
647     int32_t ret = IdentityCheckerTest::service_->DisplayOptionalInputMethod();
648     EXPECT_EQ(ret, ErrorCode::ERROR_EX_SERVICE_SPECIFIC);
649 }
650 
651 /**
652  * @tc.name: testSwitchInputMethod_001
653  * @tc.desc: has no PERMISSION_CONNECT_IME_ABILITY, and not currentIme switch subtype
654  * @tc.type: FUNC
655  * @tc.require:
656  * @tc.author:
657 */
658 HWTEST_F(IdentityCheckerTest, testSwitchInputMethod_001, TestSize.Level0)
659 {
660     IMSA_HILOGI("IdentityCheckerTest testSwitchInputMethod_001 start");
661     service_->identityChecker_ = identityCheckerImpl_;
662     int32_t ret = IdentityCheckerTest::service_->SwitchInputMethod(
663         CURRENT_BUNDLENAME, CURRENT_SUBNAME, SwitchTrigger::CURRENT_IME);
664     EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
665 }
666 
667 /**
668  * @tc.name: testSwitchInputMethod_002
669  * @tc.desc: has no PERMISSION_CONNECT_IME_ABILITY, currentIme switch subtype
670  * @tc.type: FUNC
671  * @tc.require:
672  * @tc.author:
673 */
674 HWTEST_F(IdentityCheckerTest, testSwitchInputMethod_002, TestSize.Level0)
675 {
676     IMSA_HILOGI("IdentityCheckerTest testSwitchInputMethod_002 start");
677     IdentityCheckerTest::IdentityCheckerMock::hasPermission_ = false;
678     IdentityCheckerTest::IdentityCheckerMock::isBundleNameValid_ = true;
679     int32_t ret = IdentityCheckerTest::service_->SwitchInputMethod(
680         CURRENT_BUNDLENAME, CURRENT_SUBNAME, SwitchTrigger::CURRENT_IME);
681     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
682 }
683 
684 /**
685  * @tc.name: testSwitchInputMethod_003
686  * @tc.desc: has PERMISSION_CONNECT_IME_ABILITY, not currentIme switch subtype
687  * @tc.type: FUNC
688  * @tc.require:
689  * @tc.author:
690 */
691 HWTEST_F(IdentityCheckerTest, testSwitchInputMethod_003, TestSize.Level0)
692 {
693     IMSA_HILOGI("IdentityCheckerTest testSwitchInputMethod_003 start");
694     IdentityCheckerTest::IdentityCheckerMock::hasPermission_ = true;
695     IdentityCheckerTest::IdentityCheckerMock::isBundleNameValid_ = false;
696     int32_t ret = IdentityCheckerTest::service_->SwitchInputMethod(
697         CURRENT_BUNDLENAME, CURRENT_SUBNAME, SwitchTrigger::CURRENT_IME);
698     EXPECT_EQ(ret, ErrorCode::NO_ERROR);
699 }
700 
701 /**
702  * @tc.name: testHideCurrentInputDeprecated_001
703  * @tc.desc: is broker
704  * @tc.type: FUNC
705  * @tc.require:
706  * @tc.author:
707 */
708 HWTEST_F(IdentityCheckerTest, testHideCurrentInputDeprecated_001, TestSize.Level0)
709 {
710     IMSA_HILOGI("IdentityCheckerTest testHideCurrentInputDeprecated_001 start");
711     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
712     int32_t ret = IdentityCheckerTest::service_->HideCurrentInputDeprecated();
713     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
714 }
715 
716 /**
717  * @tc.name: testHideCurrentInputDeprecated_002
718  * @tc.desc: is not broker, not focused app
719  * @tc.type: FUNC
720  * @tc.require:
721  * @tc.author:
722 */
723 HWTEST_F(IdentityCheckerTest, testHideCurrentInputDeprecated_002, TestSize.Level0)
724 {
725     IMSA_HILOGI("IdentityCheckerTest testHideCurrentInputDeprecated_002 start");
726     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
727     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = false;
728     int32_t ret = IdentityCheckerTest::service_->HideCurrentInputDeprecated();
729     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
730 }
731 
732 /**
733  * @tc.name: testHideCurrentInputDeprecated_003
734  * @tc.desc: is not broker, is focused app
735  * @tc.type: FUNC
736  * @tc.require:
737  * @tc.author:
738 */
739 HWTEST_F(IdentityCheckerTest, testHideCurrentInputDeprecated_003, TestSize.Level0)
740 {
741     IMSA_HILOGI("IdentityCheckerTest testHideCurrentInputDeprecated_003 start");
742     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
743     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = true;
744     int32_t ret = IdentityCheckerTest::service_->HideCurrentInputDeprecated();
745     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
746 }
747 
748 /**
749  * @tc.name: testShowCurrentInputDeprecated_001
750  * @tc.desc: is broker
751  * @tc.type: FUNC
752  * @tc.require:
753  * @tc.author:
754 */
755 HWTEST_F(IdentityCheckerTest, testShowCurrentInputDeprecated_001, TestSize.Level0)
756 {
757     IMSA_HILOGI("IdentityCheckerTest testShowCurrentInputDeprecated_001 start");
758     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = true;
759     int32_t ret = IdentityCheckerTest::service_->ShowCurrentInputDeprecated();
760     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
761 }
762 
763 /**
764  * @tc.name: testShowCurrentInputDeprecated_002
765  * @tc.desc: is not broker, not focused app
766  * @tc.type: FUNC
767  * @tc.require:
768  * @tc.author:
769 */
770 HWTEST_F(IdentityCheckerTest, testShowCurrentInputDeprecated_002, TestSize.Level0)
771 {
772     IMSA_HILOGI("IdentityCheckerTest testShowCurrentInputDeprecated_002 start");
773     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
774     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = false;
775     int32_t ret = IdentityCheckerTest::service_->ShowCurrentInputDeprecated();
776     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOCUSED);
777 }
778 
779 /**
780  * @tc.name: testShowCurrentInputDeprecated_003
781  * @tc.desc: is not broker, is focused app
782  * @tc.type: FUNC
783  * @tc.require:
784  * @tc.author:
785 */
786 HWTEST_F(IdentityCheckerTest, testShowCurrentInputDeprecated_003, TestSize.Level0)
787 {
788     IMSA_HILOGI("IdentityCheckerTest testShowCurrentInputDeprecated_003 start");
789     IdentityCheckerTest::IdentityCheckerMock::isBroker_ = false;
790     IdentityCheckerTest::IdentityCheckerMock::isFocused_ = true;
791     int32_t ret = IdentityCheckerTest::service_->ShowCurrentInputDeprecated();
792     EXPECT_EQ(ret, ErrorCode::ERROR_CLIENT_NOT_FOUND);
793 }
794 } // namespace MiscServices
795 } // namespace OHOS