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
18 #define private public
19 #include "app_running_manager.h"
20 #include "app_running_record.h"
21 #ifdef SUPPORT_CHILD_PROCESS
22 #include "child_process_record.h"
23 #endif // SUPPORT_CHILD_PROCESS
24 #undef private
25
26 #include "app_record_id.h"
27 #include "exit_resident_process_manager.h"
28 #include "hilog_tag_wrapper.h"
29 #include "mock_app_mgr_service_inner.h"
30 #include "mock_application.h"
31 #include "quick_fix_callback_proxy.h"
32 #include "quick_fix_callback_stub.h"
33
34 using namespace testing;
35 using namespace testing::ext;
36
37 namespace OHOS {
38 namespace AppExecFwk {
39 namespace {
40 constexpr int32_t USR_ID_100 = 100;
41 constexpr int32_t USR_ID_101 = 101;
42 const std::string BUNDLE_NAME = "testBundleName";
43 const std::string PROCESS_NAME = "testProcessName";
44
45
46 class QuickFixCallbackImpl : public QuickFixCallbackStub {
47 public:
48 QuickFixCallbackImpl() = default;
49 virtual ~QuickFixCallbackImpl() = default;
50
OnLoadPatchDone(int32_t resultCode,int32_t recordId)51 void OnLoadPatchDone(int32_t resultCode, [[maybe_unused]] int32_t recordId) override
52 {}
53
OnUnloadPatchDone(int32_t resultCode,int32_t recordId)54 void OnUnloadPatchDone(int32_t resultCode, [[maybe_unused]] int32_t recordId) override
55 {}
56
OnReloadPageDone(int32_t resultCode,int32_t recordId)57 void OnReloadPageDone(int32_t resultCode, [[maybe_unused]] int32_t recordId) override
58 {}
59 };
60 }
61
62 class AppRunningManagerSecondTest : public testing::Test {
63 public:
64 static void SetUpTestCase();
65 static void TearDownTestCase();
66 void SetUp() override;
67 void TearDown() override;
68
69 protected:
70 static BundleInfo bundleInfo;
71 static std::shared_ptr<ApplicationInfo> appInfo_;
72 static std::shared_ptr<MockAppMgrServiceInner> appServiceInner_;
73 static sptr<MockApplication> mockApp1_;
74 };
75
76 BundleInfo AppRunningManagerSecondTest::bundleInfo;
77 std::shared_ptr<ApplicationInfo> AppRunningManagerSecondTest::appInfo_ = nullptr;
78 std::shared_ptr<MockAppMgrServiceInner> AppRunningManagerSecondTest::appServiceInner_ = nullptr;
79 sptr<MockApplication> AppRunningManagerSecondTest::mockApp1_ = nullptr;
80
SetUpTestCase(void)81 void AppRunningManagerSecondTest::SetUpTestCase(void)
82 {
83 appInfo_ = std::make_shared<ApplicationInfo>();
84 appInfo_->bundleName = BUNDLE_NAME;
85 appServiceInner_ = std::make_shared<MockAppMgrServiceInner>();
86 mockApp1_ = sptr<MockApplication>::MakeSptr();
87 }
88
TearDownTestCase(void)89 void AppRunningManagerSecondTest::TearDownTestCase(void)
90 {}
91
SetUp()92 void AppRunningManagerSecondTest::SetUp()
93 {}
94
TearDown()95 void AppRunningManagerSecondTest::TearDown()
96 {}
97
98 /**
99 * @tc.name: AppRunningManager_CheckAppRunningRecordIsExistByUid_0100
100 * @tc.desc: Test CheckAppRunningRecordIsExistByUid
101 * @tc.type: FUNC
102 */
103 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_CheckAppRunningRecordIsExistByUid_0100, TestSize.Level1)
104 {
105 /**
106 * @tc.steps: step1. Initialize AppRunningManager&AppRunningRecord instance
107 * @tc.expected: expect step1 succeed
108 */
109 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_CheckAppRunningRecordIsExistByUid_0100 start");
110 auto appRunningManager = std::make_shared<AppRunningManager>();
111 EXPECT_NE(appRunningManager, nullptr);
112 std::shared_ptr<AppRunningRecord> record =
113 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
114 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_CheckAppRunningRecordIsExistByUid_0100 start 2");
115 /**
116 * @tc.steps: step2. SetUid USR_ID_100, SetRestartAppFlag false
117 * @tc.expected: step2. expect CheckAppRunningRecordIsExistByUid true
118 */
119 EXPECT_NE(record, nullptr);
120 record->SetUid(USR_ID_100);
121 record->SetRestartAppFlag(false);
122 bool ret = appRunningManager->CheckAppRunningRecordIsExistByUid(USR_ID_100);
123 EXPECT_TRUE(ret);
124
125 /**
126 * @tc.steps: step3. SetRestartAppFlag true
127 * @tc.expected: step3. expect CheckAppRunningRecordIsExistByUid false
128 */
129 record->SetRestartAppFlag(true);
130 ret = appRunningManager->CheckAppRunningRecordIsExistByUid(USR_ID_100);
131 EXPECT_FALSE(ret);
132
133 /**
134 * @tc.steps: step4. call CheckAppRunningRecordIsExistByUid USR_ID_101
135 * @tc.expected: step4. expect call CheckAppRunningRecordIsExistByUid false
136 */
137 ret = appRunningManager->CheckAppRunningRecordIsExistByUid(USR_ID_101);
138 EXPECT_FALSE(ret);
139
140 /**
141 * @tc.steps: step5. appRunningRecord is nullptr
142 * @tc.expected: step5. expect CheckAppRunningRecordIsExistByUid false
143 */
144 appRunningManager->appRunningRecordMap_.clear();
145 auto recordId = AppRecordId::Create();
146 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
147 ret = appRunningManager->CheckAppRunningRecordIsExistByUid(USR_ID_101);
148 EXPECT_FALSE(ret);
149 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_CheckAppRunningRecordIsExistByUid_0100 end");
150 }
151
152 /**
153 * @tc.name: AppRunningManager_CheckAppCloneRunningRecordIsExistByBundleName_0100
154 * @tc.desc: Test CheckAppCloneRunningRecordIsExistByBundleName
155 * @tc.type: FUNC
156 */
157 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_CheckAppCloneRunningRecordIsExistByBundleName_0100,
158 TestSize.Level1)
159 {
160 /**
161 * @tc.steps: step1. Initialize AppRunningManager instance
162 * @tc.expected: expect step1 succeed
163 */
164 auto appRunningManager = std::make_shared<AppRunningManager>();
165 EXPECT_NE(appRunningManager, nullptr);
166 appInfo_->bundleName = BUNDLE_NAME;
167 const std::string processName = "testProcessName";
168 std::shared_ptr<AppRunningRecord> record =
169 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
170 ASSERT_NE(record, nullptr);
171
172 /**
173 * @tc.steps: step2. SetRestartAppFlag false, SetAppIndex 0
174 * @tc.expected: step2. expect isRunning true
175 */
176 bool isRunning = false;
177 record->SetRestartAppFlag(false);
178 record->SetAppIndex(0);
179 appRunningManager->CheckAppCloneRunningRecordIsExistByBundleName(BUNDLE_NAME, 0, isRunning);
180 EXPECT_TRUE(isRunning);
181
182 /**
183 * @tc.steps: step3. call CheckAppCloneRunningRecordIsExistByBundleName appIndex 1
184 * @tc.expected: step3. expect isRunning false
185 */
186 isRunning = false;
187 appRunningManager->CheckAppCloneRunningRecordIsExistByBundleName(BUNDLE_NAME, 1, isRunning); // 1 means appIndex
188 EXPECT_FALSE(isRunning);
189
190 /**
191 * @tc.steps: step4. SetRestartAppFlag false, SetRestartAppFlag true.
192 * @tc.expected: step4. expect isRunning false
193 */
194 record->SetRestartAppFlag(true);
195 appRunningManager->CheckAppCloneRunningRecordIsExistByBundleName(BUNDLE_NAME, 0, isRunning);
196 EXPECT_FALSE(isRunning);
197
198 /**
199 * @tc.steps: step5. SetRestartAppFlag false
200 * @tc.expected: step5. expect isRunning false by empty BundleName
201 */
202 record->SetRestartAppFlag(false);
203 appRunningManager->CheckAppCloneRunningRecordIsExistByBundleName("", 0, isRunning);
204 EXPECT_FALSE(isRunning);
205
206 /**
207 * @tc.steps: step6. SetRestartAppFlag false, SetRestartAppFlag true.
208 * @tc.expected: step6. expect isRunning false
209 */
210 appRunningManager->appRunningRecordMap_.clear();
211 auto recordId = AppRecordId::Create();
212 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
213 appRunningManager->CheckAppCloneRunningRecordIsExistByBundleName("", 0, isRunning);
214 EXPECT_FALSE(isRunning);
215
216 /**
217 * @tc.steps: step7. clear appRunningRecordMap_.
218 * @tc.expected: step7. expect isRunning false
219 */
220 appRunningManager->appRunningRecordMap_.clear();
221 int32_t ret = appRunningManager->CheckAppCloneRunningRecordIsExistByBundleName("", 0, isRunning);
222 EXPECT_EQ(ret, ERR_OK);
223 }
224
225 /**
226 * @tc.name: AppRunningManager_ProcessExitByBundleName_0100
227 * @tc.desc: Test ProcessExitByBundleName
228 * @tc.type: FUNC
229 */
230 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_ProcessExitByBundleName_0100, TestSize.Level1)
231 {
232 /**
233 * @tc.steps: step1. Initialize AppRunningManager instance
234 * @tc.expected: expect step1 succeed
235 */
236 auto appRunningManager = std::make_shared<AppRunningManager>();
237 EXPECT_NE(appRunningManager, nullptr);
238 std::shared_ptr<AppRunningRecord> record1 =
239 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
240 ASSERT_NE(record1, nullptr);
241 record1->appInfos_.emplace(BUNDLE_NAME, appInfo_);
242
243 /**
244 * @tc.steps: step2. SetKeepAliveBundle false, SetPid valid pid
245 * @tc.expected: step2. expect pids not empty
246 */
247 record1->SetKeepAliveBundle(false); // not resident process, can kill
248 record1->GetPriorityObject()->SetPid(10000); // 10000 means valid process id
249 std::list<pid_t> pids;
250 appRunningManager->ProcessExitByBundleName(BUNDLE_NAME, pids, true);
251 EXPECT_EQ(pids.size(), 1); // 1 means exit pid list size
252
253 /**
254 * @tc.steps: step3. ProcessExitByBundleName by empty bundleName
255 * @tc.expected: step3. expect pids empty
256 */
257 pids.clear();
258 appRunningManager->ProcessExitByBundleName("", pids, false);
259 EXPECT_TRUE(pids.empty());
260
261 /**
262 * @tc.steps: step4. SetKeepAliveBundle false, SetPid Invalid pid
263 * @tc.expected: step4. expect pids empty
264 */
265 record1->GetPriorityObject()->SetPid(0); // 10000 means invalid process id
266 appRunningManager->ProcessExitByBundleName(BUNDLE_NAME, pids, false);
267 EXPECT_TRUE(pids.empty());
268 }
269
270 /**
271 * @tc.name: AppRunningManager_ProcessExitByBundleName_0200
272 * @tc.desc: Test ProcessExitByBundleName
273 * @tc.type: FUNC
274 */
275 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_ProcessExitByBundleName_0200, TestSize.Level1)
276 {
277 /**
278 * @tc.steps: step1. Initialize AppRunningManager instance
279 * @tc.expected: expect step1 succeed
280 */
281 auto appRunningManager = std::make_shared<AppRunningManager>();
282 EXPECT_NE(appRunningManager, nullptr);
283 appInfo_->bundleName = BUNDLE_NAME;
284 std::shared_ptr<AppRunningRecord> record1 =
285 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
286 ASSERT_NE(record1, nullptr);
287 record1->appInfos_.emplace(BUNDLE_NAME, appInfo_);
288
289 /**
290 * @tc.steps: step2. process resident process and ExitResidentProcessManager Memory Size Insufficent
291 * @tc.expected: step2. expect pids not empty
292 */
293 std::vector<ExitResidentProcessInfo> processInfos;
294 record1->SetUid(BASE_USER_RANGE);
295 record1->SetKeepAliveBundle(true);
296 record1->SetKeepAliveEnableState(true);
297 record1->SetKeepAliveDkv(true);
298 record1->SetMainProcess(true);
299 record1->GetPriorityObject()->SetPid(10000); // 10000 means valid process id
300 ExitResidentProcessManager::GetInstance().HandleMemorySizeInSufficent(); // marked mem insufficient
301 std::list<pid_t> pids;
302 appRunningManager->ProcessExitByBundleName(BUNDLE_NAME, pids, false);
303 EXPECT_TRUE(pids.empty());
304
305 /**
306 * @tc.steps: step2. process resident process and ExitResidentProcessManager Memory Size Insufficent
307 * @tc.expected: step2. expect pids not empty, memory size sufficient
308 */
309 pids.clear();
310 ExitResidentProcessManager::GetInstance().HandleMemorySizeSufficient(processInfos); // marked mem sufficient
311 appRunningManager->ProcessExitByBundleName(BUNDLE_NAME, pids, true);
312 EXPECT_TRUE(pids.empty());
313 }
314
315 /**
316 * @tc.name: AppRunningManager_GetPidsByBundleNameUserIdAndAppIndex_0100
317 * @tc.desc: Test GetPidsByBundleNameUserIdAndAppIndex
318 * @tc.type: FUNC
319 */
320 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_GetPidsByBundleNameUserIdAndAppIndex_0100, TestSize.Level1)
321 {
322 /**
323 * @tc.steps: step1. Initialize AppRunningManager instance
324 * @tc.expected: expect step1 succeed
325 */
326 auto appRunningManager = std::make_shared<AppRunningManager>();
327 EXPECT_NE(appRunningManager, nullptr);
328 appInfo_->appIndex = 0;
329 appInfo_->bundleName = BUNDLE_NAME;
330 std::shared_ptr<AppRunningRecord> record1 =
331 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
332 ASSERT_NE(record1, nullptr);
333 record1->appInfos_.emplace(BUNDLE_NAME, appInfo_);
334
335 /**
336 * @tc.steps: step2. SetKeepAliveBundle false, SetPid valid pid
337 * @tc.expected: step2. expect pids not empty
338 */
339 record1->SetUid(0);
340 record1->GetPriorityObject()->SetPid(10000); // 10000 means valid process id
341 std::list<pid_t> pids;
342 appRunningManager->GetPidsByBundleNameUserIdAndAppIndex(BUNDLE_NAME, 0, 0, pids);
343 EXPECT_EQ(pids.size(), 1); // 1 means exit pid list size
344
345 /**
346 * @tc.steps: step3. GetPidsByBundleNameUserIdAndAppIndex by appIndex 1
347 * @tc.expected: step3. expect pids empty
348 */
349 pids.clear();
350 appRunningManager->GetPidsByBundleNameUserIdAndAppIndex(BUNDLE_NAME, 0, 1, pids); // 1 means appIndex
351 EXPECT_TRUE(pids.empty()); // not exist
352
353 /**
354 * @tc.steps: step4. GetPidsByBundleNameUserIdAndAppIndex by userid 1
355 * @tc.expected: step4. expect pids empty
356 */
357 appRunningManager->GetPidsByBundleNameUserIdAndAppIndex(BUNDLE_NAME, 1, 0, pids); // 1 means usrid
358 EXPECT_TRUE(pids.empty()); // not exist
359
360 /**
361 * @tc.steps: step5. GetPidsByBundleNameUserIdAndAppIndex by empty bundleName
362 * @tc.expected: step5. expect pids empty
363 */
364 appRunningManager->GetPidsByBundleNameUserIdAndAppIndex("", 0, 0, pids); // 1 means usrid
365 EXPECT_TRUE(pids.empty()); // not exist
366
367 /**
368 * @tc.steps: step6. GetPidsByBundleNameUserIdAndAppIndex with invalid pid
369 * @tc.expected: step6. expect pids empty
370 */
371 record1->GetPriorityObject()->SetPid(0); // set invalid pid
372 appRunningManager->GetPidsByBundleNameUserIdAndAppIndex(BUNDLE_NAME, 0, 0, pids); // 1 means usrid
373 EXPECT_TRUE(pids.empty()); // not exist
374
375 /**
376 * @tc.steps: step7. GetPidsByBundleNameUserIdAndAppIndex clear appInfos
377 * @tc.expected: step7. expect pids empty
378 */
379 record1->GetPriorityObject()->SetPid(10000); // set invalid pid
380 record1->appInfos_.clear();
381 appRunningManager->GetPidsByBundleNameUserIdAndAppIndex(BUNDLE_NAME, 0, 0, pids); // 1 means usrid
382 EXPECT_TRUE(pids.empty()); // not exist
383 }
384
385 /**
386 * @tc.name: AppRunningManager_OnRemoteDied_0100
387 * @tc.desc: Test OnRemoteDied
388 * @tc.type: FUNC
389 */
390 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_OnRemoteDied_0100, TestSize.Level1)
391 {
392 /**
393 * @tc.steps: step1. Initialize AppRunningManager instance
394 * @tc.expected: expect step1 succeed
395 */
396 auto appRunningManager = std::make_shared<AppRunningManager>();
397 EXPECT_NE(appRunningManager, nullptr);
398 appInfo_->bundleName = BUNDLE_NAME;
399 std::shared_ptr<AppRunningRecord> record =
400 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
401 ASSERT_NE(record, nullptr);
402 std::shared_ptr<MockAppMgrServiceInner> appServiceInner = std::make_shared<MockAppMgrServiceInner>();
403 sptr<MockApplication> mockApp1 = sptr<MockApplication>::MakeSptr();
404 wptr<MockApplication> wp1 = mockApp1;
405
406 /**
407 * @tc.steps: step2. OnRemoteDied
408 * @tc.expected: step2. expect not matched appRunningRecord
409 */
410 EXPECT_FALSE(appRunningManager->appRunningRecordMap_.empty());
411 sptr<MockApplication> mockApp2 = sptr<MockApplication>::MakeSptr();
412 wptr<MockApplication> wp2 = mockApp2;
413 std::shared_ptr<AppRunningRecord> appRecord1 = appRunningManager->OnRemoteDied(wp2, appServiceInner); // not matched
414 EXPECT_EQ(appRecord1, nullptr); // not matched
415
416 /**
417 * @tc.steps: step3. OnRemoteDied
418 * @tc.expected: step3. expect clear matched appRunningRecord
419 */
420 record->SetApplicationClient(mockApp1);
421 std::shared_ptr<AppRunningRecord> appRecord2 = appRunningManager->OnRemoteDied(wp1, appServiceInner);
422 EXPECT_EQ(appRecord2, record); // matched
423 EXPECT_EQ(record->GetApplicationClient(), nullptr); // client set nullptr
424 }
425
426 /**
427 * @tc.name: AppRunningManager_NotifyMemoryLevel_0100
428 * @tc.desc: Test NotifyMemoryLevel
429 * @tc.type: FUNC
430 */
431 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyMemoryLevel_0100, TestSize.Level1)
432 {
433 /**
434 * @tc.steps: step1. Initialize AppRunningManager instance
435 * @tc.expected: expect step1 succeed
436 */
437 auto appRunningManager = std::make_shared<AppRunningManager>();
438 EXPECT_NE(appRunningManager, nullptr);
439 appInfo_->bundleName = BUNDLE_NAME;
440 std::shared_ptr<AppRunningRecord> record =
441 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
442 auto recordId = AppRecordId::Create();
443 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
444 std::shared_ptr<AppRunningRecord> record2 =
445 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
446 record2->priorityObject_ = nullptr;
447 auto ret = appRunningManager->NotifyMemoryLevel(1);
448
449 EXPECT_EQ(ret, ERR_OK);
450 }
451
452 /**
453 * @tc.name: AppRunningManager_NotifyProcMemoryLevel_0100
454 * @tc.desc: Test NotifyMemoryLevel
455 * @tc.type: FUNC
456 */
457 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyProcMemoryLevel_0100, TestSize.Level1)
458 {
459 /**
460 * @tc.steps: step1. Initialize AppRunningManager instance
461 * @tc.expected: expect step1 succeed
462 */
463 auto appRunningManager = std::make_shared<AppRunningManager>();
464 EXPECT_NE(appRunningManager, nullptr);
465 appInfo_->bundleName = BUNDLE_NAME;
466 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
467 auto recordId = AppRecordId::Create();
468 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
469 std::shared_ptr<AppRunningRecord> record2 =
470 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
471 record2->priorityObject_ = nullptr;
472 std::map<pid_t, MemoryLevel> procLevelMap;
473 auto ret = appRunningManager->NotifyProcMemoryLevel(procLevelMap);
474
475 EXPECT_EQ(ret, ERR_OK);
476 }
477
478 /**
479 * @tc.name: AppRunningManager_DumpHeapMemory_0100
480 * @tc.desc: Test NotifyMemoryLevel
481 * @tc.type: FUNC
482 */
483 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_DumpHeapMemory_0100, TestSize.Level1)
484 {
485 /**
486 * @tc.steps: step1. Initialize AppRunningManager instance
487 * @tc.expected: expect step1 succeed
488 */
489 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_DumpHeapMemory_0100 start");
490 auto appRunningManager = std::make_shared<AppRunningManager>();
491 EXPECT_NE(appRunningManager, nullptr);
492 appInfo_->bundleName = BUNDLE_NAME;
493 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
494
495 auto record2 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
496 record2->priorityObject_ = nullptr;
497 OHOS::AppExecFwk::MallocInfo mallocInfo;
498 auto ret = appRunningManager->DumpHeapMemory(1, mallocInfo);
499
500 EXPECT_EQ(ret, ERR_INVALID_VALUE);
501 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_DumpHeapMemory_0100 end");
502 }
503
504 /**
505 * @tc.name: GetAppRunningRecordByRenderPid
506 * @tc.desc: Test GetAppRunningRecordByRenderPid
507 * @tc.type: FUNC
508 */
509 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_GetAppRunningRecordByRenderPid_0100, TestSize.Level1)
510 {
511 /**
512 * @tc.steps: step1. Initialize AppRunningManager instance
513 * @tc.expected: expect step1 succeed
514 */
515 auto appRunningManager = std::make_shared<AppRunningManager>();
516 EXPECT_NE(appRunningManager, nullptr);
517 appInfo_->bundleName = BUNDLE_NAME;
518 auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
519 auto record2 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
520 auto renderRecord = std::make_shared<RenderRecord>(0, "", FdGuard(-1), FdGuard(-1), FdGuard(-1), record2);
521 record2->AddRenderRecord(renderRecord);
522 auto ret = appRunningManager->GetAppRunningRecordByRenderPid(1);
523
524 EXPECT_EQ(ret, nullptr);
525 }
526
527 /**
528 * @tc.name: AppRunningManager_NotifyLoadRepairPatch_0100
529 * @tc.desc: Test NotifyLoadRepairPatch
530 * @tc.type: FUNC
531 */
532 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyLoadRepairPatch_0100, TestSize.Level1)
533 {
534 /**
535 * @tc.steps: step1. Initialize AppRunningManager instance
536 * @tc.expected: expect step1 succeed
537 */
538 auto appRunningManager = std::make_shared<AppRunningManager>();
539 EXPECT_NE(appRunningManager, nullptr);
540 appInfo_->bundleName = BUNDLE_NAME;
541 auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
542 auto ret = appRunningManager->NotifyLoadRepairPatch(BUNDLE_NAME, nullptr);
543
544 /**
545 * @tc.steps: step1. nullptr
546 * @tc.expected: expect ERR_INVALID_VALUE
547 */
548 EXPECT_EQ(ret, ERR_INVALID_VALUE);
549 }
550
551 /**
552 * @tc.name: AppRunningManager_NotifyLoadRepairPatch_0200
553 * @tc.desc: Test NotifyLoadRepairPatch
554 * @tc.type: FUNC
555 */
556 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyLoadRepairPatch_0200, TestSize.Level1)
557 {
558 /**
559 * @tc.steps: step1. Initialize AppRunningManager instance
560 * @tc.expected: expect step1 succeed
561 */
562 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyLoadRepairPatch_0200 start");
563 auto appRunningManager = std::make_shared<AppRunningManager>();
564 EXPECT_NE(appRunningManager, nullptr);
565 appInfo_->bundleName = BUNDLE_NAME;
566 auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
567 sptr<MockApplication> mockApp1 = sptr<MockApplication>::MakeSptr();
568 record1->SetApplicationClient(mockApp1);
569 EXPECT_CALL(*mockApp1, ScheduleNotifyLoadRepairPatch(_, _, _)).Times(1).WillOnce(Return(ERR_OK));
570
571 auto proxy = sptr<QuickFixCallbackProxy>::MakeSptr(new QuickFixCallbackImpl());
572 auto ret = appRunningManager->NotifyLoadRepairPatch(BUNDLE_NAME, proxy);
573
574 /**
575 * @tc.steps: step1. nullptr
576 * @tc.expected: expect ERR_OK
577 */
578 EXPECT_EQ(ret, ERR_OK);
579 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyLoadRepairPatch_0200 end");
580 }
581
582 /**
583 * @tc.name: AppRunningManager_NotifyLoadRepairPatch_0300
584 * @tc.desc: Test NotifyLoadRepairPatch
585 * @tc.type: FUNC
586 */
587 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyLoadRepairPatch_0300, TestSize.Level1)
588 {
589 /**
590 * @tc.steps: step1. Initialize AppRunningManager instance
591 * @tc.expected: expect step1 succeed
592 */
593 auto proxy = sptr<QuickFixCallbackProxy>::MakeSptr(new QuickFixCallbackImpl());
594 auto appRunningManager = std::make_shared<AppRunningManager>();
595 EXPECT_NE(appRunningManager, nullptr);
596 appInfo_->bundleName = BUNDLE_NAME;
597 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
598 auto recordId = AppRecordId::Create();
599 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
600
601 /**
602 * @tc.steps: step1. Initialize AppRunningManager instance
603 * @tc.expected: expect step1 succeed
604 */
605 auto ret = appRunningManager->NotifyLoadRepairPatch("", proxy);
606 EXPECT_EQ(ret, ERR_OK);
607 }
608
609 /**
610 * @tc.name: AppRunningManager_NotifyHotReloadPage_0100
611 * @tc.desc: Test NotifyHotReloadPage
612 * @tc.type: FUNC
613 */
614 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyHotReloadPage_0100, TestSize.Level1)
615 {
616 /**
617 * @tc.steps: step1. Initialize AppRunningManager instance
618 * @tc.expected: expect step1 succeed
619 */
620 auto appRunningManager = std::make_shared<AppRunningManager>();
621 EXPECT_NE(appRunningManager, nullptr);
622 appInfo_->bundleName = BUNDLE_NAME;
623 auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
624 auto ret = appRunningManager->NotifyHotReloadPage(BUNDLE_NAME, nullptr);
625
626 /**
627 * @tc.steps: step1. nullptr
628 * @tc.expected: expect ERR_INVALID_VALUE
629 */
630 EXPECT_EQ(ret, ERR_INVALID_VALUE);
631 }
632
633 /**
634 * @tc.name: AppRunningManager_NotifyHotReloadPage_0200
635 * @tc.desc: Test NotifyLoadRepairPatch
636 * @tc.type: FUNC
637 */
638 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyHotReloadPage_0200, TestSize.Level1)
639 {
640 /**
641 * @tc.steps: step1. Initialize AppRunningManager instance
642 * @tc.expected: expect step1 succeed
643 */
644 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyHotReloadPage_0200 start");
645 auto appRunningManager = std::make_shared<AppRunningManager>();
646 EXPECT_NE(appRunningManager, nullptr);
647 appInfo_->bundleName = BUNDLE_NAME;
648 auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
649 sptr<MockApplication> mockApp1 = sptr<MockApplication>::MakeSptr();
650 record1->SetApplicationClient(mockApp1);
651 EXPECT_CALL(*mockApp1, ScheduleNotifyHotReloadPage(_, _)).Times(1).WillOnce(Return(ERR_OK));
652
653 auto proxy = sptr<QuickFixCallbackProxy>::MakeSptr(new QuickFixCallbackImpl());
654 auto ret = appRunningManager->NotifyHotReloadPage(BUNDLE_NAME, proxy);
655
656 /**
657 * @tc.steps: step1. nullptr
658 * @tc.expected: expect ERR_OK
659 */
660 EXPECT_EQ(ret, ERR_OK);
661 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyHotReloadPage_0200 end");
662 }
663
664 /**
665 * @tc.name: AppRunningManager_NotifyHotReloadPage_0300
666 * @tc.desc: Test NotifyLoadRepairPatch
667 * @tc.type: FUNC
668 */
669 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyHotReloadPage_0300, TestSize.Level1)
670 {
671 /**
672 * @tc.steps: step1. Initialize AppRunningManager instance
673 * @tc.expected: expect step1 succeed
674 */
675 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyHotReloadPage_0300 start");
676 auto proxy = sptr<QuickFixCallbackProxy>::MakeSptr(new QuickFixCallbackImpl());
677 auto appRunningManager = std::make_shared<AppRunningManager>();
678 EXPECT_NE(appRunningManager, nullptr);
679 appInfo_->bundleName = BUNDLE_NAME;
680 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
681 auto recordId = AppRecordId::Create();
682 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
683
684 /**
685 * @tc.steps: step1. Initialize AppRunningManager instance
686 * @tc.expected: expect step1 succeed
687 */
688 auto ret = appRunningManager->NotifyHotReloadPage("", proxy);
689 EXPECT_EQ(ret, ERR_OK);
690 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyHotReloadPage_0300 end");
691 }
692
693 /**
694 * @tc.name: AppRunningManager_NotifyHotReloadPage_0100
695 * @tc.desc: Test NotifyHotReloadPage
696 * @tc.type: FUNC
697 */
698 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyUnLoadRepairPatch_0100, TestSize.Level1)
699 {
700 /**
701 * @tc.steps: step1. Initialize AppRunningManager instance
702 * @tc.expected: expect step1 succeed
703 */
704 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyUnLoadRepairPatch_0100 start");
705 auto appRunningManager = std::make_shared<AppRunningManager>();
706 EXPECT_NE(appRunningManager, nullptr);
707 appInfo_->bundleName = BUNDLE_NAME;
708 auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
709 auto ret = appRunningManager->NotifyUnLoadRepairPatch(BUNDLE_NAME, nullptr);
710
711 /**
712 * @tc.steps: step1. nullptr
713 * @tc.expected: expect ERR_INVALID_VALUE
714 */
715 EXPECT_EQ(ret, ERR_INVALID_VALUE);
716 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyUnLoadRepairPatch_0100 end");
717 }
718
719 /**
720 * @tc.name: AppRunningManager_NotifyUnLoadRepairPatch_0200
721 * @tc.desc: Test NotifyUnLoadRepairPatch
722 * @tc.type: FUNC
723 */
724 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyUnLoadRepairPatch_0200, TestSize.Level1)
725 {
726 /**
727 * @tc.steps: step1. Initialize AppRunningManager instance
728 * @tc.expected: expect step1 succeed
729 */
730 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyUnLoadRepairPatch_0200 start");
731 auto appRunningManager = std::make_shared<AppRunningManager>();
732 EXPECT_NE(appRunningManager, nullptr);
733 appInfo_->bundleName = BUNDLE_NAME;
734 auto record1 = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
735 sptr<MockApplication> mockApp1 = sptr<MockApplication>::MakeSptr();
736 record1->SetApplicationClient(mockApp1);
737 EXPECT_CALL(*mockApp1, ScheduleNotifyUnLoadRepairPatch(_, _, _)).Times(1).WillOnce(Return(ERR_OK));
738
739 auto proxy = sptr<QuickFixCallbackProxy>::MakeSptr(new QuickFixCallbackImpl());
740 auto ret = appRunningManager->NotifyUnLoadRepairPatch(BUNDLE_NAME, proxy);
741
742 /**
743 * @tc.steps: step1. nullptr
744 * @tc.expected: expect ERR_OK
745 */
746 EXPECT_EQ(ret, ERR_OK);
747 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyUnLoadRepairPatch_0200 end");
748 }
749
750 /**
751 * @tc.name: AppRunningManager_NotifyUnLoadRepairPatch_0300
752 * @tc.desc: Test NotifyUnLoadRepairPatch
753 * @tc.type: FUNC
754 */
755 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_NotifyUnLoadRepairPatch_0300, TestSize.Level1)
756 {
757 /**
758 * @tc.steps: step1. Initialize AppRunningManager instance
759 * @tc.expected: expect step1 succeed
760 */
761 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyUnLoadRepairPatch_0300 start");
762 auto proxy = sptr<QuickFixCallbackProxy>::MakeSptr(new QuickFixCallbackImpl());
763 auto appRunningManager = std::make_shared<AppRunningManager>();
764 EXPECT_NE(appRunningManager, nullptr);
765 appInfo_->bundleName = BUNDLE_NAME;
766 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
767 auto recordId = AppRecordId::Create();
768 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
769
770 /**
771 * @tc.steps: step1. Initialize AppRunningManager instance
772 * @tc.expected: expect step1 succeed
773 */
774 auto ret = appRunningManager->NotifyUnLoadRepairPatch("", proxy);
775 EXPECT_EQ(ret, ERR_OK);
776 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_NotifyUnLoadRepairPatch_0300 end");
777 }
778
779 /**
780 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0100
781 * @tc.desc: Test IsApplicationFirstForeground
782 * @tc.type: FUNC
783 */
784 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0100, TestSize.Level1)
785 {
786 /**
787 * @tc.steps: step1. Initialize AppRunningManager instance
788 * @tc.expected: expect step1 succeed
789 */
790 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0100 start");
791 auto appRunningManager = std::make_shared<AppRunningManager>();
792 EXPECT_NE(appRunningManager, nullptr);
793
794 /**
795 * @tc.steps: step1. Initialize AppRunningManager instance
796 * @tc.expected: expect step1 succeed
797 */
798 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
799 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::UI;
800 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
801 EXPECT_FALSE(ret);
802 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0100 end");
803 }
804
805 /**
806 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0200
807 * @tc.desc: Test IsApplicationFirstForeground
808 * @tc.type: FUNC
809 */
810 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0200, TestSize.Level1)
811 {
812 /**
813 * @tc.steps: step1. Initialize AppRunningManager instance
814 * @tc.expected: expect step1 succeed
815 */
816 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0200 start");
817 auto appRunningManager = std::make_shared<AppRunningManager>();
818 EXPECT_NE(appRunningManager, nullptr);
819
820 /**
821 * @tc.steps: step1. Initialize AppRunningManager instance
822 * @tc.expected: expect step1 succeed
823 */
824 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
825 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::WINDOW;
826 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
827 EXPECT_FALSE(ret);
828 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0200 end");
829 }
830
831 /**
832 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0300
833 * @tc.desc: Test IsApplicationFirstForeground
834 * @tc.type: FUNC
835 */
836 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0300, TestSize.Level1)
837 {
838 /**
839 * @tc.steps: step1. Initialize AppRunningManager instance
840 * @tc.expected: expect step1 succeed
841 */
842 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0300 start");
843 auto appRunningManager = std::make_shared<AppRunningManager>();
844 EXPECT_NE(appRunningManager, nullptr);
845
846 /**
847 * @tc.steps: step1. Initialize AppRunningManager instance
848 * @tc.expected: expect true
849 */
850 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
851 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
852 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
853 EXPECT_TRUE(ret);
854 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0300 end");
855 }
856
857 /**
858 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0400
859 * @tc.desc: Test IsApplicationFirstForeground
860 * @tc.type: FUNC
861 */
862 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0400, TestSize.Level1)
863 {
864 /**
865 * @tc.steps: step1. Initialize AppRunningManager instance
866 * @tc.expected: expect step1 succeed
867 */
868 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0400 start");
869 auto appRunningManager = std::make_shared<AppRunningManager>();
870 EXPECT_NE(appRunningManager, nullptr);
871 auto recordId = AppRecordId::Create();
872 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
873
874 /**
875 * @tc.steps: step1. Initialize AppRunningManager instance
876 * @tc.expected: expect step1 not matched record return false
877 */
878 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
879 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
880 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
881 EXPECT_TRUE(ret);
882 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0400 end");
883 }
884
885 /**
886 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0500
887 * @tc.desc: Test IsApplicationFirstForeground
888 * @tc.type: FUNC
889 */
890 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0500, TestSize.Level1)
891 {
892 /**
893 * @tc.steps: step1. Initialize AppRunningManager instance
894 * @tc.expected: expect step1 succeed
895 */
896 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0500 start");
897 auto appRunningManager = std::make_shared<AppRunningManager>();
898 EXPECT_NE(appRunningManager, nullptr);
899 auto recordId = AppRecordId::Create();
900 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
901
902 /**
903 * @tc.steps: step1. Initialize AppRunningManager instance
904 * @tc.expected: expect first Foreground
905 */
906 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
907 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
908 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
909 EXPECT_TRUE(ret);
910 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0500 end");
911 }
912
913 /**
914 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0600
915 * @tc.desc: Test IsApplicationFirstForeground
916 * @tc.type: FUNC
917 */
918 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0600, TestSize.Level1)
919 {
920 /**
921 * @tc.steps: step1. Initialize AppRunningManager instance
922 * @tc.expected: expect step1 succeed
923 */
924 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0600 start");
925 auto appRunningManager = std::make_shared<AppRunningManager>();
926 EXPECT_NE(appRunningManager, nullptr);
927 appInfo_->bundleName = BUNDLE_NAME;
928 std::shared_ptr<AppRunningRecord> record =
929 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
930
931 /**
932 * @tc.steps: step1. Initialize AppRunningManager instance
933 * @tc.expected: expect first Foreground
934 */
935 appInfo_->bundleName = "";
936 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
937 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
938 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
939 EXPECT_TRUE(ret);
940 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0600 end");
941 }
942
943 /**
944 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0700
945 * @tc.desc: Test IsApplicationFirstForeground
946 * @tc.type: FUNC
947 */
948 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0700, TestSize.Level1)
949 {
950 /**
951 * @tc.steps: step1. Initialize AppRunningManager instance
952 * @tc.expected: expect step1 succeed
953 */
954 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0700 start");
955 auto appRunningManager = std::make_shared<AppRunningManager>();
956 EXPECT_NE(appRunningManager, nullptr);
957 appInfo_->bundleName = BUNDLE_NAME;
958 std::shared_ptr<AppRunningRecord> record =
959 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
960 record->extensionType_ = AppExecFwk::ExtensionAbilityType::UI;
961
962 /**
963 * @tc.steps: step1. Initialize AppRunningManager instance
964 * @tc.expected: expect first Foreground
965 */
966 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
967 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
968 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
969 EXPECT_TRUE(ret);
970 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0700 end");
971 }
972
973 /**
974 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0800
975 * @tc.desc: Test IsApplicationFirstForeground
976 * @tc.type: FUNC
977 */
978 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0800, TestSize.Level1)
979 {
980 /**
981 * @tc.steps: step1. Initialize AppRunningManager instance
982 * @tc.expected: expect step1 succeed
983 */
984 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0800 start");
985 auto appRunningManager = std::make_shared<AppRunningManager>();
986 EXPECT_NE(appRunningManager, nullptr);
987 appInfo_->bundleName = BUNDLE_NAME;
988 std::shared_ptr<AppRunningRecord> record =
989 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
990 record->extensionType_ = AppExecFwk::ExtensionAbilityType::UI;
991
992 /**
993 * @tc.steps: step1. Initialize AppRunningManager instance
994 * @tc.expected: expect first Foreground
995 */
996 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
997 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
998 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
999 EXPECT_TRUE(ret);
1000 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0800 end");
1001 }
1002
1003 /**
1004 * @tc.name: AppRunningManager_IsApplicationFirstForeground_0900
1005 * @tc.desc: Test IsApplicationFirstForeground
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_0900, TestSize.Level1)
1009 {
1010 /**
1011 * @tc.steps: step1. Initialize AppRunningManager instance
1012 * @tc.expected: expect step1 succeed
1013 */
1014 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0900 start");
1015 auto appRunningManager = std::make_shared<AppRunningManager>();
1016 EXPECT_NE(appRunningManager, nullptr);
1017 appInfo_->bundleName = BUNDLE_NAME;
1018 std::shared_ptr<AppRunningRecord> record =
1019 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1020 record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1021 record->SetAppIndex(0);
1022
1023 /**
1024 * @tc.steps: step1. Initialize AppRunningManager instance
1025 * @tc.expected: expect first Foreground
1026 */
1027 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
1028 foregroundingRecord.SetAppIndex(1);
1029 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1030 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
1031 EXPECT_TRUE(ret);
1032 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_0900 end");
1033 }
1034
1035 /**
1036 * @tc.name: AppRunningManager_IsApplicationFirstForeground_1000
1037 * @tc.desc: Test IsApplicationFirstForeground
1038 * @tc.type: FUNC
1039 */
1040 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_1000, TestSize.Level1)
1041 {
1042 /**
1043 * @tc.steps: step1. Initialize AppRunningManager instance
1044 * @tc.expected: expect step1 succeed
1045 */
1046 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_1000 start");
1047 auto appRunningManager = std::make_shared<AppRunningManager>();
1048 EXPECT_NE(appRunningManager, nullptr);
1049 appInfo_->bundleName = BUNDLE_NAME;
1050 std::shared_ptr<AppRunningRecord> record =
1051 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1052 record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1053 record->SetAppIndex(1);
1054 record->SetState(ApplicationState::APP_STATE_FOREGROUND);
1055
1056 /**
1057 * @tc.steps: step1. Initialize AppRunningManager instance
1058 * @tc.expected: expect first Foreground
1059 */
1060 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
1061 foregroundingRecord.SetAppIndex(1);
1062 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1063 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
1064 EXPECT_FALSE(ret);
1065 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_1000 end");
1066 }
1067
1068 /**
1069 * @tc.name: AppRunningManager_IsApplicationFirstForeground_1100
1070 * @tc.desc: Test IsApplicationFirstForeground
1071 * @tc.type: FUNC
1072 */
1073 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstForeground_1100, TestSize.Level1)
1074 {
1075 /**
1076 * @tc.steps: step1. Initialize AppRunningManager instance
1077 * @tc.expected: expect step1 succeed
1078 */
1079 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_1100 start");
1080 auto appRunningManager = std::make_shared<AppRunningManager>();
1081 EXPECT_NE(appRunningManager, nullptr);
1082 appInfo_->bundleName = BUNDLE_NAME;
1083 std::shared_ptr<AppRunningRecord> record =
1084 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1085 record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1086 record->SetAppIndex(1);
1087 record->SetState(ApplicationState::APP_STATE_BACKGROUND);
1088
1089 /**
1090 * @tc.steps: step1. Initialize AppRunningManager instance
1091 * @tc.expected: expect first Foreground
1092 */
1093 AppRunningRecord foregroundingRecord(appInfo_, 1, PROCESS_NAME);
1094 foregroundingRecord.SetAppIndex(1);
1095 foregroundingRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1096 auto ret = appRunningManager->IsApplicationFirstForeground(foregroundingRecord);
1097 EXPECT_TRUE(ret);
1098 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstForeground_1000 end");
1099 }
1100
1101 /**
1102 * @tc.name: AppRunningManager_IsApplicationBackground_0100
1103 * @tc.desc: Test IsApplicationBackground
1104 * @tc.type: FUNC
1105 */
1106 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_0100, TestSize.Level1)
1107 {
1108 /**
1109 * @tc.steps: step1. Initialize AppRunningManager instance
1110 * @tc.expected: expect step1 succeed
1111 */
1112 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0100 start");
1113 auto appRunningManager = std::make_shared<AppRunningManager>();
1114 EXPECT_NE(appRunningManager, nullptr);
1115
1116 /**
1117 * @tc.steps: step1. Initialize AppRunningManager instance
1118 * @tc.expected: expect true
1119 */
1120 AppRunningRecord backgroundRecord(appInfo_, 1, PROCESS_NAME);
1121 backgroundRecord.extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1122 auto ret = appRunningManager->IsApplicationBackground(backgroundRecord);
1123 EXPECT_TRUE(ret);
1124 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0100 end");
1125 }
1126
1127 /**
1128 * @tc.name: AppRunningManager_IsApplicationBackground_0200
1129 * @tc.desc: Test IsApplicationBackground
1130 * @tc.type: FUNC
1131 */
1132 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_0200, TestSize.Level1)
1133 {
1134 /**
1135 * @tc.steps: step1. Initialize AppRunningManager instance
1136 * @tc.expected: expect step1 succeed
1137 */
1138 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0200 start");
1139 auto appRunningManager = std::make_shared<AppRunningManager>();
1140 EXPECT_NE(appRunningManager, nullptr);
1141 auto recordId = AppRecordId::Create();
1142 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
1143
1144 /**
1145 * @tc.steps: step1. Initialize AppRunningManager instance
1146 * @tc.expected: expect step1 not matched record return false
1147 */
1148 AppRunningRecord backgroundRecord(appInfo_, 1, PROCESS_NAME);
1149 auto ret = appRunningManager->IsApplicationBackground(backgroundRecord);
1150 EXPECT_FALSE(ret);
1151 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0200 end");
1152 }
1153
1154 /**
1155 * @tc.name: AppRunningManager_IsApplicationBackground_0300
1156 * @tc.desc: Test IsApplicationBackground
1157 * @tc.type: FUNC
1158 */
1159 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_0300, TestSize.Level1)
1160 {
1161 /**
1162 * @tc.steps: step1. Initialize AppRunningManager instance
1163 * @tc.expected: expect step1 succeed
1164 */
1165 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0300 start");
1166 auto appRunningManager = std::make_shared<AppRunningManager>();
1167 EXPECT_NE(appRunningManager, nullptr);
1168 appInfo_->bundleName = BUNDLE_NAME;
1169 auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1170 record->extensionType_ = AppExecFwk::ExtensionAbilityType::UI;
1171
1172 /**
1173 * @tc.steps: step1. Initialize AppRunningManager instance
1174 * @tc.expected: expect first Foreground
1175 */
1176 AppRunningRecord backgroundRecord(appInfo_, 1, PROCESS_NAME);
1177 auto ret = appRunningManager->IsApplicationBackground(backgroundRecord);
1178 EXPECT_TRUE(ret);
1179 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0300 end");
1180 }
1181
1182 /**
1183 * @tc.name: AppRunningManager_IsApplicationBackground_0400
1184 * @tc.desc: Test IsApplicationBackground
1185 * @tc.type: FUNC
1186 */
1187 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_0400, TestSize.Level1)
1188 {
1189 /**
1190 * @tc.steps: step1. Initialize AppRunningManager instance
1191 * @tc.expected: expect step1 succeed
1192 */
1193 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0400 start");
1194 auto appRunningManager = std::make_shared<AppRunningManager>();
1195 EXPECT_NE(appRunningManager, nullptr);
1196 appInfo_->bundleName = BUNDLE_NAME;
1197 auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1198 record->extensionType_ = AppExecFwk::ExtensionAbilityType::WINDOW;
1199
1200 /**
1201 * @tc.steps: step1. Initialize AppRunningManager instance
1202 * @tc.expected: expect first Foreground
1203 */
1204 AppRunningRecord backgroundRecord(appInfo_, 1, PROCESS_NAME);
1205 auto ret = appRunningManager->IsApplicationBackground(backgroundRecord);
1206 EXPECT_TRUE(ret);
1207 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0400 end");
1208 }
1209
1210 /**
1211 * @tc.name: AppRunningManager_IsApplicationBackground_0500
1212 * @tc.desc: Test IsApplicationBackground
1213 * @tc.type: FUNC
1214 */
1215 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_0500, TestSize.Level1)
1216 {
1217 /**
1218 * @tc.steps: step1. Initialize AppRunningManager instance
1219 * @tc.expected: expect step1 succeed
1220 */
1221 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0500 start");
1222 auto appRunningManager = std::make_shared<AppRunningManager>();
1223 EXPECT_NE(appRunningManager, nullptr);
1224
1225 appInfo_->bundleName = BUNDLE_NAME;
1226 auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1227 record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1228 record->SetState(ApplicationState::APP_STATE_FOREGROUND);
1229
1230 /**
1231 * @tc.steps: step1. Initialize AppRunningManager instance
1232 * @tc.expected: expect step1 not matched record return false
1233 */
1234 AppRunningRecord backgroundRecord(appInfo_, 1, PROCESS_NAME);
1235 auto ret = appRunningManager->IsApplicationBackground(backgroundRecord);
1236 EXPECT_FALSE(ret);
1237 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0500 end");
1238 }
1239
1240 /**
1241 * @tc.name: AppRunningManager_IsApplicationBackground_0500
1242 * @tc.desc: Test IsApplicationBackground
1243 * @tc.type: FUNC
1244 */
1245 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationBackground_0600, TestSize.Level1)
1246 {
1247 /**
1248 * @tc.steps: step1. Initialize AppRunningManager instance
1249 * @tc.expected: expect step1 succeed
1250 */
1251 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0600 start");
1252 auto appRunningManager = std::make_shared<AppRunningManager>();
1253 EXPECT_NE(appRunningManager, nullptr);
1254 appInfo_->bundleName = BUNDLE_NAME;
1255 auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1256 record->extensionType_ = AppExecFwk::ExtensionAbilityType::SERVICE;
1257 record->SetAppIndex(1);
1258 record->SetState(ApplicationState::APP_STATE_BACKGROUND);
1259
1260 /**
1261 * @tc.steps: step1. Initialize AppRunningManager instance
1262 * @tc.expected: expect step1 not matched record return false
1263 */
1264 appInfo_->bundleName = "";
1265 AppRunningRecord backgroundRecord(appInfo_, 1, PROCESS_NAME);
1266 backgroundRecord.SetAppIndex(1);
1267 auto ret = appRunningManager->IsApplicationBackground(backgroundRecord);
1268 EXPECT_TRUE(ret);
1269 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationBackground_0600 end");
1270 }
1271
1272 /**
1273 * @tc.name: AppRunningManager_IsApplicationFirstFocused_0100
1274 * @tc.desc: Test IsApplicationFirstFocused
1275 * @tc.type: FUNC
1276 */
1277 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocused_0100, TestSize.Level1)
1278 {
1279 /**
1280 * @tc.steps: step1. Initialize AppRunningManager instance
1281 * @tc.expected: expect step1 succeed
1282 */
1283 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0100 start");
1284 auto appRunningManager = std::make_shared<AppRunningManager>();
1285 EXPECT_NE(appRunningManager, nullptr);
1286 auto recordId = AppRecordId::Create();
1287 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
1288
1289 /**
1290 * @tc.steps: step2. Initialize AppRunningManager instance
1291 * @tc.expected: expect step1 first focused true
1292 */
1293 AppRunningRecord focusRecord(appInfo_, 1, PROCESS_NAME);
1294 auto ret = appRunningManager->IsApplicationFirstFocused(focusRecord);
1295 EXPECT_TRUE(ret);
1296 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0100 end");
1297 }
1298
1299 /**
1300 * @tc.name: AppRunningManager_IsApplicationFirstFocused_0200
1301 * @tc.desc: Test IsApplicationFirstFocused
1302 * @tc.type: FUNC
1303 */
1304 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocused_0200, TestSize.Level1)
1305 {
1306 /**
1307 * @tc.steps: step1. Initialize AppRunningManager instance
1308 * @tc.expected: expect step1 succeed
1309 */
1310 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0200 start");
1311 auto appRunningManager = std::make_shared<AppRunningManager>();
1312 EXPECT_NE(appRunningManager, nullptr);
1313 appInfo_->bundleName = BUNDLE_NAME;
1314 std::shared_ptr<AppRunningRecord> record =
1315 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1316
1317 /**
1318 * @tc.steps: step2. Initialize AppRunningManager instance
1319 * @tc.expected: expect step1 different bundle first focused true
1320 */
1321 appInfo_->bundleName = "";
1322 AppRunningRecord focusRecord(appInfo_, 1, PROCESS_NAME);
1323 auto ret = appRunningManager->IsApplicationFirstFocused(focusRecord);
1324 EXPECT_TRUE(ret);
1325 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0200 end");
1326 }
1327
1328 /**
1329 * @tc.name: AppRunningManager_IsApplicationFirstFocused_0300
1330 * @tc.desc: Test IsApplicationFirstFocused
1331 * @tc.type: FUNC
1332 */
1333 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocused_0300, TestSize.Level1)
1334 {
1335 /**
1336 * @tc.steps: step1. Initialize AppRunningManager instance
1337 * @tc.expected: expect step1 succeed
1338 */
1339 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0300 start");
1340 auto appRunningManager = std::make_shared<AppRunningManager>();
1341 EXPECT_NE(appRunningManager, nullptr);
1342 appInfo_->bundleName = BUNDLE_NAME;
1343 std::shared_ptr<AppRunningRecord> record =
1344 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1345
1346 /**
1347 * @tc.steps: step2. Initialize AppRunningManager instance
1348 * @tc.expected: expect step2 focused false
1349 */
1350 AppRunningRecord focusRecord(appInfo_, 1, PROCESS_NAME);
1351 auto ret = appRunningManager->IsApplicationFirstFocused(focusRecord);
1352 EXPECT_TRUE(ret);
1353 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0300 end");
1354 }
1355
1356 /**
1357 * @tc.name: AppRunningManager_IsApplicationFirstFocused_0400
1358 * @tc.desc: Test IsApplicationFirstFocused
1359 * @tc.type: FUNC
1360 */
1361 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocused_0400, TestSize.Level1)
1362 {
1363 /**
1364 * @tc.steps: step1. Initialize AppRunningManager instance
1365 * @tc.expected: expect step1 succeed
1366 */
1367 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0400 start");
1368 auto appRunningManager = std::make_shared<AppRunningManager>();
1369 EXPECT_NE(appRunningManager, nullptr);
1370 appInfo_->bundleName = BUNDLE_NAME;
1371 auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1372 auto abilityInfo = std::make_shared<AbilityInfo>();
1373 auto ability = std::make_shared<AbilityRunningRecord>(abilityInfo, nullptr, 0);
1374 record->AbilityFocused(ability);
1375 EXPECT_TRUE(record->GetFocusFlag());
1376
1377 /**
1378 * @tc.steps: step2. Initialize AppRunningManager instance
1379 * @tc.expected: expect step1 focused false
1380 */
1381 AppRunningRecord focusRecord(appInfo_, 1, PROCESS_NAME);
1382 focusRecord.appRecordId_ = record->GetRecordId();
1383 auto ret = appRunningManager->IsApplicationFirstFocused(focusRecord);
1384 EXPECT_TRUE(ret);
1385 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0400 end");
1386 }
1387
1388 /**
1389 * @tc.name: AppRunningManager_IsApplicationFirstFocused_0500
1390 * @tc.desc: Test IsApplicationFirstFocused
1391 * @tc.type: FUNC
1392 */
1393 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationFirstFocused_0500, TestSize.Level1)
1394 {
1395 /**
1396 * @tc.steps: step1. Initialize AppRunningManager instance
1397 * @tc.expected: expect step1 succeed
1398 */
1399 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0500 start");
1400 auto appRunningManager = std::make_shared<AppRunningManager>();
1401 EXPECT_NE(appRunningManager, nullptr);
1402 appInfo_->bundleName = BUNDLE_NAME;
1403 auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1404 auto abilityInfo = std::make_shared<AbilityInfo>();
1405 auto ability = std::make_shared<AbilityRunningRecord>(abilityInfo, nullptr, 0);
1406 record->AbilityFocused(ability);
1407 EXPECT_TRUE(record->GetFocusFlag());
1408
1409 /**
1410 * @tc.steps: step2. Initialize AppRunningManager instance
1411 * @tc.expected: expect step1 focused false
1412 */
1413 AppRunningRecord focusRecord(appInfo_, 1, PROCESS_NAME);
1414 focusRecord.appRecordId_ = record->GetRecordId() + 1;
1415 auto ret = appRunningManager->IsApplicationFirstFocused(focusRecord);
1416 EXPECT_FALSE(ret);
1417 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationFirstFocused_0500 end");
1418 }
1419
1420 /**
1421 * @tc.name: AppRunningManager_IsApplicationUnfocused_0100
1422 * @tc.desc: Test IsApplicationFirstFocused
1423 * @tc.type: FUNC
1424 */
1425 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationUnfocused_0100, TestSize.Level1)
1426 {
1427 /**
1428 * @tc.steps: step1. Initialize AppRunningManager instance
1429 * @tc.expected: expect step1 succeed
1430 */
1431 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationUnfocused_0100 start");
1432 auto appRunningManager = std::make_shared<AppRunningManager>();
1433 EXPECT_NE(appRunningManager, nullptr);
1434 auto recordId = AppRecordId::Create();
1435 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
1436
1437 /**
1438 * @tc.steps: step2. Initialize AppRunningManager instance
1439 * @tc.expected: expect step1 first focused true
1440 */
1441 auto ret = appRunningManager->IsApplicationUnfocused("");
1442 EXPECT_TRUE(ret);
1443 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationUnfocused_0100 end");
1444 }
1445
1446 /**
1447 * @tc.name: AppRunningManager_IsApplicationUnfocused_0200
1448 * @tc.desc: Test IsApplicationUnfocused
1449 * @tc.type: FUNC
1450 */
1451 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationUnfocused_0200, TestSize.Level1)
1452 {
1453 /**
1454 * @tc.steps: step1. Initialize AppRunningManager instance
1455 * @tc.expected: expect step1 succeed
1456 */
1457 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationUnfocused_0200 start");
1458 auto appRunningManager = std::make_shared<AppRunningManager>();
1459 EXPECT_NE(appRunningManager, nullptr);
1460 appInfo_->bundleName = BUNDLE_NAME;
1461 std::shared_ptr<AppRunningRecord> record =
1462 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1463
1464 /**
1465 * @tc.steps: step2. Initialize AppRunningManager instance
1466 * @tc.expected: expect step1 different bundle unfocused true
1467 */
1468 auto ret = appRunningManager->IsApplicationUnfocused("");
1469 EXPECT_TRUE(ret);
1470 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationUnfocused_0200 end");
1471 }
1472
1473 /**
1474 * @tc.name: AppRunningManager_IsApplicationUnfocused_0300
1475 * @tc.desc: Test IsApplicationFirstFocused
1476 * @tc.type: FUNC
1477 */
1478 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationUnfocused_0300, TestSize.Level1)
1479 {
1480 /**
1481 * @tc.steps: step1. Initialize AppRunningManager instance
1482 * @tc.expected: expect step1 succeed
1483 */
1484 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationUnfocused_0300 start");
1485 auto appRunningManager = std::make_shared<AppRunningManager>();
1486 EXPECT_NE(appRunningManager, nullptr);
1487 appInfo_->bundleName = BUNDLE_NAME;
1488 std::shared_ptr<AppRunningRecord> record =
1489 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1490
1491 /**
1492 * @tc.steps: step2. Initialize AppRunningManager instance
1493 * @tc.expected: expect step2 focused false
1494 */
1495 auto ret = appRunningManager->IsApplicationUnfocused(BUNDLE_NAME);
1496 EXPECT_TRUE(ret);
1497 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationUnfocused_0300 end");
1498 }
1499
1500 /**
1501 * @tc.name: AppRunningManager_IsApplicationUnfocused_0400
1502 * @tc.desc: Test IsApplicationFirstFocused
1503 * @tc.type: FUNC
1504 */
1505 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_IsApplicationUnfocused_0400, TestSize.Level1)
1506 {
1507 /**
1508 * @tc.steps: step1. Initialize AppRunningManager instance
1509 * @tc.expected: expect step1 succeed
1510 */
1511 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationUnfocused_0400 start");
1512 auto appRunningManager = std::make_shared<AppRunningManager>();
1513 EXPECT_NE(appRunningManager, nullptr);
1514 appInfo_->bundleName = BUNDLE_NAME;
1515 auto record = appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1516 auto abilityInfo = std::make_shared<AbilityInfo>();
1517 auto ability = std::make_shared<AbilityRunningRecord>(abilityInfo, nullptr, 0);
1518 record->AbilityFocused(ability);
1519 EXPECT_TRUE(record->GetFocusFlag());
1520
1521 /**
1522 * @tc.steps: step2. Initialize AppRunningManager instance
1523 * @tc.expected: expect step1 focused false
1524 */
1525 auto ret = appRunningManager->IsApplicationUnfocused(BUNDLE_NAME);
1526 EXPECT_FALSE(ret);
1527 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_IsApplicationUnfocused_0400 end");
1528 }
1529
1530 /**
1531 * @tc.name: AppRunningManager_SignRestartAppFlag_0100
1532 * @tc.desc: Test SignRestartAppFlag
1533 * @tc.type: FUNC
1534 */
1535 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_SignRestartAppFlag_0100, TestSize.Level1)
1536 {
1537 /**
1538 * @tc.steps: step1. Initialize AppRunningManager instance
1539 * @tc.expected: expect step1 succeed
1540 */
1541 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0100 start");
1542 auto appRunningManager = std::make_shared<AppRunningManager>();
1543 EXPECT_NE(appRunningManager, nullptr);
1544 auto recordId = AppRecordId::Create();
1545 appRunningManager->appRunningRecordMap_.emplace(recordId, nullptr);
1546
1547 /**
1548 * @tc.steps: step2. Initialize AppRunningManager instance
1549 * @tc.expected: expect step1 first focused true
1550 */
1551 auto ret = appRunningManager->SignRestartAppFlag(0, "");
1552 EXPECT_EQ(ret, ERR_INVALID_VALUE);
1553 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0100 end");
1554 }
1555
1556 /**
1557 * @tc.name: AppRunningManager_SignRestartAppFlag_0200
1558 * @tc.desc: Test IsApplicationUnfocused
1559 * @tc.type: FUNC
1560 */
1561 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_SignRestartAppFlag_0200, TestSize.Level1)
1562 {
1563 /**
1564 * @tc.steps: step1. Initialize AppRunningManager instance
1565 * @tc.expected: expect step1 succeed
1566 */
1567 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0200 start");
1568 auto appRunningManager = std::make_shared<AppRunningManager>();
1569 EXPECT_NE(appRunningManager, nullptr);
1570 appInfo_->bundleName = BUNDLE_NAME;
1571 std::shared_ptr<AppRunningRecord> record =
1572 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1573
1574 /**
1575 * @tc.steps: step2. Initialize AppRunningManager instance
1576 * @tc.expected: expect step1 different bundle unfocused true
1577 */
1578 auto ret = appRunningManager->SignRestartAppFlag(0, "");
1579 EXPECT_EQ(ret, ERR_INVALID_VALUE);
1580 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0200 end");
1581 }
1582
1583 /**
1584 * @tc.name: AppRunningManager_SignRestartAppFlag_0300
1585 * @tc.desc: Test IsApplicationFirstFocused
1586 * @tc.type: FUNC
1587 */
1588 HWTEST_F(AppRunningManagerSecondTest, AppRunningManager_SignRestartAppFlag_0300, TestSize.Level1)
1589 {
1590 /**
1591 * @tc.steps: step1. Initialize AppRunningManager instance
1592 * @tc.expected: expect step1 succeed
1593 */
1594 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0300 start");
1595 auto appRunningManager = std::make_shared<AppRunningManager>();
1596 EXPECT_NE(appRunningManager, nullptr);
1597 appInfo_->bundleName = BUNDLE_NAME;
1598 std::shared_ptr<AppRunningRecord> record =
1599 appRunningManager->CreateAppRunningRecord(appInfo_, PROCESS_NAME, bundleInfo, "");
1600 record->SetUid(0);
1601
1602 /**
1603 * @tc.steps: step2. Initialize AppRunningManager instance
1604 * @tc.expected: expect step2 focused false
1605 */
1606 auto ret = appRunningManager->SignRestartAppFlag(0, "");
1607 EXPECT_EQ(ret, ERR_OK);
1608 EXPECT_TRUE(record->GetRestartAppFlag());
1609 TAG_LOGI(AAFwkTag::TEST, "AppRunningManager_SignRestartAppFlag_0300 end");
1610 }
1611 } // namespace AppExecFwk
1612 } // namespace OHOS