• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 "cache_process_manager.h"
20 #undef private
21 #undef protected
22 #include "mock_app_mgr_service_inner.h"
23 #include "mock_ability_token.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS {
29 namespace AppExecFwk {
30 
31 const std::string ABILITY_RECORD_NAME = "Ability_Name_Z";
32 const std::string DEFAULT_BUNDLE_NAME = "com.tdd.cacheprocessmanager";
33 const int32_t DEFAULT_UID = 101010;
34 
35 class CacheProcessManagerTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp() override;
40     void TearDown() override;
41     std::shared_ptr<AppRunningRecord> MockAppRecord(int apiLevel = 12);
42     int recordId = 0;
43 };
44 
45 
SetUpTestCase(void)46 void CacheProcessManagerTest::SetUpTestCase(void)
47 {}
48 
TearDownTestCase(void)49 void CacheProcessManagerTest::TearDownTestCase(void)
50 {}
51 
SetUp()52 void CacheProcessManagerTest::SetUp()
53 {}
54 
TearDown()55 void CacheProcessManagerTest::TearDown()
56 {}
57 
MockAppRecord(int apiLevel)58 std::shared_ptr<AppRunningRecord> CacheProcessManagerTest::MockAppRecord(int apiLevel)
59 {
60     std::shared_ptr<ApplicationInfo> appInfo = std::make_shared<ApplicationInfo>();
61     appInfo->bundleName = DEFAULT_BUNDLE_NAME;
62     appInfo->uid = DEFAULT_UID;
63     appInfo->accessTokenId = 1;
64     appInfo->apiTargetVersion = apiLevel;
65     std::shared_ptr<AppRunningRecord> appRecord = std::make_shared<AppRunningRecord>(appInfo, recordId++, "process");
66     std::shared_ptr<PriorityObject> priorityObject = std::make_shared<PriorityObject>();
67     priorityObject->SetPid(1);
68     appRecord->priorityObject_ = priorityObject;
69     appRecord->SetUid(DEFAULT_UID);
70     appRecord->SetState(ApplicationState::APP_STATE_CREATE);
71     appRecord->SetContinuousTaskAppState(false);
72     appRecord->SetKeepAliveEnableState(false);
73     appRecord->SetEmptyKeepAliveAppState(false);
74     appRecord->SetRequestProcCode(1);
75     appRecord->isFocused_ = false;
76     return appRecord;
77 }
78 /**
79  * @tc.name: CacheProcessManager_QueryEnableProcessCache_0100
80  * @tc.desc: Test the state of QueryEnableProcessCache
81  * @tc.type: FUNC
82  */
83 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_QueryEnableProcessCache_0100, TestSize.Level1)
84 {
85     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
86     EXPECT_NE(cacheProcMgr, nullptr);
87     cacheProcMgr->maxProcCacheNum_ = 0;
88     cacheProcMgr->warmStartProcesEnable_  = false;
89     EXPECT_EQ(cacheProcMgr->QueryEnableProcessCache(), false);
90 }
91 
92 /**
93  * @tc.name: CacheProcessManager_QueryEnableProcessCache_0200
94  * @tc.desc: Test the state of QueryEnableProcessCache
95  * @tc.type: FUNC
96  */
97 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_QueryEnableProcessCache_0200, TestSize.Level1)
98 {
99     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
100     EXPECT_NE(cacheProcMgr, nullptr);
101     cacheProcMgr->maxProcCacheNum_ = 100;
102     cacheProcMgr->warmStartProcesEnable_  = false;
103     EXPECT_EQ(cacheProcMgr->QueryEnableProcessCache(), true);
104 }
105 
106 /**
107  * @tc.name: CacheProcessManager_SetAppMgr_0100
108  * @tc.desc: Test the state of SetAppMgr
109  * @tc.type: FUNC
110  */
111 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_SetAppMgr_0100, TestSize.Level1)
112 {
113     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
114     auto appMgrInner = std::make_shared<MockAppMgrServiceInner>();
115     EXPECT_NE(cacheProcMgr, nullptr);
116     cacheProcMgr->SetAppMgr(appMgrInner);
117     EXPECT_NE(appMgrInner, nullptr);
118 }
119 
120 /**
121  * @tc.name: CacheProcessManager_PenddingCacheProcess_0100
122  * @tc.desc: Test the state of PenddingCacheProcess
123  * @tc.type: FUNC
124  */
125 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_PenddingCacheProcess_0100, TestSize.Level1)
126 {
127     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
128     EXPECT_NE(cacheProcMgr, nullptr);
129     cacheProcMgr->maxProcCacheNum_ = 2;
130     // keepalive not allowed
131     auto appRecord = MockAppRecord();
132     EXPECT_NE(appRecord, nullptr);
133     appRecord->SetKeepAliveEnableState(true);
134     appRecord->SetSingleton(true);
135     appRecord->SetEmptyKeepAliveAppState(true);
136     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord), false);
137     // nullptr not allowed
138     std::shared_ptr<AppRunningRecord> appRecord2 = nullptr;
139     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), false);
140     // pending without real shrink
141     auto appRecord3 = MockAppRecord();
142     EXPECT_NE(appRecord3, nullptr);
143     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord3), true);
144     // pending without real shrink
145     auto appRecord4 = MockAppRecord();
146     EXPECT_NE(appRecord4, nullptr);
147     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord4), true);
148     // pending with shrinking
149     auto appRecord5 = MockAppRecord();
150     EXPECT_NE(appRecord5, nullptr);
151     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord5), true);
152 }
153 
154 /**
155  * @tc.name: CacheProcessManager_CheckAndCacheProcess_0100
156  * @tc.desc: Test the state of CheckAndCacheProcess
157  * @tc.type: FUNC
158  */
159 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_CheckAndCacheProcess_0100, TestSize.Level1)
160 {
161     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
162     EXPECT_NE(cacheProcMgr, nullptr);
163     cacheProcMgr->maxProcCacheNum_ = 2;
164     // nullptr not allowed
165     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
166     EXPECT_EQ(cacheProcMgr->CheckAndCacheProcess(appRecord), false);
167     // not cached
168     auto appRecord2 = MockAppRecord();
169     EXPECT_NE(appRecord2, nullptr);
170     EXPECT_EQ(cacheProcMgr->CheckAndCacheProcess(appRecord2), false);
171     // cached but no appMgrSerInner
172     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
173     EXPECT_EQ(cacheProcMgr->CheckAndCacheProcess(appRecord2), true);
174     // all normal
175     auto appMgrInner = std::make_shared<MockAppMgrServiceInner>();
176     cacheProcMgr->SetAppMgr(appMgrInner);
177     EXPECT_EQ(cacheProcMgr->CheckAndCacheProcess(appRecord2), true);
178 }
179 
180 /**
181  * @tc.name: CacheProcessManager_IsCachedProcess_0100
182  * @tc.desc: Test the state of IsCachedProcess
183  * @tc.type: FUNC
184  */
185 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsCachedProcess_0100, TestSize.Level1)
186 {
187     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
188     EXPECT_NE(cacheProcMgr, nullptr);
189     cacheProcMgr->maxProcCacheNum_ = 2;
190     // nullptr not allowed
191     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
192     EXPECT_EQ(cacheProcMgr->IsCachedProcess(appRecord), false);
193     // all normal
194     auto appRecord2 = MockAppRecord();
195     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
196     EXPECT_EQ(cacheProcMgr->IsCachedProcess(appRecord2), true);
197 }
198 
199 /**
200  * @tc.name: CacheProcessManager_OnProcessKilled_0100
201  * @tc.desc: Test the state of OnProcessKilled
202  * @tc.type: FUNC
203  */
204 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_OnProcessKilled_0100, TestSize.Level1)
205 {
206     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
207     EXPECT_NE(cacheProcMgr, nullptr);
208     cacheProcMgr->maxProcCacheNum_ = 2;
209     // nullptr not allowed
210     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
211     cacheProcMgr->OnProcessKilled(appRecord);
212     // not cached
213     auto appRecord2 = MockAppRecord();
214     cacheProcMgr->OnProcessKilled(appRecord2);
215     // cached, but appMgr is nullptr
216     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
217     cacheProcMgr->OnProcessKilled(appRecord2);
218     // all normal
219     auto appMgrInner = std::make_shared<MockAppMgrServiceInner>();
220     cacheProcMgr->SetAppMgr(appMgrInner);
221     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
222     cacheProcMgr->OnProcessKilled(appRecord2);
223 }
224 
225 /**
226  * @tc.name: CacheProcessManager_ReuseCachedProcess_0100
227  * @tc.desc: Test the state of ReuseCachedProcess
228  * @tc.type: FUNC
229  */
230 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_ReuseCachedProcess_0100, TestSize.Level1)
231 {
232     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
233     EXPECT_NE(cacheProcMgr, nullptr);
234     cacheProcMgr->maxProcCacheNum_ = 2;
235     // nullptr not allowed
236     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
237     cacheProcMgr->ReuseCachedProcess(appRecord);
238     // not cached
239     auto appRecord2 = MockAppRecord();
240     cacheProcMgr->ReuseCachedProcess(appRecord2);
241     // no appMgr
242     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
243     cacheProcMgr->ReuseCachedProcess(appRecord2);
244     // all normal
245     auto appMgrInner = std::make_shared<MockAppMgrServiceInner>();
246     cacheProcMgr->SetAppMgr(appMgrInner);
247     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
248     cacheProcMgr->OnProcessKilled(appRecord2);
249 }
250 
251 /**
252  * @tc.name: CacheProcessManager_IsAppSupportProcessCache_0100
253  * @tc.desc: Test the state of IsAppSupportProcessCache
254  * @tc.type: FUNC
255  */
256 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppSupportProcessCache_0100, TestSize.Level1)
257 {
258     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
259     EXPECT_NE(cacheProcMgr, nullptr);
260     cacheProcMgr->maxProcCacheNum_ = 2;
261     // nullptr not allowed
262     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
263     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord), false);
264     // API earlier than 12 not allowed
265     auto appRecord2 = MockAppRecord(11);
266     EXPECT_NE(appRecord2, nullptr);
267     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord2), false);
268     // different supportState
269     auto appRecord3 = MockAppRecord(12);
270     EXPECT_NE(appRecord3, nullptr);
271     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), false);
272     appRecord3->SetSupportedProcessCache(true);
273     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), true);
274     appRecord3->procCacheSupportState_ = SupportProcessCacheState::NOT_SUPPORT;
275     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), false);
276 }
277 
278 /**
279  * @tc.name: CacheProcessManager_RefreshCacheNum_0100
280  * @tc.desc: Test the state of RefreshCacheNum
281  * @tc.type: FUNC
282  */
283 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_RefreshCacheNum_0100, TestSize.Level1)
284 {
285     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
286     EXPECT_NE(cacheProcMgr, nullptr);
287     cacheProcMgr->maxProcCacheNum_ = 2;
288     cacheProcMgr->RefreshCacheNum();
289 }
290 
291 /**
292  * @tc.name: CacheProcessManager_GetCurrentCachedProcNum_0100
293  * @tc.desc: Test the state of GetCurrentCachedProcNum
294  * @tc.type: FUNC
295  */
296 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_GetCurrentCachedProcNum_0100, TestSize.Level1)
297 {
298     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
299     EXPECT_NE(cacheProcMgr, nullptr);
300     cacheProcMgr->maxProcCacheNum_ = 2;
301     auto appRecord = MockAppRecord();
302     EXPECT_NE(appRecord, nullptr);
303     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord), true);
304     EXPECT_EQ(cacheProcMgr->GetCurrentCachedProcNum(), 1);
305     auto appRecord2 = MockAppRecord();
306     EXPECT_NE(appRecord2, nullptr);
307     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
308     EXPECT_EQ(cacheProcMgr->GetCurrentCachedProcNum(), 2);
309 }
310 
311 /**
312  * @tc.name: CacheProcessManager_KillProcessByRecord_0100
313  * @tc.desc: Test the state of KillProcessByRecord
314  * @tc.type: FUNC
315  */
316 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_KillProcessByRecord_0100, TestSize.Level1)
317 {
318     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
319     EXPECT_NE(cacheProcMgr, nullptr);
320     cacheProcMgr->maxProcCacheNum_ = 2;
321     auto appRecord = MockAppRecord();
322     EXPECT_NE(appRecord, nullptr);
323     EXPECT_EQ(cacheProcMgr->KillProcessByRecord(appRecord), false);
324 }
325 
326 /**
327  * @tc.name: CacheProcessManager_IsAppShouldCache_0100
328  * @tc.desc: Test the state of IsAppShouldCache
329  * @tc.type: FUNC
330  */
331 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppShouldCache_0100, TestSize.Level1)
332 {
333     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
334     EXPECT_NE(cacheProcMgr, nullptr);
335 
336     // nullptr check
337     EXPECT_EQ(cacheProcMgr->IsAppShouldCache(nullptr), false);
338 
339     // Not enable
340     cacheProcMgr->maxProcCacheNum_ = 0;
341     cacheProcMgr->warmStartProcesEnable_  = false;
342     EXPECT_EQ(cacheProcMgr->IsAppShouldCache(nullptr), false);
343 
344     // Cached app
345     cacheProcMgr->maxProcCacheNum_ = 2;
346     auto appRecord = MockAppRecord();
347     EXPECT_NE(appRecord, nullptr);
348     cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord);
349     EXPECT_EQ(cacheProcMgr->IsAppShouldCache(appRecord), true);
350 
351     // App not support cache
352     cacheProcMgr->cachedAppRecordQueue_.clear();
353     appRecord->procCacheSupportState_ = SupportProcessCacheState::NOT_SUPPORT;
354     EXPECT_EQ(cacheProcMgr->IsAppShouldCache(appRecord), false);
355 }
356 
357 /**
358  * @tc.name: CacheProcessManager_IsAppAbilitiesEmpty_0100
359  * @tc.desc: Test the state of IsAppAbilitiesEmpty
360  * @tc.type: FUNC
361  */
362 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppAbilitiesEmpty_0100, TestSize.Level1)
363 {
364     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
365     EXPECT_NE(cacheProcMgr, nullptr);
366     cacheProcMgr->maxProcCacheNum_ = 2;
367 
368     // Abilities empty
369     auto appRecord = MockAppRecord();
370     EXPECT_NE(appRecord, nullptr);
371     EXPECT_EQ(cacheProcMgr->IsAppAbilitiesEmpty(appRecord), true);
372 
373     // Not empty
374     auto caseAbilityInfo = std::make_shared<AbilityInfo>();
375     caseAbilityInfo->name = ABILITY_RECORD_NAME;
376     sptr<IRemoteObject> token = new MockAbilityToken();
377     HapModuleInfo hapModuleInfo;
378     hapModuleInfo.moduleName = "Module";
379     auto appInfo = std::make_shared<ApplicationInfo>();
380     appInfo->bundleName = "com.ohos.test.helloworld";
381     appRecord->AddModule(appInfo, caseAbilityInfo, token, hapModuleInfo, nullptr, 0);
382     auto moduleRecord = appRecord->GetModuleRecordByModuleName(appInfo->bundleName,
383         hapModuleInfo.moduleName);
384     auto caseAbilityRunningRecord = moduleRecord->AddAbility(token, caseAbilityInfo, nullptr, 0);
385     EXPECT_TRUE(caseAbilityRunningRecord == nullptr);
386     EXPECT_EQ(cacheProcMgr->IsAppAbilitiesEmpty(appRecord), false);
387 }
388 
389 /**
390  * @tc.name: CacheProcessManager_ShrinkAndKillCache_0100
391  * @tc.desc: Test the state of ShrinkAndKillCache
392  * @tc.type: FUNC
393  */
394 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_ShrinkAndKillCache_0100, TestSize.Level1)
395 {
396     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
397     EXPECT_NE(cacheProcMgr, nullptr);
398     cacheProcMgr->maxProcCacheNum_ = 2;
399 
400     auto appRecord1 = MockAppRecord();
401     EXPECT_NE(appRecord1, nullptr);
402     auto appRecord2 = MockAppRecord();
403     EXPECT_NE(appRecord2, nullptr);
404     auto appRecord3 = MockAppRecord();
405     EXPECT_NE(appRecord3, nullptr);
406 
407     cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord1);
408     cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord2);
409     cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord3);
410 
411     cacheProcMgr->ShrinkAndKillCache();
412 }
413 
414 /**
415  * @tc.name: CacheProcessManager_PrintCacheQueue_0100
416  * @tc.desc: Test the state of PrintCacheQueue
417  * @tc.type: FUNC
418  */
419 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_PrintCacheQueue_0100, TestSize.Level1)
420 {
421     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
422     EXPECT_NE(cacheProcMgr, nullptr);
423     cacheProcMgr->maxProcCacheNum_ = 2;
424 
425     auto appRecord1 = MockAppRecord();
426     EXPECT_NE(appRecord1, nullptr);
427     auto appRecord2 = MockAppRecord();
428     EXPECT_NE(appRecord2, nullptr);
429 
430     EXPECT_NE(cacheProcMgr->PrintCacheQueue(), "");
431 }
432 
433 /**
434  * @tc.name: CacheProcessManager_AddToApplicationSet_0100
435  * @tc.desc: Test the state of AddToApplicationSet
436  * @tc.type: FUNC
437  */
438 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_AddToApplicationSet_0100, TestSize.Level1)
439 {
440     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
441     EXPECT_NE(cacheProcMgr, nullptr);
442     cacheProcMgr->maxProcCacheNum_ = 2;
443 
444     auto appRecord1 = MockAppRecord();
445     EXPECT_NE(appRecord1, nullptr);
446     auto appRecord2 = MockAppRecord();
447     EXPECT_NE(appRecord2, nullptr);
448 
449     cacheProcMgr->AddToApplicationSet(appRecord1);
450     cacheProcMgr->AddToApplicationSet(appRecord2);
451 
452     EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) != cacheProcMgr->sameAppSet.end());
453     EXPECT_TRUE(cacheProcMgr->sameAppSet[DEFAULT_BUNDLE_NAME].find(DEFAULT_UID) !=
454         cacheProcMgr->sameAppSet[DEFAULT_BUNDLE_NAME].end());
455 }
456 
457 /**
458  * @tc.name: CacheProcessManager_RemoveFromApplicationSet_0100
459  * @tc.desc: Test the state of RemoveFromApplicationSet
460  * @tc.type: FUNC
461  */
462 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_RemoveFromApplicationSet_0100, TestSize.Level1)
463 {
464     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
465     EXPECT_NE(cacheProcMgr, nullptr);
466     cacheProcMgr->maxProcCacheNum_ = 2;
467 
468     auto appRecord1 = MockAppRecord();
469     EXPECT_NE(appRecord1, nullptr);
470     auto appRecord2 = MockAppRecord();
471     EXPECT_NE(appRecord2, nullptr);
472 
473     cacheProcMgr->AddToApplicationSet(appRecord1);
474     cacheProcMgr->RemoveFromApplicationSet(appRecord2);
475     EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) != cacheProcMgr->sameAppSet.end());
476 
477     cacheProcMgr->RemoveFromApplicationSet(appRecord1);
478     EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) == cacheProcMgr->sameAppSet.end());
479 }
480 
481 /**
482  * @tc.name: CacheProcessManager_RemoveFromApplicationSet_0100
483  * @tc.desc: Test the state of RemoveFromApplicationSet
484  * @tc.type: FUNC
485  */
486 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppContainsSrvExt_0100, TestSize.Level1)
487 {
488     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
489     EXPECT_NE(cacheProcMgr, nullptr);
490     cacheProcMgr->maxProcCacheNum_ = 2;
491 
492     auto abilityInfo = std::make_shared<AbilityInfo>();
493     abilityInfo->name = "test_ability_name1";
494     auto appInfo = std::make_shared<ApplicationInfo>();
495     appInfo->name = "test_app_name1";
496     std::string processName = "com.ohos.test.helloworld";
497     auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, AppRecordId::Create(), processName);
498     EXPECT_TRUE(appRunningRecord != nullptr);
499     sptr<IRemoteObject> token = new MockAbilityToken();
500     HapModuleInfo hapModuleInfo;
501     hapModuleInfo.moduleName = "module789";
502     abilityInfo->type = AppExecFwk::AbilityType::EXTENSION;
503     abilityInfo->extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE;
504     hapModuleInfo.abilityInfos.push_back(*abilityInfo);
505     appRunningRecord->AddModule(appInfo, abilityInfo, token, hapModuleInfo, nullptr, 0);
506     auto moduleRecord = appRunningRecord->GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName);
507     EXPECT_TRUE(moduleRecord != nullptr);
508     auto abilityRunningRecord = moduleRecord->GetAbilityRunningRecordByToken(token);
509     EXPECT_TRUE(abilityRunningRecord != nullptr);
510 
511     EXPECT_EQ(cacheProcMgr->IsAppContainsSrvExt(appRunningRecord), true);
512 }
513 } // namespace AppExecFwk
514 } // namespace OHOS