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