• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "ability_foreground_state_observer_proxy.h"
19 #define private public
20 #include "app_state_observer_manager.h"
21 #undef private
22 #include "app_foreground_state_observer_proxy.h"
23 #include "app_foreground_state_observer_stub.h"
24 #include "application_state_observer_stub.h"
25 #include "iapplication_state_observer.h"
26 #include "iremote_broker.h"
27 #include "mock_ability_foreground_state_observer_server_stub.h"
28 #include "mock_i_remote_object.h"
29 
30 using namespace testing;
31 using namespace testing::ext;
32 
33 namespace OHOS {
34 namespace AppExecFwk {
35 namespace {
36 const int BUNDLE_NAME_LIST_MAX_SIZE = 128;
37 }
38 class MockApplicationStateObserver : public IApplicationStateObserver {
39 public:
40     MockApplicationStateObserver() = default;
41     virtual ~MockApplicationStateObserver() = default;
OnForegroundApplicationChanged(const AppStateData & appStateData)42     void OnForegroundApplicationChanged(const AppStateData &appStateData) override
43     {}
OnAbilityStateChanged(const AbilityStateData & abilityStateData)44     void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override
45     {}
OnExtensionStateChanged(const AbilityStateData & abilityStateData)46     void OnExtensionStateChanged(const AbilityStateData &abilityStateData) override
47     {}
OnProcessCreated(const ProcessData & processData)48     void OnProcessCreated(const ProcessData &processData) override
49     {}
OnProcessStateChanged(const ProcessData & processData)50     void OnProcessStateChanged(const ProcessData &processData) override
51     {}
OnProcessDied(const ProcessData & processData)52     void OnProcessDied(const ProcessData &processData) override
53     {}
OnApplicationStateChanged(const AppStateData & appStateData)54     void OnApplicationStateChanged(const AppStateData &appStateData) override
55     {}
OnAppStateChanged(const AppStateData & appStateData)56     void OnAppStateChanged(const AppStateData &appStateData) override
57     {}
OnAppStarted(const AppStateData & appStateData)58     void OnAppStarted(const AppStateData &appStateData) override
59     {}
OnAppStopped(const AppStateData & appStateData)60     void OnAppStopped(const AppStateData &appStateData) override
61     {}
AsObject()62     sptr<IRemoteObject> AsObject() override
63     {
64         return {};
65     }
66 };
67 class AppForegroundStateObserver : public AppForegroundStateObserverStub {
68 public:
69     AppForegroundStateObserver() = default;
70     virtual ~AppForegroundStateObserver() = default;
OnAppStateChanged(const AppStateData & appStateData)71     void OnAppStateChanged(const AppStateData &appStateData) override
72     {}
73 };
74 class AppSpawnSocketTest : public testing::Test {
75 public:
76     static void SetUpTestCase();
77     static void TearDownTestCase();
78     void SetUp();
79     void TearDown();
80     std::shared_ptr<AppRunningRecord> MockAppRecord();
81     sptr<IApplicationStateObserver> observer_ {nullptr};
82 };
83 
SetUpTestCase()84 void AppSpawnSocketTest::SetUpTestCase()
85 {}
86 
TearDownTestCase()87 void AppSpawnSocketTest::TearDownTestCase()
88 {}
89 
SetUp()90 void AppSpawnSocketTest::SetUp()
91 {
92     sptr<IApplicationStateObserver> observer_ = new MockApplicationStateObserver();
93 }
94 
TearDown()95 void AppSpawnSocketTest::TearDown()
96 {}
97 
MockAppRecord()98 std::shared_ptr<AppRunningRecord> AppSpawnSocketTest::MockAppRecord()
99 {
100     ApplicationInfo appInfo;
101     appInfo.accessTokenId = 1;
102     std::shared_ptr<ApplicationInfo> info = std::make_shared<ApplicationInfo>(appInfo);
103     info->accessTokenId = 1;
104     std::shared_ptr<AppRunningRecord> appRecord = std::make_shared<AppRunningRecord>(info, 0, "process");
105     std::shared_ptr<PriorityObject> priorityObject = std::make_shared<PriorityObject>();
106     priorityObject->SetPid(1);
107     appRecord->priorityObject_ = priorityObject;
108     appRecord->SetUid(1);
109     appRecord->SetState(ApplicationState::APP_STATE_CREATE);
110     appRecord->SetContinuousTaskAppState(false);
111     appRecord->SetKeepAliveEnableState(false);
112     appRecord->SetKeepAliveDkv(false);
113     appRecord->SetEmptyKeepAliveAppState(false);
114     appRecord->SetRequestProcCode(1);
115     appRecord->isFocused_ = false;
116     return appRecord;
117 }
118 
119 /*
120  * Feature: AppStateObserverManager
121  * Function: RegisterApplicationStateObserver
122  * SubFunction: NA
123  * FunctionPoints: AppStateObserverManager RegisterApplicationStateObserver
124  * EnvConditions: NA
125  * CaseDescription: Verify RegisterApplicationStateObserver
126  */
127 HWTEST_F(AppSpawnSocketTest, RegisterApplicationStateObserver_001, TestSize.Level0)
128 {
129     auto manager = std::make_shared<AppStateObserverManager>();
130     vector<std::string> bundleNameList;
131     int32_t res = manager->RegisterApplicationStateObserver(nullptr, bundleNameList);
132     EXPECT_EQ(res, ERR_PERMISSION_DENIED);
133 }
134 
135 /*
136  * Feature: AppStateObserverManager
137  * Function: RegisterApplicationStateObserver
138  * SubFunction: NA
139  * FunctionPoints: AppStateObserverManager RegisterApplicationStateObserver
140  * EnvConditions: NA
141  * CaseDescription: Verify RegisterApplicationStateObserver
142  */
143 HWTEST_F(AppSpawnSocketTest, RegisterApplicationStateObserver_002, TestSize.Level0)
144 {
145     auto manager = std::make_shared<AppStateObserverManager>();
146     vector<std::string> bundleNameList;
147     while (bundleNameList.size() <= BUNDLE_NAME_LIST_MAX_SIZE) {
148         bundleNameList.push_back("a");
149     }
150     int32_t res = manager->RegisterApplicationStateObserver(nullptr, bundleNameList);
151     EXPECT_EQ(res, ERR_INVALID_VALUE);
152 }
153 
154 /*
155  * Feature: AppStateObserverManager
156  * Function: UnregisterApplicationStateObserver
157  * SubFunction: NA
158  * FunctionPoints: AppStateObserverManager UnregisterApplicationStateObserver
159  * EnvConditions: NA
160  * CaseDescription: Verify UnregisterApplicationStateObserver
161  */
162 HWTEST_F(AppSpawnSocketTest, UnregisterApplicationStateObserver_001, TestSize.Level0)
163 {
164     auto manager = std::make_shared<AppStateObserverManager>();
165     int32_t res = manager->UnregisterApplicationStateObserver(nullptr);
166     EXPECT_EQ(res, ERR_PERMISSION_DENIED);
167 }
168 
169 /*
170  * Feature: AppStateObserverManager
171  * Function: OnAppStarted
172  * SubFunction: NA
173  * FunctionPoints: AppStateObserverManager OnAppStarted
174  * EnvConditions: NA
175  * CaseDescription: Verify OnAppStarted
176  */
177 HWTEST_F(AppSpawnSocketTest, OnAppStarted_001, TestSize.Level0)
178 {
179     auto manager = std::make_shared<AppStateObserverManager>();
180     ASSERT_NE(manager, nullptr);
181     std::shared_ptr<AppRunningRecord> appRecord;
182     manager->OnAppStarted(appRecord);
183     manager->Init();
184     manager->OnAppStarted(appRecord);
185 }
186 
187 /*
188  * Feature: AppStateObserverManager
189  * Function: OnAppStopped
190  * SubFunction: NA
191  * FunctionPoints: AppStateObserverManager OnAppStopped
192  * EnvConditions: NA
193  * CaseDescription: Verify OnAppStopped
194  */
195 HWTEST_F(AppSpawnSocketTest, OnAppStopped_001, TestSize.Level0)
196 {
197     auto manager = std::make_shared<AppStateObserverManager>();
198     ASSERT_NE(manager, nullptr);
199     std::shared_ptr<AppRunningRecord> appRecord;
200     manager->OnAppStopped(appRecord);
201     manager->Init();
202     manager->OnAppStopped(appRecord);
203 }
204 
205 /*
206  * Feature: AppStateObserverManager
207  * Function: OnAppStateChanged
208  * SubFunction: NA
209  * FunctionPoints: AppStateObserverManager OnAppStateChanged
210  * EnvConditions: NA
211  * CaseDescription: Verify OnAppStateChanged
212  */
213 HWTEST_F(AppSpawnSocketTest, OnAppStateChanged_001, TestSize.Level0)
214 {
215     auto manager = std::make_shared<AppStateObserverManager>();
216     ASSERT_NE(manager, nullptr);
217     std::shared_ptr<AppRunningRecord> appRecord;
218     ApplicationState state = ApplicationState::APP_STATE_CREATE;
219     bool needNotifyApp = false;
220     manager->OnAppStateChanged(appRecord, state, needNotifyApp, false);
221 }
222 
223 /*
224  * Feature: AppStateObserverManager
225  * Function: OnAppStateChanged
226  * SubFunction: NA
227  * FunctionPoints: AppStateObserverManager OnAppStateChanged
228  * EnvConditions: NA
229  * CaseDescription: Verify OnAppStateChanged
230  */
231 HWTEST_F(AppSpawnSocketTest, OnAppStateChanged_002, TestSize.Level0)
232 {
233     auto manager = std::make_shared<AppStateObserverManager>();
234     ASSERT_NE(manager, nullptr);
235     std::shared_ptr<AppRunningRecord> appRecord;
236     ApplicationState state = ApplicationState::APP_STATE_CREATE;
237     bool needNotifyApp = false;
238     manager->Init();
239     manager->OnAppStateChanged(appRecord, state, needNotifyApp, false);
240 }
241 
242 /*
243  * Feature: AppStateObserverManager
244  * Function: OnProcessDied
245  * SubFunction: NA
246  * FunctionPoints: AppStateObserverManager OnProcessDied
247  * EnvConditions: NA
248  * CaseDescription: Verify OnProcessDied
249  */
250 HWTEST_F(AppSpawnSocketTest, OnProcessDied_001, TestSize.Level0)
251 {
252     auto manager = std::make_shared<AppStateObserverManager>();
253     ASSERT_NE(manager, nullptr);
254     std::shared_ptr<AppRunningRecord> appRecord;
255     manager->OnProcessDied(appRecord);
256     manager->Init();
257     manager->OnProcessDied(appRecord);
258 }
259 
260 /*
261  * Feature: AppStateObserverManager
262  * Function: OnRenderProcessDied
263  * SubFunction: NA
264  * FunctionPoints: AppStateObserverManager OnRenderProcessDied
265  * EnvConditions: NA
266  * CaseDescription: Verify OnRenderProcessDied
267  */
268 HWTEST_F(AppSpawnSocketTest, OnRenderProcessDied_001, TestSize.Level0)
269 {
270     auto manager = std::make_shared<AppStateObserverManager>();
271     ASSERT_NE(manager, nullptr);
272     std::shared_ptr<RenderRecord> renderRecord;
273     manager->OnRenderProcessDied(renderRecord);
274     manager->Init();
275     manager->OnRenderProcessDied(renderRecord);
276 }
277 
278 /*
279  * Feature: AppStateObserverManager
280  * Function: OnProcessStateChanged
281  * SubFunction: NA
282  * FunctionPoints: AppStateObserverManager OnProcessStateChanged
283  * EnvConditions: NA
284  * CaseDescription: Verify OnProcessStateChanged
285  */
286 HWTEST_F(AppSpawnSocketTest, OnProcessStateChanged_001, TestSize.Level0)
287 {
288     auto manager = std::make_shared<AppStateObserverManager>();
289     ASSERT_NE(manager, nullptr);
290     std::shared_ptr<AppRunningRecord> appRecord;
291     manager->OnProcessStateChanged(appRecord);
292     manager->Init();
293     manager->OnProcessStateChanged(appRecord);
294 }
295 
296 /*
297  * Feature: AppStateObserverManager
298  * Function: OnProcessCreated
299  * SubFunction: NA
300  * FunctionPoints: AppStateObserverManager OnProcessCreated
301  * EnvConditions: NA
302  * CaseDescription: Verify OnProcessCreated
303  */
304 HWTEST_F(AppSpawnSocketTest, OnProcessCreated_001, TestSize.Level0)
305 {
306     auto manager = std::make_shared<AppStateObserverManager>();
307     ASSERT_NE(manager, nullptr);
308     std::shared_ptr<AppRunningRecord> appRecord;
309     manager->OnProcessCreated(appRecord, false);
310     manager->Init();
311     manager->OnProcessCreated(appRecord, false);
312 }
313 
314 /*
315  * Feature: AppStateObserverManager
316  * Function: OnWindowShow
317  * SubFunction: NA
318  * FunctionPoints: AppStateObserverManager OnWindowShow
319  * EnvConditions: NA
320  * CaseDescription: Verify OnWindowShow
321  */
322 HWTEST_F(AppSpawnSocketTest, OnWindowShow_001, TestSize.Level0)
323 {
324     auto manager = std::make_shared<AppStateObserverManager>();
325     ASSERT_NE(manager, nullptr);
326     std::shared_ptr<AppRunningRecord> appRecord;
327     manager->OnWindowShow(appRecord);
328     manager->Init();
329     manager->OnWindowShow(appRecord);
330 }
331 
332 /*
333  * Feature: AppStateObserverManager
334  * Function: OnWindowHidden
335  * SubFunction: NA
336  * FunctionPoints: AppStateObserverManager OnWindowHidden
337  * EnvConditions: NA
338  * CaseDescription: Verify OnWindowHidden
339  */
340 HWTEST_F(AppSpawnSocketTest, OnWindowHidden_001, TestSize.Level0)
341 {
342     auto manager = std::make_shared<AppStateObserverManager>();
343     ASSERT_NE(manager, nullptr);
344     std::shared_ptr<AppRunningRecord> appRecord;
345     manager->OnWindowHidden(appRecord);
346     manager->Init();
347     manager->OnWindowHidden(appRecord);
348 }
349 
350 /*
351  * Feature: AppStateObserverManager
352  * Function: HandleOnWindowShow
353  * SubFunction: NA
354  * FunctionPoints: AppStateObserverManager HandleOnWindowShow
355  * EnvConditions: NA
356  * CaseDescription: Verify HandleOnWindowShow
357  */
358 HWTEST_F(AppSpawnSocketTest, HandleOnWindowShow_001, TestSize.Level0)
359 {
360     auto manager = std::make_shared<AppStateObserverManager>();
361     ASSERT_NE(manager, nullptr);
362     manager->HandleOnWindowShow(nullptr);
363 }
364 
365 /*
366  * Feature: AppStateObserverManager
367  * Function: HandleOnWindowShow
368  * SubFunction: NA
369  * FunctionPoints: AppStateObserverManager HandleOnWindowShow
370  * EnvConditions: NA
371  * CaseDescription: Verify HandleOnWindowShow
372  */
373 HWTEST_F(AppSpawnSocketTest, HandleOnWindowShow_002, TestSize.Level0)
374 {
375     auto manager = std::make_shared<AppStateObserverManager>();
376     ASSERT_NE(manager, nullptr);
377     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
378     std::vector<std::string> bundleNameList;
379     std::string bundleName = "com.ohos.unittest";
380     appRecord->mainBundleName_ = bundleName;
381     bundleNameList.push_back(bundleName);
382     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
383     manager->HandleOnWindowShow(appRecord);
384 }
385 
386 /*
387  * Feature: AppStateObserverManager
388  * Function: HandleOnWindowHidden
389  * SubFunction: NA
390  * FunctionPoints: AppStateObserverManager HandleOnWindowHidden
391  * EnvConditions: NA
392  * CaseDescription: Verify HandleOnWindowHidden
393  */
394 HWTEST_F(AppSpawnSocketTest, HandleOnWindowHidden_001, TestSize.Level0)
395 {
396     auto manager = std::make_shared<AppStateObserverManager>();
397     ASSERT_NE(manager, nullptr);
398     manager->HandleOnWindowHidden(nullptr);
399 }
400 
401 /*
402  * Feature: AppStateObserverManager
403  * Function: HandleOnWindowHidden
404  * SubFunction: NA
405  * FunctionPoints: AppStateObserverManager HandleOnWindowHidden
406  * EnvConditions: NA
407  * CaseDescription: Verify HandleOnWindowHidden
408  */
409 HWTEST_F(AppSpawnSocketTest, HandleOnWindowHidden_002, TestSize.Level0)
410 {
411     auto manager = std::make_shared<AppStateObserverManager>();
412     ASSERT_NE(manager, nullptr);
413     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
414     std::vector<std::string> bundleNameList;
415     std::string bundleName = "com.ohos.unittest";
416     appRecord->mainBundleName_ = bundleName;
417     bundleNameList.push_back(bundleName);
418     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
419     manager->HandleOnWindowHidden(appRecord);
420 }
421 
422 /*
423  * Feature: AppStateObserverManager
424  * Function: OnRenderProcessCreated
425  * SubFunction: NA
426  * FunctionPoints: AppStateObserverManager OnRenderProcessCreated
427  * EnvConditions: NA
428  * CaseDescription: Verify OnRenderProcessCreated
429  */
430 HWTEST_F(AppSpawnSocketTest, OnRenderProcessCreated_001, TestSize.Level0)
431 {
432     auto manager = std::make_shared<AppStateObserverManager>();
433     ASSERT_NE(manager, nullptr);
434     std::shared_ptr<RenderRecord> renderRecord;
435     manager->OnRenderProcessCreated(renderRecord, false);
436     manager->Init();
437     manager->OnRenderProcessCreated(renderRecord, false);
438 }
439 
440 /*
441  * Feature: AppStateObserverManager
442  * Function: StateChangedNotifyObserver
443  * SubFunction: NA
444  * FunctionPoints: AppStateObserverManager StateChangedNotifyObserver
445  * EnvConditions: NA
446  * CaseDescription: Verify StateChangedNotifyObserver
447  */
448 HWTEST_F(AppSpawnSocketTest, StateChangedNotifyObserver_001, TestSize.Level0)
449 {
450     auto manager = std::make_shared<AppStateObserverManager>();
451     ASSERT_NE(manager, nullptr);
452     AbilityStateData abilityStateData;
453     bool isAbility = false;
454     manager->StateChangedNotifyObserver(abilityStateData, isAbility, false);
455     manager->Init();
456     manager->StateChangedNotifyObserver(abilityStateData, isAbility, false);
457 }
458 
459 /*
460  * Feature: AppStateObserverManager
461  * Function: HandleOnAppStarted
462  * SubFunction: NA
463  * FunctionPoints: AppStateObserverManager HandleOnAppStarted
464  * EnvConditions: NA
465  * CaseDescription: Verify HandleOnAppStarted
466  */
467 HWTEST_F(AppSpawnSocketTest, HandleOnAppStarted_001, TestSize.Level0)
468 {
469     auto manager = std::make_shared<AppStateObserverManager>();
470     ASSERT_NE(manager, nullptr);
471     manager->HandleOnAppStarted(nullptr);
472     std::vector<std::string> bundleNameList;
473     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
474     std::string bundleName = "com.ohos.unittest";
475     appRecord->mainBundleName_ = bundleName;
476     bundleNameList.push_back(bundleName);
477     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
478     manager->HandleOnAppStarted(appRecord);
479 }
480 
481 /*
482  * Feature: AppStateObserverManager
483  * Function: HandleOnAppStarted
484  * SubFunction: NA
485  * FunctionPoints: AppStateObserverManager HandleOnAppStarted
486  * EnvConditions: NA
487  * CaseDescription: Verify HandleOnAppStarted
488  */
489 HWTEST_F(AppSpawnSocketTest, HandleOnAppStarted_002, TestSize.Level0)
490 {
491     auto manager = std::make_shared<AppStateObserverManager>();
492     ASSERT_NE(manager, nullptr);
493     std::vector<std::string> bundleNameList;
494     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
495     std::string bundleName = "com.ohos.unittest";
496     appRecord->mainBundleName_ = bundleName;
497     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
498     manager->HandleOnAppStarted(appRecord);
499 }
500 
501 /*
502  * Feature: AppStateObserverManager
503  * Function: HandleOnAppStarted
504  * SubFunction: NA
505  * FunctionPoints: AppStateObserverManager HandleOnAppStarted
506  * EnvConditions: NA
507  * CaseDescription: Verify HandleOnAppStarted
508  */
509 HWTEST_F(AppSpawnSocketTest, HandleOnAppStarted_003, TestSize.Level0)
510 {
511     auto manager = std::make_shared<AppStateObserverManager>();
512     ASSERT_NE(manager, nullptr);
513     std::vector<std::string> bundleNameList;
514     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
515     std::string bundleName1 = "com.ohos.unittest1";
516     std::string bundleName2 = "com.ohos.unittest2";
517     appRecord->mainBundleName_ = bundleName1;
518     bundleNameList.push_back(bundleName2);
519     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
520     manager->HandleOnAppStarted(appRecord);
521 }
522 
523 /*
524  * Feature: AppStateObserverManager
525  * Function: HandleOnAppStarted
526  * SubFunction: NA
527  * FunctionPoints: AppStateObserverManager HandleOnAppStarted
528  * EnvConditions: NA
529  * CaseDescription: Verify HandleOnAppStarted
530  */
531 HWTEST_F(AppSpawnSocketTest, HandleOnAppStarted_004, TestSize.Level0)
532 {
533     auto manager = std::make_shared<AppStateObserverManager>();
534     ASSERT_NE(manager, nullptr);
535     std::vector<std::string> bundleNameList;
536     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
537     std::string bundleName = "com.ohos.unittest";
538     appRecord->mainBundleName_ = bundleName;
539     bundleNameList.push_back(bundleName);
540     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
541     manager->HandleOnAppStarted(appRecord);
542 }
543 
544 /*
545  * Feature: AppStateObserverManager
546  * Function: HandleOnAppStopped
547  * SubFunction: NA
548  * FunctionPoints: AppStateObserverManager HandleOnAppStopped
549  * EnvConditions: NA
550  * CaseDescription: Verify HandleOnAppStopped
551  */
552 HWTEST_F(AppSpawnSocketTest, HandleOnAppStopped_001, TestSize.Level0)
553 {
554     auto manager = std::make_shared<AppStateObserverManager>();
555     ASSERT_NE(manager, nullptr);
556     manager->HandleOnAppStopped(nullptr);
557     std::vector<std::string> bundleNameList;
558     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
559     std::string bundleName = "com.ohos.unittest";
560     appRecord->mainBundleName_ = bundleName;
561     bundleNameList.push_back(bundleName);
562     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
563     manager->HandleOnAppStopped(appRecord);
564 }
565 
566 /*
567  * Feature: AppStateObserverManager
568  * Function: HandleOnAppStopped
569  * SubFunction: NA
570  * FunctionPoints: AppStateObserverManager HandleOnAppStopped
571  * EnvConditions: NA
572  * CaseDescription: Verify HandleOnAppStopped
573  */
574 HWTEST_F(AppSpawnSocketTest, HandleOnAppStopped_002, TestSize.Level0)
575 {
576     auto manager = std::make_shared<AppStateObserverManager>();
577     ASSERT_NE(manager, nullptr);
578     std::vector<std::string> bundleNameList;
579     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
580     std::string bundleName = "com.ohos.unittest";
581     appRecord->mainBundleName_ = bundleName;
582     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
583     manager->HandleOnAppStopped(appRecord);
584 }
585 
586 /*
587  * Feature: AppStateObserverManager
588  * Function: HandleOnAppStopped
589  * SubFunction: NA
590  * FunctionPoints: AppStateObserverManager HandleOnAppStopped
591  * EnvConditions: NA
592  * CaseDescription: Verify HandleOnAppStopped
593  */
594 HWTEST_F(AppSpawnSocketTest, HandleOnAppStopped_003, TestSize.Level0)
595 {
596     auto manager = std::make_shared<AppStateObserverManager>();
597     ASSERT_NE(manager, nullptr);
598     std::vector<std::string> bundleNameList;
599     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
600     std::string bundleName1 = "com.ohos.unittest1";
601     std::string bundleName2 = "com.ohos.unittest2";
602     appRecord->mainBundleName_ = bundleName1;
603     bundleNameList.push_back(bundleName2);
604     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
605     manager->HandleOnAppStopped(appRecord);
606 }
607 
608 /*
609  * Feature: AppStateObserverManager
610  * Function: HandleOnAppStopped
611  * SubFunction: NA
612  * FunctionPoints: AppStateObserverManager HandleOnAppStopped
613  * EnvConditions: NA
614  * CaseDescription: Verify HandleOnAppStopped
615  */
616 HWTEST_F(AppSpawnSocketTest, HandleOnAppStopped_004, TestSize.Level0)
617 {
618     auto manager = std::make_shared<AppStateObserverManager>();
619     ASSERT_NE(manager, nullptr);
620     std::vector<std::string> bundleNameList;
621     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
622     std::string bundleName = "com.ohos.unittest";
623     appRecord->mainBundleName_ = bundleName;
624     bundleNameList.push_back(bundleName);
625     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
626     manager->HandleOnAppStopped(appRecord);
627 }
628 
629 /*
630  * Feature: AppStateObserverManager
631  * Function: HandleAppStateChanged
632  * SubFunction: NA
633  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
634  * EnvConditions: NA
635  * CaseDescription: Verify HandleAppStateChanged
636  */
637 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_001, TestSize.Level0)
638 {
639     auto manager = std::make_shared<AppStateObserverManager>();
640     ASSERT_NE(manager, nullptr);
641     std::vector<std::string> bundleNameList;
642     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
643     ApplicationState state = ApplicationState::APP_STATE_FOREGROUND;
644     bool needNotifyApp = true;
645     std::string bundleName = "com.ohos.unittest";
646     appRecord->mainBundleName_ = bundleName;
647     bundleNameList.push_back(bundleName);
648     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
649     manager->HandleAppStateChanged(appRecord, state, needNotifyApp, false);
650 }
651 
652 /*
653  * Feature: AppStateObserverManager
654  * Function: HandleAppStateChanged
655  * SubFunction: NA
656  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
657  * EnvConditions: NA
658  * CaseDescription: Verify HandleAppStateChanged
659  */
660 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_002, TestSize.Level0)
661 {
662     auto manager = std::make_shared<AppStateObserverManager>();
663     ASSERT_NE(manager, nullptr);
664     std::vector<std::string> bundleNameList;
665     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
666     ApplicationState state = ApplicationState::APP_STATE_BACKGROUND;
667     bool needNotifyApp = false;
668     std::string bundleName = "com.ohos.unittest";
669     appRecord->mainBundleName_ = bundleName;
670     bundleNameList.push_back(bundleName);
671     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
672     manager->HandleAppStateChanged(appRecord, state, needNotifyApp, false);
673 }
674 
675 /*
676  * Feature: AppStateObserverManager
677  * Function: HandleAppStateChanged
678  * SubFunction: NA
679  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
680  * EnvConditions: NA
681  * CaseDescription: Verify HandleAppStateChanged
682  */
683 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_003, TestSize.Level0)
684 {
685     auto manager = std::make_shared<AppStateObserverManager>();
686     ASSERT_NE(manager, nullptr);
687     std::vector<std::string> bundleNameList;
688     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
689     ApplicationState state = ApplicationState::APP_STATE_BACKGROUND;
690     bool needNotifyApp = false;
691     std::string bundleName = "com.ohos.unittest";
692     appRecord->mainBundleName_ = bundleName;
693     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
694     manager->HandleAppStateChanged(appRecord, state, needNotifyApp, false);
695 }
696 
697 /*
698  * Feature: AppStateObserverManager
699  * Function: HandleAppStateChanged
700  * SubFunction: NA
701  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
702  * EnvConditions: NA
703  * CaseDescription: Verify HandleAppStateChanged
704  */
705 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_004, TestSize.Level0)
706 {
707     auto manager = std::make_shared<AppStateObserverManager>();
708     ASSERT_NE(manager, nullptr);
709     std::vector<std::string> bundleNameList;
710     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
711     ApplicationState state = ApplicationState::APP_STATE_CREATE;
712     bool needNotifyApp = false;
713     std::string bundleName = "com.ohos.unittest";
714     appRecord->mainBundleName_ = bundleName;
715     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
716     manager->HandleAppStateChanged(appRecord, state, needNotifyApp, false);
717 }
718 
719 /*
720  * Feature: AppStateObserverManager
721  * Function: HandleAppStateChanged
722  * SubFunction: NA
723  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
724  * EnvConditions: NA
725  * CaseDescription: Verify HandleAppStateChanged
726  */
727 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_005, TestSize.Level0)
728 {
729     auto manager = std::make_shared<AppStateObserverManager>();
730     ASSERT_NE(manager, nullptr);
731     std::vector<std::string> bundleNameList;
732     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
733     ApplicationState state = ApplicationState::APP_STATE_TERMINATED;
734     bool needNotifyApp = false;
735     std::string bundleName = "com.ohos.unittest";
736     appRecord->mainBundleName_ = bundleName;
737     bundleNameList.push_back(bundleName);
738     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
739     manager->HandleAppStateChanged(appRecord, state, needNotifyApp, false);
740 }
741 
742 /*
743  * Feature: AppStateObserverManager
744  * Function: HandleAppStateChanged
745  * SubFunction: NA
746  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
747  * EnvConditions: NA
748  * CaseDescription: Verify HandleAppStateChanged
749  */
750 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_006, TestSize.Level0)
751 {
752     auto manager = std::make_shared<AppStateObserverManager>();
753     ASSERT_NE(manager, nullptr);
754     std::vector<std::string> bundleNameList;
755     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
756     ApplicationState state = ApplicationState::APP_STATE_CREATE;
757     bool needNotifyApp = false;
758     std::string bundleName1 = "com.ohos.unittest1";
759     std::string bundleName2 = "com.ohos.unittest2";
760     appRecord->mainBundleName_ = bundleName1;
761     bundleNameList.push_back(bundleName2);
762     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
763     manager->HandleAppStateChanged(appRecord, state, needNotifyApp, false);
764 }
765 
766 /*
767  * Feature: AppStateObserverManager
768  * Function: HandleAppStateChanged
769  * SubFunction: NA
770  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
771  * EnvConditions: NA
772  * CaseDescription: Verify HandleAppStateChanged
773  */
774 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_007, TestSize.Level0)
775 {
776     auto manager = std::make_shared<AppStateObserverManager>();
777     ASSERT_NE(manager, nullptr);
778     std::vector<std::string> bundleNameList;
779     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
780     ApplicationState state = ApplicationState::APP_STATE_CREATE;
781     bool needNotifyApp = false;
782     std::string bundleName = "com.ohos.unittest";
783     appRecord->mainBundleName_ = bundleName;
784     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
785     manager->HandleAppStateChanged(appRecord, state, needNotifyApp, false);
786 }
787 
788 /*
789  * Feature: AppStateObserverManager
790  * Function: HandleAppStateChanged
791  * SubFunction: NA
792  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
793  * EnvConditions: NA
794  * CaseDescription: Verify HandleAppStateChanged
795  */
796 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_008, TestSize.Level0)
797 {
798     auto manager = std::make_shared<AppStateObserverManager>();
799     ASSERT_NE(manager, nullptr);
800     std::vector<std::string> bundleNameList;
801     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
802     ApplicationState state = ApplicationState::APP_STATE_END;
803     bool needNotifyApp = false;
804     manager->HandleAppStateChanged(appRecord, state, needNotifyApp, false);
805 }
806 
807 /*
808  * Feature: AppStateObserverManager
809  * Function: HandleStateChangedNotifyObserver
810  * SubFunction: NA
811  * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver
812  * EnvConditions: NA
813  * CaseDescription: Verify HandleStateChangedNotifyObserver
814  */
815 HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_001, TestSize.Level0)
816 {
817     auto manager = std::make_shared<AppStateObserverManager>();
818     ASSERT_NE(manager, nullptr);
819     AbilityStateData abilityStateData;
820     bool isAbility = true;
821     std::vector<std::string> bundleNameList;
822     std::string bundleName = "com.ohos.unittest";
823     abilityStateData.bundleName = bundleName;
824     bundleNameList.push_back(bundleName);
825     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
826     manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility, false);
827 }
828 
829 /*
830  * Feature: AppStateObserverManager
831  * Function: HandleStateChangedNotifyObserver
832  * SubFunction: NA
833  * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver
834  * EnvConditions: NA
835  * CaseDescription: Verify HandleStateChangedNotifyObserver
836  */
837 HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_002, TestSize.Level0)
838 {
839     auto manager = std::make_shared<AppStateObserverManager>();
840     ASSERT_NE(manager, nullptr);
841     AbilityStateData abilityStateData;
842     bool isAbility = false;
843     std::vector<std::string> bundleNameList;
844     std::string bundleName = "com.ohos.unittest";
845     abilityStateData.bundleName = bundleName;
846     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
847     manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility, false);
848 }
849 
850 /*
851  * Feature: AppStateObserverManager
852  * Function: HandleStateChangedNotifyObserver
853  * SubFunction: NA
854  * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver
855  * EnvConditions: NA
856  * CaseDescription: Verify HandleStateChangedNotifyObserver
857  */
858 HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_003, TestSize.Level0)
859 {
860     auto manager = std::make_shared<AppStateObserverManager>();
861     ASSERT_NE(manager, nullptr);
862     AbilityStateData abilityStateData;
863     bool isAbility = false;
864     std::vector<std::string> bundleNameList;
865     std::string bundleName1 = "com.ohos.unittest1";
866     std::string bundleName2 = "com.ohos.unittest2";
867     abilityStateData.bundleName = bundleName1;
868     bundleNameList.push_back(bundleName2);
869     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
870     manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility, false);
871 }
872 
873 /*
874  * Feature: AppStateObserverManager
875  * Function: HandleStateChangedNotifyObserver
876  * SubFunction: NA
877  * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver
878  * EnvConditions: NA
879  * CaseDescription: Verify HandleStateChangedNotifyObserver
880  */
881 HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_004, TestSize.Level0)
882 {
883     auto manager = std::make_shared<AppStateObserverManager>();
884     ASSERT_NE(manager, nullptr);
885     AbilityStateData abilityStateData;
886     bool isAbility = false;
887     std::vector<std::string> bundleNameList;
888     std::string bundleName = "com.ohos.unittest";
889     abilityStateData.bundleName = bundleName;
890     bundleNameList.push_back(bundleName);
891     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
892     manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility, false);
893 }
894 
895 /*
896  * Feature: AppStateObserverManager
897  * Function: HandleOnAppProcessCreated
898  * SubFunction: NA
899  * FunctionPoints: AppStateObserverManager HandleOnAppProcessCreated
900  * EnvConditions: NA
901  * CaseDescription: Verify HandleOnAppProcessCreated
902  */
903 HWTEST_F(AppSpawnSocketTest, HandleOnAppProcessCreated_001, TestSize.Level0)
904 {
905     auto manager = std::make_shared<AppStateObserverManager>();
906     ASSERT_NE(manager, nullptr);
907     manager->HandleOnAppProcessCreated(nullptr, false);
908     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
909     manager->HandleOnAppProcessCreated(appRecord, false);
910 }
911 
912 /*
913  * Feature: AppStateObserverManager
914  * Function: HandleOnRenderProcessCreated
915  * SubFunction: NA
916  * FunctionPoints: AppStateObserverManager HandleOnRenderProcessCreated
917  * EnvConditions: NA
918  * CaseDescription: Verify HandleOnRenderProcessCreated
919  */
920 HWTEST_F(AppSpawnSocketTest, HandleOnRenderProcessCreated_001, TestSize.Level0)
921 {
922     auto manager = std::make_shared<AppStateObserverManager>();
923     ASSERT_NE(manager, nullptr);
924     manager->HandleOnRenderProcessCreated(nullptr, false);
925     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
926     std::shared_ptr<RenderRecord> renderRecord =
927         std::make_shared<RenderRecord>(1, "param", FdGuard(1), FdGuard(1), FdGuard(1), appRecord);
928     renderRecord->SetPid(1);
929     manager->HandleOnRenderProcessCreated(renderRecord, false);
930 }
931 
932 /*
933  * Feature: AppStateObserverManager
934  * Function: HandleOnProcessCreated
935  * SubFunction: NA
936  * FunctionPoints: AppStateObserverManager HandleOnProcessCreated
937  * EnvConditions: NA
938  * CaseDescription: Verify HandleOnProcessCreated
939  */
940 HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_001, TestSize.Level0)
941 {
942     auto manager = std::make_shared<AppStateObserverManager>();
943     ASSERT_NE(manager, nullptr);
944     ProcessData data;
945     std::vector<std::string> bundleNameList;
946     std::string bundleName = "com.ohos.unittest";
947     data.bundleName = bundleName;
948     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
949     manager->HandleOnProcessCreated(data);
950 }
951 
952 /*
953  * Feature: AppStateObserverManager
954  * Function: HandleOnProcessCreated
955  * SubFunction: NA
956  * FunctionPoints: AppStateObserverManager HandleOnProcessCreated
957  * EnvConditions: NA
958  * CaseDescription: Verify HandleOnProcessCreated
959  */
960 HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_002, TestSize.Level0)
961 {
962     auto manager = std::make_shared<AppStateObserverManager>();
963     ASSERT_NE(manager, nullptr);
964     ProcessData data;
965     std::vector<std::string> bundleNameList;
966     std::string bundleName = "com.ohos.unittest";
967     data.bundleName = bundleName;
968     bundleNameList.push_back(bundleName);
969     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
970     manager->HandleOnProcessCreated(data);
971 }
972 
973 /*
974  * Feature: AppStateObserverManager
975  * Function: HandleOnProcessCreated
976  * SubFunction: NA
977  * FunctionPoints: AppStateObserverManager HandleOnProcessCreated
978  * EnvConditions: NA
979  * CaseDescription: Verify HandleOnProcessCreated
980  */
981 HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_003, TestSize.Level0)
982 {
983     auto manager = std::make_shared<AppStateObserverManager>();
984     ASSERT_NE(manager, nullptr);
985     ProcessData data;
986     std::vector<std::string> bundleNameList;
987     std::string bundleName1 = "com.ohos.unittest";
988     std::string bundleName2 = "com.ohos.unittest";
989     data.bundleName = bundleName1;
990     bundleNameList.push_back(bundleName2);
991     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
992     manager->HandleOnProcessCreated(data);
993 }
994 
995 /*
996  * Feature: AppStateObserverManager
997  * Function: HandleOnProcessCreated
998  * SubFunction: NA
999  * FunctionPoints: AppStateObserverManager HandleOnProcessCreated
1000  * EnvConditions: NA
1001  * CaseDescription: Verify HandleOnProcessCreated
1002  */
1003 HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_004, TestSize.Level0)
1004 {
1005     auto manager = std::make_shared<AppStateObserverManager>();
1006     ASSERT_NE(manager, nullptr);
1007     ProcessData data;
1008     std::vector<std::string> bundleNameList;
1009     std::string bundleName = "com.ohos.unittest";
1010     data.bundleName = bundleName;
1011     bundleNameList.push_back(bundleName);
1012     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
1013     manager->HandleOnProcessCreated(data);
1014 }
1015 
1016 /*
1017  * Feature: AppStateObserverManager
1018  * Function: HandleOnProcessStateChanged
1019  * SubFunction: NA
1020  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
1021  * EnvConditions: NA
1022  * CaseDescription: Verify HandleOnProcessStateChanged
1023  */
1024 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_001, TestSize.Level0)
1025 {
1026     auto manager = std::make_shared<AppStateObserverManager>();
1027     ASSERT_NE(manager, nullptr);
1028     manager->HandleOnProcessStateChanged(nullptr);
1029 }
1030 
1031 /*
1032  * Feature: AppStateObserverManager
1033  * Function: HandleOnProcessStateChanged
1034  * SubFunction: NA
1035  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
1036  * EnvConditions: NA
1037  * CaseDescription: Verify HandleOnProcessStateChanged
1038  */
1039 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_002, TestSize.Level0)
1040 {
1041     auto manager = std::make_shared<AppStateObserverManager>();
1042     ASSERT_NE(manager, nullptr);
1043     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1044     std::vector<std::string> bundleNameList;
1045     std::string bundleName = "com.ohos.unittest";
1046     appRecord->mainBundleName_ = bundleName;
1047     bundleNameList.push_back(bundleName);
1048     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
1049     manager->HandleOnProcessStateChanged(appRecord);
1050 }
1051 
1052 /*
1053  * Feature: AppStateObserverManager
1054  * Function: HandleOnProcessStateChanged
1055  * SubFunction: NA
1056  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
1057  * EnvConditions: NA
1058  * CaseDescription: Verify HandleOnProcessStateChanged
1059  */
1060 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_003, TestSize.Level0)
1061 {
1062     auto manager = std::make_shared<AppStateObserverManager>();
1063     ASSERT_NE(manager, nullptr);
1064     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1065     std::vector<std::string> bundleNameList;
1066     std::string bundleName = "com.ohos.unittest";
1067     appRecord->mainBundleName_ = bundleName;
1068     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
1069     manager->HandleOnProcessStateChanged(appRecord);
1070 }
1071 
1072 /*
1073  * Feature: AppStateObserverManager
1074  * Function: HandleOnProcessStateChanged
1075  * SubFunction: NA
1076  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
1077  * EnvConditions: NA
1078  * CaseDescription: Verify HandleOnProcessStateChanged
1079  */
1080 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_004, TestSize.Level0)
1081 {
1082     auto manager = std::make_shared<AppStateObserverManager>();
1083     ASSERT_NE(manager, nullptr);
1084     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1085     std::vector<std::string> bundleNameList;
1086     std::string bundleName1 = "com.ohos.unittest1";
1087     std::string bundleName2 = "com.ohos.unittest2";
1088     appRecord->mainBundleName_ = bundleName1;
1089     bundleNameList.push_back(bundleName2);
1090     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
1091     manager->HandleOnProcessStateChanged(appRecord);
1092 }
1093 
1094 /*
1095  * Feature: AppStateObserverManager
1096  * Function: HandleOnProcessStateChanged
1097  * SubFunction: NA
1098  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
1099  * EnvConditions: NA
1100  * CaseDescription: Verify HandleOnProcessStateChanged
1101  */
1102 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_005, TestSize.Level0)
1103 {
1104     auto manager = std::make_shared<AppStateObserverManager>();
1105     ASSERT_NE(manager, nullptr);
1106     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1107     std::vector<std::string> bundleNameList;
1108     std::string bundleName = "com.ohos.unittest";
1109     appRecord->mainBundleName_ = bundleName;
1110     bundleNameList.push_back(bundleName);
1111     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
1112     manager->HandleOnProcessStateChanged(appRecord);
1113 }
1114 
1115 /*
1116  * Feature: AppStateObserverManager
1117  * Function: HandleOnAppProcessDied
1118  * SubFunction: NA
1119  * FunctionPoints: AppStateObserverManager HandleOnAppProcessDied
1120  * EnvConditions: NA
1121  * CaseDescription: Verify HandleOnAppProcessDied
1122  */
1123 HWTEST_F(AppSpawnSocketTest, HandleOnAppProcessDied_001, TestSize.Level0)
1124 {
1125     auto manager = std::make_shared<AppStateObserverManager>();
1126     ASSERT_NE(manager, nullptr);
1127     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1128     manager->HandleOnAppProcessDied(nullptr);
1129     manager->HandleOnAppProcessDied(appRecord);
1130 }
1131 
1132 /*
1133  * Feature: AppStateObserverManager
1134  * Function: HandleOnRenderProcessDied
1135  * SubFunction: NA
1136  * FunctionPoints: AppStateObserverManager HandleOnRenderProcessDied
1137  * EnvConditions: NA
1138  * CaseDescription: Verify HandleOnRenderProcessDied
1139  */
1140 HWTEST_F(AppSpawnSocketTest, HandleOnRenderProcessDied_001, TestSize.Level0)
1141 {
1142     auto manager = std::make_shared<AppStateObserverManager>();
1143     ASSERT_NE(manager, nullptr);
1144     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1145     std::shared_ptr<RenderRecord> renderRecord =
1146         std::make_shared<RenderRecord>(1, "param", FdGuard(1), FdGuard(1), FdGuard(1), appRecord);
1147     renderRecord->SetPid(1);
1148     manager->HandleOnRenderProcessDied(nullptr);
1149     manager->HandleOnRenderProcessDied(renderRecord);
1150 }
1151 
1152 /*
1153  * Feature: AppStateObserverManager
1154  * Function: HandleOnProcessDied
1155  * SubFunction: NA
1156  * FunctionPoints: AppStateObserverManager HandleOnProcessDied
1157  * EnvConditions: NA
1158  * CaseDescription: Verify HandleOnProcessDied
1159  */
1160 HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_001, TestSize.Level0)
1161 {
1162     auto manager = std::make_shared<AppStateObserverManager>();
1163     ASSERT_NE(manager, nullptr);
1164     ProcessData data;
1165     std::vector<std::string> bundleNameList;
1166     std::string bundleName = "com.ohos.unittest";
1167     data.bundleName = bundleName;
1168     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
1169     manager->HandleOnProcessDied(data);
1170 }
1171 
1172 /*
1173  * Feature: AppStateObserverManager
1174  * Function: HandleOnProcessDied
1175  * SubFunction: NA
1176  * FunctionPoints: AppStateObserverManager HandleOnProcessDied
1177  * EnvConditions: NA
1178  * CaseDescription: Verify HandleOnProcessDied
1179  */
1180 HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_002, TestSize.Level0)
1181 {
1182     auto manager = std::make_shared<AppStateObserverManager>();
1183     ASSERT_NE(manager, nullptr);
1184     ProcessData data;
1185     std::vector<std::string> bundleNameList;
1186     std::string bundleName = "com.ohos.unittest";
1187     data.bundleName = bundleName;
1188     bundleNameList.push_back(bundleName);
1189     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
1190     manager->HandleOnProcessDied(data);
1191 }
1192 
1193 /*
1194  * Feature: AppStateObserverManager
1195  * Function: HandleOnProcessDied
1196  * SubFunction: NA
1197  * FunctionPoints: AppStateObserverManager HandleOnProcessDied
1198  * EnvConditions: NA
1199  * CaseDescription: Verify HandleOnProcessDied
1200  */
1201 HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_003, TestSize.Level0)
1202 {
1203     auto manager = std::make_shared<AppStateObserverManager>();
1204     ASSERT_NE(manager, nullptr);
1205     ProcessData data;
1206     std::vector<std::string> bundleNameList;
1207     std::string bundleName1 = "com.ohos.unittest1";
1208     std::string bundleName2 = "com.ohos.unittest2";
1209     data.bundleName = bundleName1;
1210     bundleNameList.push_back(bundleName2);
1211     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
1212     manager->HandleOnProcessDied(data);
1213 }
1214 
1215 /*
1216  * Feature: AppStateObserverManager
1217  * Function: HandleOnProcessDied
1218  * SubFunction: NA
1219  * FunctionPoints: AppStateObserverManager HandleOnProcessDied
1220  * EnvConditions: NA
1221  * CaseDescription: Verify HandleOnProcessDied
1222  */
1223 HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_004, TestSize.Level0)
1224 {
1225     auto manager = std::make_shared<AppStateObserverManager>();
1226     ASSERT_NE(manager, nullptr);
1227     ProcessData data;
1228     std::vector<std::string> bundleNameList;
1229     std::string bundleName1 = "com.ohos.unittest1";
1230     std::string bundleName2 = "com.ohos.unittest2";
1231     data.bundleName = bundleName1;
1232     bundleNameList.push_back(bundleName2);
1233     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
1234     manager->HandleOnProcessDied(data);
1235 }
1236 
1237 /*
1238  * Feature: AppStateObserverManager
1239  * Function: ObserverExist
1240  * SubFunction: NA
1241  * FunctionPoints: AppStateObserverManager ObserverExist
1242  * EnvConditions: NA
1243  * CaseDescription: Verify ObserverExist
1244  */
1245 HWTEST_F(AppSpawnSocketTest, ObserverExist_001, TestSize.Level0)
1246 {
1247     auto manager = std::make_shared<AppStateObserverManager>();
1248     bool res = manager->ObserverExist(nullptr);
1249     EXPECT_FALSE(res);
1250 }
1251 
1252 /*
1253  * Feature: AppStateObserverManager
1254  * Function: ObserverExist
1255  * SubFunction: NA
1256  * FunctionPoints: AppStateObserverManager ObserverExist
1257  * EnvConditions: NA
1258  * CaseDescription: Verify ObserverExist
1259  */
1260 HWTEST_F(AppSpawnSocketTest, ObserverExist_002, TestSize.Level0)
1261 {
1262     auto manager = std::make_shared<AppStateObserverManager>();
1263     sptr<IApplicationStateObserver> observer = new MockApplicationStateObserver();
1264     std::vector<std::string> bundleNameList;
1265     manager->appStateObserverMap_.emplace(observer, AppStateObserverInfo{0, bundleNameList});
1266     bool res = manager->ObserverExist(observer);
1267     EXPECT_TRUE(res);
1268 }
1269 
1270 /**
1271  * @tc.name: RegisterAbilityForegroundStateObserver_0100
1272  * @tc.desc: The test returns when the permission judgment is inconsistent.
1273  * @tc.type: FUNC
1274  */
1275 HWTEST_F(AppSpawnSocketTest, RegisterAbilityForegroundStateObserver_0100, TestSize.Level1)
1276 {
1277     auto manager = std::make_shared<AppStateObserverManager>();
1278     ASSERT_NE(manager, nullptr);
1279     sptr<IAbilityForegroundStateObserver> observer = new AbilityForegroundStateObserverProxy(nullptr);
1280     manager->abilityForegroundObserverMap_.emplace(observer, 0);
1281     auto res = manager->RegisterAbilityForegroundStateObserver(observer);
1282     EXPECT_EQ(res, ERR_PERMISSION_DENIED);
1283 }
1284 
1285 /**
1286  * @tc.name: UnregisterAbilityForegroundStateObserver_0100
1287  * @tc.desc: The test returns when the permission judgment is inconsistent.
1288  * @tc.type: FUNC
1289  */
1290 HWTEST_F(AppSpawnSocketTest, UnregisterAbilityForegroundStateObserver_0100, TestSize.Level1)
1291 {
1292     sptr<IAbilityForegroundStateObserver> observer = new AbilityForegroundStateObserverProxy(nullptr);
1293     auto manager = std::make_shared<AppStateObserverManager>();
1294     ASSERT_NE(manager, nullptr);
1295     manager->abilityForegroundObserverMap_.emplace(observer, 0);
1296     auto res = manager->UnregisterAbilityForegroundStateObserver(observer);
1297     EXPECT_EQ(res, ERR_PERMISSION_DENIED);
1298 }
1299 
1300 /**
1301  * @tc.name: IsAbilityForegroundObserverExist_0100
1302  * @tc.desc: Test return when abilityForegroundObserverMap_ is not empty and
1303  *      the conditions within the loop are met.
1304  * @tc.type: FUNC
1305  */
1306 HWTEST_F(AppSpawnSocketTest, IsAbilityForegroundObserverExist_0100, TestSize.Level1)
1307 {
1308     sptr<IRemoteBroker> observer = new AppForegroundStateObserverProxy(nullptr);
1309     sptr<IAbilityForegroundStateObserver> observers = new AbilityForegroundStateObserverProxy(nullptr);
1310     auto manager = std::make_shared<AppStateObserverManager>();
1311     ASSERT_NE(manager, nullptr);
1312     manager->abilityForegroundObserverMap_.emplace(observers, 0);
1313     auto res = manager->IsAbilityForegroundObserverExist(observer);
1314     EXPECT_EQ(res, true);
1315 }
1316 
1317 /**
1318  * @tc.name: AddObserverDeathRecipient_0100
1319  * @tc.desc: Verify that AddObserverDeathRecipient can be called normally(type is APPLICATION_STATE_OBSERVER)
1320  * @tc.type: FUNC
1321  */
1322 HWTEST_F(AppSpawnSocketTest, AddObserverDeathRecipient_0100, TestSize.Level1)
1323 {
1324     auto observerStub = new MockAbilityForegroundStateObserverServerStub();
1325     sptr<IRemoteBroker> observer = new AppForegroundStateObserverProxy(observerStub);
1326     auto manager = std::make_shared<AppStateObserverManager>();
1327     ASSERT_NE(manager, nullptr);
1328     ObserverType type = ObserverType::APPLICATION_STATE_OBSERVER;
1329     manager->AddObserverDeathRecipient(observer, type);
1330     ASSERT_FALSE(manager->recipientMap_.empty());
1331 }
1332 
1333 /**
1334  * @tc.name: AddObserverDeathRecipient_0200
1335  * @tc.desc: Verify that AddObserverDeathRecipient can be called normally(type is ABILITY_FOREGROUND_STATE_OBSERVER)
1336  * @tc.type: FUNC
1337  */
1338 HWTEST_F(AppSpawnSocketTest, AddObserverDeathRecipient_0200, TestSize.Level1)
1339 {
1340     auto observerStub = new MockAbilityForegroundStateObserverServerStub();
1341     sptr<IRemoteBroker> observer = new AppForegroundStateObserverProxy(observerStub);
1342     auto manager = std::make_shared<AppStateObserverManager>();
1343     ASSERT_NE(manager, nullptr);
1344     ObserverType type = ObserverType::ABILITY_FOREGROUND_STATE_OBSERVER;
1345     manager->AddObserverDeathRecipient(observer, type);
1346     ASSERT_FALSE(manager->recipientMap_.empty());
1347 }
1348 
1349 /**
1350  * @tc.name: AddObserverDeathRecipient_0300
1351  * @tc.desc: Verify that AddObserverDeathRecipient can be called normally(observer is nullptr)
1352  * @tc.type: FUNC
1353  */
1354 HWTEST_F(AppSpawnSocketTest, AddObserverDeathRecipient_0300, TestSize.Level1)
1355 {
1356     sptr<IRemoteBroker> observer = new AppForegroundStateObserverProxy(nullptr);
1357     auto manager = std::make_shared<AppStateObserverManager>();
1358     ASSERT_NE(manager, nullptr);
1359     ObserverType type = ObserverType::ABILITY_FOREGROUND_STATE_OBSERVER;
1360     manager->AddObserverDeathRecipient(observer, type);
1361     ASSERT_TRUE(manager->recipientMap_.empty());
1362 }
1363 
1364 /**
1365  * @tc.name: RemoveObserverDeathRecipient_0100
1366  * @tc.desc: Verify that RemoveObserverDeathRecipient can be called normally
1367  * @tc.type: FUNC
1368  */
1369 HWTEST_F(AppSpawnSocketTest, RemoveObserverDeathRecipient_0100, TestSize.Level1)
1370 {
1371     auto observerStub = new MockAbilityForegroundStateObserverServerStub();
1372     sptr<IRemoteBroker> observer = new AppForegroundStateObserverProxy(observerStub);
1373     auto manager = std::make_shared<AppStateObserverManager>();
1374     ASSERT_NE(manager, nullptr);
1375     manager->RemoveObserverDeathRecipient(observer);
1376     ASSERT_TRUE(manager->recipientMap_.empty());
1377 }
1378 
1379 /**
1380  * @tc.name: RemoveObserverDeathRecipient_0200
1381  * @tc.desc: Verify that RemoveObserverDeathRecipient can be called normally(observer is nullptr)
1382  * @tc.type: FUNC
1383  */
1384 HWTEST_F(AppSpawnSocketTest, RemoveObserverDeathRecipient_0200, TestSize.Level1)
1385 {
1386     sptr<IRemoteBroker> observer = new AppForegroundStateObserverProxy(nullptr);
1387     auto manager = std::make_shared<AppStateObserverManager>();
1388     ASSERT_NE(manager, nullptr);
1389     manager->RemoveObserverDeathRecipient(observer);
1390     ASSERT_TRUE(manager->recipientMap_.empty());
1391 }
1392 
1393 /**
1394  * @tc.name: RegisterAppForegroundStateObserver_0100
1395  * @tc.desc: Test when observer is not nullptr and without permission.
1396  *      and observer not exist.
1397  * @tc.type: FUNC
1398  */
1399 HWTEST_F(AppSpawnSocketTest, RegisterAppForegroundStateObserver_0100, TestSize.Level1)
1400 {
1401     auto manager = std::make_shared<AppStateObserverManager>();
1402     sptr<IAppForegroundStateObserver> observer = new (std::nothrow) AppForegroundStateObserver();
1403     auto res = manager->RegisterAppForegroundStateObserver(observer);
1404     EXPECT_EQ(ERR_PERMISSION_DENIED, res);
1405 }
1406 
1407 /**
1408  * @tc.name: UnregisterAppForegroundStateObserver_0100
1409  * @tc.desc: Test when observer is not nullptr and without permission.
1410  * @tc.type: FUNC
1411  */
1412 HWTEST_F(AppSpawnSocketTest, UnregisterAppForegroundStateObserver_0100, TestSize.Level1)
1413 {
1414     auto manager = std::make_shared<AppStateObserverManager>();
1415     sptr<IAppForegroundStateObserver> observer = new (std::nothrow) AppForegroundStateObserver();
1416     manager->appForegroundStateObserverMap_.emplace(observer, 0);
1417     auto res = manager->UnregisterAppForegroundStateObserver(observer);
1418     EXPECT_EQ(ERR_PERMISSION_DENIED, res);
1419 }
1420 
1421 /**
1422  * @tc.name: IsAppForegroundObserverExist_0100
1423  * @tc.desc: Test when observer and appForegroundStateObserverMap is not nullptr
1424  *      and asObject of them is same.
1425  * @tc.type: FUNC
1426  */
1427 HWTEST_F(AppSpawnSocketTest, IsAppForegroundObserverExist_0100, TestSize.Level1)
1428 {
1429     auto manager = std::make_shared<AppStateObserverManager>();
1430     sptr<IAppForegroundStateObserver> observer = new (std::nothrow) AppForegroundStateObserver();
1431     manager->appForegroundStateObserverMap_.emplace(observer, 0);
1432     auto res = manager->IsAppForegroundObserverExist(observer);
1433     EXPECT_EQ(true, res);
1434 }
1435 
1436 /**
1437  * @tc.name: OnObserverDied_0100
1438  * @tc.desc: Test when observer is not nullptr and type is APPLICATION_STATE_OBSERVER.
1439  * @tc.type: FUNC
1440  */
1441 HWTEST_F(AppSpawnSocketTest, OnObserverDied_0100, TestSize.Level1)
1442 {
1443     sptr<IRemoteObject> remoteObject = new (std::nothrow) AppForegroundStateObserver();
1444     wptr<IRemoteObject> remote(remoteObject);
1445     ObserverType type = ObserverType::APPLICATION_STATE_OBSERVER;
1446     DelayedSingleton<AppStateObserverManager>::GetInstance()->OnObserverDied(remote, type);
1447     auto appStateObserverMapSize =
1448         DelayedSingleton<AppStateObserverManager>::GetInstance()->appStateObserverMap_.size();
1449     EXPECT_EQ(0, appStateObserverMapSize);
1450 }
1451 
1452 /**
1453  * @tc.name: OnObserverDied_0200
1454  * @tc.desc: Test when observer is not nullptr and type is ABILITY_FOREGROUND_STATE_OBSERVER.
1455  * @tc.type: FUNC
1456  */
1457 HWTEST_F(AppSpawnSocketTest, OnObserverDied_0200, TestSize.Level1)
1458 {
1459     sptr<IRemoteObject> remoteObject = new (std::nothrow) AppForegroundStateObserver();
1460     wptr<IRemoteObject> remote(remoteObject);
1461     ObserverType type = ObserverType::ABILITY_FOREGROUND_STATE_OBSERVER;
1462     DelayedSingleton<AppStateObserverManager>::GetInstance()->OnObserverDied(remote, type);
1463     auto abilityforegroundObserverSetSize =
1464         DelayedSingleton<AppStateObserverManager>::GetInstance()->abilityForegroundObserverMap_.size();
1465     EXPECT_EQ(0, abilityforegroundObserverSetSize);
1466 }
1467 
1468 /**
1469  * @tc.name: OnObserverDied_0300
1470  * @tc.desc: Test when observer is not nullptr and type is ABILITY_FOREGROUND_STATE_OBSERVER.
1471  * @tc.type: FUNC
1472  */
1473 HWTEST_F(AppSpawnSocketTest, OnObserverDied_0300, TestSize.Level1)
1474 {
1475     sptr<IRemoteObject> remoteObject = new (std::nothrow) AppForegroundStateObserver();
1476     wptr<IRemoteObject> remote(remoteObject);
1477     ObserverType type = ObserverType::ABILITY_FOREGROUND_STATE_OBSERVER;
1478     DelayedSingleton<AppStateObserverManager>::GetInstance()->OnObserverDied(remote, type);
1479     auto appForegroundStateObserverSetSize =
1480         DelayedSingleton<AppStateObserverManager>::GetInstance()->appForegroundStateObserverMap_.size();
1481     EXPECT_EQ(0, appForegroundStateObserverSetSize);
1482 }
1483 
1484 /*
1485  * Feature: AppStateObserverManager
1486  * Function: OnAppCacheStateChanged
1487  * SubFunction: NA
1488  * FunctionPoints: AppStateObserverManager OnAppCacheStateChanged
1489  * EnvConditions: NA
1490  * CaseDescription: Verify OnAppCacheStateChanged
1491  */
1492 HWTEST_F(AppSpawnSocketTest, OnAppCacheStateChanged_001, TestSize.Level0)
1493 {
1494     auto manager = std::make_shared<AppStateObserverManager>();
1495     ASSERT_NE(manager, nullptr);
1496     std::shared_ptr<AppRunningRecord> appRecord;
1497     manager->OnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_CACHED);
1498     manager->Init();
1499     manager->OnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_CACHED);
1500 }
1501 
1502 /*
1503  * Feature: AppStateObserverManager
1504  * Function: HandleOnAppCacheStateChanged
1505  * SubFunction: NA
1506  * FunctionPoints: AppStateObserverManager HandleOnAppCacheStateChanged
1507  * EnvConditions: NA
1508  * CaseDescription: Verify HandleOnAppCacheStateChanged
1509  */
1510 HWTEST_F(AppSpawnSocketTest, HandleOnAppCacheStateChanged_001, TestSize.Level0)
1511 {
1512     auto manager = std::make_shared<AppStateObserverManager>();
1513     ASSERT_NE(manager, nullptr);
1514     manager->HandleOnAppCacheStateChanged(nullptr, ApplicationState::APP_STATE_CREATE);
1515     std::vector<std::string> bundleNameList;
1516     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1517     std::string bundleName = "com.ohos.unittest";
1518     appRecord->mainBundleName_ = bundleName;
1519     bundleNameList.push_back(bundleName);
1520     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
1521     manager->HandleOnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_CREATE);
1522 }
1523 
1524 /*
1525  * Feature: AppStateObserverManager
1526  * Function: HandleOnAppCacheStateChanged
1527  * SubFunction: NA
1528  * FunctionPoints: AppStateObserverManager HandleOnAppCacheStateChanged
1529  * EnvConditions: NA
1530  * CaseDescription: Verify HandleOnAppCacheStateChanged
1531  */
1532 HWTEST_F(AppSpawnSocketTest, HandleOnAppCacheStateChanged_002, TestSize.Level0)
1533 {
1534     auto manager = std::make_shared<AppStateObserverManager>();
1535     ASSERT_NE(manager, nullptr);
1536     std::vector<std::string> bundleNameList;
1537     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1538     std::string bundleName = "com.ohos.unittest";
1539     appRecord->mainBundleName_ = bundleName;
1540     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
1541     manager->HandleOnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_CREATE);
1542 }
1543 
1544 /*
1545  * Feature: AppStateObserverManager
1546  * Function: HandleOnAppCacheStateChanged
1547  * SubFunction: NA
1548  * FunctionPoints: AppStateObserverManager HandleOnAppCacheStateChanged
1549  * EnvConditions: NA
1550  * CaseDescription: Verify HandleOnAppCacheStateChanged
1551  */
1552 HWTEST_F(AppSpawnSocketTest, HandleOnAppCacheStateChanged_003, TestSize.Level0)
1553 {
1554     auto manager = std::make_shared<AppStateObserverManager>();
1555     ASSERT_NE(manager, nullptr);
1556     std::vector<std::string> bundleNameList;
1557     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1558     std::string bundleName1 = "com.ohos.unittest1";
1559     std::string bundleName2 = "com.ohos.unittest2";
1560     appRecord->mainBundleName_ = bundleName1;
1561     bundleNameList.push_back(bundleName2);
1562     manager->appStateObserverMap_.emplace(observer_, AppStateObserverInfo{0, bundleNameList});
1563     manager->HandleOnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_CREATE);
1564 }
1565 
1566 /*
1567  * Feature: AppStateObserverManager
1568  * Function: HandleOnAppCacheStateChanged
1569  * SubFunction: NA
1570  * FunctionPoints: AppStateObserverManager HandleOnAppCacheStateChanged
1571  * EnvConditions: NA
1572  * CaseDescription: Verify HandleOnAppCacheStateChanged
1573  */
1574 HWTEST_F(AppSpawnSocketTest, HandleOnAppCacheStateChanged_004, TestSize.Level0)
1575 {
1576     auto manager = std::make_shared<AppStateObserverManager>();
1577     ASSERT_NE(manager, nullptr);
1578     std::vector<std::string> bundleNameList;
1579     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
1580     std::string bundleName = "com.ohos.unittest";
1581     appRecord->mainBundleName_ = bundleName;
1582     bundleNameList.push_back(bundleName);
1583     manager->appStateObserverMap_.emplace(nullptr, AppStateObserverInfo{0, bundleNameList});
1584     manager->HandleOnAppCacheStateChanged(appRecord, ApplicationState::APP_STATE_CREATE);
1585 }
1586 } // namespace AppExecFwk
1587 } // namespace OHOS
1588