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 #include <gtest/gtest.h>
17 #define private public
18 #define protected public
19 #include "ability_manager_service.h"
20 #include "interceptor/ability_jump_interceptor.h"
21 #include "interceptor/ecological_rule_interceptor.h"
22 #include "interceptor/disposed_rule_interceptor.h"
23 #undef private
24 #undef protected
25 
26 #include "bundlemgr/mock_bundle_manager.h"
27 #include "interceptor/ability_interceptor_executer.h"
28 #include "interceptor/control_interceptor.h"
29 #include "interceptor/crowd_test_interceptor.h"
30 #include "permission_constants.h"
31 #include "start_ability_utils.h"
32 
33 using namespace testing;
34 using namespace testing::ext;
35 using namespace OHOS::AppExecFwk;
36 
37 namespace {
38 const std::string BUNDLE_NAME = "testBundle";
39 const std::string ATOMIC_SERVICE_BUNDLE_NAME = "com.test.atomicservice";
40 const std::string PASS_ABILITY_NAME = "com.test.pass";
41 const std::string DENY_ABILITY_NAME = "com.test.deny";
42 const std::string JUMP_ABILITY_NAME = "com.test.jump";
43 }
44 
45 namespace OHOS {
46 namespace AAFwk {
47 class AbilityInterceptorTest : public testing::Test {
48 public:
49     static void SetUpTestCase();
50     static void TearDownTestCase();
51     void SetUp();
52     void TearDown();
53 
54 public:
55 };
56 
SetUpTestCase()57 void AbilityInterceptorTest::SetUpTestCase()
58 {
59     GTEST_LOG_(INFO) << "AbilityInterceptorTest SetUpTestCase called";
60     OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
61 
62     OHOS::DelayedSingleton<SaMgrClient>::GetInstance()->RegisterSystemAbility(
63         OHOS::BUNDLE_MGR_SERVICE_SYS_ABILITY_ID, new BundleMgrService());
64 }
65 
TearDownTestCase()66 void AbilityInterceptorTest::TearDownTestCase()
67 {
68     GTEST_LOG_(INFO) << "AbilityInterceptorTest TearDownTestCase called";
69     OHOS::DelayedSingleton<SaMgrClient>::DestroyInstance();
70 }
71 
SetUp()72 void AbilityInterceptorTest::SetUp()
73 {}
74 
TearDown()75 void AbilityInterceptorTest::TearDown()
76 {}
77 
78 HWTEST_F(AbilityInterceptorTest, CreateExecuter_001, TestSize.Level1)
79 {
80     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
81     EXPECT_NE(executer, nullptr);
82 }
83 
84 /**
85  * @tc.name: AbilityInterceptorTest_CrowdTestInterceptor_001
86  * @tc.desc: CrowdTestInterceptor
87  * @tc.type: FUNC
88  * @tc.require: issueI5I0DY
89  */
90 HWTEST_F(AbilityInterceptorTest, CrowdTestInterceptor_001, TestSize.Level1)
91 {
92     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
93     Want want;
94     ElementName element("", "com.test.crowdtest", "CrowdtestExpired");
95     want.SetElement(element);
96     int requestCode = 0;
97     int userId = 100;
98     executer->AddInterceptor("CrowdTest", std::make_shared<CrowdTestInterceptor>());
99     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
100     int result = executer->DoProcess(param);
101     EXPECT_EQ(result, ERR_OK);
102 }
103 
104 /**
105  * @tc.name: AbilityInterceptorTest_CrowdTestInterceptor_002
106  * @tc.desc: CrowdTestInterceptor
107  * @tc.type: FUNC
108  * @tc.require: issueI5I0DY
109  */
110 HWTEST_F(AbilityInterceptorTest, CrowdTestInterceptor_002, TestSize.Level1)
111 {
112     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
113     Want want;
114     ElementName element("", "com.test.crowdtest", "CrowdtestExpired");
115     want.SetElement(element);
116     int userId = 100;
117     executer->AddInterceptor("CrowdTest", std::make_shared<CrowdTestInterceptor>());
118     AbilityInterceptorParam param = AbilityInterceptorParam(want, 0, userId, false, nullptr);
119     int result = executer->DoProcess(param);
120     EXPECT_EQ(result, ERR_OK);
121 }
122 
123 /**
124  * @tc.name: AbilityInterceptorTest_ControlInterceptor_001
125  * @tc.desc: ControlInterceptor
126  * @tc.type: FUNC
127  * @tc.require: issueI5QT7P
128  */
129 HWTEST_F(AbilityInterceptorTest, ControlInterceptor_001, TestSize.Level1)
130 {
131     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
132     Want want;
133     ElementName element("", "com.test.control", "MainAbility");
134     want.SetElement(element);
135     int requestCode = 0;
136     int userId = 100;
137     executer->AddInterceptor("Control", std::make_shared<ControlInterceptor>());
138     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
139     int result = executer->DoProcess(param);
140     EXPECT_EQ(result, ERR_OK);
141 }
142 
143 /**
144  * @tc.name: AbilityInterceptorTest_ControlInterceptor_002
145  * @tc.desc: ControlInterceptor
146  * @tc.type: FUNC
147  * @tc.require: issueI5QT7P
148  */
149 HWTEST_F(AbilityInterceptorTest, ControlInterceptor_002, TestSize.Level1)
150 {
151     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
152     Want want;
153     ElementName element("", "com.test.control", "MainAbility");
154     want.SetElement(element);
155     int userId = 100;
156     executer->AddInterceptor("Control", std::make_shared<ControlInterceptor>());
157     AbilityInterceptorParam param = AbilityInterceptorParam(want, 0, userId, false, nullptr);
158     int result = executer->DoProcess(param);
159     EXPECT_EQ(result, ERR_OK);
160 }
161 
162 /**
163  * @tc.name: AbilityInterceptorTest_ControlInterceptor_003
164  * @tc.desc: ControlInterceptor
165  * @tc.type: FUNC
166  * @tc.require: issueI5QT7P
167  */
168 HWTEST_F(AbilityInterceptorTest, ControlInterceptor_003, TestSize.Level1)
169 {
170     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
171     Want want;
172     ElementName element("", "com.test.control2", "MainAbility");
173     want.SetElement(element);
174     int userId = 100;
175     executer->AddInterceptor("Control", std::make_shared<ControlInterceptor>());
176     AbilityInterceptorParam param = AbilityInterceptorParam(want, 0, userId, false, nullptr);
177     int result = executer->DoProcess(param);
178     EXPECT_EQ(result, ERR_OK);
179 }
180 
181 /**
182  * @tc.name: AbilityInterceptorTest_ControlInterceptor_004
183  * @tc.desc: ControlInterceptor
184  * @tc.type: FUNC
185  * @tc.require: issueI5QT7P
186  */
187 HWTEST_F(AbilityInterceptorTest, ControlInterceptor_004, TestSize.Level1)
188 {
189     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
190     Want want;
191     ElementName element("", "com.test.control3", "MainAbility");
192     want.SetElement(element);
193     int userId = 100;
194     executer->AddInterceptor("Control", std::make_shared<ControlInterceptor>());
195     AbilityInterceptorParam param = AbilityInterceptorParam(want, 0, userId, false, nullptr);
196     int result = executer->DoProcess(param);
197     EXPECT_EQ(result, ERR_OK);
198 }
199 
200 /**
201  * @tc.name: AbilityInterceptorTest_ControlInterceptor_005
202  * @tc.desc: ControlInterceptor
203  * @tc.type: FUNC
204  * @tc.require: issueI5QT7P
205  */
206 HWTEST_F(AbilityInterceptorTest, ControlInterceptor_005, TestSize.Level1)
207 {
208     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
209     Want want;
210     ElementName element("", "com.test.control", "MainAbility");
211     want.SetElement(element);
212     int userId = 100;
213     auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
214     // make appControlRule become nullptr by crowdtest interceptor
215     executer->AddInterceptor("CrowdTest", std::make_shared<CrowdTestInterceptor>());
216     executer->AddInterceptor("Control", std::make_shared<ControlInterceptor>());
217     AbilityInterceptorParam param = AbilityInterceptorParam(want, 0, userId, false, nullptr);
218     int result = executer->DoProcess(param);
219     EXPECT_EQ(result, ERR_OK);
220 }
221 
222 /**
223  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_001
224  * @tc.desc: DisposedRuleInterceptor
225  * @tc.type: FUNC
226  * @tc.require: issueI8D3OD
227  */
228 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_001, TestSize.Level1)
229 {
230     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
231     Want want;
232     ElementName element("", "com.acts.disposedrulehap", "ServiceAbility2", "entry");
233     want.SetElement(element);
234     int requestCode = 0;
235     int userId = 100;
236     executer->AddInterceptor("DisposedRule", std::make_shared<DisposedRuleInterceptor>());
237     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, false, nullptr);
238     int result = executer->DoProcess(param);
239     EXPECT_EQ(result, ERR_OK);
240 }
241 
242 /**
243  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_002
244  * @tc.desc: DisposedRuleInterceptor
245  * @tc.type: FUNC
246  * @tc.require: issueI8D3OD
247  */
248 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_002, TestSize.Level1)
249 {
250     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
251     Want want;
252     ElementName element("", "com.acts.disposedrulehap", "MainAbility2", "entry");
253     want.SetElement(element);
254     int requestCode = 0;
255     int userId = 100;
256     executer->AddInterceptor("Disposed", std::make_shared<DisposedRuleInterceptor>());
257     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
258     int result = executer->DoProcess(param);
259     EXPECT_EQ(result, ERR_OK);
260 }
261 
262 /**
263  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_003
264  * @tc.desc: DisposedRuleInterceptor
265  * @tc.type: FUNC
266  * @tc.require: issueI8D3OD
267  */
268 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_003, TestSize.Level1)
269 {
270     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
271     Want want;
272     ElementName element("", "com.acts.disposedrulehap", "MainAbility3", "entry");
273     want.SetElement(element);
274     int requestCode = 0;
275     int userId = 100;
276     executer->AddInterceptor("DisposedRule", std::make_shared<DisposedRuleInterceptor>());
277     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
278     int result = executer->DoProcess(param);
279     EXPECT_EQ(result, ERR_OK);
280 }
281 
282 /**
283  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_004
284  * @tc.desc: DisposedRuleInterceptor
285  * @tc.type: FUNC
286  * @tc.require: issueI8D3OD
287  */
288 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_004, TestSize.Level1)
289 {
290     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
291     Want want;
292     ElementName element("", "com.acts.disposedrulehap", "MainAbility4", "entry");
293     want.SetElement(element);
294     int requestCode = 0;
295     int userId = 100;
296     executer->AddInterceptor("DisposedRule", std::make_shared<DisposedRuleInterceptor>());
297     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
298     int result = executer->DoProcess(param);
299     EXPECT_EQ(result, ERR_OK);
300 }
301 
302 /**
303  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_005
304  * @tc.desc: DisposedRuleInterceptor
305  * @tc.type: FUNC
306  * @tc.require: issueI8D3OD
307  */
308 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_005, TestSize.Level1)
309 {
310     std::shared_ptr<AbilityInterceptorExecuter> executer = std::make_shared<AbilityInterceptorExecuter>();
311     Want want;
312     ElementName element("", "com.test.disposedrule", "MainAbility", "entry");
313     want.SetElement(element);
314     int requestCode = 0;
315     int userId = 100;
316     executer->AddInterceptor("DisposedRule", std::make_shared<DisposedRuleInterceptor>());
317     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
318     int result = executer->DoProcess(param);
319     EXPECT_EQ(result, ERR_OK);
320 }
321 
322 /**
323  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_006
324  * @tc.desc: DisposedRuleInterceptor
325  * @tc.type: FUNC
326  * @tc.require: No
327  */
328 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_006, TestSize.Level1)
329 {
330     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
331     Want want;
332     ElementName element("", "com.test.disposedrule", "MainAbility5", "entry");
333     want.SetElement(element);
334     int requestCode = 0;
335     int userId = 100;
336     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
337     int result = executer->DoProcess(param);
338     EXPECT_EQ(result, ERR_OK);
339 }
340 
341 /**
342  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_007
343  * @tc.desc: DisposedRuleInterceptor
344  * @tc.type: FUNC
345  * @tc.require: No
346  */
347 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_007, TestSize.Level1)
348 {
349     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
350     Want want;
351     ElementName element("", "com.test.disposedrule", "MainAbility6", "entry");
352     want.SetElement(element);
353     AppExecFwk::DisposedRule disposedRule;
354     bool result = executer->CheckDisposedRule(want, disposedRule);
355     EXPECT_EQ(result, false);
356 }
357 
358 /**
359  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_008
360  * @tc.desc: DisposedRuleInterceptor
361  * @tc.type: FUNC
362  * @tc.require: No
363  */
364 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_008, TestSize.Level1)
365 {
366     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
367     Want want;
368     ElementName element("", "com.test.disposedrule", "MainAbility6", "entry");
369     want.SetElement(element);
370     AppExecFwk::DisposedRule disposedRule;
371     disposedRule.disposedType = AppExecFwk::DisposedType::NON_BLOCK;
372     bool result = executer->CheckDisposedRule(want, disposedRule);
373     EXPECT_EQ(result, false);
374 }
375 
376 /**
377  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_009
378  * @tc.desc: DisposedRuleInterceptor
379  * @tc.type: FUNC
380  * @tc.require: No
381  */
382 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_009, TestSize.Level1)
383 {
384     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
385     Want want;
386     ElementName element("", "com.test.disposedrule", "MainAbility6", "entry");
387     want.SetElement(element);
388     AppExecFwk::DisposedRule disposedRule;
389     disposedRule.disposedType = AppExecFwk::DisposedType::BLOCK_APPLICATION;
390     bool result = executer->CheckDisposedRule(want, disposedRule);
391     EXPECT_EQ(result, false);
392 }
393 
394 /**
395  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_010
396  * @tc.desc: DisposedRuleInterceptor
397  * @tc.type: FUNC
398  * @tc.require: No
399  */
400 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_010, TestSize.Level1)
401 {
402     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
403     Want want;
404     ElementName element("", "com.test.disposedrule", "MainAbility6", "entry");
405     want.SetElement(element);
406     AppExecFwk::DisposedRule disposedRule;
407     disposedRule.disposedType = AppExecFwk::DisposedType::BLOCK_APPLICATION;
408     disposedRule.controlType = AppExecFwk::ControlType::ALLOWED_LIST;
409     bool result = executer->CheckDisposedRule(want, disposedRule);
410     EXPECT_EQ(result, false);
411 }
412 
413 /**
414  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_011
415  * @tc.desc: DisposedRuleInterceptor
416  * @tc.type: FUNC
417  * @tc.require: No
418  */
419 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_011, TestSize.Level1)
420 {
421     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
422     Want want;
423     ElementName element("", "com.test.disposedrule", "MainAbility6", "entry");
424     want.SetElement(element);
425     AppExecFwk::DisposedRule disposedRule;
426     disposedRule.disposedType = AppExecFwk::DisposedType::BLOCK_APPLICATION;
427     disposedRule.controlType = AppExecFwk::ControlType::DISALLOWED_LIST;
428     bool result = executer->CheckDisposedRule(want, disposedRule);
429     EXPECT_EQ(result, true);
430 }
431 
432 /**
433  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_012
434  * @tc.desc: DisposedRuleInterceptor
435  * @tc.type: FUNC
436  * @tc.require: No
437  */
438 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_012, TestSize.Level1)
439 {
440     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
441     Want want;
442     AppExecFwk::DisposedRule disposedRule;
443     ErrCode result = executer->StartNonBlockRule(want, disposedRule);
444     EXPECT_EQ(result, ERR_OK);
445 }
446 
447 /**
448  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_013
449  * @tc.desc: DisposedRuleInterceptor
450  * @tc.type: FUNC
451  * @tc.require: No
452  */
453 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_013, TestSize.Level1)
454 {
455     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
456     std::string bundleName = "com.example.disposedruletest1";
457     Want want;
458     want.SetBundle(bundleName);
459     DisposedRule disposedRule;
460     ErrCode result = executer->StartNonBlockRule(want, disposedRule);
461     EXPECT_EQ(result, ERR_OK);
462 }
463 
464 /**
465  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_014
466  * @tc.desc: DisposedRuleInterceptor
467  * @tc.type: FUNC
468  * @tc.require: No
469  */
470 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_014, TestSize.Level1)
471 {
472     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
473     Want want;
474     ElementName element("", "com.acts.disposedrulehap", "MainAbility", "entry");
475     want.SetElement(element);
476     int requestCode = 0;
477     int userId = 100;
478     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
479     executer->DoProcess(param);
480     EXPECT_NE(executer->GetAppMgr(), nullptr);
481 }
482 
483 /**
484  * @tc.name: AbilityInterceptorTest_DisposedRuleInterceptor_015
485  * @tc.desc: DisposedRuleInterceptor
486  * @tc.type: FUNC
487  * @tc.require: No
488  */
489 HWTEST_F(AbilityInterceptorTest, DisposedRuleInterceptor_015, TestSize.Level1)
490 {
491     std::shared_ptr<DisposedRuleInterceptor> executer = std::make_shared<DisposedRuleInterceptor>();
492     std::string bundleName = "com.example.disposedruletest";
493     Want want;
494     want.SetBundle(bundleName);
495     sptr<IRemoteObject> callerToken;
496     ErrCode result = executer->CreateModalUIExtension(want, callerToken);
497     EXPECT_EQ(result, INNER_ERR);
498 }
499 
500 /**
501  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_001
502  * @tc.desc: DoProcess
503  * @tc.type: FUNC
504  * @tc.require: No
505  */
506 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_001, TestSize.Level1)
507 {
508     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
509     Want want;
510     int requestCode = 0;
511     int userId = 100;
512     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, false, nullptr);
513     int result = interceptor->DoProcess(param);
514     EXPECT_EQ(result, ERR_OK);
515 }
516 
517 /**
518  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_002
519  * @tc.desc: DoProcess
520  * @tc.type: FUNC
521  * @tc.require: No
522  */
523 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_002, TestSize.Level1)
524 {
525     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
526     std::string bundleName = "interceptor_callerBundleName";
527     Want want;
528     want.SetBundle(bundleName);
529     int requestCode = 0;
530     int userId = 100;
531     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
532     int result = interceptor->DoProcess(param);
533     EXPECT_EQ(result, ERR_OK);
534 }
535 
536 /**
537  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_003
538  * @tc.desc: DoProcess
539  * @tc.type: FUNC
540  * @tc.require: No
541  */
542 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_003, TestSize.Level1)
543 {
544     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
545     Want want;
546     ElementName element("", "com.test.jumpinterceptor", "MainAbility", "entry");
547     want.SetElement(element);
548     int requestCode = 1;
549     int userId = 100;
550     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, nullptr);
551     int result = interceptor->DoProcess(param);
552     EXPECT_EQ(result, ERR_OK);
553 }
554 
555 /**
556  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_004
557  * @tc.desc: CheckControl
558  * @tc.type: FUNC
559  * @tc.require: No
560  */
561 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_004, TestSize.Level1)
562 {
563     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
564     std::shared_ptr<AppExecFwk::BundleMgrHelper> bundleMgrHelper = std::make_shared<AppExecFwk::BundleMgrHelper>();
565     Want want;
566     int32_t userId = 10;
567     AppExecFwk::AppJumpControlRule controlRule;
568     bool result = interceptor->CheckControl(bundleMgrHelper, want, userId, controlRule);
569     EXPECT_EQ(result, false);
570 }
571 
572 /**
573  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_005
574  * @tc.desc: CheckControl
575  * @tc.type: FUNC
576  * @tc.require: No
577  */
578 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_005, TestSize.Level1)
579 {
580     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
581     std::shared_ptr<AppExecFwk::BundleMgrHelper> bundleMgrHelper = std::make_shared<AppExecFwk::BundleMgrHelper>();
582     std::string bundleName = "interceptor_callerBundleName";
583     Want want;
584     int32_t userId = 10;
585     AppExecFwk::AppJumpControlRule controlRule;
586     bool result = interceptor->CheckControl(bundleMgrHelper, want, userId, controlRule);
587     EXPECT_EQ(result, false);
588 }
589 
590 /**
591  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_006
592  * @tc.desc: CheckControl
593  * @tc.type: FUNC
594  * @tc.require: No
595  */
596 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_006, TestSize.Level1)
597 {
598     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
599     std::shared_ptr<AppExecFwk::BundleMgrHelper> bundleMgrHelper = std::make_shared<AppExecFwk::BundleMgrHelper>();
600     std::string bundleName = "interceptor_callerBundleName";
601     Want want;
602     want.SetBundle(bundleName);
603     int32_t userId = 10;
604     AppExecFwk::AppJumpControlRule controlRule;
605     controlRule.callerPkg = "interceptor_callerBundleName";
606     bool result = interceptor->CheckControl(bundleMgrHelper, want, userId, controlRule);
607     EXPECT_EQ(result, false);
608 }
609 
610 /**
611  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_007
612  * @tc.desc: CheckControl
613  * @tc.type: FUNC
614  * @tc.require: No
615  */
616 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_007, TestSize.Level1)
617 {
618     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
619     std::shared_ptr<AppExecFwk::BundleMgrHelper> bundleMgrHelper = std::make_shared<AppExecFwk::BundleMgrHelper>();
620     std::string bundleName = "BundleName";
621     Want want;
622     want.SetBundle(bundleName);
623     int32_t userId = 10;
624     AppExecFwk::AppJumpControlRule controlRule;
625     controlRule.callerPkg = "interceptor_callerBundleName";
626     bool result = interceptor->CheckControl(bundleMgrHelper, want, userId, controlRule);
627     EXPECT_EQ(result, false);
628 }
629 
630 /**
631  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_008
632  * @tc.desc: CheckIfJumpExempt
633  * @tc.type: FUNC
634  * @tc.require: No
635  */
636 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_008, TestSize.Level1)
637 {
638     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
639     AppExecFwk::AppJumpControlRule controlRule;
640     controlRule.callerPkg = "interceptor_callerBundleName";
641     int32_t userId = 10;
642     bool result = interceptor->CheckIfJumpExempt(controlRule, userId);
643     EXPECT_EQ(result, false);
644 }
645 
646 /**
647  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_009
648  * @tc.desc: CheckIfJumpExempt
649  * @tc.type: FUNC
650  * @tc.require: No
651  */
652 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_009, TestSize.Level1)
653 {
654     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
655     AppExecFwk::AppJumpControlRule controlRule;
656     controlRule.targetPkg = "interceptor_callerBundleName";
657     int32_t userId = 10;
658     bool result = interceptor->CheckIfJumpExempt(controlRule, userId);
659     EXPECT_EQ(result, false);
660 }
661 
662 /**
663  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_010
664  * @tc.desc: CheckIfExemptByBundleName
665  * @tc.type: FUNC
666  * @tc.require: No
667  */
668 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_010, TestSize.Level1)
669 {
670     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
671     std::string bundleName = "interceptor_callerBundleName";
672     std::string permission = PermissionConstants::PERMISSION_EXEMPT_AS_CALLER;
673     int32_t userId = 10;
674     bool result = interceptor->CheckIfExemptByBundleName(bundleName, permission, userId);
675     EXPECT_EQ(result, false);
676 }
677 
678 /**
679  * @tc.name: AbilityInterceptorTest_AbilityJumpInterceptor_011
680  * @tc.desc: CheckIfExemptByBundleName
681  * @tc.type: FUNC
682  * @tc.require: No
683  */
684 HWTEST_F(AbilityInterceptorTest, AbilityJumpInterceptor_011, TestSize.Level1)
685 {
686     std::shared_ptr<AbilityJumpInterceptor> interceptor = std::make_shared<AbilityJumpInterceptor>();
687     std::string bundleName = "interceptor_callerBundleName";
688     Want want;
689     want.SetBundle(bundleName);
690     int32_t abilityuserId = 0;
691     int32_t appIndex = 0;
692     StartAbilityUtils::startAbilityInfo =  StartAbilityInfo::CreateStartExtensionInfo(want,
693             abilityuserId, appIndex);
694     std::string permission = PermissionConstants::PERMISSION_EXEMPT_AS_CALLER;
695     int32_t userId = 10;
696     bool result = interceptor->CheckIfExemptByBundleName(bundleName, permission, userId);
697     EXPECT_EQ(result, false);
698 }
699 
700 /**
701  * @tc.name: AbilityInterceptorTest_EcologicalRuleInterceptor_001
702  * @tc.desc: DoProcess
703  * @tc.type: FUNC
704  * @tc.require: No
705  */
706 HWTEST_F(AbilityInterceptorTest, EcologicalRuleInterceptor_001, TestSize.Level1)
707 {
708     std::shared_ptr<EcologicalRuleInterceptor> interceptor = std::make_shared<EcologicalRuleInterceptor>();
709     Want want;
710     int requestCode = 0;
711     int userId = 100;
712     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, false, nullptr);
713     ErrCode result = interceptor->DoProcess(param);
714     EXPECT_EQ(result, ERR_OK);
715 }
716 
717 /**
718  * @tc.name: AbilityInterceptorTest_EcologicalRuleInterceptor_002
719  * @tc.desc: DoProcess
720  * @tc.type: FUNC
721  * @tc.require: No
722  */
723 HWTEST_F(AbilityInterceptorTest, EcologicalRuleInterceptor_002, TestSize.Level1)
724 {
725     std::shared_ptr<EcologicalRuleInterceptor> interceptor = std::make_shared<EcologicalRuleInterceptor>();
726     std::string bundleName = "com.ohos.sceneboard";
727     Want want;
728     want.SetBundle(bundleName);
729     int requestCode = 0;
730     int userId = 100;
731     sptr<IRemoteObject> token;
732     AbilityInterceptorParam param = AbilityInterceptorParam(want, requestCode, userId, true, token);
733     ErrCode result = interceptor->DoProcess(param);
734     EXPECT_EQ(result, ERR_OK);
735 }
736 
737 /**
738  * @tc.name: AbilityInterceptorTest_EcologicalRuleInterceptor_003
739  * @tc.desc: DoProcess
740  * @tc.type: FUNC
741  * @tc.require: No
742  */
743 HWTEST_F(AbilityInterceptorTest, EcologicalRuleInterceptor_003, TestSize.Level1)
744 {
745     std::shared_ptr<EcologicalRuleInterceptor> interceptor = std::make_shared<EcologicalRuleInterceptor>();
746     Want want;
747     int userId = 100;
748     bool result = interceptor->DoProcess(want, userId);
749     EXPECT_EQ(result, true);
750 }
751 } // namespace AAFwk
752 } // namespace OHOS
753