• 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 #define private public
19 #include "app_state_observer_manager.h"
20 #undef private
21 #include "application_state_observer_stub.h"
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 namespace {
29 const int BUNDLE_NAME_LIST_MAX_SIZE = 128;
30 }
31 class MockApplicationStateObserver : public IApplicationStateObserver {
32 public:
33     MockApplicationStateObserver() = default;
34     virtual ~MockApplicationStateObserver() = default;
OnForegroundApplicationChanged(const AppStateData & appStateData)35     void OnForegroundApplicationChanged(const AppStateData &appStateData) override
36     {}
OnAbilityStateChanged(const AbilityStateData & abilityStateData)37     void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override
38     {}
OnExtensionStateChanged(const AbilityStateData & abilityStateData)39     void OnExtensionStateChanged(const AbilityStateData &abilityStateData) override
40     {}
OnProcessCreated(const ProcessData & processData)41     void OnProcessCreated(const ProcessData &processData) override
42     {}
OnProcessStateChanged(const ProcessData & processData)43     void OnProcessStateChanged(const ProcessData &processData) override
44     {}
OnProcessDied(const ProcessData & processData)45     void OnProcessDied(const ProcessData &processData) override
46     {}
OnApplicationStateChanged(const AppStateData & appStateData)47     void OnApplicationStateChanged(const AppStateData &appStateData) override
48     {}
OnAppStateChanged(const AppStateData & appStateData)49     void OnAppStateChanged(const AppStateData &appStateData) override
50     {}
AsObject()51     sptr<IRemoteObject> AsObject() override
52     {
53         return {};
54     }
55 };
56 class AppSpawnSocketTest : public testing::Test {
57 public:
58     static void SetUpTestCase();
59     static void TearDownTestCase();
60     void SetUp();
61     void TearDown();
62     std::shared_ptr<AppRunningRecord> MockAppRecord();
63     sptr<IApplicationStateObserver> observer_ {nullptr};
64 };
65 
SetUpTestCase()66 void AppSpawnSocketTest::SetUpTestCase()
67 {}
68 
TearDownTestCase()69 void AppSpawnSocketTest::TearDownTestCase()
70 {}
71 
SetUp()72 void AppSpawnSocketTest::SetUp()
73 {
74     sptr<IApplicationStateObserver> observer_ = new MockApplicationStateObserver();
75 }
76 
TearDown()77 void AppSpawnSocketTest::TearDown()
78 {}
79 
MockAppRecord()80 std::shared_ptr<AppRunningRecord> AppSpawnSocketTest::MockAppRecord()
81 {
82     ApplicationInfo appInfo;
83     appInfo.accessTokenId = 1;
84     std::shared_ptr<ApplicationInfo> info = std::make_shared<ApplicationInfo>(appInfo);
85     info->accessTokenId = 1;
86     std::shared_ptr<AppRunningRecord> appRecord = std::make_shared<AppRunningRecord>(info, 0, "process");
87     std::shared_ptr<PriorityObject> priorityObject = std::make_shared<PriorityObject>();
88     priorityObject->SetPid(1);
89     appRecord->priorityObject_ = priorityObject;
90     appRecord->SetUid(1);
91     appRecord->SetState(ApplicationState::APP_STATE_CREATE);
92     appRecord->SetContinuousTaskAppState(false);
93     appRecord->SetKeepAliveAppState(false, false);
94     appRecord->isFocused_ = false;
95     return appRecord;
96 }
97 
98 /*
99  * Feature: AppStateObserverManager
100  * Function: RegisterApplicationStateObserver
101  * SubFunction: NA
102  * FunctionPoints: AppStateObserverManager RegisterApplicationStateObserver
103  * EnvConditions: NA
104  * CaseDescription: Verify RegisterApplicationStateObserver
105  */
106 HWTEST_F(AppSpawnSocketTest, RegisterApplicationStateObserver_001, TestSize.Level0)
107 {
108     auto manager = std::make_shared<AppStateObserverManager>();
109     vector<std::string> bundleNameList;
110     int32_t res = manager->RegisterApplicationStateObserver(nullptr, bundleNameList);
111     EXPECT_EQ(res, ERR_PERMISSION_DENIED);
112 }
113 
114 /*
115  * Feature: AppStateObserverManager
116  * Function: RegisterApplicationStateObserver
117  * SubFunction: NA
118  * FunctionPoints: AppStateObserverManager RegisterApplicationStateObserver
119  * EnvConditions: NA
120  * CaseDescription: Verify RegisterApplicationStateObserver
121  */
122 HWTEST_F(AppSpawnSocketTest, RegisterApplicationStateObserver_002, TestSize.Level0)
123 {
124     auto manager = std::make_shared<AppStateObserverManager>();
125     vector<std::string> bundleNameList;
126     while (bundleNameList.size() <= BUNDLE_NAME_LIST_MAX_SIZE) {
127         bundleNameList.push_back("a");
128     }
129     int32_t res = manager->RegisterApplicationStateObserver(nullptr, bundleNameList);
130     EXPECT_EQ(res, ERR_INVALID_VALUE);
131 }
132 
133 /*
134  * Feature: AppStateObserverManager
135  * Function: UnregisterApplicationStateObserver
136  * SubFunction: NA
137  * FunctionPoints: AppStateObserverManager UnregisterApplicationStateObserver
138  * EnvConditions: NA
139  * CaseDescription: Verify UnregisterApplicationStateObserver
140  */
141 HWTEST_F(AppSpawnSocketTest, UnregisterApplicationStateObserver_001, TestSize.Level0)
142 {
143     auto manager = std::make_shared<AppStateObserverManager>();
144     int32_t res = manager->UnregisterApplicationStateObserver(nullptr);
145     EXPECT_EQ(res, ERR_PERMISSION_DENIED);
146 }
147 
148 /*
149  * Feature: AppStateObserverManager
150  * Function: OnAppStateChanged
151  * SubFunction: NA
152  * FunctionPoints: AppStateObserverManager OnAppStateChanged
153  * EnvConditions: NA
154  * CaseDescription: Verify OnAppStateChanged
155  */
156 HWTEST_F(AppSpawnSocketTest, OnAppStateChanged_001, TestSize.Level0)
157 {
158     auto manager = std::make_shared<AppStateObserverManager>();
159     std::shared_ptr<AppRunningRecord> appRecord;
160     ApplicationState state = ApplicationState::APP_STATE_CREATE;
161     bool needNotifyApp = false;
162     manager->OnAppStateChanged(appRecord, state, needNotifyApp);
163 }
164 
165 /*
166  * Feature: AppStateObserverManager
167  * Function: OnAppStateChanged
168  * SubFunction: NA
169  * FunctionPoints: AppStateObserverManager OnAppStateChanged
170  * EnvConditions: NA
171  * CaseDescription: Verify OnAppStateChanged
172  */
173 HWTEST_F(AppSpawnSocketTest, OnAppStateChanged_002, TestSize.Level0)
174 {
175     auto manager = std::make_shared<AppStateObserverManager>();
176     std::shared_ptr<AppRunningRecord> appRecord;
177     ApplicationState state = ApplicationState::APP_STATE_CREATE;
178     bool needNotifyApp = false;
179     manager->Init();
180     manager->OnAppStateChanged(appRecord, state, needNotifyApp);
181 }
182 
183 /*
184  * Feature: AppStateObserverManager
185  * Function: OnProcessDied
186  * SubFunction: NA
187  * FunctionPoints: AppStateObserverManager OnProcessDied
188  * EnvConditions: NA
189  * CaseDescription: Verify OnProcessDied
190  */
191 HWTEST_F(AppSpawnSocketTest, OnProcessDied_001, TestSize.Level0)
192 {
193     auto manager = std::make_shared<AppStateObserverManager>();
194     std::shared_ptr<AppRunningRecord> appRecord;
195     manager->OnProcessDied(appRecord);
196     manager->Init();
197     manager->OnProcessDied(appRecord);
198 }
199 
200 /*
201  * Feature: AppStateObserverManager
202  * Function: OnRenderProcessDied
203  * SubFunction: NA
204  * FunctionPoints: AppStateObserverManager OnRenderProcessDied
205  * EnvConditions: NA
206  * CaseDescription: Verify OnRenderProcessDied
207  */
208 HWTEST_F(AppSpawnSocketTest, OnRenderProcessDied_001, TestSize.Level0)
209 {
210     auto manager = std::make_shared<AppStateObserverManager>();
211     std::shared_ptr<RenderRecord> renderRecord;
212     manager->OnRenderProcessDied(renderRecord);
213     manager->Init();
214     manager->OnRenderProcessDied(renderRecord);
215 }
216 
217 /*
218  * Feature: AppStateObserverManager
219  * Function: OnProcessStateChanged
220  * SubFunction: NA
221  * FunctionPoints: AppStateObserverManager OnProcessStateChanged
222  * EnvConditions: NA
223  * CaseDescription: Verify OnProcessStateChanged
224  */
225 HWTEST_F(AppSpawnSocketTest, OnProcessStateChanged_001, TestSize.Level0)
226 {
227     auto manager = std::make_shared<AppStateObserverManager>();
228     std::shared_ptr<AppRunningRecord> appRecord;
229     manager->OnProcessStateChanged(appRecord);
230     manager->Init();
231     manager->OnProcessStateChanged(appRecord);
232 }
233 
234 /*
235  * Feature: AppStateObserverManager
236  * Function: OnProcessCreated
237  * SubFunction: NA
238  * FunctionPoints: AppStateObserverManager OnProcessCreated
239  * EnvConditions: NA
240  * CaseDescription: Verify OnProcessCreated
241  */
242 HWTEST_F(AppSpawnSocketTest, OnProcessCreated_001, TestSize.Level0)
243 {
244     auto manager = std::make_shared<AppStateObserverManager>();
245     std::shared_ptr<AppRunningRecord> appRecord;
246     manager->OnProcessCreated(appRecord);
247     manager->Init();
248     manager->OnProcessCreated(appRecord);
249 }
250 
251 /*
252  * Feature: AppStateObserverManager
253  * Function: OnRenderProcessCreated
254  * SubFunction: NA
255  * FunctionPoints: AppStateObserverManager OnRenderProcessCreated
256  * EnvConditions: NA
257  * CaseDescription: Verify OnRenderProcessCreated
258  */
259 HWTEST_F(AppSpawnSocketTest, OnRenderProcessCreated_001, TestSize.Level0)
260 {
261     auto manager = std::make_shared<AppStateObserverManager>();
262     std::shared_ptr<RenderRecord> renderRecord;
263     manager->OnRenderProcessCreated(renderRecord);
264     manager->Init();
265     manager->OnRenderProcessCreated(renderRecord);
266 }
267 
268 /*
269  * Feature: AppStateObserverManager
270  * Function: StateChangedNotifyObserver
271  * SubFunction: NA
272  * FunctionPoints: AppStateObserverManager StateChangedNotifyObserver
273  * EnvConditions: NA
274  * CaseDescription: Verify StateChangedNotifyObserver
275  */
276 HWTEST_F(AppSpawnSocketTest, StateChangedNotifyObserver_001, TestSize.Level0)
277 {
278     auto manager = std::make_shared<AppStateObserverManager>();
279     AbilityStateData abilityStateData;
280     bool isAbility = false;
281     manager->StateChangedNotifyObserver(abilityStateData, isAbility);
282     manager->Init();
283     manager->StateChangedNotifyObserver(abilityStateData, isAbility);
284 }
285 
286 /*
287  * Feature: AppStateObserverManager
288  * Function: HandleAppStateChanged
289  * SubFunction: NA
290  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
291  * EnvConditions: NA
292  * CaseDescription: Verify HandleAppStateChanged
293  */
294 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_001, TestSize.Level0)
295 {
296     auto manager = std::make_shared<AppStateObserverManager>();
297     std::vector<std::string> bundleNameList;
298     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
299     ApplicationState state = ApplicationState::APP_STATE_FOREGROUND;
300     bool needNotifyApp = true;
301     std::string bundleName = "com.ohos.unittest";
302     appRecord->mainBundleName_ = bundleName;
303     bundleNameList.push_back(bundleName);
304     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
305     manager->HandleAppStateChanged(appRecord, state, needNotifyApp);
306 }
307 
308 /*
309  * Feature: AppStateObserverManager
310  * Function: HandleAppStateChanged
311  * SubFunction: NA
312  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
313  * EnvConditions: NA
314  * CaseDescription: Verify HandleAppStateChanged
315  */
316 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_002, TestSize.Level0)
317 {
318     auto manager = std::make_shared<AppStateObserverManager>();
319     std::vector<std::string> bundleNameList;
320     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
321     ApplicationState state = ApplicationState::APP_STATE_BACKGROUND;
322     bool needNotifyApp = false;
323     std::string bundleName = "com.ohos.unittest";
324     appRecord->mainBundleName_ = bundleName;
325     bundleNameList.push_back(bundleName);
326     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
327     manager->HandleAppStateChanged(appRecord, state, needNotifyApp);
328 }
329 
330 /*
331  * Feature: AppStateObserverManager
332  * Function: HandleAppStateChanged
333  * SubFunction: NA
334  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
335  * EnvConditions: NA
336  * CaseDescription: Verify HandleAppStateChanged
337  */
338 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_003, TestSize.Level0)
339 {
340     auto manager = std::make_shared<AppStateObserverManager>();
341     std::vector<std::string> bundleNameList;
342     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
343     ApplicationState state = ApplicationState::APP_STATE_BACKGROUND;
344     bool needNotifyApp = false;
345     std::string bundleName = "com.ohos.unittest";
346     appRecord->mainBundleName_ = bundleName;
347     manager->appStateObserverMap_.emplace(nullptr, bundleNameList);
348     manager->HandleAppStateChanged(appRecord, state, needNotifyApp);
349 }
350 
351 /*
352  * Feature: AppStateObserverManager
353  * Function: HandleAppStateChanged
354  * SubFunction: NA
355  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
356  * EnvConditions: NA
357  * CaseDescription: Verify HandleAppStateChanged
358  */
359 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_004, TestSize.Level0)
360 {
361     auto manager = std::make_shared<AppStateObserverManager>();
362     std::vector<std::string> bundleNameList;
363     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
364     ApplicationState state = ApplicationState::APP_STATE_CREATE;
365     bool needNotifyApp = false;
366     std::string bundleName = "com.ohos.unittest";
367     appRecord->mainBundleName_ = bundleName;
368     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
369     manager->HandleAppStateChanged(appRecord, state, needNotifyApp);
370 }
371 
372 /*
373  * Feature: AppStateObserverManager
374  * Function: HandleAppStateChanged
375  * SubFunction: NA
376  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
377  * EnvConditions: NA
378  * CaseDescription: Verify HandleAppStateChanged
379  */
380 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_005, TestSize.Level0)
381 {
382     auto manager = std::make_shared<AppStateObserverManager>();
383     std::vector<std::string> bundleNameList;
384     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
385     ApplicationState state = ApplicationState::APP_STATE_TERMINATED;
386     bool needNotifyApp = false;
387     std::string bundleName = "com.ohos.unittest";
388     appRecord->mainBundleName_ = bundleName;
389     bundleNameList.push_back(bundleName);
390     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
391     manager->HandleAppStateChanged(appRecord, state, needNotifyApp);
392 }
393 
394 /*
395  * Feature: AppStateObserverManager
396  * Function: HandleAppStateChanged
397  * SubFunction: NA
398  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
399  * EnvConditions: NA
400  * CaseDescription: Verify HandleAppStateChanged
401  */
402 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_006, TestSize.Level0)
403 {
404     auto manager = std::make_shared<AppStateObserverManager>();
405     std::vector<std::string> bundleNameList;
406     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
407     ApplicationState state = ApplicationState::APP_STATE_CREATE;
408     bool needNotifyApp = false;
409     std::string bundleName1 = "com.ohos.unittest1";
410     std::string bundleName2 = "com.ohos.unittest2";
411     appRecord->mainBundleName_ = bundleName1;
412     bundleNameList.push_back(bundleName2);
413     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
414     manager->HandleAppStateChanged(appRecord, state, needNotifyApp);
415 }
416 
417 /*
418  * Feature: AppStateObserverManager
419  * Function: HandleAppStateChanged
420  * SubFunction: NA
421  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
422  * EnvConditions: NA
423  * CaseDescription: Verify HandleAppStateChanged
424  */
425 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_007, TestSize.Level0)
426 {
427     auto manager = std::make_shared<AppStateObserverManager>();
428     std::vector<std::string> bundleNameList;
429     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
430     ApplicationState state = ApplicationState::APP_STATE_CREATE;
431     bool needNotifyApp = false;
432     std::string bundleName = "com.ohos.unittest";
433     appRecord->mainBundleName_ = bundleName;
434     manager->appStateObserverMap_.emplace(nullptr, bundleNameList);
435     manager->HandleAppStateChanged(appRecord, state, needNotifyApp);
436 }
437 
438 /*
439  * Feature: AppStateObserverManager
440  * Function: HandleAppStateChanged
441  * SubFunction: NA
442  * FunctionPoints: AppStateObserverManager HandleAppStateChanged
443  * EnvConditions: NA
444  * CaseDescription: Verify HandleAppStateChanged
445  */
446 HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_008, TestSize.Level0)
447 {
448     auto manager = std::make_shared<AppStateObserverManager>();
449     std::vector<std::string> bundleNameList;
450     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
451     ApplicationState state = ApplicationState::APP_STATE_END;
452     bool needNotifyApp = false;
453     manager->HandleAppStateChanged(appRecord, state, needNotifyApp);
454 }
455 
456 /*
457  * Feature: AppStateObserverManager
458  * Function: HandleStateChangedNotifyObserver
459  * SubFunction: NA
460  * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver
461  * EnvConditions: NA
462  * CaseDescription: Verify HandleStateChangedNotifyObserver
463  */
464 HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_001, TestSize.Level0)
465 {
466     auto manager = std::make_shared<AppStateObserverManager>();
467     AbilityStateData abilityStateData;
468     bool isAbility = true;
469     std::vector<std::string> bundleNameList;
470     std::string bundleName = "com.ohos.unittest";
471     abilityStateData.bundleName = bundleName;
472     bundleNameList.push_back(bundleName);
473     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
474     manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility);
475 }
476 
477 /*
478  * Feature: AppStateObserverManager
479  * Function: HandleStateChangedNotifyObserver
480  * SubFunction: NA
481  * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver
482  * EnvConditions: NA
483  * CaseDescription: Verify HandleStateChangedNotifyObserver
484  */
485 HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_002, TestSize.Level0)
486 {
487     auto manager = std::make_shared<AppStateObserverManager>();
488     AbilityStateData abilityStateData;
489     bool isAbility = false;
490     std::vector<std::string> bundleNameList;
491     std::string bundleName = "com.ohos.unittest";
492     abilityStateData.bundleName = bundleName;
493     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
494     manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility);
495 }
496 
497 /*
498  * Feature: AppStateObserverManager
499  * Function: HandleStateChangedNotifyObserver
500  * SubFunction: NA
501  * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver
502  * EnvConditions: NA
503  * CaseDescription: Verify HandleStateChangedNotifyObserver
504  */
505 HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_003, TestSize.Level0)
506 {
507     auto manager = std::make_shared<AppStateObserverManager>();
508     AbilityStateData abilityStateData;
509     bool isAbility = false;
510     std::vector<std::string> bundleNameList;
511     std::string bundleName1 = "com.ohos.unittest1";
512     std::string bundleName2 = "com.ohos.unittest2";
513     abilityStateData.bundleName = bundleName1;
514     bundleNameList.push_back(bundleName2);
515     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
516     manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility);
517 }
518 
519 /*
520  * Feature: AppStateObserverManager
521  * Function: HandleStateChangedNotifyObserver
522  * SubFunction: NA
523  * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver
524  * EnvConditions: NA
525  * CaseDescription: Verify HandleStateChangedNotifyObserver
526  */
527 HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_004, TestSize.Level0)
528 {
529     auto manager = std::make_shared<AppStateObserverManager>();
530     AbilityStateData abilityStateData;
531     bool isAbility = false;
532     std::vector<std::string> bundleNameList;
533     std::string bundleName = "com.ohos.unittest";
534     abilityStateData.bundleName = bundleName;
535     bundleNameList.push_back(bundleName);
536     manager->appStateObserverMap_.emplace(nullptr, bundleNameList);
537     manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility);
538 }
539 
540 /*
541  * Feature: AppStateObserverManager
542  * Function: HandleOnAppProcessCreated
543  * SubFunction: NA
544  * FunctionPoints: AppStateObserverManager HandleOnAppProcessCreated
545  * EnvConditions: NA
546  * CaseDescription: Verify HandleOnAppProcessCreated
547  */
548 HWTEST_F(AppSpawnSocketTest, HandleOnAppProcessCreated_001, TestSize.Level0)
549 {
550     auto manager = std::make_shared<AppStateObserverManager>();
551     manager->HandleOnAppProcessCreated(nullptr);
552     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
553     manager->HandleOnAppProcessCreated(appRecord);
554 }
555 
556 /*
557  * Feature: AppStateObserverManager
558  * Function: HandleOnRenderProcessCreated
559  * SubFunction: NA
560  * FunctionPoints: AppStateObserverManager HandleOnRenderProcessCreated
561  * EnvConditions: NA
562  * CaseDescription: Verify HandleOnRenderProcessCreated
563  */
564 HWTEST_F(AppSpawnSocketTest, HandleOnRenderProcessCreated_001, TestSize.Level0)
565 {
566     auto manager = std::make_shared<AppStateObserverManager>();
567     manager->HandleOnRenderProcessCreated(nullptr);
568     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
569     std::shared_ptr<RenderRecord> renderRecord = std::make_shared<RenderRecord>(1, "param", 1, 1, appRecord);
570     renderRecord->SetPid(1);
571     manager->HandleOnRenderProcessCreated(renderRecord);
572 }
573 
574 /*
575  * Feature: AppStateObserverManager
576  * Function: HandleOnProcessCreated
577  * SubFunction: NA
578  * FunctionPoints: AppStateObserverManager HandleOnProcessCreated
579  * EnvConditions: NA
580  * CaseDescription: Verify HandleOnProcessCreated
581  */
582 HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_001, TestSize.Level0)
583 {
584     auto manager = std::make_shared<AppStateObserverManager>();
585     ProcessData data;
586     std::vector<std::string> bundleNameList;
587     std::string bundleName = "com.ohos.unittest";
588     data.bundleName = bundleName;
589     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
590     manager->HandleOnProcessCreated(data);
591 }
592 
593 /*
594  * Feature: AppStateObserverManager
595  * Function: HandleOnProcessCreated
596  * SubFunction: NA
597  * FunctionPoints: AppStateObserverManager HandleOnProcessCreated
598  * EnvConditions: NA
599  * CaseDescription: Verify HandleOnProcessCreated
600  */
601 HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_002, TestSize.Level0)
602 {
603     auto manager = std::make_shared<AppStateObserverManager>();
604     ProcessData data;
605     std::vector<std::string> bundleNameList;
606     std::string bundleName = "com.ohos.unittest";
607     data.bundleName = bundleName;
608     bundleNameList.push_back(bundleName);
609     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
610     manager->HandleOnProcessCreated(data);
611 }
612 
613 /*
614  * Feature: AppStateObserverManager
615  * Function: HandleOnProcessCreated
616  * SubFunction: NA
617  * FunctionPoints: AppStateObserverManager HandleOnProcessCreated
618  * EnvConditions: NA
619  * CaseDescription: Verify HandleOnProcessCreated
620  */
621 HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_003, TestSize.Level0)
622 {
623     auto manager = std::make_shared<AppStateObserverManager>();
624     ProcessData data;
625     std::vector<std::string> bundleNameList;
626     std::string bundleName1 = "com.ohos.unittest";
627     std::string bundleName2 = "com.ohos.unittest";
628     data.bundleName = bundleName1;
629     bundleNameList.push_back(bundleName2);
630     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
631     manager->HandleOnProcessCreated(data);
632 }
633 
634 /*
635  * Feature: AppStateObserverManager
636  * Function: HandleOnProcessCreated
637  * SubFunction: NA
638  * FunctionPoints: AppStateObserverManager HandleOnProcessCreated
639  * EnvConditions: NA
640  * CaseDescription: Verify HandleOnProcessCreated
641  */
642 HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_004, TestSize.Level0)
643 {
644     auto manager = std::make_shared<AppStateObserverManager>();
645     ProcessData data;
646     std::vector<std::string> bundleNameList;
647     std::string bundleName = "com.ohos.unittest";
648     data.bundleName = bundleName;
649     bundleNameList.push_back(bundleName);
650     manager->appStateObserverMap_.emplace(nullptr, bundleNameList);
651     manager->HandleOnProcessCreated(data);
652 }
653 
654 /*
655  * Feature: AppStateObserverManager
656  * Function: HandleOnProcessStateChanged
657  * SubFunction: NA
658  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
659  * EnvConditions: NA
660  * CaseDescription: Verify HandleOnProcessStateChanged
661  */
662 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_001, TestSize.Level0)
663 {
664     auto manager = std::make_shared<AppStateObserverManager>();
665     manager->HandleOnProcessStateChanged(nullptr);
666 }
667 
668 /*
669  * Feature: AppStateObserverManager
670  * Function: HandleOnProcessStateChanged
671  * SubFunction: NA
672  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
673  * EnvConditions: NA
674  * CaseDescription: Verify HandleOnProcessStateChanged
675  */
676 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_002, TestSize.Level0)
677 {
678     auto manager = std::make_shared<AppStateObserverManager>();
679     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
680     std::vector<std::string> bundleNameList;
681     std::string bundleName = "com.ohos.unittest";
682     appRecord->mainBundleName_ = bundleName;
683     bundleNameList.push_back(bundleName);
684     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
685     manager->HandleOnProcessStateChanged(appRecord);
686 }
687 
688 /*
689  * Feature: AppStateObserverManager
690  * Function: HandleOnProcessStateChanged
691  * SubFunction: NA
692  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
693  * EnvConditions: NA
694  * CaseDescription: Verify HandleOnProcessStateChanged
695  */
696 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_003, TestSize.Level0)
697 {
698     auto manager = std::make_shared<AppStateObserverManager>();
699     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
700     std::vector<std::string> bundleNameList;
701     std::string bundleName = "com.ohos.unittest";
702     appRecord->mainBundleName_ = bundleName;
703     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
704     manager->HandleOnProcessStateChanged(appRecord);
705 }
706 
707 /*
708  * Feature: AppStateObserverManager
709  * Function: HandleOnProcessStateChanged
710  * SubFunction: NA
711  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
712  * EnvConditions: NA
713  * CaseDescription: Verify HandleOnProcessStateChanged
714  */
715 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_004, TestSize.Level0)
716 {
717     auto manager = std::make_shared<AppStateObserverManager>();
718     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
719     std::vector<std::string> bundleNameList;
720     std::string bundleName1 = "com.ohos.unittest1";
721     std::string bundleName2 = "com.ohos.unittest2";
722     appRecord->mainBundleName_ = bundleName1;
723     bundleNameList.push_back(bundleName2);
724     manager->appStateObserverMap_.emplace(nullptr, bundleNameList);
725     manager->HandleOnProcessStateChanged(appRecord);
726 }
727 
728 /*
729  * Feature: AppStateObserverManager
730  * Function: HandleOnProcessStateChanged
731  * SubFunction: NA
732  * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged
733  * EnvConditions: NA
734  * CaseDescription: Verify HandleOnProcessStateChanged
735  */
736 HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_005, TestSize.Level0)
737 {
738     auto manager = std::make_shared<AppStateObserverManager>();
739     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
740     std::vector<std::string> bundleNameList;
741     std::string bundleName = "com.ohos.unittest";
742     appRecord->mainBundleName_ = bundleName;
743     bundleNameList.push_back(bundleName);
744     manager->appStateObserverMap_.emplace(nullptr, bundleNameList);
745     manager->HandleOnProcessStateChanged(appRecord);
746 }
747 
748 /*
749  * Feature: AppStateObserverManager
750  * Function: HandleOnAppProcessDied
751  * SubFunction: NA
752  * FunctionPoints: AppStateObserverManager HandleOnAppProcessDied
753  * EnvConditions: NA
754  * CaseDescription: Verify HandleOnAppProcessDied
755  */
756 HWTEST_F(AppSpawnSocketTest, HandleOnAppProcessDied_001, TestSize.Level0)
757 {
758     auto manager = std::make_shared<AppStateObserverManager>();
759     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
760     manager->HandleOnAppProcessDied(nullptr);
761     manager->HandleOnAppProcessDied(appRecord);
762 }
763 
764 /*
765  * Feature: AppStateObserverManager
766  * Function: HandleOnRenderProcessDied
767  * SubFunction: NA
768  * FunctionPoints: AppStateObserverManager HandleOnRenderProcessDied
769  * EnvConditions: NA
770  * CaseDescription: Verify HandleOnRenderProcessDied
771  */
772 HWTEST_F(AppSpawnSocketTest, HandleOnRenderProcessDied_001, TestSize.Level0)
773 {
774     auto manager = std::make_shared<AppStateObserverManager>();
775     std::shared_ptr<AppRunningRecord> appRecord = MockAppRecord();
776     std::shared_ptr<RenderRecord> renderRecord = std::make_shared<RenderRecord>(1, "param", 1, 1, appRecord);
777     renderRecord->SetPid(1);
778     manager->HandleOnRenderProcessDied(nullptr);
779     manager->HandleOnRenderProcessDied(renderRecord);
780 }
781 
782 /*
783  * Feature: AppStateObserverManager
784  * Function: HandleOnProcessDied
785  * SubFunction: NA
786  * FunctionPoints: AppStateObserverManager HandleOnProcessDied
787  * EnvConditions: NA
788  * CaseDescription: Verify HandleOnProcessDied
789  */
790 HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_001, TestSize.Level0)
791 {
792     auto manager = std::make_shared<AppStateObserverManager>();
793     ProcessData data;
794     std::vector<std::string> bundleNameList;
795     std::string bundleName = "com.ohos.unittest";
796     data.bundleName = bundleName;
797     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
798     manager->HandleOnProcessDied(data);
799 }
800 
801 /*
802  * Feature: AppStateObserverManager
803  * Function: HandleOnProcessDied
804  * SubFunction: NA
805  * FunctionPoints: AppStateObserverManager HandleOnProcessDied
806  * EnvConditions: NA
807  * CaseDescription: Verify HandleOnProcessDied
808  */
809 HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_002, TestSize.Level0)
810 {
811     auto manager = std::make_shared<AppStateObserverManager>();
812     ProcessData data;
813     std::vector<std::string> bundleNameList;
814     std::string bundleName = "com.ohos.unittest";
815     data.bundleName = bundleName;
816     bundleNameList.push_back(bundleName);
817     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
818     manager->HandleOnProcessDied(data);
819 }
820 
821 /*
822  * Feature: AppStateObserverManager
823  * Function: HandleOnProcessDied
824  * SubFunction: NA
825  * FunctionPoints: AppStateObserverManager HandleOnProcessDied
826  * EnvConditions: NA
827  * CaseDescription: Verify HandleOnProcessDied
828  */
829 HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_003, TestSize.Level0)
830 {
831     auto manager = std::make_shared<AppStateObserverManager>();
832     ProcessData data;
833     std::vector<std::string> bundleNameList;
834     std::string bundleName1 = "com.ohos.unittest1";
835     std::string bundleName2 = "com.ohos.unittest2";
836     data.bundleName = bundleName1;
837     bundleNameList.push_back(bundleName2);
838     manager->appStateObserverMap_.emplace(observer_, bundleNameList);
839     manager->HandleOnProcessDied(data);
840 }
841 
842 /*
843  * Feature: AppStateObserverManager
844  * Function: HandleOnProcessDied
845  * SubFunction: NA
846  * FunctionPoints: AppStateObserverManager HandleOnProcessDied
847  * EnvConditions: NA
848  * CaseDescription: Verify HandleOnProcessDied
849  */
850 HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_004, TestSize.Level0)
851 {
852     auto manager = std::make_shared<AppStateObserverManager>();
853     ProcessData data;
854     std::vector<std::string> bundleNameList;
855     std::string bundleName1 = "com.ohos.unittest1";
856     std::string bundleName2 = "com.ohos.unittest2";
857     data.bundleName = bundleName1;
858     bundleNameList.push_back(bundleName2);
859     manager->appStateObserverMap_.emplace(nullptr, bundleNameList);
860     manager->HandleOnProcessDied(data);
861 }
862 
863 /*
864  * Feature: AppStateObserverManager
865  * Function: ObserverExist
866  * SubFunction: NA
867  * FunctionPoints: AppStateObserverManager ObserverExist
868  * EnvConditions: NA
869  * CaseDescription: Verify ObserverExist
870  */
871 HWTEST_F(AppSpawnSocketTest, ObserverExist_001, TestSize.Level0)
872 {
873     auto manager = std::make_shared<AppStateObserverManager>();
874     bool res = manager->ObserverExist(nullptr);
875     EXPECT_FALSE(res);
876 }
877 
878 /*
879  * Feature: AppStateObserverManager
880  * Function: ObserverExist
881  * SubFunction: NA
882  * FunctionPoints: AppStateObserverManager ObserverExist
883  * EnvConditions: NA
884  * CaseDescription: Verify ObserverExist
885  */
886 HWTEST_F(AppSpawnSocketTest, ObserverExist_002, TestSize.Level0)
887 {
888     auto manager = std::make_shared<AppStateObserverManager>();
889     sptr<IApplicationStateObserver> observer = new MockApplicationStateObserver();
890     std::vector<std::string> bundleNameList;
891     manager->appStateObserverMap_.emplace(observer, bundleNameList);
892     bool res = manager->ObserverExist(observer);
893     EXPECT_TRUE(res);
894 }
895 
896 /*
897  * Feature: AppStateObserverManager
898  * Function: AddObserverDeathRecipient
899  * SubFunction: NA
900  * FunctionPoints: AppStateObserverManager AddObserverDeathRecipient
901  * EnvConditions: NA
902  * CaseDescription: Verify AddObserverDeathRecipient
903  */
904 HWTEST_F(AppSpawnSocketTest, AddObserverDeathRecipient_001, TestSize.Level0)
905 {
906     auto manager = std::make_shared<AppStateObserverManager>();
907     manager->AddObserverDeathRecipient(nullptr);
908     manager->AddObserverDeathRecipient(observer_);
909 }
910 
911 /*
912  * Feature: AppStateObserverManager
913  * Function: RemoveObserverDeathRecipient
914  * SubFunction: NA
915  * FunctionPoints: AppStateObserverManager RemoveObserverDeathRecipient
916  * EnvConditions: NA
917  * CaseDescription: Verify RemoveObserverDeathRecipient
918  */
919 HWTEST_F(AppSpawnSocketTest, RemoveObserverDeathRecipient_001, TestSize.Level0)
920 {
921     auto manager = std::make_shared<AppStateObserverManager>();
922     manager->RemoveObserverDeathRecipient(nullptr);
923     manager->AddObserverDeathRecipient(observer_);
924 }
925 }  // namespace AppExecFwk
926 }  // namespace OHOS
927