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     appRecord->SetKeepAliveBundle(true);
137     appRecord->SetMainProcess(true);
138     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord), false);
139     // nullptr not allowed
140     std::shared_ptr<AppRunningRecord> appRecord2 = nullptr;
141     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), false);
142     // pending without real shrink
143     auto appRecord3 = MockAppRecord();
144     EXPECT_NE(appRecord3, nullptr);
145     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord3), true);
146     // pending without real shrink
147     auto appRecord4 = MockAppRecord();
148     EXPECT_NE(appRecord4, nullptr);
149     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord4), true);
150     // pending with shrinking
151     auto appRecord5 = MockAppRecord();
152     EXPECT_NE(appRecord5, nullptr);
153     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord5), true);
154 }
155 
156 /**
157  * @tc.name: CacheProcessManager_CheckAndCacheProcess_0100
158  * @tc.desc: Test the state of CheckAndCacheProcess
159  * @tc.type: FUNC
160  */
161 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_CheckAndCacheProcess_0100, TestSize.Level1)
162 {
163     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
164     EXPECT_NE(cacheProcMgr, nullptr);
165     cacheProcMgr->maxProcCacheNum_ = 2;
166     // nullptr not allowed
167     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
168     EXPECT_EQ(cacheProcMgr->CheckAndCacheProcess(appRecord), false);
169     // not cached
170     auto appRecord2 = MockAppRecord();
171     EXPECT_NE(appRecord2, nullptr);
172     EXPECT_EQ(cacheProcMgr->CheckAndCacheProcess(appRecord2), false);
173     // cached but no appMgrSerInner
174     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
175     EXPECT_EQ(cacheProcMgr->CheckAndCacheProcess(appRecord2), true);
176     // all normal
177     auto appMgrInner = std::make_shared<MockAppMgrServiceInner>();
178     cacheProcMgr->SetAppMgr(appMgrInner);
179     EXPECT_EQ(cacheProcMgr->CheckAndCacheProcess(appRecord2), true);
180 }
181 
182 /**
183  * @tc.name: CacheProcessManager_IsCachedProcess_0100
184  * @tc.desc: Test the state of IsCachedProcess
185  * @tc.type: FUNC
186  */
187 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsCachedProcess_0100, TestSize.Level1)
188 {
189     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
190     EXPECT_NE(cacheProcMgr, nullptr);
191     cacheProcMgr->maxProcCacheNum_ = 2;
192     // nullptr not allowed
193     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
194     EXPECT_EQ(cacheProcMgr->IsCachedProcess(appRecord), false);
195     // all normal
196     auto appRecord2 = MockAppRecord();
197     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
198     EXPECT_EQ(cacheProcMgr->IsCachedProcess(appRecord2), true);
199 }
200 
201 /**
202  * @tc.name: CacheProcessManager_OnProcessKilled_0100
203  * @tc.desc: Test the state of OnProcessKilled
204  * @tc.type: FUNC
205  */
206 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_OnProcessKilled_0100, TestSize.Level1)
207 {
208     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
209     EXPECT_NE(cacheProcMgr, nullptr);
210     cacheProcMgr->maxProcCacheNum_ = 2;
211     // nullptr not allowed
212     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
213     cacheProcMgr->OnProcessKilled(appRecord);
214     // not cached
215     auto appRecord2 = MockAppRecord();
216     cacheProcMgr->OnProcessKilled(appRecord2);
217     // cached, but appMgr is nullptr
218     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
219     cacheProcMgr->OnProcessKilled(appRecord2);
220     // all normal
221     auto appMgrInner = std::make_shared<MockAppMgrServiceInner>();
222     cacheProcMgr->SetAppMgr(appMgrInner);
223     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
224     cacheProcMgr->OnProcessKilled(appRecord2);
225 }
226 
227 /**
228  * @tc.name: CacheProcessManager_ReuseCachedProcess_0100
229  * @tc.desc: Test the state of ReuseCachedProcess
230  * @tc.type: FUNC
231  */
232 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_ReuseCachedProcess_0100, TestSize.Level1)
233 {
234     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
235     EXPECT_NE(cacheProcMgr, nullptr);
236     cacheProcMgr->maxProcCacheNum_ = 2;
237     // nullptr not allowed
238     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
239     cacheProcMgr->ReuseCachedProcess(appRecord);
240     // not cached
241     auto appRecord2 = MockAppRecord();
242     cacheProcMgr->ReuseCachedProcess(appRecord2);
243     // no appMgr
244     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
245     cacheProcMgr->ReuseCachedProcess(appRecord2);
246     // all normal
247     auto appMgrInner = std::make_shared<MockAppMgrServiceInner>();
248     cacheProcMgr->SetAppMgr(appMgrInner);
249     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
250     cacheProcMgr->OnProcessKilled(appRecord2);
251 }
252 
253 /**
254  * @tc.name: CacheProcessManager_IsAppSupportProcessCache_0100
255  * @tc.desc: Test the state of IsAppSupportProcessCache
256  * @tc.type: FUNC
257  */
258 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppSupportProcessCache_0100, TestSize.Level1)
259 {
260     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
261     EXPECT_NE(cacheProcMgr, nullptr);
262     cacheProcMgr->maxProcCacheNum_ = 2;
263     // nullptr not allowed
264     std::shared_ptr<AppRunningRecord> appRecord = nullptr;
265     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord), false);
266     // API earlier than 12 not allowed
267     auto appRecord2 = MockAppRecord(11);
268     EXPECT_NE(appRecord2, nullptr);
269     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord2), false);
270     // different supportState
271     auto appRecord3 = MockAppRecord(12);
272     EXPECT_NE(appRecord3, nullptr);
273     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), false);
274     appRecord3->SetSupportedProcessCache(true);
275     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), true);
276     appRecord3->SetUIAbilityLaunched(true);
277     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), true);
278     appRecord3->procCacheSupportState_ = SupportProcessCacheState::NOT_SUPPORT;
279     EXPECT_EQ(cacheProcMgr->IsAppSupportProcessCache(appRecord3), false);
280 }
281 
282 /**
283  * @tc.name: CacheProcessManager_RefreshCacheNum_0100
284  * @tc.desc: Test the state of RefreshCacheNum
285  * @tc.type: FUNC
286  */
287 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_RefreshCacheNum_0100, TestSize.Level1)
288 {
289     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
290     EXPECT_NE(cacheProcMgr, nullptr);
291     cacheProcMgr->maxProcCacheNum_ = 2;
292     cacheProcMgr->RefreshCacheNum();
293 }
294 
295 /**
296  * @tc.name: CacheProcessManager_GetCurrentCachedProcNum_0100
297  * @tc.desc: Test the state of GetCurrentCachedProcNum
298  * @tc.type: FUNC
299  */
300 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_GetCurrentCachedProcNum_0100, TestSize.Level1)
301 {
302     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
303     EXPECT_NE(cacheProcMgr, nullptr);
304     cacheProcMgr->maxProcCacheNum_ = 2;
305     auto appRecord = MockAppRecord();
306     EXPECT_NE(appRecord, nullptr);
307     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord), true);
308     EXPECT_EQ(cacheProcMgr->GetCurrentCachedProcNum(), 1);
309     auto appRecord2 = MockAppRecord();
310     EXPECT_NE(appRecord2, nullptr);
311     EXPECT_EQ(cacheProcMgr->PenddingCacheProcess(appRecord2), true);
312     EXPECT_EQ(cacheProcMgr->GetCurrentCachedProcNum(), 2);
313 }
314 
315 /**
316  * @tc.name: CacheProcessManager_KillProcessByRecord_0100
317  * @tc.desc: Test the state of KillProcessByRecord
318  * @tc.type: FUNC
319  */
320 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_KillProcessByRecord_0100, TestSize.Level1)
321 {
322     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
323     EXPECT_NE(cacheProcMgr, nullptr);
324     cacheProcMgr->maxProcCacheNum_ = 2;
325     auto appRecord = MockAppRecord();
326     EXPECT_NE(appRecord, nullptr);
327     EXPECT_EQ(cacheProcMgr->KillProcessByRecord(appRecord), false);
328 }
329 
330 /**
331  * @tc.name: CacheProcessManager_IsAppShouldCache_0100
332  * @tc.desc: Test the state of IsAppShouldCache
333  * @tc.type: FUNC
334  */
335 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppShouldCache_0100, TestSize.Level1)
336 {
337     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
338     EXPECT_NE(cacheProcMgr, nullptr);
339 
340     // nullptr check
341     EXPECT_EQ(cacheProcMgr->IsAppShouldCache(nullptr), false);
342 
343     // Not enable
344     cacheProcMgr->maxProcCacheNum_ = 0;
345     cacheProcMgr->warmStartProcesEnable_  = false;
346     EXPECT_EQ(cacheProcMgr->IsAppShouldCache(nullptr), false);
347 
348     // Cached app
349     cacheProcMgr->maxProcCacheNum_ = 2;
350     auto appRecord = MockAppRecord();
351     EXPECT_NE(appRecord, nullptr);
352     cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord);
353     EXPECT_EQ(cacheProcMgr->IsAppShouldCache(appRecord), true);
354 
355     // App not support cache
356     cacheProcMgr->cachedAppRecordQueue_.clear();
357     appRecord->procCacheSupportState_ = SupportProcessCacheState::NOT_SUPPORT;
358     EXPECT_EQ(cacheProcMgr->IsAppShouldCache(appRecord), false);
359 }
360 
361 /**
362  * @tc.name: CacheProcessManager_IsAppAbilitiesEmpty_0100
363  * @tc.desc: Test the state of IsAppAbilitiesEmpty
364  * @tc.type: FUNC
365  */
366 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppAbilitiesEmpty_0100, TestSize.Level1)
367 {
368     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
369     EXPECT_NE(cacheProcMgr, nullptr);
370     cacheProcMgr->maxProcCacheNum_ = 2;
371 
372     // Abilities empty
373     auto appRecord = MockAppRecord();
374     EXPECT_NE(appRecord, nullptr);
375     EXPECT_EQ(cacheProcMgr->IsAppAbilitiesEmpty(appRecord), true);
376 
377     // Not empty
378     auto caseAbilityInfo = std::make_shared<AbilityInfo>();
379     caseAbilityInfo->name = ABILITY_RECORD_NAME;
380     sptr<IRemoteObject> token = new MockAbilityToken();
381     HapModuleInfo hapModuleInfo;
382     hapModuleInfo.moduleName = "Module";
383     auto appInfo = std::make_shared<ApplicationInfo>();
384     appInfo->bundleName = "com.ohos.test.helloworld";
385     appRecord->AddModule(appInfo, caseAbilityInfo, token, hapModuleInfo, nullptr, 0);
386     auto moduleRecord = appRecord->GetModuleRecordByModuleName(appInfo->bundleName,
387         hapModuleInfo.moduleName);
388     auto caseAbilityRunningRecord = moduleRecord->AddAbility(token, caseAbilityInfo, nullptr, 0);
389     EXPECT_TRUE(caseAbilityRunningRecord == nullptr);
390     EXPECT_EQ(cacheProcMgr->IsAppAbilitiesEmpty(appRecord), false);
391 }
392 
393 /**
394  * @tc.name: CacheProcessManager_ShrinkAndKillCache_0100
395  * @tc.desc: Test the state of ShrinkAndKillCache
396  * @tc.type: FUNC
397  */
398 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_ShrinkAndKillCache_0100, TestSize.Level1)
399 {
400     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
401     EXPECT_NE(cacheProcMgr, nullptr);
402     cacheProcMgr->maxProcCacheNum_ = 2;
403 
404     auto appRecord1 = MockAppRecord();
405     EXPECT_NE(appRecord1, nullptr);
406     auto appRecord2 = MockAppRecord();
407     EXPECT_NE(appRecord2, nullptr);
408     auto appRecord3 = MockAppRecord();
409     EXPECT_NE(appRecord3, nullptr);
410 
411     cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord1);
412     cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord2);
413     cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord3);
414 
415     cacheProcMgr->ShrinkAndKillCache();
416 }
417 
418 /**
419  * @tc.name: CacheProcessManager_PrintCacheQueue_0100
420  * @tc.desc: Test the state of PrintCacheQueue
421  * @tc.type: FUNC
422  */
423 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_PrintCacheQueue_0100, TestSize.Level1)
424 {
425     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
426     EXPECT_NE(cacheProcMgr, nullptr);
427     cacheProcMgr->maxProcCacheNum_ = 2;
428 
429     auto appRecord1 = MockAppRecord();
430     EXPECT_NE(appRecord1, nullptr);
431     auto appRecord2 = MockAppRecord();
432     EXPECT_NE(appRecord2, nullptr);
433 
434     EXPECT_NE(cacheProcMgr->PrintCacheQueue(), "");
435 }
436 
437 /**
438  * @tc.name: CacheProcessManager_AddToApplicationSet_0100
439  * @tc.desc: Test the state of AddToApplicationSet
440  * @tc.type: FUNC
441  */
442 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_AddToApplicationSet_0100, TestSize.Level1)
443 {
444     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
445     EXPECT_NE(cacheProcMgr, nullptr);
446     cacheProcMgr->maxProcCacheNum_ = 2;
447 
448     auto appRecord1 = MockAppRecord();
449     EXPECT_NE(appRecord1, nullptr);
450     auto appRecord2 = MockAppRecord();
451     EXPECT_NE(appRecord2, nullptr);
452 
453     cacheProcMgr->AddToApplicationSet(appRecord1);
454     cacheProcMgr->AddToApplicationSet(appRecord2);
455 
456     EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) != cacheProcMgr->sameAppSet.end());
457     EXPECT_TRUE(cacheProcMgr->sameAppSet[DEFAULT_BUNDLE_NAME].find(DEFAULT_UID) !=
458         cacheProcMgr->sameAppSet[DEFAULT_BUNDLE_NAME].end());
459 }
460 
461 /**
462  * @tc.name: CacheProcessManager_RemoveFromApplicationSet_0100
463  * @tc.desc: Test the state of RemoveFromApplicationSet
464  * @tc.type: FUNC
465  */
466 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_RemoveFromApplicationSet_0100, TestSize.Level1)
467 {
468     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
469     EXPECT_NE(cacheProcMgr, nullptr);
470     cacheProcMgr->maxProcCacheNum_ = 2;
471 
472     auto appRecord1 = MockAppRecord();
473     EXPECT_NE(appRecord1, nullptr);
474     auto appRecord2 = MockAppRecord();
475     EXPECT_NE(appRecord2, nullptr);
476 
477     cacheProcMgr->AddToApplicationSet(appRecord1);
478     cacheProcMgr->RemoveFromApplicationSet(appRecord2);
479     EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) != cacheProcMgr->sameAppSet.end());
480 
481     cacheProcMgr->RemoveFromApplicationSet(appRecord1);
482     EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) == cacheProcMgr->sameAppSet.end());
483 }
484 
485 /**
486  * @tc.name: CacheProcessManager_RemoveFromApplicationSet_0100
487  * @tc.desc: Test the state of RemoveFromApplicationSet
488  * @tc.type: FUNC
489  */
490 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppContainsSrvExt_0100, TestSize.Level1)
491 {
492     auto cacheProcMgr = std::make_shared<CacheProcessManager>();
493     EXPECT_NE(cacheProcMgr, nullptr);
494     cacheProcMgr->maxProcCacheNum_ = 2;
495 
496     auto abilityInfo = std::make_shared<AbilityInfo>();
497     abilityInfo->name = "test_ability_name1";
498     auto appInfo = std::make_shared<ApplicationInfo>();
499     appInfo->name = "test_app_name1";
500     std::string processName = "com.ohos.test.helloworld";
501     auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, AppRecordId::Create(), processName);
502     EXPECT_TRUE(appRunningRecord != nullptr);
503     sptr<IRemoteObject> token = new MockAbilityToken();
504     HapModuleInfo hapModuleInfo;
505     hapModuleInfo.moduleName = "module789";
506     abilityInfo->type = AppExecFwk::AbilityType::EXTENSION;
507     abilityInfo->extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE;
508     hapModuleInfo.abilityInfos.push_back(*abilityInfo);
509     appRunningRecord->AddModule(appInfo, abilityInfo, token, hapModuleInfo, nullptr, 0);
510     auto moduleRecord = appRunningRecord->GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName);
511     EXPECT_TRUE(moduleRecord != nullptr);
512     auto abilityRunningRecord = moduleRecord->GetAbilityRunningRecordByToken(token);
513     EXPECT_TRUE(abilityRunningRecord != nullptr);
514 
515     EXPECT_EQ(cacheProcMgr->IsAppContainsSrvExt(appRunningRecord), false);
516 }
517 } // namespace AppExecFwk
518 } // namespace OHOS