• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "ability_foreground_state_observer_interface.h"
19 #include "app_foreground_state_observer_stub.h"
20 #include "app_mgr_proxy.h"
21 #include "hilog_tag_wrapper.h"
22 #include "mock_ability_foreground_state_observer_stub.h"
23 #include "mock_app_mgr_service.h"
24 #include "quick_fix_callback_stub.h"
25 #include "render_state_observer_stub.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 namespace {
33 const int32_t USER_ID = 100;
34 } // namespace
35 
36 class AppForegroundStateObserverMock : public AppForegroundStateObserverStub {
37 public:
38     AppForegroundStateObserverMock() = default;
39     virtual ~AppForegroundStateObserverMock() = default;
40 
OnAppStateChanged(const AppStateData & appStateData)41     void OnAppStateChanged(const AppStateData &appStateData) override
42     {}
43 };
44 
45 class RenderStateObserverMock : public RenderStateObserverStub {
46 public:
47     RenderStateObserverMock() = default;
48     virtual ~RenderStateObserverMock() = default;
OnRenderStateChanged(const RenderStateData & renderStateData)49     void OnRenderStateChanged(const RenderStateData &renderStateData) override
50     {}
51 };
52 
53 class QuickFixCallbackImpl : public AppExecFwk::QuickFixCallbackStub {
54 public:
55     QuickFixCallbackImpl() = default;
56     virtual ~QuickFixCallbackImpl() = default;
57 
OnLoadPatchDone(int32_t resultCode,int32_t recordId)58     void OnLoadPatchDone(int32_t resultCode, int32_t recordId) override
59     {
60         TAG_LOGD(AAFwkTag::TEST, "function called.");
61     }
62 
OnUnloadPatchDone(int32_t resultCode,int32_t recordId)63     void OnUnloadPatchDone(int32_t resultCode, int32_t recordId) override
64     {
65         TAG_LOGD(AAFwkTag::TEST, "function called.");
66     }
67 
OnReloadPageDone(int32_t resultCode,int32_t recordId)68     void OnReloadPageDone(int32_t resultCode, int32_t recordId) override
69     {
70         TAG_LOGD(AAFwkTag::TEST, "function called.");
71     }
72 };
73 
74 class AppMgrProxyTest : public testing::Test {
75 public:
76     static void SetUpTestCase();
77     static void TearDownTestCase();
78     void SetUp() override;
79     void TearDown() override;
80 
81     sptr<MockAppMgrService> mockAppMgrService_;
82     sptr<AppMgrProxy> appMgrProxy_;
83 };
84 
SetUpTestCase(void)85 void AppMgrProxyTest::SetUpTestCase(void)
86 {}
87 
TearDownTestCase(void)88 void AppMgrProxyTest::TearDownTestCase(void)
89 {}
90 
SetUp()91 void AppMgrProxyTest::SetUp()
92 {
93     GTEST_LOG_(INFO) << "AppMgrProxyTest::SetUp()";
94 
95     mockAppMgrService_ = new MockAppMgrService();
96     appMgrProxy_ = new AppMgrProxy(mockAppMgrService_);
97 }
98 
TearDown()99 void AppMgrProxyTest::TearDown()
100 {}
101 
102 /**
103  * @tc.name: AppMgrProxy_GetProcessRunningInfosByUserId_0100
104  * @tc.desc: GetProcessRunningInfosByUserId
105  * @tc.type: FUNC
106  * @tc.require: SR000GH1GO
107  */
108 HWTEST_F(AppMgrProxyTest, AppMgrProxy_GetProcessRunningInfosByUserId_0100, TestSize.Level0)
109 {
110     GTEST_LOG_(INFO) << "AppMgrProxy_GetProcessRunningInfosByUserId_0100 start";
111 
112     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
113         .Times(1)
114         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
115 
116     std::vector<RunningProcessInfo> info;
117     appMgrProxy_->GetProcessRunningInfosByUserId(info, USER_ID);
118 
119     EXPECT_EQ(
120         mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_USER_ID));
121 
122     GTEST_LOG_(INFO) << "AppMgrProxy_GetProcessRunningInfosByUserId_0100 end";
123 }
124 
125 /**
126  * @tc.name: AppMgrProxy_GetAllRenderProcesses_0100
127  * @tc.desc: GetAllRenderProcesses
128  * @tc.type: FUNC
129  */
130 HWTEST_F(AppMgrProxyTest, AppMgrProxy_GetAllRenderProcesses_0100, TestSize.Level0)
131 {
132     GTEST_LOG_(INFO) << "AppMgrProxy_GetAllRenderProcesses_0100 start";
133 
134     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
135         .Times(1)
136         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
137 
138     std::vector<RenderProcessInfo> info;
139     appMgrProxy_->GetAllRenderProcesses(info);
140 
141     EXPECT_EQ(
142         mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_ALL_RENDER_PROCESSES));
143 
144     GTEST_LOG_(INFO) << "AppMgrProxy_GetAllRenderProcesses_0100 end";
145 }
146 
147 #ifdef SUPPORT_CHILD_PROCESS
148 /**
149  * @tc.name: AppMgrProxy_GetAllChildrenProcesses_0100
150  * @tc.desc: GetAllChildrenProcesses
151  * @tc.type: FUNC
152  */
153 HWTEST_F(AppMgrProxyTest, AppMgrProxy_GetAllChildrenProcesses_0100, TestSize.Level0)
154 {
155     GTEST_LOG_(INFO) << "AppMgrProxy_GetAllChildrenProcesses_0100 start";
156 
157     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
158         .Times(1)
159         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
160 
161     std::vector<ChildProcessInfo> info;
162     appMgrProxy_->GetAllChildrenProcesses(info);
163 
164     EXPECT_EQ(
165         mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_CHILDREN_PROCESSES));
166 
167     GTEST_LOG_(INFO) << "AppMgrProxy_GetAllChildrenProcesses_0100 end";
168 }
169 #endif // SUPPORT_CHILD_PROCESS
170 
171 /**
172  * @tc.name: GetAppRunningStateByBundleName_0100
173  * @tc.desc: Get app running state by bundle name.
174  * @tc.type: FUNC
175  * @tc.require: issueI581VW
176  */
177 HWTEST_F(AppMgrProxyTest, GetAppRunningStateByBundleName_0100, TestSize.Level0)
178 {
179     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
180 
181     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
182         .Times(1)
183         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
184 
185     std::string bundleName = "testBundleName";
186     appMgrProxy_->GetAppRunningStateByBundleName(bundleName);
187 
188     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_RUNNING_STATE));
189 
190     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
191 }
192 
193 /**
194  * @tc.name: NotifyLoadRepairPatch_0100
195  * @tc.desc: Notify load repair patch.
196  * @tc.type: FUNC
197  * @tc.require: issueI581VW
198  */
199 HWTEST_F(AppMgrProxyTest, NotifyLoadRepairPatch_0100, TestSize.Level0)
200 {
201     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
202 
203     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
204         .Times(1)
205         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
206 
207     std::string bundleName = "testBundleName";
208     sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
209     appMgrProxy_->NotifyLoadRepairPatch(bundleName, callback);
210 
211     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_LOAD_REPAIR_PATCH));
212 
213     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
214 }
215 
216 /**
217  * @tc.name: NotifyHotReloadPage_0100
218  * @tc.desc: Notify ace execute hot reload page.
219  * @tc.type: FUNC
220  * @tc.require: issueI581VW
221  */
222 HWTEST_F(AppMgrProxyTest, NotifyHotReloadPage_0100, TestSize.Level0)
223 {
224     TAG_LOGI(AAFwkTag::TEST, "%{public}s start", __func__);
225 
226     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
227         .Times(1)
228         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
229 
230     std::string bundleName = "testBundleName";
231     sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
232     appMgrProxy_->NotifyHotReloadPage(bundleName, callback);
233 
234     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_HOT_RELOAD_PAGE));
235 
236     TAG_LOGI(AAFwkTag::TEST, "%{public}s end", __func__);
237 }
238 
239 /**
240  * @tc.name: NotifyUnLoadRepairPatch_0100
241  * @tc.desc: Notify unload repair patch.
242  * @tc.type: FUNC
243  * @tc.require: issueI581VW
244  */
245 HWTEST_F(AppMgrProxyTest, NotifyUnLoadRepairPatch_0100, TestSize.Level0)
246 {
247     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
248 
249     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
250         .Times(1)
251         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
252 
253     std::string bundleName = "testBundleName";
254     sptr<IQuickFixCallback> callback = new QuickFixCallbackImpl();
255     appMgrProxy_->NotifyUnLoadRepairPatch(bundleName, callback);
256 
257     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_UNLOAD_REPAIR_PATCH));
258 
259     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
260 }
261 
262 /**
263  * @tc.name: PreStartNWebSpawnProcess_001
264  * @tc.desc: prestart nwebspawn process.
265  * @tc.type: FUNC
266  * @tc.require: issueI5W4S7
267  */
268 HWTEST_F(AppMgrProxyTest, PreStartNWebSpawnProcess_001, TestSize.Level0)
269 {
270     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
271 
272     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
273         .Times(1)
274         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
275 
276     appMgrProxy_->PreStartNWebSpawnProcess();
277     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS));
278 
279     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
280 }
281 
282 /**
283  * @tc.name: GetProcessMemoryByPid_001
284  * @tc.desc: Get memorySize by pid.
285  * @tc.type: FUNC
286  * @tc.require: issueI76JBF
287  */
288 HWTEST_F(AppMgrProxyTest, GetProcessMemoryByPid_001, TestSize.Level0)
289 {
290     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
291 
292     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
293         .Times(1)
294         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
295 
296     int32_t pid = 0;
297     int32_t memorySize = 0;
298     appMgrProxy_->GetProcessMemoryByPid(pid, memorySize);
299     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::GET_PROCESS_MEMORY_BY_PID));
300 
301     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
302 }
303 
304 /**
305  * @tc.name: GetRunningProcessInformation_001
306  * @tc.desc: Get application processes information list by bundleName.
307  * @tc.type: FUNC
308  * @tc.require: issueI76JBF
309  */
310 HWTEST_F(AppMgrProxyTest, GetRunningProcessInformation_001, TestSize.Level0)
311 {
312     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
313 
314     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
315         .Times(1)
316         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
317 
318     std::string bundleName = "testBundleName";
319     int32_t userId = USER_ID;
320     std::vector<RunningProcessInfo> info;
321     appMgrProxy_->GetRunningProcessInformation(bundleName, userId, info);
322     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::GET_PIDS_BY_BUNDLENAME));
323 
324     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
325 }
326 
327 /**
328  * @tc.name: NotifyAppFault_001
329  * @tc.desc: Notify app fault.
330  * @tc.type: FUNC
331  * @tc.require: issueI79RY8
332  */
333 HWTEST_F(AppMgrProxyTest, NotifyAppFault_001, TestSize.Level1)
334 {
335     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
336         .Times(1)
337         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
338     FaultData faultData;
339     appMgrProxy_->NotifyAppFault(faultData);
340     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT));
341 }
342 
343 /**
344  * @tc.name: NotifyAppFaultBySA_001
345  * @tc.desc: Notify app fault by SA.
346  * @tc.type: FUNC
347  * @tc.require: issueI79RY8
348  */
349 HWTEST_F(AppMgrProxyTest, NotifyAppFaultBySA_001, TestSize.Level1)
350 {
351     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
352         .Times(1)
353         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
354     AppFaultDataBySA faultData;
355     appMgrProxy_->NotifyAppFaultBySA(faultData);
356     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA));
357 }
358 
359 /**
360  * @tc.name: SetAppFreezeFilter_001
361  * @tc.desc: Set appfreeze filter.
362  * @tc.type: FUNC
363  */
364 HWTEST_F(AppMgrProxyTest, SetAppFreezeFilter_001, TestSize.Level1)
365 {
366     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
367         .Times(1)
368         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
369     int32_t pid = 0; // test value
370     appMgrProxy_->SetAppFreezeFilter(pid);
371     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::SET_APPFREEZE_FILTER));
372 }
373 
374 /**
375  * @tc.name: ChangeAppGcState_001
376  * @tc.desc: Change app Gc state.
377  * @tc.type: FUNC
378  * @tc.require: issuesI85VVU
379  */
380 HWTEST_F(AppMgrProxyTest, ChangeAppGcState_001, TestSize.Level1)
381 {
382     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
383         .Times(1)
384         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
385     int32_t pid = 0;
386     int32_t state = 0;
387     appMgrProxy_->ChangeAppGcState(pid, state);
388     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::CHANGE_APP_GC_STATE));
389 }
390 
391 /**
392  * @tc.name: IsApplicationRunning_001
393  * @tc.desc: Send request to query the running status of the application.
394  * @tc.type: FUNC
395  */
396 HWTEST_F(AppMgrProxyTest, IsApplicationRunning_001, TestSize.Level1)
397 {
398     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
399         .Times(1)
400         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
401 
402     std::string bundleName = "testBundleName";
403     bool isRunning = false;
404     appMgrProxy_->IsApplicationRunning(bundleName, isRunning);
405     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::IS_APPLICATION_RUNNING));
406 }
407 
408 /**
409  * @tc.name: IsAppRunning_001
410  * @tc.desc: Send request to query the running status of the application.
411  * @tc.type: FUNC
412  */
413 HWTEST_F(AppMgrProxyTest, IsAppRunning_001, TestSize.Level1)
414 {
415     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
416         .Times(1)
417         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
418 
419     std::string bundleName = "testBundleName";
420     int32_t appCloneIndex = 0;
421     bool isRunning = false;
422 
423     appMgrProxy_->IsAppRunning(bundleName, appCloneIndex, isRunning);
424     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::IS_APP_RUNNING));
425 }
426 
427 /**
428  * @tc.number: RegisterAbilityForegroundStateObserver_0100
429  * @tc.desc: Verify that the RegisterAbilityForegroundStateObserver function is called normally.
430  * @tc.type: FUNC
431  */
432 HWTEST_F(AppMgrProxyTest, RegisterAbilityForegroundStateObserver_0100, TestSize.Level1)
433 {
434     sptr<IAbilityForegroundStateObserver> observer = new MockAbilityForegroundStateObserverStub();
435     EXPECT_NE(observer->AsObject(), nullptr);
436     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
437         .Times(1)
438         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
439     appMgrProxy_->RegisterAbilityForegroundStateObserver(observer);
440     EXPECT_EQ(mockAppMgrService_->code_,
441         static_cast<uint32_t>(AppMgrInterfaceCode::REGISTER_ABILITY_FOREGROUND_STATE_OBSERVER));
442 }
443 
444 /**
445  * @tc.number: RegisterAbilityForegroundStateObserver_0200
446  * @tc.desc: Verify that the RegisterAbilityForegroundStateObserver parameter of the function is null.
447  * @tc.type: FUNC
448  */
449 HWTEST_F(AppMgrProxyTest, RegisterAbilityForegroundStateObserver_0200, TestSize.Level1)
450 {
451     sptr<IAbilityForegroundStateObserver> observer = nullptr;
452     auto result = appMgrProxy_->RegisterAbilityForegroundStateObserver(observer);
453     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
454 }
455 
456 /**
457  * @tc.number: UnregisterAbilityForegroundStateObserver_0100
458  * @tc.desc: Verify that the UnregisterAbilityForegroundStateObserver function is called normally.
459  * @tc.type: FUNC
460  */
461 HWTEST_F(AppMgrProxyTest, UnregisterAbilityForegroundStateObserver_0100, TestSize.Level1)
462 {
463     sptr<IAbilityForegroundStateObserver> observer = new MockAbilityForegroundStateObserverStub();
464     EXPECT_NE(observer->AsObject(), nullptr);
465     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
466         .Times(1)
467         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
468     appMgrProxy_->UnregisterAbilityForegroundStateObserver(observer);
469     EXPECT_EQ(mockAppMgrService_->code_,
470         static_cast<uint32_t>(AppMgrInterfaceCode::UNREGISTER_ABILITY_FOREGROUND_STATE_OBSERVER));
471 }
472 
473 /**
474  * @tc.number: RegisterAbilityForegroundStateObserver_0200
475  * @tc.desc: Verify that the UnregisterAbilityForegroundStateObserver parameter of the function is null.
476  * @tc.type: FUNC
477  */
478 HWTEST_F(AppMgrProxyTest, UnregisterAbilityForegroundStateObserver_0200, TestSize.Level1)
479 {
480     sptr<IAbilityForegroundStateObserver> observer = nullptr;
481     auto result = appMgrProxy_->UnregisterAbilityForegroundStateObserver(observer);
482     EXPECT_EQ(result, OHOS::ERR_INVALID_VALUE);
483 }
484 
485 /**
486  * @tc.name: RegisterAppForegroundStateObserver_0100
487  * @tc.desc: Test when all condition not met.
488  * @tc.type: FUNC
489  */
490 HWTEST_F(AppMgrProxyTest, RegisterAppForegroundStateObserver_0100, TestSize.Level1)
491 {
492     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
493     sptr<IAppForegroundStateObserver> observer = new (std::nothrow) AppForegroundStateObserverMock();
494     auto res = appMgrProxy_->RegisterAppForegroundStateObserver(observer);
495     EXPECT_EQ(res, NO_ERROR);
496 }
497 
498 /**
499  * @tc.name: UnregisterAppForegroundStateObserver_0100
500  * @tc.desc: Test when all condition not met.
501  * @tc.type: FUNC
502  */
503 HWTEST_F(AppMgrProxyTest, UnregisterAppForegroundStateObserver_0100, TestSize.Level1)
504 {
505     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
506     sptr<IAppForegroundStateObserver> observer = new (std::nothrow) AppForegroundStateObserverMock();
507     auto res = appMgrProxy_->RegisterAppForegroundStateObserver(observer);
508     EXPECT_EQ(res, NO_ERROR);
509 }
510 
511 /**
512  * @tc.name: RegisterRenderStateObserver_0100
513  * @tc.desc: Test registerRenderStateObserversendRequest.
514  * @tc.type: FUNC
515  */
516 HWTEST_F(AppMgrProxyTest, RegisterRenderStateObserver_0100, TestSize.Level1)
517 {
518     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
519     sptr<IRenderStateObserver> observer = new (std::nothrow) RenderStateObserverMock();
520     auto res = appMgrProxy_->RegisterRenderStateObserver(observer);
521     EXPECT_EQ(res, NO_ERROR);
522 }
523 
524 /**
525  * @tc.name: UnregisterRenderStateObserver_0100
526  * @tc.desc: Test unregisterRenderStateObserversendRequest.
527  * @tc.type: FUNC
528  */
529 HWTEST_F(AppMgrProxyTest, UnregisterRenderStateObserver_0100, TestSize.Level1)
530 {
531     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
532     sptr<IRenderStateObserver> observer = new (std::nothrow) RenderStateObserverMock();
533     auto res = appMgrProxy_->UnregisterRenderStateObserver(observer);
534     EXPECT_EQ(res, NO_ERROR);
535 }
536 
537 /**
538  * @tc.name: UpdateRenderState_0100
539  * @tc.desc: Test updateRenderState sendRequest.
540  * @tc.type: FUNC
541  */
542 HWTEST_F(AppMgrProxyTest, UpdateRenderState_0100, TestSize.Level1)
543 {
544     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
545     pid_t renderPid = 0;
546     int32_t state = 0;
547     auto res = appMgrProxy_->UpdateRenderState(renderPid, state);
548     EXPECT_EQ(res, NO_ERROR);
549 }
550 
551 /**
552  * @tc.name: SignRestartAppFlag_0100
553  * @tc.desc: Test SignRestartAppFlag.
554  * @tc.type: FUNC
555  */
556 HWTEST_F(AppMgrProxyTest, SignRestartAppFlag_0100, TestSize.Level1)
557 {
558     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
559     int32_t uid = 0;
560     auto res = appMgrProxy_->SignRestartAppFlag(uid, "");
561     EXPECT_EQ(res, NO_ERROR);
562 }
563 
564 /**
565  * @tc.name: NotifyMemorySizeStateChanged_0100
566  * @tc.desc: Test NotifyMemorySizeStateChanged.
567  * @tc.type: FUNC
568  */
569 HWTEST_F(AppMgrProxyTest, NotifyMemorySizeStateChanged_0100, TestSize.Level1)
570 {
571     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
572     auto res = appMgrProxy_->NotifyMemorySizeStateChanged(true);
573     EXPECT_EQ(res, NO_ERROR);
574 }
575 
576 /**
577  * @tc.name: NotifyMemorySizeStateChanged_0200
578  * @tc.desc: Test NotifyMemorySizeStateChanged.
579  * @tc.type: FUNC
580  */
581 HWTEST_F(AppMgrProxyTest, NotifyMemorySizeStateChanged_0200, TestSize.Level1)
582 {
583     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _)).Times(1);
584     auto res = appMgrProxy_->NotifyMemorySizeStateChanged(false);
585     EXPECT_EQ(res, NO_ERROR);
586 }
587 
588 /**
589  * @tc.name: GetAllUIExtensionRootHostPid_0100
590  * @tc.desc: Get all ui extension root host pid.
591  * @tc.type: FUNC
592  */
593 HWTEST_F(AppMgrProxyTest, GetAllUIExtensionRootHostPid_0100, TestSize.Level1)
594 {
595     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
596         .Times(1)
597         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
598     pid_t pid = 0;
599     std::vector<pid_t> hostPids;
600     auto res = appMgrProxy_->GetAllUIExtensionRootHostPid(pid, hostPids);
601     EXPECT_EQ(res, NO_ERROR);
602     EXPECT_EQ(mockAppMgrService_->code_,
603         static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_ROOT_HOST_PID));
604 }
605 
606 /**
607  * @tc.name: GetAllUIExtensionProviderPid_0100
608  * @tc.desc: Get all ui extension provider pid.
609  * @tc.type: FUNC
610  */
611 HWTEST_F(AppMgrProxyTest, GetAllUIExtensionProviderPid_0100, TestSize.Level1)
612 {
613     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
614         .Times(1)
615         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
616     pid_t hostPid = 0;
617     std::vector<pid_t> providerPids;
618     auto res = appMgrProxy_->GetAllUIExtensionProviderPid(hostPid, providerPids);
619     EXPECT_EQ(res, NO_ERROR);
620     EXPECT_EQ(mockAppMgrService_->code_,
621         static_cast<uint32_t>(AppMgrInterfaceCode::GET_ALL_UI_EXTENSION_PROVIDER_PID));
622 }
623 
624 /**
625  * @tc.name: PreloadApplication_0100
626  * @tc.desc: Preload application.
627  * @tc.type: FUNC
628  * @tc.Function: PreloadApplication
629  * @tc.SubFunction: NA
630  * @tc.EnvConditions: NA
631  */
632 HWTEST_F(AppMgrProxyTest, PreloadApplication_0100, TestSize.Level1)
633 {
634     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
635         .Times(1)
636         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
637 
638     std::string bundleName = "com.acts.preloadtest";
639     int32_t userId = 100;
640     PreloadMode preloadMode = PreloadMode::PRE_MAKE;
641     int32_t appIndex = 0;
642     auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex);
643     EXPECT_EQ(ret, NO_ERROR);
644     EXPECT_EQ(mockAppMgrService_->code_,
645         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION));
646 }
647 
648 /**
649  * @tc.name: PreloadApplication_0200
650  * @tc.desc: Preload application.
651  * @tc.type: FUNC
652  * @tc.Function: PreloadApplication
653  * @tc.SubFunction: NA
654  * @tc.EnvConditions: NA
655  */
656 HWTEST_F(AppMgrProxyTest, PreloadApplication_0200, TestSize.Level1)
657 {
658     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
659         .Times(1)
660         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
661 
662     std::string bundleName = "";
663     int32_t userId = 100;
664     PreloadMode preloadMode = PreloadMode::PRE_MAKE;
665     int32_t appIndex = 0;
666     auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex);
667     EXPECT_EQ(ret, NO_ERROR);
668     EXPECT_EQ(mockAppMgrService_->code_,
669         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION));
670 }
671 
672 /**
673  * @tc.name: PreloadApplication_0300
674  * @tc.desc: Preload application.
675  * @tc.type: FUNC
676  * @tc.Function: PreloadApplication
677  * @tc.SubFunction: NA
678  * @tc.EnvConditions: NA
679  */
680 HWTEST_F(AppMgrProxyTest, PreloadApplication_0300, TestSize.Level1)
681 {
682     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
683         .Times(1)
684         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
685 
686     std::string bundleName = "com.acts.preloadtest";
687     int32_t userId = 100;
688     PreloadMode preloadMode = PreloadMode::PRESS_DOWN;
689     int32_t appIndex = 0;
690     auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex);
691     EXPECT_EQ(ret, NO_ERROR);
692     EXPECT_EQ(mockAppMgrService_->code_,
693         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION));
694 }
695 
696 /**
697  * @tc.name: PreloadApplication_0400
698  * @tc.desc: Preload application.
699  * @tc.type: FUNC
700  * @tc.Function: PreloadApplication
701  * @tc.SubFunction: NA
702  * @tc.EnvConditions: NA
703  */
704 HWTEST_F(AppMgrProxyTest, PreloadApplication_0400, TestSize.Level1)
705 {
706     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
707         .Times(1)
708         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
709 
710     std::string bundleName = "";
711     int32_t userId = 100;
712     PreloadMode preloadMode = PreloadMode::PRESS_DOWN;
713     int32_t appIndex = 0;
714     auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex);
715     EXPECT_EQ(ret, NO_ERROR);
716     EXPECT_EQ(mockAppMgrService_->code_,
717         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION));
718 }
719 
720 /**
721  * @tc.name: PreloadApplication_0500
722  * @tc.desc: Preload application.
723  * @tc.type: FUNC
724  * @tc.Function: PreloadApplication
725  * @tc.SubFunction: NA
726  * @tc.EnvConditions: NA
727  */
728 HWTEST_F(AppMgrProxyTest, PreloadApplication_0500, TestSize.Level1)
729 {
730     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
731         .Times(1)
732         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
733 
734     std::string bundleName = "com.acts.preloadtest";
735     int32_t userId = -1;
736     PreloadMode preloadMode = PreloadMode::PRE_MAKE;
737     int32_t appIndex = 0;
738     auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex);
739     EXPECT_EQ(ret, NO_ERROR);
740     EXPECT_EQ(mockAppMgrService_->code_,
741         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION));
742 }
743 
744 /**
745  * @tc.name: PreloadApplication_0600
746  * @tc.desc: Preload application.
747  * @tc.type: FUNC
748  * @tc.Function: PreloadApplication
749  * @tc.SubFunction: NA
750  * @tc.EnvConditions: NA
751  */
752 HWTEST_F(AppMgrProxyTest, PreloadApplication_0600, TestSize.Level1)
753 {
754     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
755         .Times(1)
756         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
757 
758     std::string bundleName = "";
759     int32_t userId = -1;
760     PreloadMode preloadMode = PreloadMode::PRE_MAKE;
761     int32_t appIndex = 0;
762     auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex);
763     EXPECT_EQ(ret, NO_ERROR);
764     EXPECT_EQ(mockAppMgrService_->code_,
765         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION));
766 }
767 
768 /**
769  * @tc.name: PreloadApplication_0700
770  * @tc.desc: Preload application.
771  * @tc.type: FUNC
772  * @tc.Function: PreloadApplication
773  * @tc.SubFunction: NA
774  * @tc.EnvConditions: NA
775  */
776 HWTEST_F(AppMgrProxyTest, PreloadApplication_0700, TestSize.Level1)
777 {
778     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
779         .Times(1)
780         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
781 
782     std::string bundleName = "com.acts.preloadtest";
783     int32_t userId = -1;
784     PreloadMode preloadMode = PreloadMode::PRESS_DOWN;
785     int32_t appIndex = 0;
786     auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex);
787     EXPECT_EQ(ret, NO_ERROR);
788     EXPECT_EQ(mockAppMgrService_->code_,
789         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION));
790 }
791 
792 /**
793  * @tc.name: PreloadApplication_0800
794  * @tc.desc: Preload application.
795  * @tc.type: FUNC
796  * @tc.Function: PreloadApplication
797  * @tc.SubFunction: NA
798  * @tc.EnvConditions: NA
799  */
800 HWTEST_F(AppMgrProxyTest, PreloadApplication_0800, TestSize.Level1)
801 {
802     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
803         .Times(1)
804         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
805 
806     std::string bundleName = "";
807     int32_t userId = -1;
808     PreloadMode preloadMode = PreloadMode::PRESS_DOWN;
809     int32_t appIndex = 0;
810     auto ret = appMgrProxy_->PreloadApplication(bundleName, userId, preloadMode, appIndex);
811     EXPECT_EQ(ret, NO_ERROR);
812     EXPECT_EQ(mockAppMgrService_->code_,
813         static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION));
814 }
815 
816 /**
817  * @tc.name: SetSupportedProcessCacheSelf_001
818  * @tc.desc: The application sets itself whether or not to support process cache.
819  * @tc.type: FUNC
820  */
821 HWTEST_F(AppMgrProxyTest, SetSupportedProcessCacheSelf_001, TestSize.Level0)
822 {
823     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
824 
825     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
826         .Times(1)
827         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
828     bool isSupported = false;
829     appMgrProxy_->SetSupportedProcessCacheSelf(isSupported);
830     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE_SELF));
831 
832     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
833 }
834 
835 /**
836  * @tc.name: GetRunningMultiAppInfoByBundleName_001
837  * @tc.desc: Get multiApp information by bundleName.
838  * @tc.type: FUNC
839  * @tc.require: issueI9HMAO
840  */
841 HWTEST_F(AppMgrProxyTest, GetRunningMultiAppInfoByBundleName_001, TestSize.Level1)
842 {
843     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
844 
845     MessageParcel data;
846     MessageParcel reply;
847     MessageOption option;
848 
849     data.WriteInterfaceToken(AppMgrStub::GetDescriptor());
850     std::string bundleName = "testBundleName";
851     data.WriteString(bundleName);
852 
853     EXPECT_CALL(*mockAppMgrService_, GetRunningMultiAppInfoByBundleName(_, _)).Times(1);
854 
855     auto result = mockAppMgrService_->OnRemoteRequest(
856         static_cast<uint32_t>(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME), data, reply, option);
857     EXPECT_EQ(result, NO_ERROR);
858 
859     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
860 }
861 
862 /**
863  * @tc.name: GetAllRunningInstanceKeysBySelf_001
864  * @tc.desc: GetAllRunningInstanceKeysBySelf.
865  * @tc.type: FUNC
866  * @tc.require: issueI9HMAO
867  */
868 HWTEST_F(AppMgrProxyTest, GetAllRunningInstanceKeysBySelf_001, TestSize.Level1)
869 {
870     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
871 
872     MessageParcel data;
873     MessageParcel reply;
874     MessageOption option;
875 
876     data.WriteInterfaceToken(AppMgrStub::GetDescriptor());
877 
878     EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysBySelf(_)).Times(1);
879 
880     auto result = mockAppMgrService_->OnRemoteRequest(
881         static_cast<uint32_t>(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_SELF), data, reply, option);
882     EXPECT_EQ(result, NO_ERROR);
883 
884     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
885 }
886 
887 /**
888  * @tc.name: GetAllRunningInstanceKeysByBundleName_001
889  * @tc.desc: GetAllRunningInstanceKeysByBundleName.
890  * @tc.type: FUNC
891  * @tc.require: issueI9HMAO
892  */
893 HWTEST_F(AppMgrProxyTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Level1)
894 {
895     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
896 
897     MessageParcel data;
898     MessageParcel reply;
899     MessageOption option;
900 
901     data.WriteInterfaceToken(AppMgrStub::GetDescriptor());
902     std::string bundleName = "testBundleName";
903     data.WriteString(bundleName);
904     int32_t userId = -1;
905     data.WriteInt32(userId);
906 
907     EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _, _)).Times(1);
908 
909     auto result = mockAppMgrService_->OnRemoteRequest(
910         static_cast<uint32_t>(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME), data, reply, option);
911     EXPECT_EQ(result, NO_ERROR);
912 
913     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
914 }
915 
916 /**
917  * @tc.name: GetSupportedProcessCachePids_001
918  * @tc.desc: Get pids of processes which belong to specific bundle name and support process cache feature.
919  * @tc.type: FUNC
920  * @tc.require: issueIAGZ7H
921  */
922 HWTEST_F(AppMgrProxyTest, GetSupportedProcessCachePids_001, TestSize.Level0)
923 {
924     TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
925 
926     EXPECT_CALL(*mockAppMgrService_, SendRequest(_, _, _, _))
927         .Times(1)
928         .WillOnce(Invoke(mockAppMgrService_.GetRefPtr(), &MockAppMgrService::InvokeSendRequest));
929 
930     std::string bundleName = "testBundleName";
931     std::vector<int32_t> pidList;
932     appMgrProxy_->GetSupportedProcessCachePids(bundleName, pidList);
933     EXPECT_EQ(mockAppMgrService_->code_, static_cast<uint32_t>(AppMgrInterfaceCode::GET_SUPPORTED_PROCESS_CACHE_PIDS));
934 
935     TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
936 }
937 } // namespace AppExecFwk
938 } // namespace OHOS
939