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 #define private public
19 #define protected public
20 #include "app_foreground_state_observer_stub.h"
21 #include "app_mgr_stub.h"
22 #undef private
23 #undef protected
24
25 #include "hilog_tag_wrapper.h"
26 #include "ipc_types.h"
27 #include "mock_app_mgr_service.h"
28 #include "render_state_observer_stub.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32
33 namespace OHOS {
34 namespace AppExecFwk {
35 namespace {
36 const int32_t USER_ID = 100;
37 } // namespace
38
39 class AppForegroundStateObserverMock : public AppForegroundStateObserverStub {
40 public:
41 AppForegroundStateObserverMock() = default;
42 virtual ~AppForegroundStateObserverMock() = default;
OnAppStateChanged(const AppStateData & appStateData)43 void OnAppStateChanged(const AppStateData &appStateData) override
44 {}
45 };
46
47 class RenderStateObserverMock : public RenderStateObserverStub {
48 public:
49 RenderStateObserverMock() = default;
50 virtual ~RenderStateObserverMock() = default;
OnRenderStateChanged(const RenderStateData & renderStateData)51 void OnRenderStateChanged(const RenderStateData &renderStateData) override
52 {}
53 };
54
55 class AppMgrStubTest : public testing::Test {
56 public:
57 static void SetUpTestCase();
58 static void TearDownTestCase();
59 void SetUp() override;
60 void TearDown() override;
61
62 sptr<MockAppMgrService> mockAppMgrService_;
63
64 void WriteInterfaceToken(MessageParcel& data);
65 };
66
SetUpTestCase(void)67 void AppMgrStubTest::SetUpTestCase(void)
68 {}
69
TearDownTestCase(void)70 void AppMgrStubTest::TearDownTestCase(void)
71 {}
72
SetUp()73 void AppMgrStubTest::SetUp()
74 {
75 GTEST_LOG_(INFO) << "AppMgrStubTest::SetUp()";
76
77 mockAppMgrService_ = new MockAppMgrService();
78 }
79
TearDown()80 void AppMgrStubTest::TearDown()
81 {}
82
WriteInterfaceToken(MessageParcel & data)83 void AppMgrStubTest::WriteInterfaceToken(MessageParcel& data)
84 {
85 GTEST_LOG_(INFO) << "AppMgrStubTest::WriteInterfaceToken()";
86
87 data.WriteInterfaceToken(AppMgrStub::GetDescriptor());
88 }
89
90 /**
91 * @tc.name: AppMgrStub_GetProcessRunningInfosByUserId_0100
92 * @tc.desc: GetProcessRunningInfosByUserId
93 * @tc.type: FUNC
94 * @tc.require: SR000GH1GO
95 */
96 HWTEST_F(AppMgrStubTest, AppMgrStub_GetProcessRunningInfosByUserId_0100, TestSize.Level0)
97 {
98 GTEST_LOG_(INFO) << "AppMgrStub_GetProcessRunningInfosByUserId_0100 start";
99
100 MessageParcel data;
101 MessageParcel reply;
102 MessageOption option;
103
104 WriteInterfaceToken(data);
105 data.WriteInt32(USER_ID);
106
107 EXPECT_CALL(*mockAppMgrService_, GetProcessRunningInfosByUserId(_, _)).Times(1);
108
109 auto result = mockAppMgrService_->OnRemoteRequest(
110 static_cast<uint32_t>(AppMgrInterfaceCode::APP_GET_RUNNING_PROCESSES_BY_USER_ID), data, reply, option);
111 EXPECT_EQ(result, NO_ERROR);
112
113 GTEST_LOG_(INFO) << "AppMgrStub_GetProcessRunningInfosByUserId_0100 end";
114 }
115
116 /**
117 * @tc.name: HandleGetAppRunningStateByBundleName_0100
118 * @tc.desc: Handle get app running state by bundle name.
119 * @tc.type: FUNC
120 * @tc.require: issueI581VW
121 */
122 HWTEST_F(AppMgrStubTest, HandleGetAppRunningStateByBundleName_0100, TestSize.Level0)
123 {
124 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
125
126 MessageParcel data;
127 MessageParcel reply;
128 MessageOption option;
129
130 WriteInterfaceToken(data);
131 std::string bundleName = "testBundleName";
132 data.WriteString(bundleName);
133
134 EXPECT_CALL(*mockAppMgrService_, GetAppRunningStateByBundleName(_)).Times(1);
135
136 auto result = mockAppMgrService_->OnRemoteRequest(
137 static_cast<uint32_t>(AppMgrInterfaceCode::GET_APP_RUNNING_STATE), data, reply, option);
138 EXPECT_EQ(result, NO_ERROR);
139
140 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
141 }
142
143 /**
144 * @tc.name: HandleNotifyLoadRepairPatch_0100
145 * @tc.desc: Handle notify load repair patch.
146 * @tc.type: FUNC
147 * @tc.require: issueI581VW
148 */
149 HWTEST_F(AppMgrStubTest, HandleNotifyLoadRepairPatch_0100, TestSize.Level0)
150 {
151 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
152
153 MessageParcel data;
154 MessageParcel reply;
155 MessageOption option;
156
157 WriteInterfaceToken(data);
158 std::string bundleName = "testBundleName";
159 data.WriteString(bundleName);
160 mockAppMgrService_->HandleNotifyLoadRepairPatch(data, reply);
161 EXPECT_TRUE(mockAppMgrService_ != nullptr);
162
163 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
164 }
165
166 /**
167 * @tc.name: HandleNotifyHotReloadPage_0100
168 * @tc.desc: Handle notify ace hot reload page.
169 * @tc.type: FUNC
170 * @tc.require: issueI581VW
171 */
172 HWTEST_F(AppMgrStubTest, HandleNotifyHotReloadPage_0100, TestSize.Level0)
173 {
174 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
175
176 MessageParcel data;
177 MessageParcel reply;
178 MessageOption option;
179
180 WriteInterfaceToken(data);
181 std::string bundleName = "testBundleName";
182 data.WriteString(bundleName);
183 mockAppMgrService_->HandleNotifyHotReloadPage(data, reply);
184 EXPECT_TRUE(mockAppMgrService_ != nullptr);
185
186 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
187 }
188
189 /**
190 * @tc.name: HandleNotifyUnLoadRepairPatch_0100
191 * @tc.desc: Handle notify unload repair patch.
192 * @tc.type: FUNC
193 * @tc.require: issueI581VW
194 */
195 HWTEST_F(AppMgrStubTest, HandleNotifyUnLoadRepairPatch_0100, TestSize.Level0)
196 {
197 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
198
199 MessageParcel data;
200 MessageParcel reply;
201 MessageOption option;
202
203 WriteInterfaceToken(data);
204 std::string bundleName = "testBundleName";
205 data.WriteString(bundleName);
206 mockAppMgrService_->HandleNotifyUnLoadRepairPatch(data, reply);
207 EXPECT_TRUE(mockAppMgrService_ != nullptr);
208
209 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
210 }
211
212 /**
213 * @tc.name: PreStartNWebSpawnProcess_001
214 * @tc.desc: prestart nwebspawn process.
215 * @tc.type: FUNC
216 * @tc.require: issueI5W4S7
217 */
218 HWTEST_F(AppMgrStubTest, PreStartNWebSpawnProcess_001, TestSize.Level0)
219 {
220 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
221 MessageParcel data;
222 MessageParcel reply;
223 MessageOption option;
224 WriteInterfaceToken(data);
225 EXPECT_CALL(*mockAppMgrService_, PreStartNWebSpawnProcess()).Times(1);
226
227 auto result = mockAppMgrService_->OnRemoteRequest(
228 static_cast<uint32_t>(AppMgrInterfaceCode::PRE_START_NWEBSPAWN_PROCESS), data, reply, option);
229 EXPECT_EQ(result, NO_ERROR);
230
231 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
232 }
233
234 /**
235 * @tc.name: GetProcessMemoryByPid_001
236 * @tc.desc: Get memorySize by pid.
237 * @tc.type: FUNC
238 * @tc.require: issueI76JBF
239 */
240 HWTEST_F(AppMgrStubTest, GetProcessMemoryByPid_001, TestSize.Level0)
241 {
242 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
243 MessageParcel data;
244 MessageParcel reply;
245 MessageOption option;
246
247 WriteInterfaceToken(data);
248 int32_t pid = 0;
249 data.WriteInt32(pid);
250
251 EXPECT_CALL(*mockAppMgrService_, GetProcessMemoryByPid(_, _)).Times(1);
252
253 auto result = mockAppMgrService_->OnRemoteRequest(
254 static_cast<uint32_t>(AppMgrInterfaceCode::GET_PROCESS_MEMORY_BY_PID), data, reply, option);
255 EXPECT_EQ(result, NO_ERROR);
256
257 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
258 }
259
260 /**
261 * @tc.name: GetRunningProcessInformation_001
262 * @tc.desc: Get pid list by bundleName.
263 * @tc.type: FUNC
264 * @tc.require: issueI76JBF
265 */
266 HWTEST_F(AppMgrStubTest, GetRunningProcessInformation_001, TestSize.Level0)
267 {
268 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
269 MessageParcel data;
270 MessageParcel reply;
271 MessageOption option;
272
273 WriteInterfaceToken(data);
274 std::string bundleName = "testBundleName";
275 int32_t userId = 0;
276 data.WriteString(bundleName);
277 data.WriteInt32(userId);
278
279 EXPECT_CALL(*mockAppMgrService_, GetRunningProcessInformation(_, _, _)).Times(1);
280
281 auto result = mockAppMgrService_->OnRemoteRequest(
282 static_cast<uint32_t>(AppMgrInterfaceCode::GET_PIDS_BY_BUNDLENAME), data, reply, option);
283 EXPECT_EQ(result, NO_ERROR);
284
285 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
286 }
287
288 /**
289 * @tc.name: HandleNotifyFault_001
290 * @tc.desc: Handle notify fault.
291 * @tc.type: FUNC
292 * @tc.require: issueI79RY8
293 */
294 HWTEST_F(AppMgrStubTest, HandleNotifyFault_001, TestSize.Level1)
295 {
296 MessageParcel data;
297 MessageParcel reply;
298 MessageOption option;
299 WriteInterfaceToken(data);
300 FaultData faultData;
301 faultData.errorObject.name = "testName";
302 faultData.errorObject.message = "testMessage";
303 faultData.errorObject.stack = "testStack";
304 faultData.faultType = FaultDataType::UNKNOWN;
305 data.WriteParcelable(&faultData);
306 EXPECT_CALL(*mockAppMgrService_, NotifyAppFault(_)).Times(1);
307 auto result = mockAppMgrService_->OnRemoteRequest(
308 static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT), data, reply, option);
309 EXPECT_EQ(result, NO_ERROR);
310 }
311
312 /**
313 * @tc.name: HandleNotifyFaultBySA_001
314 * @tc.desc: Handle notify fault by SA.
315 * @tc.type: FUNC
316 * @tc.require: issueI79RY8
317 */
318 HWTEST_F(AppMgrStubTest, HandleNotifyFaultBySA_001, TestSize.Level1)
319 {
320 MessageParcel data;
321 MessageParcel reply;
322 MessageOption option;
323 WriteInterfaceToken(data);
324 AppFaultDataBySA faultData;
325 faultData.errorObject.name = "testName";
326 faultData.errorObject.message = "testMessage";
327 faultData.errorObject.stack = "testStack";
328 faultData.faultType = FaultDataType::UNKNOWN;
329 faultData.pid = 24;
330 data.WriteParcelable(&faultData);
331 EXPECT_CALL(*mockAppMgrService_, NotifyAppFaultBySA(_)).Times(1);
332 auto result = mockAppMgrService_->OnRemoteRequest(
333 static_cast<uint32_t>(AppMgrInterfaceCode::NOTIFY_APP_FAULT_BY_SA), data, reply, option);
334 EXPECT_EQ(result, NO_ERROR);
335 }
336
337 /**
338 * @tc.name: HandleSetAppFreezeFilter_001
339 * @tc.desc: Handle Set AppFreeze Filter.
340 * @tc.type: FUNC
341 */
342 HWTEST_F(AppMgrStubTest, HandleSetAppFreezeFilter_001, TestSize.Level1)
343 {
344 MessageParcel data;
345 MessageParcel reply;
346 MessageOption option;
347 WriteInterfaceToken(data);
348 data.WriteInt32(0);
349 auto result = mockAppMgrService_->OnRemoteRequest(
350 static_cast<uint32_t>(AppMgrInterfaceCode::SET_APPFREEZE_FILTER), data, reply, option);
351 EXPECT_EQ(result, NO_ERROR);
352 }
353
354 /**
355 * @tc.name: HandleChangeAppGcState_001
356 * @tc.desc: Handle change app Gc state.
357 * @tc.type: FUNC
358 * @tc.require: issuesI85VVU
359 */
360 HWTEST_F(AppMgrStubTest, HandleChangeAppGcState_001, TestSize.Level1)
361 {
362 MessageParcel data;
363 MessageParcel reply;
364 MessageOption option;
365 WriteInterfaceToken(data);
366 data.WriteInt32(0);
367 data.WriteInt32(0);
368 auto result = mockAppMgrService_->OnRemoteRequest(
369 static_cast<uint32_t>(AppMgrInterfaceCode::CHANGE_APP_GC_STATE), data, reply, option);
370 EXPECT_EQ(result, NO_ERROR);
371 }
372
373 /**
374 * @tc.name: IsAppRunning_001
375 * @tc.desc: On remote request to query the running status of the application.
376 * @tc.type: FUNC
377 */
378 HWTEST_F(AppMgrStubTest, IsAppRunning_0100, TestSize.Level1)
379 {
380 MessageParcel data;
381 MessageParcel reply;
382 MessageOption option;
383
384 WriteInterfaceToken(data);
385 std::string bundleName = "testBundleName";
386 int32_t appCloneIndex = 0;
387 bool isRunning = false;
388 data.WriteString(bundleName);
389 data.WriteInt32(appCloneIndex);
390 data.WriteBool(isRunning);
391
392 EXPECT_CALL(*mockAppMgrService_, IsAppRunning(_, _, _)).Times(1);
393
394 auto result = mockAppMgrService_->OnRemoteRequest(
395 static_cast<uint32_t>(AppMgrInterfaceCode::IS_APP_RUNNING), data, reply, option);
396 EXPECT_EQ(result, NO_ERROR);
397 }
398
399 /**
400 * @tc.name: IsApplicationRunning_001
401 * @tc.desc: On remote request to query the running status of the application.
402 * @tc.type: FUNC
403 */
404 HWTEST_F(AppMgrStubTest, IsApplicationRunning_0100, TestSize.Level1)
405 {
406 MessageParcel data;
407 MessageParcel reply;
408 MessageOption option;
409
410 WriteInterfaceToken(data);
411 std::string bundleName = "testBundleName";
412 bool isRunning = false;
413 data.WriteString(bundleName);
414 data.WriteBool(isRunning);
415
416 EXPECT_CALL(*mockAppMgrService_, IsApplicationRunning(_, _)).Times(1);
417
418 auto result = mockAppMgrService_->OnRemoteRequest(
419 static_cast<uint32_t>(AppMgrInterfaceCode::IS_APPLICATION_RUNNING), data, reply, option);
420 EXPECT_EQ(result, NO_ERROR);
421 }
422
423 /**
424 * @tc.number: HandleRegisterAbilityForegroundStateObserver_0100
425 * @tc.desc: Verify it when write result success.
426 * @tc.type: FUNC
427 */
428 HWTEST_F(AppMgrStubTest, HandleRegisterAbilityForegroundStateObserver_0100, TestSize.Level1)
429 {
430 MessageParcel data;
431 MessageParcel reply;
432 mockAppMgrService_->HandleRegisterAbilityForegroundStateObserver(data, reply);
433 EXPECT_TRUE(mockAppMgrService_ != nullptr);
434 }
435
436 /**
437 * @tc.number: HandleUnregisterAbilityForegroundStateObserver_0100
438 * @tc.desc: Verify it when write result success.
439 * @tc.type: FUNC
440 */
441 HWTEST_F(AppMgrStubTest, HandleUnregisterAbilityForegroundStateObserver_0100, TestSize.Level1)
442 {
443 MessageParcel data;
444 MessageParcel reply;
445 auto result = mockAppMgrService_->HandleUnregisterAbilityForegroundStateObserver(data, reply);
446 EXPECT_EQ(result, NO_ERROR);
447 }
448
449 /**
450 * @tc.name: HandleRegisterAppForegroundStateObserver_0100
451 * @tc.desc: Test when callback is not nullptr the return of writeInt32 is true.
452 * @tc.type: FUNC
453 */
454 HWTEST_F(AppMgrStubTest, HandleRegisterAppForegroundStateObserver_0100, TestSize.Level1)
455 {
456 MessageParcel data;
457 MessageParcel reply;
458 sptr<IRemoteObject> object = new (std::nothrow) AppForegroundStateObserverMock();
459 data.WriteRemoteObject(object);
460 int32_t pid = 1;
461 reply.WriteInt32(pid);
462 auto res = mockAppMgrService_->HandleRegisterAppForegroundStateObserver(data, reply);
463 EXPECT_EQ(res, NO_ERROR);
464 }
465
466 /**
467 * @tc.name: HandleUnregisterAppForegroundStateObserver_0100
468 * @tc.desc: Test when callback is not nullptr the return of writeInt32 is true.
469 * @tc.type: FUNC
470 */
471 HWTEST_F(AppMgrStubTest, HandleUnregisterAppForegroundStateObserver_0100, TestSize.Level1)
472 {
473 MessageParcel data;
474 MessageParcel reply;
475 sptr<IRemoteObject> object = new (std::nothrow) AppForegroundStateObserverMock();
476 data.WriteRemoteObject(object);
477 int32_t pid = 1;
478 reply.WriteInt32(pid);
479 auto res = mockAppMgrService_->HandleUnregisterAppForegroundStateObserver(data, reply);
480 EXPECT_EQ(res, NO_ERROR);
481 }
482
483 /**
484 * @tc.name: HandleRegisterRenderStateObserver_0100
485 * @tc.desc: Test register observer success.
486 * @tc.type: FUNC
487 */
488 HWTEST_F(AppMgrStubTest, HandleRegisterRenderStateObserver_0100, TestSize.Level1)
489 {
490 MessageParcel data;
491 MessageParcel reply;
492 sptr<IRemoteObject> object = new (std::nothrow) RenderStateObserverMock();
493 data.WriteRemoteObject(object);
494 EXPECT_CALL(*mockAppMgrService_, RegisterRenderStateObserver(_)).Times(1);
495 auto res = mockAppMgrService_->HandleRegisterRenderStateObserver(data, reply);
496 EXPECT_EQ(res, NO_ERROR);
497 }
498
499 /**
500 * @tc.name: HandleUnregisterRenderStateObserver_0100
501 * @tc.desc: Test unregister observer success.
502 * @tc.type: FUNC
503 */
504 HWTEST_F(AppMgrStubTest, HandleUnregisterRenderStateObserver_0100, TestSize.Level1)
505 {
506 MessageParcel data;
507 MessageParcel reply;
508 sptr<IRemoteObject> object = new (std::nothrow) RenderStateObserverMock();
509 data.WriteRemoteObject(object);
510 EXPECT_CALL(*mockAppMgrService_, UnregisterRenderStateObserver(_)).Times(1);
511 auto res = mockAppMgrService_->HandleUnregisterRenderStateObserver(data, reply);
512 EXPECT_EQ(res, NO_ERROR);
513 }
514
515 /**
516 * @tc.name: HandleUpdateRenderState_0100
517 * @tc.desc: Test update render state success.
518 * @tc.type: FUNC
519 */
520 HWTEST_F(AppMgrStubTest, HandleUpdateRenderState_0100, TestSize.Level1)
521 {
522 MessageParcel data;
523 MessageParcel reply;
524 pid_t renderPid = 0;
525 data.WriteInt32(renderPid);
526 int32_t state = 0;
527 data.WriteInt32(state);
528 EXPECT_CALL(*mockAppMgrService_, UpdateRenderState(_, _)).Times(1);
529 auto res = mockAppMgrService_->HandleUpdateRenderState(data, reply);
530 EXPECT_EQ(res, NO_ERROR);
531 }
532
533 /**
534 * @tc.name: HandleSignRestartAppFlag_0100
535 * @tc.desc: Test sign restart app flag success.
536 * @tc.type: FUNC
537 */
538 HWTEST_F(AppMgrStubTest, HandleSignRestartAppFlag_0100, TestSize.Level1)
539 {
540 MessageParcel data;
541 MessageParcel reply;
542 int32_t uid = 0;
543 data.WriteInt32(uid);
544 auto res = mockAppMgrService_->HandleSignRestartAppFlag(data, reply);
545 EXPECT_EQ(res, NO_ERROR);
546 }
547
548 /**
549 * @tc.name: HandleNotifyMemorySizeStateChanged_0100
550 * @tc.desc: Test notify memory size state changed.
551 * @tc.type: FUNC
552 */
553 HWTEST_F(AppMgrStubTest, HandleNotifyMemorySizeStateChanged_0100, TestSize.Level1)
554 {
555 MessageParcel data;
556 MessageParcel reply;
557 data.WriteBool(true);
558 auto res = mockAppMgrService_->HandleNotifyMemorySizeStateChanged(data, reply);
559 EXPECT_EQ(res, NO_ERROR);
560 }
561
562 /**
563 * @tc.name: HandleNotifyMemorySizeStateChanged_0200
564 * @tc.desc: Test notify memory size state changed.
565 * @tc.type: FUNC
566 */
567 HWTEST_F(AppMgrStubTest, HandleNotifyMemorySizeStateChanged_0200, TestSize.Level1)
568 {
569 MessageParcel data;
570 MessageParcel reply;
571 data.WriteBool(false);
572 auto res = mockAppMgrService_->HandleNotifyMemorySizeStateChanged(data, reply);
573 EXPECT_EQ(res, NO_ERROR);
574 }
575
576 /**
577 * @tc.name: HandleGetAllUIExtensionRootHostPid_0100
578 * @tc.desc: Get all ui extension root host pid.
579 * @tc.type: FUNC
580 */
581 HWTEST_F(AppMgrStubTest, HandleGetAllUIExtensionRootHostPid_0100, TestSize.Level1)
582 {
583 MessageParcel data;
584 MessageParcel reply;
585 pid_t pid = 1;
586 data.WriteInt32(pid);
587 auto res = mockAppMgrService_->HandleGetAllUIExtensionRootHostPid(data, reply);
588 EXPECT_EQ(res, NO_ERROR);
589 int32_t size = reply.ReadInt32();
590 EXPECT_EQ(size, 0);
591 }
592
593 /**
594 * @tc.name: HandleGetAllUIExtensionProviderPid_0100
595 * @tc.desc: Get all ui extension root host pid.
596 * @tc.type: FUNC
597 */
598 HWTEST_F(AppMgrStubTest, HandleGetAllUIExtensionProviderPid_0100, TestSize.Level1)
599 {
600 MessageParcel data;
601 MessageParcel reply;
602 pid_t hostPid = 1;
603 data.WriteInt32(hostPid);
604 auto res = mockAppMgrService_->HandleGetAllUIExtensionProviderPid(data, reply);
605 EXPECT_EQ(res, NO_ERROR);
606 int32_t size = reply.ReadInt32();
607 EXPECT_EQ(size, 0);
608 }
609
610 /**
611 * @tc.name: PreloadApplication_0100
612 * @tc.desc: Preload application.
613 * @tc.type: FUNC
614 */
615 HWTEST_F(AppMgrStubTest, PreloadApplication_0100, TestSize.Level1)
616 {
617 MessageParcel data;
618 MessageParcel reply;
619 MessageOption option;
620
621 WriteInterfaceToken(data);
622 std::string bundleName = "com.acts.preloadtest";
623 int32_t userId = 100;
624 PreloadMode preloadMode = PreloadMode::PRE_MAKE;
625 int32_t appIndex = 0;
626
627 data.WriteString16(Str8ToStr16(bundleName));
628 data.WriteInt32(userId);
629 data.WriteInt32(static_cast<int32_t>(preloadMode));
630 data.WriteInt32(appIndex);
631
632 auto result = mockAppMgrService_->OnRemoteRequest(
633 static_cast<uint32_t>(AppMgrInterfaceCode::PRELOAD_APPLICATION), data, reply, option);
634 EXPECT_EQ(result, NO_ERROR);
635 }
636
637 /**
638 * @tc.name: SetSupportedProcessCacheSelf_001
639 * @tc.desc: The application sets itself whether or not to support process cache.
640 * @tc.type: FUNC
641 */
642 HWTEST_F(AppMgrStubTest, SetSupportedProcessCacheSelf_001, TestSize.Level0)
643 {
644 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
645 MessageParcel data;
646 MessageParcel reply;
647 MessageOption option;
648
649 WriteInterfaceToken(data);
650 bool isSupported = false;
651 data.WriteBool(isSupported);
652
653 EXPECT_CALL(*mockAppMgrService_, SetSupportedProcessCacheSelf(_)).Times(1);
654
655 auto result = mockAppMgrService_->OnRemoteRequest(
656 static_cast<uint32_t>(AppMgrInterfaceCode::SET_SUPPORTED_PROCESS_CACHE_SELF), data, reply, option);
657 EXPECT_EQ(result, NO_ERROR);
658
659 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
660 }
661
662 /**
663 * @tc.name: GetRunningMultiAppInfoByBundleName_001
664 * @tc.desc: Get multiapp information by bundleName.
665 * @tc.type: FUNC
666 * @tc.require: issueI9HMAO
667 */
668 HWTEST_F(AppMgrStubTest, GetRunningMultiAppInfoByBundleName_001, TestSize.Level1)
669 {
670 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
671 MessageParcel data;
672 MessageParcel reply;
673 MessageOption option;
674
675 WriteInterfaceToken(data);
676 std::string bundleName = "testBundleName";
677 data.WriteString(bundleName);
678
679 EXPECT_CALL(*mockAppMgrService_, GetRunningMultiAppInfoByBundleName(_, _)).Times(1);
680
681 auto result = mockAppMgrService_->OnRemoteRequest(
682 static_cast<uint32_t>(AppMgrInterfaceCode::GET_RUNNING_MULTIAPP_INFO_BY_BUNDLENAME), data, reply, option);
683 EXPECT_EQ(result, NO_ERROR);
684
685 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
686 }
687
688 /**
689 * @tc.name: GetSupportedProcessCachePids_001
690 * @tc.desc: Get pids of processes which belong to specific bundle name and support process cache feature.
691 * @tc.type: FUNC
692 * @tc.require: issueIAGZ7H
693 */
694 HWTEST_F(AppMgrStubTest, GetSupportedProcessCachePids_001, TestSize.Level0)
695 {
696 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
697 MessageParcel data;
698 MessageParcel reply;
699 MessageOption option;
700
701 WriteInterfaceToken(data);
702 std::string bundleName = "testBundleName";
703 data.WriteString(bundleName);
704
705 EXPECT_CALL(*mockAppMgrService_, GetSupportedProcessCachePids(_, _)).Times(1);
706
707 auto result = mockAppMgrService_->OnRemoteRequest(
708 static_cast<uint32_t>(AppMgrInterfaceCode::GET_SUPPORTED_PROCESS_CACHE_PIDS), data, reply, option);
709 EXPECT_EQ(result, NO_ERROR);
710
711 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
712 }
713
714 /**
715 * @tc.name: GetAllRunningInstanceKeysBySelf_001
716 * @tc.desc: GetAllRunningInstanceKeysBySelf.
717 * @tc.type: FUNC
718 * @tc.require: issueI9HMAO
719 */
720 HWTEST_F(AppMgrStubTest, GetAllRunningInstanceKeysBySelf_001, TestSize.Level1)
721 {
722 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
723 MessageParcel data;
724 MessageParcel reply;
725 MessageOption option;
726
727 WriteInterfaceToken(data);
728
729 EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysBySelf(_)).Times(1);
730
731 auto result = mockAppMgrService_->OnRemoteRequest(
732 static_cast<uint32_t>(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_SELF), data, reply, option);
733 EXPECT_EQ(result, NO_ERROR);
734
735 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
736 }
737
738 /**
739 * @tc.name: GetAllRunningInstanceKeysByBundleName_001
740 * @tc.desc: GetAllRunningInstanceKeysByBundleName.
741 * @tc.type: FUNC
742 * @tc.require: issueI9HMAO
743 */
744 HWTEST_F(AppMgrStubTest, GetAllRunningInstanceKeysByBundleName_001, TestSize.Level1)
745 {
746 TAG_LOGI(AAFwkTag::TEST, "%{public}s start.", __func__);
747 MessageParcel data;
748 MessageParcel reply;
749 MessageOption option;
750
751 WriteInterfaceToken(data);
752 std::string bundleName = "testBundleName";
753 data.WriteString(bundleName);
754 int32_t userId = -1;
755 data.WriteInt32(userId);
756
757 EXPECT_CALL(*mockAppMgrService_, GetAllRunningInstanceKeysByBundleName(_, _, _)).Times(1);
758
759 auto result = mockAppMgrService_->OnRemoteRequest(
760 static_cast<uint32_t>(AppMgrInterfaceCode::GET_All_RUNNING_INSTANCE_KEYS_BY_BUNDLENAME), data, reply, option);
761 EXPECT_EQ(result, NO_ERROR);
762
763 TAG_LOGI(AAFwkTag::TEST, "%{public}s end.", __func__);
764 }
765 } // namespace AppExecFwk
766 } // namespace OHOS
767