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_IsAppShouldCache_0100
334 * @tc.desc: Test the state of IsAppShouldCache
335 * @tc.type: FUNC
336 */
337 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppShouldCache_0100, TestSize.Level1)
338 {
339 auto cacheProcMgr = std::make_shared<CacheProcessManager>();
340 EXPECT_NE(cacheProcMgr, nullptr);
341
342 // nullptr check
343 EXPECT_EQ(cacheProcMgr->IsAppShouldCache(nullptr), false);
344
345 // Not enable
346 cacheProcMgr->maxProcCacheNum_ = 0;
347 cacheProcMgr->warmStartProcesEnable_ = false;
348 EXPECT_EQ(cacheProcMgr->IsAppShouldCache(nullptr), false);
349
350 // Cached app
351 cacheProcMgr->maxProcCacheNum_ = 2;
352 auto appRecord = MockAppRecord();
353 EXPECT_NE(appRecord, nullptr);
354 cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord);
355 EXPECT_EQ(cacheProcMgr->IsAppShouldCache(appRecord), true);
356
357 // App not support cache
358 cacheProcMgr->cachedAppRecordQueue_.clear();
359 appRecord->procCacheSupportState_ = SupportProcessCacheState::NOT_SUPPORT;
360 EXPECT_EQ(cacheProcMgr->IsAppShouldCache(appRecord), false);
361 }
362
363 /**
364 * @tc.name: CacheProcessManager_IsAppAbilitiesEmpty_0100
365 * @tc.desc: Test the state of IsAppAbilitiesEmpty
366 * @tc.type: FUNC
367 */
368 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppAbilitiesEmpty_0100, TestSize.Level1)
369 {
370 auto cacheProcMgr = std::make_shared<CacheProcessManager>();
371 EXPECT_NE(cacheProcMgr, nullptr);
372 cacheProcMgr->maxProcCacheNum_ = 2;
373
374 // Abilities empty
375 auto appRecord = MockAppRecord();
376 EXPECT_NE(appRecord, nullptr);
377 EXPECT_EQ(cacheProcMgr->IsAppAbilitiesEmpty(appRecord), true);
378
379 // Not empty
380 auto caseAbilityInfo = std::make_shared<AbilityInfo>();
381 caseAbilityInfo->name = ABILITY_RECORD_NAME;
382 sptr<IRemoteObject> token = new MockAbilityToken();
383 HapModuleInfo hapModuleInfo;
384 hapModuleInfo.moduleName = "Module";
385 auto appInfo = std::make_shared<ApplicationInfo>();
386 appInfo->bundleName = "com.ohos.test.helloworld";
387 appRecord->AddModule(appInfo, caseAbilityInfo, token, hapModuleInfo, nullptr, 0);
388 auto moduleRecord = appRecord->GetModuleRecordByModuleName(appInfo->bundleName,
389 hapModuleInfo.moduleName);
390 auto caseAbilityRunningRecord = moduleRecord->AddAbility(token, caseAbilityInfo, nullptr, 0);
391 EXPECT_TRUE(caseAbilityRunningRecord == nullptr);
392 EXPECT_EQ(cacheProcMgr->IsAppAbilitiesEmpty(appRecord), false);
393 }
394
395 /**
396 * @tc.name: CacheProcessManager_ShrinkAndKillCache_0100
397 * @tc.desc: Test the state of ShrinkAndKillCache
398 * @tc.type: FUNC
399 */
400 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_ShrinkAndKillCache_0100, TestSize.Level1)
401 {
402 auto cacheProcMgr = std::make_shared<CacheProcessManager>();
403 EXPECT_NE(cacheProcMgr, nullptr);
404 cacheProcMgr->maxProcCacheNum_ = 2;
405
406 auto appRecord1 = MockAppRecord();
407 EXPECT_NE(appRecord1, nullptr);
408 auto appRecord2 = MockAppRecord();
409 EXPECT_NE(appRecord2, nullptr);
410 auto appRecord3 = MockAppRecord();
411 EXPECT_NE(appRecord3, nullptr);
412
413 cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord1);
414 cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord2);
415 cacheProcMgr->cachedAppRecordQueue_.push_back(appRecord3);
416
417 cacheProcMgr->ShrinkAndKillCache();
418 }
419
420 /**
421 * @tc.name: CacheProcessManager_PrintCacheQueue_0100
422 * @tc.desc: Test the state of PrintCacheQueue
423 * @tc.type: FUNC
424 */
425 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_PrintCacheQueue_0100, TestSize.Level1)
426 {
427 auto cacheProcMgr = std::make_shared<CacheProcessManager>();
428 EXPECT_NE(cacheProcMgr, nullptr);
429 cacheProcMgr->maxProcCacheNum_ = 2;
430
431 auto appRecord1 = MockAppRecord();
432 EXPECT_NE(appRecord1, nullptr);
433 auto appRecord2 = MockAppRecord();
434 EXPECT_NE(appRecord2, nullptr);
435
436 EXPECT_NE(cacheProcMgr->PrintCacheQueue(), "");
437 }
438
439 /**
440 * @tc.name: CacheProcessManager_AddToApplicationSet_0100
441 * @tc.desc: Test the state of AddToApplicationSet
442 * @tc.type: FUNC
443 */
444 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_AddToApplicationSet_0100, TestSize.Level1)
445 {
446 auto cacheProcMgr = std::make_shared<CacheProcessManager>();
447 EXPECT_NE(cacheProcMgr, nullptr);
448 cacheProcMgr->maxProcCacheNum_ = 2;
449
450 auto appRecord1 = MockAppRecord();
451 EXPECT_NE(appRecord1, nullptr);
452 auto appRecord2 = MockAppRecord();
453 EXPECT_NE(appRecord2, nullptr);
454
455 cacheProcMgr->AddToApplicationSet(appRecord1);
456 cacheProcMgr->AddToApplicationSet(appRecord2);
457
458 EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) != cacheProcMgr->sameAppSet.end());
459 EXPECT_TRUE(cacheProcMgr->sameAppSet[DEFAULT_BUNDLE_NAME].find(DEFAULT_UID) !=
460 cacheProcMgr->sameAppSet[DEFAULT_BUNDLE_NAME].end());
461 }
462
463 /**
464 * @tc.name: CacheProcessManager_RemoveFromApplicationSet_0100
465 * @tc.desc: Test the state of RemoveFromApplicationSet
466 * @tc.type: FUNC
467 */
468 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_RemoveFromApplicationSet_0100, TestSize.Level1)
469 {
470 auto cacheProcMgr = std::make_shared<CacheProcessManager>();
471 EXPECT_NE(cacheProcMgr, nullptr);
472 cacheProcMgr->maxProcCacheNum_ = 2;
473
474 auto appRecord1 = MockAppRecord();
475 EXPECT_NE(appRecord1, nullptr);
476 auto appRecord2 = MockAppRecord();
477 EXPECT_NE(appRecord2, nullptr);
478
479 cacheProcMgr->AddToApplicationSet(appRecord1);
480 cacheProcMgr->RemoveFromApplicationSet(appRecord2);
481 EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) != cacheProcMgr->sameAppSet.end());
482
483 cacheProcMgr->RemoveFromApplicationSet(appRecord1);
484 EXPECT_TRUE(cacheProcMgr->sameAppSet.find(DEFAULT_BUNDLE_NAME) == cacheProcMgr->sameAppSet.end());
485 }
486
487 /**
488 * @tc.name: CacheProcessManager_RemoveFromApplicationSet_0100
489 * @tc.desc: Test the state of RemoveFromApplicationSet
490 * @tc.type: FUNC
491 */
492 HWTEST_F(CacheProcessManagerTest, CacheProcessManager_IsAppContainsSrvExt_0100, TestSize.Level1)
493 {
494 auto cacheProcMgr = std::make_shared<CacheProcessManager>();
495 EXPECT_NE(cacheProcMgr, nullptr);
496 cacheProcMgr->maxProcCacheNum_ = 2;
497
498 auto abilityInfo = std::make_shared<AbilityInfo>();
499 abilityInfo->name = "test_ability_name1";
500 auto appInfo = std::make_shared<ApplicationInfo>();
501 appInfo->name = "test_app_name1";
502 std::string processName = "com.ohos.test.helloworld";
503 auto appRunningRecord = std::make_shared<AppRunningRecord>(appInfo, AppRecordId::Create(), processName);
504 EXPECT_TRUE(appRunningRecord != nullptr);
505 sptr<IRemoteObject> token = new MockAbilityToken();
506 HapModuleInfo hapModuleInfo;
507 hapModuleInfo.moduleName = "module789";
508 abilityInfo->type = AppExecFwk::AbilityType::EXTENSION;
509 abilityInfo->extensionAbilityType = AppExecFwk::ExtensionAbilityType::SERVICE;
510 hapModuleInfo.abilityInfos.push_back(*abilityInfo);
511 appRunningRecord->AddModule(appInfo, abilityInfo, token, hapModuleInfo, nullptr, 0);
512 auto moduleRecord = appRunningRecord->GetModuleRecordByModuleName(appInfo->bundleName, hapModuleInfo.moduleName);
513 EXPECT_TRUE(moduleRecord != nullptr);
514 auto abilityRunningRecord = moduleRecord->GetAbilityRunningRecordByToken(token);
515 EXPECT_TRUE(abilityRunningRecord != nullptr);
516
517 EXPECT_EQ(cacheProcMgr->IsAppContainsSrvExt(appRunningRecord), false);
518 }
519 } // namespace AppExecFwk
520 } // namespace OHOS