• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include <string>
18 #include <system_ability_definition.h>
19 #include <vector>
20 
21 #include "application_manager_proxy.h"
22 #include "edm_sys_manager_mock.h"
23 #include "enterprise_device_mgr_stub_mock.h"
24 #include "utils.h"
25 
26 using namespace testing::ext;
27 using namespace testing;
28 
29 namespace OHOS {
30 namespace EDM {
31 namespace TEST {
32 const std::string ADMIN_PACKAGENAME = "com.edm.test.demo";
33 class ApplicationManagerProxyTest : public testing::Test {
34 protected:
35     void SetUp() override;
36 
37     void TearDown() override;
38 
39     static void TearDownTestSuite(void);
40     std::shared_ptr<ApplicationManagerProxy> applicationManagerProxy_ = nullptr;
41     std::shared_ptr<EdmSysManager> edmSysManager_ = nullptr;
42     sptr<EnterpriseDeviceMgrStubMock> object_ = nullptr;
43 };
44 
SetUp()45 void ApplicationManagerProxyTest::SetUp()
46 {
47     applicationManagerProxy_ = ApplicationManagerProxy::GetApplicationManagerProxy();
48     edmSysManager_ = std::make_shared<EdmSysManager>();
49     object_ = new (std::nothrow) EnterpriseDeviceMgrStubMock();
50     edmSysManager_->RegisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID, object_);
51     Utils::SetEdmServiceEnable();
52 }
53 
TearDown()54 void ApplicationManagerProxyTest::TearDown()
55 {
56     applicationManagerProxy_.reset();
57     edmSysManager_->UnregisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID);
58     object_ = nullptr;
59     Utils::SetEdmServiceDisable();
60 }
61 
TearDownTestSuite()62 void ApplicationManagerProxyTest::TearDownTestSuite()
63 {
64     ASSERT_FALSE(Utils::GetEdmServiceState());
65     std::cout << "EdmServiceState : " << Utils::GetEdmServiceState() << std::endl;
66 }
67 
68 /**
69  * @tc.name: TestAddDisallowedRunningBundlesSuc
70  * @tc.desc: Test AddDisallowedRunningBundles success func.
71  * @tc.type: FUNC
72  */
73 HWTEST_F(ApplicationManagerProxyTest, AddDisallowedRunningBundlesSuc, TestSize.Level1)
74 {
75     OHOS::AppExecFwk::ElementName admin;
76     std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
77     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
78         .Times(1)
79         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
80     ErrCode ret = applicationManagerProxy_->AddDisallowedRunningBundles(admin, bundles, DEFAULT_USER_ID);
81     ASSERT_TRUE(ret == ERR_OK);
82 }
83 
84 /**
85  * @tc.name: TestAddDisallowedRunningBundlesFail
86  * @tc.desc: Test AddDisallowedRunningBundles without enable edm service func.
87  * @tc.type: FUNC
88  */
89 HWTEST_F(ApplicationManagerProxyTest, AddDisallowedRunningBundles, TestSize.Level1)
90 {
91     Utils::SetEdmServiceDisable();
92     OHOS::AppExecFwk::ElementName admin;
93     std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
94     ErrCode ret = applicationManagerProxy_->AddDisallowedRunningBundles(admin, bundles, DEFAULT_USER_ID);
95     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
96 }
97 
98 /**
99  * @tc.name: TestRemoveDisallowedRunningBundlesSuc
100  * @tc.desc: Test RemoveDisallowedRunningBundles success func.
101  * @tc.type: FUNC
102  */
103 HWTEST_F(ApplicationManagerProxyTest, RemoveDisallowedRunningBundlesSuc, TestSize.Level1)
104 {
105     OHOS::AppExecFwk::ElementName admin;
106     std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
107     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
108         .Times(1)
109         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
110     ErrCode ret = applicationManagerProxy_->RemoveDisallowedRunningBundles(admin, bundles, DEFAULT_USER_ID);
111     ASSERT_TRUE(ret == ERR_OK);
112 }
113 
114 /**
115  * @tc.name: TestRemoveDisallowedRunningBundlesFail
116  * @tc.desc: Test RemoveDisallowedRunningBundles without enable edm service func.
117  * @tc.type: FUNC
118  */
119 HWTEST_F(ApplicationManagerProxyTest, RemoveDisallowedRunningBundlesFail, TestSize.Level1)
120 {
121     Utils::SetEdmServiceDisable();
122     OHOS::AppExecFwk::ElementName admin;
123     std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
124     ErrCode ret = applicationManagerProxy_->RemoveDisallowedRunningBundles(admin, bundles, DEFAULT_USER_ID);
125     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
126 }
127 
128 /**
129  * @tc.name: TestGetDisallowedRunningBundlesSuc
130  * @tc.desc: Test GetDisallowedRunningBundles success func.
131  * @tc.type: FUNC
132  */
133 HWTEST_F(ApplicationManagerProxyTest, GetDisallowedRunningBundlesSuc, TestSize.Level1)
134 {
135     OHOS::AppExecFwk::ElementName admin;
136     std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
137     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
138         .Times(1)
139         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
140     ErrCode ret = applicationManagerProxy_->GetDisallowedRunningBundles(admin, DEFAULT_USER_ID, bundles);
141     ASSERT_TRUE(ret == ERR_OK);
142     ASSERT_TRUE(bundles.size() == 1);
143     ASSERT_TRUE(bundles[0] == RETURN_STRING);
144 }
145 
146 /**
147  * @tc.name: TestGetDisallowedRunningBundlesFail
148  * @tc.desc: Test GetDisallowedRunningBundles without enable edm service func.
149  * @tc.type: FUNC
150  */
151 HWTEST_F(ApplicationManagerProxyTest, GetDisallowedRunningBundlesFail, TestSize.Level1)
152 {
153     Utils::SetEdmServiceDisable();
154     OHOS::AppExecFwk::ElementName admin;
155     std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
156     ErrCode ret = applicationManagerProxy_->GetDisallowedRunningBundles(admin, DEFAULT_USER_ID, bundles);
157     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
158 }
159 
160 /**
161  * @tc.name: TestAddAutoStartAppsFail
162  * @tc.desc: Test AddAutoStartApps without enable edm service func.
163  * @tc.type: FUNC
164  */
165 HWTEST_F(ApplicationManagerProxyTest, TestAddAutoStartAppsFail, TestSize.Level1)
166 {
167     Utils::SetEdmServiceDisable();
168     MessageParcel data;
169     OHOS::AppExecFwk::ElementName admin;
170     std::vector<std::string> apps;
171     data.WriteParcelable(&admin);
172     data.WriteStringVector(apps);
173 
174     ErrCode ret = applicationManagerProxy_->AddOrRemoveAutoStartApps(data, true);
175     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
176 }
177 
178 /**
179  * @tc.name: TestAddAutoStartAppsSuc
180  * @tc.desc: Test AddAutoStartApps success func.
181  * @tc.type: FUNC
182  */
183 HWTEST_F(ApplicationManagerProxyTest, AddAutoStartAppsSuc, TestSize.Level1)
184 {
185     MessageParcel data;
186     OHOS::AppExecFwk::ElementName admin;
187     std::vector<std::string> apps;
188     data.WriteParcelable(&admin);
189     data.WriteStringVector(apps);
190 
191     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
192         .Times(1)
193         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
194     ErrCode ret = applicationManagerProxy_->AddOrRemoveAutoStartApps(data, true);
195     ASSERT_TRUE(ret == ERR_OK);
196 }
197 
198 /**
199  * @tc.name: TestRemoveAutoStartAppsFail
200  * @tc.desc: Test RemoveAutoStartApps without enable edm service func.
201  * @tc.type: FUNC
202  */
203 HWTEST_F(ApplicationManagerProxyTest, TestRemoveAutoStartAppsFail, TestSize.Level1)
204 {
205     Utils::SetEdmServiceDisable();
206     MessageParcel data;
207     OHOS::AppExecFwk::ElementName admin;
208     std::vector<std::string> apps;
209     data.WriteParcelable(&admin);
210     data.WriteStringVector(apps);
211 
212     ErrCode ret = applicationManagerProxy_->AddOrRemoveAutoStartApps(data, false);
213     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
214 }
215 
216 /**
217  * @tc.name: TestRemoveAutoStartAppsSuc
218  * @tc.desc: Test RemoveAutoStartApps success func.
219  * @tc.type: FUNC
220  */
221 HWTEST_F(ApplicationManagerProxyTest, TestRemoveAutoStartAppsSuc, TestSize.Level1)
222 {
223     MessageParcel data;
224     OHOS::AppExecFwk::ElementName admin;
225     std::vector<std::string> apps;
226     data.WriteParcelable(&admin);
227     data.WriteStringVector(apps);
228 
229     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
230         .Times(1)
231         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
232     ErrCode ret = applicationManagerProxy_->AddOrRemoveAutoStartApps(data, false);
233     ASSERT_TRUE(ret == ERR_OK);
234 }
235 
236 /**
237  * @tc.name: TestGetAutoStartAppsSuc
238  * @tc.desc: Test GetAutoStartApps success func.
239  * @tc.type: FUNC
240  */
241 HWTEST_F(ApplicationManagerProxyTest, TestGetAutoStartAppsSuc, TestSize.Level1)
242 {
243     MessageParcel data;
244     std::vector<OHOS::AppExecFwk::ElementName> apps;
245     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
246         .Times(1)
247         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayElementSendRequestGetPolicy));
248     ErrCode ret = applicationManagerProxy_->GetAutoStartApps(data, apps);
249     ASSERT_TRUE(ret == ERR_OK);
250     ASSERT_TRUE(apps.size() == 1);
251 }
252 
253 /**
254  * @tc.name: TestGetAutoStartAppsFail
255  * @tc.desc: Test GetAutoStartApps without enable edm service func.
256  * @tc.type: FUNC
257  */
258 HWTEST_F(ApplicationManagerProxyTest, TestGetAutoStartAppsFail, TestSize.Level1)
259 {
260     Utils::SetEdmServiceDisable();
261     MessageParcel data;
262     std::vector<OHOS::AppExecFwk::ElementName> apps;
263     ErrCode ret = applicationManagerProxy_->GetAutoStartApps(data, apps);
264     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
265 }
266 
267 /**
268  * @tc.name: TestAddKeepAliveAppsFail
269  * @tc.desc: Test AddKeepAliveApps without enable edm service func.
270  * @tc.type: FUNC
271  */
272 HWTEST_F(ApplicationManagerProxyTest, TestAddKeepAliveAppsFail, TestSize.Level1)
273 {
274     Utils::SetEdmServiceDisable();
275     OHOS::AppExecFwk::ElementName admin;
276     std::vector<std::string> keepAliveApps;
277     std::string retMessage;
278     bool disallowModify = true;
279     ErrCode ret = applicationManagerProxy_->AddKeepAliveApps(admin, keepAliveApps, disallowModify,
280         DEFAULT_USER_ID, retMessage);
281     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
282 }
283 
284 /**
285  * @tc.name: TestAddKeepAliveAppsSuc
286  * @tc.desc: Test AddKeepAliveApps success func.
287  * @tc.type: FUNC
288  */
289 HWTEST_F(ApplicationManagerProxyTest, TestAddKeepAliveAppsSuc, TestSize.Level1)
290 {
291     OHOS::AppExecFwk::ElementName admin;
292     std::vector<std::string> keepAliveApps;
293     std::string retMessage;
294     bool disallowModify = true;
295     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
296         .Times(1)
297         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
298     ErrCode ret = applicationManagerProxy_->AddKeepAliveApps(admin, keepAliveApps,
299         disallowModify, DEFAULT_USER_ID, retMessage);
300     ASSERT_TRUE(ret == ERR_OK);
301 }
302 
303 /**
304  * @tc.name: TestRemoveKeepAliveAppsFail
305  * @tc.desc: Test RemoveKeepAliveApps without enable edm service func.
306  * @tc.type: FUNC
307  */
308 HWTEST_F(ApplicationManagerProxyTest, TestRemoveKeepAliveAppsFail, TestSize.Level1)
309 {
310     Utils::SetEdmServiceDisable();
311     OHOS::AppExecFwk::ElementName admin;
312     std::vector<std::string> keepAliveApps;
313     ErrCode ret = applicationManagerProxy_->RemoveKeepAliveApps(admin, keepAliveApps, DEFAULT_USER_ID);
314     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
315 }
316 
317 /**
318  * @tc.name: TestRemoveKeepAliveAppsSuc
319  * @tc.desc: Test RemoveKeepAliveApps success func.
320  * @tc.type: FUNC
321  */
322 HWTEST_F(ApplicationManagerProxyTest, TestRemoveKeepAliveAppsSuc, TestSize.Level1)
323 {
324     OHOS::AppExecFwk::ElementName admin;
325     std::vector<std::string> keepAliveApps;
326     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
327         .Times(1)
328         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
329     ErrCode ret = applicationManagerProxy_->RemoveKeepAliveApps(admin, keepAliveApps, DEFAULT_USER_ID);
330     ASSERT_TRUE(ret == ERR_OK);
331 }
332 
333 /**
334  * @tc.name: TestGetKeepAliveAppsFail
335  * @tc.desc: Test GetKeepAliveApps without enable edm service func.
336  * @tc.type: FUNC
337  */
338 HWTEST_F(ApplicationManagerProxyTest, TestGetKeepAliveAppsFail, TestSize.Level1)
339 {
340     Utils::SetEdmServiceDisable();
341     OHOS::AppExecFwk::ElementName admin;
342     std::vector<std::string> keepAliveApps;
343     ErrCode ret = applicationManagerProxy_->GetKeepAliveApps(admin, keepAliveApps, DEFAULT_USER_ID);
344     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
345 }
346 
347 /**
348  * @tc.name: TestGetKeepAliveAppsSuc
349  * @tc.desc: Test GetKeepAliveApps success func.
350  * @tc.type: FUNC
351  */
352 HWTEST_F(ApplicationManagerProxyTest, TestGetKeepAliveAppsSuc, TestSize.Level1)
353 {
354     OHOS::AppExecFwk::ElementName admin;
355     std::vector<std::string> keepAliveApps;
356     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
357         .Times(1)
358         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
359     ErrCode ret = applicationManagerProxy_->GetKeepAliveApps(admin, keepAliveApps, DEFAULT_USER_ID);
360     ASSERT_TRUE(ret == ERR_OK);
361     ASSERT_TRUE(keepAliveApps.size() == 1);
362 }
363 
364 /**
365  * @tc.name: TestSetKioskFeaturesFail
366  * @tc.desc: Test SetKioskFeatures without enable edm service func.
367  * @tc.type: FUNC
368  */
369 HWTEST_F(ApplicationManagerProxyTest, TestSetKioskFeaturesFail, TestSize.Level1)
370 {
371     Utils::SetEdmServiceDisable();
372     MessageParcel data;
373     OHOS::AppExecFwk::ElementName admin;
374     std::vector<int32_t> apps;
375     data.WriteParcelable(&admin);
376     data.WriteInt32Vector(apps);
377 
378     ErrCode ret = applicationManagerProxy_->SetKioskFeatures(data);
379     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
380 }
381 
382 /**
383  * @tc.name: TestSetKioskFeaturesSuc
384  * @tc.desc: Test SetKioskFeatures success func.
385  * @tc.type: FUNC
386  */
387 HWTEST_F(ApplicationManagerProxyTest, TestSetKioskFeaturesSuc, TestSize.Level1)
388 {
389     MessageParcel data;
390     OHOS::AppExecFwk::ElementName admin;
391     std::vector<int32_t> apps;
392     data.WriteParcelable(&admin);
393     data.WriteInt32Vector(apps);
394 
395     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
396         .Times(1)
397         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
398     ErrCode ret = applicationManagerProxy_->SetKioskFeatures(data);
399     ASSERT_TRUE(ret == ERR_OK);
400 }
401 
402 /**
403  * @tc.name: TestSetAllowedKioskAppsFail
404  * @tc.desc: Test SetAllowedKioskApps without enable edm service func.
405  * @tc.type: FUNC
406  */
407 HWTEST_F(ApplicationManagerProxyTest, TestSetAllowedKioskAppsFail, TestSize.Level1)
408 {
409     Utils::SetEdmServiceDisable();
410     OHOS::AppExecFwk::ElementName admin;
411     admin.SetBundleName(ADMIN_PACKAGENAME);
412     std::vector<std::string> bundleNames;
413     int32_t ret = applicationManagerProxy_->SetAllowedKioskApps(admin, bundleNames);
414     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
415 }
416 
417 /**
418  * @tc.name: TestSetAllowedKioskAppsSuc
419  * @tc.desc: Test SetAllowedKioskApps success func.
420  * @tc.type: FUNC
421  */
422 HWTEST_F(ApplicationManagerProxyTest, TestSetAllowedKioskAppsSuc, TestSize.Level1)
423 {
424     OHOS::AppExecFwk::ElementName admin;
425     admin.SetBundleName(ADMIN_PACKAGENAME);
426     std::vector<std::string> bundleNames;
427     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
428         .Times(1)
429         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
430     int32_t ret = applicationManagerProxy_->SetAllowedKioskApps(admin, bundleNames);
431     ASSERT_TRUE(ret == ERR_OK);
432 }
433 
434 /**
435  * @tc.name: TestGetAllowedKioskAppsFail
436  * @tc.desc: Test GetAllowedKioskApps without enable edm service func.
437  * @tc.type: FUNC
438  */
439 HWTEST_F(ApplicationManagerProxyTest, TestGetAllowedKioskAppsFail, TestSize.Level1)
440 {
441     Utils::SetEdmServiceDisable();
442     OHOS::AppExecFwk::ElementName admin;
443     admin.SetBundleName(ADMIN_PACKAGENAME);
444     std::vector<std::string> bundleNames;
445     int32_t ret = applicationManagerProxy_->GetAllowedKioskApps(admin, bundleNames);
446     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
447 }
448 
449 /**
450  * @tc.name: TestGetAllowedKioskAppsSuc
451  * @tc.desc: Test GetAllowedKioskApps success func.
452  * @tc.type: FUNC
453  */
454 HWTEST_F(ApplicationManagerProxyTest, TestGetAllowedKioskAppsSuc, TestSize.Level1)
455 {
456     OHOS::AppExecFwk::ElementName admin;
457     admin.SetBundleName(ADMIN_PACKAGENAME);
458     std::vector<std::string> bundleNames;
459     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
460         .Times(1)
461         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
462     int32_t ret = applicationManagerProxy_->GetAllowedKioskApps(admin, bundleNames);
463     ASSERT_TRUE(ret == ERR_OK);
464 }
465 
466 /**
467  * @tc.name: TestIsAppKioskAllowedFail
468  * @tc.desc: Test IsAppKioskAllowed without enable edm service func.
469  * @tc.type: FUNC
470  */
471 HWTEST_F(ApplicationManagerProxyTest, TestIsAppKioskAllowedFail, TestSize.Level1)
472 {
473     Utils::SetEdmServiceDisable();
474     std::string bundleName;
475     bool isAllowed = false;
476     int32_t ret = applicationManagerProxy_->IsAppKioskAllowed(bundleName, isAllowed);
477     ASSERT_TRUE(ret == ERR_OK);
478     ASSERT_TRUE(!isAllowed);
479 }
480 
481 /**
482  * @tc.name: TestIsAppKioskAllowedSuc
483  * @tc.desc: Test IsAppKioskAllowed success func.
484  * @tc.type: FUNC
485  */
486 HWTEST_F(ApplicationManagerProxyTest, TestIsAppKioskAllowedSuc, TestSize.Level1)
487 {
488     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
489         .Times(1)
490         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
491     std::string bundleName;
492     bool isAllowed = false;
493     int32_t ret = applicationManagerProxy_->IsAppKioskAllowed(bundleName, isAllowed);
494     ASSERT_TRUE(ret == ERR_OK);
495 }
496 
497 /**
498  * @tc.name: TestClearUpApplicationDataFail
499  * @tc.desc: Test ClearUpApplicationData without enable edm service func.
500  * @tc.type: FUNC
501  */
502 HWTEST_F(ApplicationManagerProxyTest, TestClearUpApplicationDataFail, TestSize.Level1)
503 {
504     Utils::SetEdmServiceDisable();
505     OHOS::AppExecFwk::ElementName admin;
506     admin.SetBundleName(ADMIN_PACKAGENAME);
507     ClearUpApplicationDataParam param { ADMIN_PACKAGENAME, 0, 0 };
508     int32_t ret = applicationManagerProxy_->ClearUpApplicationData(admin, param);
509     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
510 }
511 
512 /**
513  * @tc.name: TestClearUpApplicationDataSuc
514  * @tc.desc: Test ClearUpApplicationData success func.
515  * @tc.type: FUNC
516  */
517 HWTEST_F(ApplicationManagerProxyTest, TestClearUpApplicationDataSuc, TestSize.Level1)
518 {
519     OHOS::AppExecFwk::ElementName admin;
520     admin.SetBundleName(ADMIN_PACKAGENAME);
521     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
522         .Times(1)
523         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
524     ClearUpApplicationDataParam param { ADMIN_PACKAGENAME, 0, 0 };
525     int32_t ret = applicationManagerProxy_->ClearUpApplicationData(admin, param);
526     ASSERT_TRUE(ret == ERR_OK);
527 }
528 
529 /**
530  * @tc.name: TestAddKeepAliveAppsWithDisallowModifyFail
531  * @tc.desc: Test AddKeepAliveAppsWithDisallowModify without enable edm service func.
532  * @tc.type: FUNC
533  */
534 HWTEST_F(ApplicationManagerProxyTest, TestAddKeepAliveAppsWithDisallowModifyFail, TestSize.Level1)
535 {
536     Utils::SetEdmServiceDisable();
537     OHOS::AppExecFwk::ElementName admin;
538     std::vector<std::string> keepAliveApps;
539     bool disallowModify = false;
540     std::string retMessage;
541     ErrCode ret = applicationManagerProxy_->AddKeepAliveApps(admin, keepAliveApps, disallowModify,
542         DEFAULT_USER_ID, retMessage);
543     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
544 }
545 
546 /**
547  * @tc.name: TestAddKeepAliveAppsWithDisallowModifySuc
548  * @tc.desc: Test AddKeepAliveAppsWithDisallowModify success func.
549  * @tc.type: FUNC
550  */
551 HWTEST_F(ApplicationManagerProxyTest, TestAddKeepAliveAppsWithDisallowModifySuc, TestSize.Level1)
552 {
553     OHOS::AppExecFwk::ElementName admin;
554     std::vector<std::string> keepAliveApps;
555     bool disallowModify = false;
556     std::string retMessage;
557     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
558         .Times(1)
559         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
560     ErrCode ret = applicationManagerProxy_->AddKeepAliveApps(admin, keepAliveApps, disallowModify,
561         DEFAULT_USER_ID, retMessage);
562     ASSERT_TRUE(ret == ERR_OK);
563 }
564 
565 /**
566  * @tc.name: TestGetKeepAliveAppDisallowModifyFail
567  * @tc.desc: Test GetKeepAliveAppDisallowModify without enable edm service func.
568  * @tc.type: FUNC
569  */
570 HWTEST_F(ApplicationManagerProxyTest, TestGetKeepAliveAppDisallowModifyFail, TestSize.Level1)
571 {
572     Utils::SetEdmServiceDisable();
573     OHOS::AppExecFwk::ElementName admin;
574     std::string keepAliveApp;
575     bool disallowModify;
576     ErrCode ret = applicationManagerProxy_->IsModifyKeepAliveAppsDisallowed(admin, keepAliveApp,
577         DEFAULT_USER_ID, disallowModify);
578     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
579 }
580 
581 /**
582  * @tc.name: TestGetKeepAliveAppDisallowModifySuc
583  * @tc.desc: Test GetKeepAliveAppDisallowModify success func.
584  * @tc.type: FUNC
585  */
586 HWTEST_F(ApplicationManagerProxyTest, TestGetKeepAliveAppDisallowModifySuc, TestSize.Level1)
587 {
588     OHOS::AppExecFwk::ElementName admin;
589     std::string keepAliveApp;
590     bool disallowModify;
591     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
592         .Times(1)
593         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
594     ErrCode ret = applicationManagerProxy_->IsModifyKeepAliveAppsDisallowed(admin, keepAliveApp,
595         DEFAULT_USER_ID, disallowModify);
596     ASSERT_TRUE(ret == ERR_OK);
597     ASSERT_TRUE(disallowModify);
598 }
599 
600 /**
601  * @tc.name: TestAddAutoStartAppsWithDisallowModifyFail
602  * @tc.desc: Test AddAutoStartAppsWithDisallowModify without enable edm service func.
603  * @tc.type: FUNC
604  */
605 HWTEST_F(ApplicationManagerProxyTest, TestAddAutoStartAppsWithDisallowModifyFail, TestSize.Level1)
606 {
607     Utils::SetEdmServiceDisable();
608     MessageParcel data;
609     OHOS::AppExecFwk::ElementName admin;
610     std::vector<std::string> apps;
611     bool disallowModify = false;
612     data.WriteParcelable(&admin);
613     data.WriteStringVector(apps);
614     data.WriteBool(disallowModify);
615 
616     ErrCode ret = applicationManagerProxy_->AddOrRemoveAutoStartApps(data, true);
617     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
618 }
619 
620 /**
621  * @tc.name: TestAddAutoStartAppsWithDisallowModifySuc
622  * @tc.desc: Test AddAutoStartAppsWithDisallowModify success func.
623  * @tc.type: FUNC
624  */
625 HWTEST_F(ApplicationManagerProxyTest, TestAddAutoStartAppsWithDisallowModifySuc, TestSize.Level1)
626 {
627     MessageParcel data;
628     OHOS::AppExecFwk::ElementName admin;
629     std::vector<std::string> apps;
630     bool disallowModify = false;
631     data.WriteParcelable(&admin);
632     data.WriteStringVector(apps);
633     data.WriteBool(disallowModify);
634 
635     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
636         .Times(1)
637         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
638     ErrCode ret = applicationManagerProxy_->AddOrRemoveAutoStartApps(data, true);
639     ASSERT_TRUE(ret == ERR_OK);
640 }
641 
642 /**
643  * @tc.name: TestRemoveAutoStartAppsWithUserIdFail
644  * @tc.desc: Test RemoveAutoStartAppsWithUserId without enable edm service func.
645  * @tc.type: FUNC
646  */
647 HWTEST_F(ApplicationManagerProxyTest, TestRemoveAutoStartAppsWithUserIdFail, TestSize.Level1)
648 {
649     Utils::SetEdmServiceDisable();
650     MessageParcel data;
651     OHOS::AppExecFwk::ElementName admin;
652     std::vector<std::string> apps;
653     int32_t userId = 1;
654     data.WriteParcelable(&admin);
655     data.WriteStringVector(apps);
656     data.WriteInt32(userId);
657 
658     ErrCode ret = applicationManagerProxy_->AddOrRemoveAutoStartApps(data, false);
659     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
660 }
661 
662 /**
663  * @tc.name: TestRemoveAutoStartAppsWithUserIdSuc
664  * @tc.desc: Test RemoveAutoStartAppsWithUserId success func.
665  * @tc.type: FUNC
666  */
667 HWTEST_F(ApplicationManagerProxyTest, TestRemoveAutoStartAppsWithUserIdSuc, TestSize.Level1)
668 {
669     MessageParcel data;
670     OHOS::AppExecFwk::ElementName admin;
671     std::vector<std::string> apps;
672     int32_t userId = 1;
673     data.WriteParcelable(&admin);
674     data.WriteStringVector(apps);
675     data.WriteInt32(userId);
676 
677     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
678         .Times(1)
679         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
680     ErrCode ret = applicationManagerProxy_->AddOrRemoveAutoStartApps(data, false);
681     ASSERT_TRUE(ret == ERR_OK);
682 }
683 
684 /**
685  * @tc.name: TestGetAutoStartAppsWithUserIdSuc
686  * @tc.desc: Test GetAutoStartAppsWithUserId success func.
687  * @tc.type: FUNC
688  */
689 HWTEST_F(ApplicationManagerProxyTest, TestGetAutoStartAppsWithUserIdSuc, TestSize.Level1)
690 {
691     MessageParcel data;
692     int32_t userId = 1;
693     data.WriteInt32(userId);
694     std::vector<OHOS::AppExecFwk::ElementName> apps;
695     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
696         .Times(1)
697         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayElementSendRequestGetPolicy));
698     ErrCode ret = applicationManagerProxy_->GetAutoStartApps(data, apps);
699     ASSERT_TRUE(ret == ERR_OK);
700     ASSERT_TRUE(apps.size() == 1);
701 }
702 
703 /**
704  * @tc.name: TestGetAutoStartAppsWithUserIdFail
705  * @tc.desc: Test GetAutoStartAppsWithUserId without enable edm service func.
706  * @tc.type: FUNC
707  */
708 HWTEST_F(ApplicationManagerProxyTest, TestGetAutoStartAppsWithUserIdFail, TestSize.Level1)
709 {
710     Utils::SetEdmServiceDisable();
711     MessageParcel data;
712     int32_t userId = 1;
713     data.WriteInt32(userId);
714     std::vector<OHOS::AppExecFwk::ElementName> apps;
715     ErrCode ret = applicationManagerProxy_->GetAutoStartApps(data, apps);
716     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
717 }
718 
719 /**
720  * @tc.name: TestGetAutoStartAppDisallowModifyWithUserIdSuc
721  * @tc.desc: Test GetAutoStartAppDisallowModifyWithUserId success func.
722  * @tc.type: FUNC
723  */
724 HWTEST_F(ApplicationManagerProxyTest, TestGetAutoStartAppDisallowModifyWithUserIdSuc, TestSize.Level1)
725 {
726     MessageParcel data;
727     int32_t userId = 1;
728     data.WriteInt32(userId);
729     bool disallowModify = false;
730     EXPECT_CALL(*object_, SendRequest(_, _, _, _))
731         .Times(1)
732         .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayElementSendRequestGetPolicy));
733     ErrCode ret = applicationManagerProxy_->IsModifyAutoStartAppsDisallowed(data, disallowModify);
734     ASSERT_TRUE(ret == ERR_OK);
735 }
736 
737 /**
738  * @tc.name: TestGetAutoStartAppDisallowModifyWithUserIdFail
739  * @tc.desc: Test GetAutoStartAppDisallowModifyWithUserId without enable edm service func.
740  * @tc.type: FUNC
741  */
742 HWTEST_F(ApplicationManagerProxyTest, TestGetAutoStartAppDisallowModifyWithUserIdFail, TestSize.Level1)
743 {
744     Utils::SetEdmServiceDisable();
745     MessageParcel data;
746     int32_t userId = 1;
747     data.WriteInt32(userId);
748     bool disallowModify = false;
749     ErrCode ret = applicationManagerProxy_->IsModifyAutoStartAppsDisallowed(data, disallowModify);
750     ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
751 }
752 } // namespace TEST
753 } // namespace EDM
754 } // namespace OHOS
755