• 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 #define protected public
17 #define private public
18 #include "manage_auto_start_apps_plugin_test.h"
19 #undef private
20 #undef protected
21 
22 #include "bundle_info.h"
23 #include "bundle_mgr_interface.h"
24 #include "if_system_ability_manager.h"
25 #include "iremote_stub.h"
26 #include "iservice_registry.h"
27 #include "parameters.h"
28 #include "system_ability_definition.h"
29 
30 #include "array_string_serializer.h"
31 #include "edm_constants.h"
32 #include "edm_ipc_interface_code.h"
33 #include "edm_log.h"
34 #include "edm_sys_manager.h"
35 #include "install_plugin.h"
36 #include "uninstall_plugin.h"
37 #include "utils.h"
38 #include "func_code.h"
39 #include "manage_auto_start_app_info.h"
40 #include "manage_auto_start_apps_serializer.h"
41 
42 using namespace testing::ext;
43 
44 namespace OHOS {
45 namespace EDM {
46 namespace TEST {
47 const std::string RIGHT_TEST_BUNDLE = "com.example.l3jsdemo/com.example.l3jsdemo.MainAbility";
48 const std::string ERROR_TEST_BUNDLE = "com.example.l3jsdemo/com.example.l3jsdemo.ErrorAbility";
49 const std::string INVALID_TEST_BUNDLE = "com.example.l3jsdemo.com.example.l3jsdemo.ErrorAbility";
50 const std::string HAP_FILE_PATH = "/data/test/resource/enterprise_device_management/hap/right.hap";
51 const std::string BOOT_OEM_MODE = "const.boot.oemmode";
52 const std::string DEVELOP_PARAM = "rd";
53 const std::string USER_MODE = "user";
SetUpTestSuite(void)54 void ManageAutoStartAppsPluginTest::SetUpTestSuite(void)
55 {
56     Utils::SetEdmInitialEnv();
57 }
58 
TearDownTestSuite(void)59 void ManageAutoStartAppsPluginTest::TearDownTestSuite(void)
60 {
61     Utils::ResetTokenTypeAndUid();
62     ASSERT_TRUE(Utils::IsOriginalUTEnv());
63     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
64 }
65 
66 /**
67  * @tc.name: TestOnHandlePolicyAddFailWithNullData
68  * @tc.desc: Test ManageAutoStartAppsPlugin::OnHandlePolicy add when data is empty.
69  * @tc.type: FUNC
70  */
71 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnHandlePolicyAddFailWithNullData, TestSize.Level1)
72 {
73     ManageAutoStartAppsPlugin plugin;
74     MessageParcel data;
75     MessageParcel reply;
76     HandlePolicyData policyData;
77     std::vector<std::string> autoStartApps;
78     data.WriteStringVector(autoStartApps);
79 
80     std::uint32_t funcCode =
81         POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::MANAGE_AUTO_START_APPS);
82     ErrCode ret = plugin.OnHandlePolicy(funcCode, data, reply, policyData, DEFAULT_USER_ID);
83     ASSERT_TRUE(ret == ERR_OK);
84     ASSERT_TRUE(reply.ReadInt32() == ERR_OK);
85 }
86 
87 /**
88  * @tc.name: TestOnHandlePolicyRemoveFailWithNullData
89  * @tc.desc: Test ManageAutoStartAppsPlugin::OnHandlePolicy remove when data is empty.
90  * @tc.type: FUNC
91  */
92 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnHandlePolicyRemoveFailWithNullData, TestSize.Level1)
93 {
94     ManageAutoStartAppsPlugin plugin;
95     MessageParcel data;
96     MessageParcel reply;
97     HandlePolicyData policyData;
98     std::vector<std::string> autoStartApps;
99     data.WriteStringVector(autoStartApps);
100 
101     std::uint32_t funcCode =
102         POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::REMOVE, EdmInterfaceCode::MANAGE_AUTO_START_APPS);
103     ErrCode ret = plugin.OnHandlePolicy(funcCode, data, reply, policyData, DEFAULT_USER_ID);
104     ASSERT_TRUE(ret == ERR_OK);
105     ASSERT_TRUE(reply.ReadInt32() == ERR_OK);
106 }
107 
108 /**
109  * @tc.name: TestOnHandlePolicyFailWithOversizeData
110  * @tc.desc: Test ManageAutoStartAppsPlugin::OnHandlePolicy when data is oversize.
111  * @tc.type: FUNC
112  */
113 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnHandlePolicyFailWithOversizeData, TestSize.Level1)
114 {
115     ManageAutoStartAppsPlugin plugin;
116     MessageParcel data;
117     MessageParcel reply;
118     HandlePolicyData policyData;
119     plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
120     std::vector<std::string> dataStr;
121     for (int i = 0; i < 15; i++) {
122         std::string str = "test/test" + std::to_string(i);
123         dataStr.push_back(str);
124     }
125     data.WriteStringVector(dataStr);
126 
127     std::uint32_t funcCode =
128         POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::MANAGE_AUTO_START_APPS);
129     ErrCode ret = plugin.OnHandlePolicy(funcCode, data, reply, policyData, DEFAULT_USER_ID);
130     ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
131 }
132 
133 /**
134  * @tc.name: TestOnHandlePolicyAddFailWithNotExistedData
135  * @tc.desc: Test ManageAutoStartAppsPlugin::OnHandlePolicy add when app is not existed.
136  * @tc.type: FUNC
137  */
138 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnHandlePolicyAddFailWithNotExistedData, TestSize.Level1)
139 {
140     std::vector<std::string> autoStartApps = {"com.not.existed/com.not.exxisted"};
141     ManageAutoStartAppsPlugin plugin;
142     MessageParcel data;
143     MessageParcel reply;
144     data.WriteStringVector(autoStartApps);
145     HandlePolicyData policyData;
146 
147     std::uint32_t funcCode =
148         POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::MANAGE_AUTO_START_APPS);
149     ErrCode ret = plugin.OnHandlePolicy(funcCode, data, reply, policyData, DEFAULT_USER_ID);
150     ErrCode res;
151     reply.ReadInt32(res);
152     ASSERT_TRUE(res == EdmReturnErrCode::PARAM_ERROR);
153     ASSERT_TRUE(ret == res);
154 }
155 
156 /**
157  * @tc.name: TestOnHandlePolicyRemoveFailWithNotExistedData
158  * @tc.desc: Test ManageAutoStartAppsPlugin::OnHandlePolicy remove when app is not existed.
159  * @tc.type: FUNC
160  */
161 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnHandlePolicyRemoveFailWithNotExistedData, TestSize.Level1)
162 {
163     std::vector<std::string> autoStartApps = {"com.not.existed/com.not.exxisted"};
164     ManageAutoStartAppsPlugin plugin;
165     MessageParcel data;
166     MessageParcel reply;
167     data.WriteStringVector(autoStartApps);
168     HandlePolicyData policyData;
169     ArrayStringSerializer::GetInstance()->Serialize(autoStartApps, policyData.policyData);
170 
171     std::uint32_t funcCode =
172         POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::REMOVE, EdmInterfaceCode::MANAGE_AUTO_START_APPS);
173     ErrCode ret = plugin.OnHandlePolicy(funcCode, data, reply, policyData, DEFAULT_USER_ID);
174     ErrCode res;
175     reply.ReadInt32(res);
176     ASSERT_TRUE(res == ERR_OK);
177     ASSERT_TRUE(ret == res);
178 }
179 
180 /**
181  * @tc.name: TestOnGetPolicyFail
182  * @tc.desc: Test ManageAutoStartAppsPlugin::OnGetPolicy.
183  * @tc.type: FUNC
184  */
185 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnGetPolicyFail, TestSize.Level1)
186 {
187     ManageAutoStartAppsPlugin plugin;
188     std::string policyData;
189     MessageParcel data;
190     MessageParcel reply;
191     std::vector<std::string> autoStartApps;
192     data.WriteString("bundleInfo");
193     ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
194     reply.ReadStringVector(&autoStartApps);
195     ASSERT_TRUE((ret == EdmReturnErrCode::SYSTEM_ABNORMALLY) || (autoStartApps.empty()));
196 }
197 
198 /**
199  * @tc.name: TestGetDisallowModifyFail
200  * @tc.desc: Test ManageAutoStartAppsPlugin::OnGetPolicy.
201  * @tc.type: FUNC
202  */
203 HWTEST_F(ManageAutoStartAppsPluginTest, TestGetDisallowModifyFail, TestSize.Level1)
204 {
205     ManageAutoStartAppsPlugin plugin;
206     std::string policyData;
207     MessageParcel data;
208     MessageParcel reply;
209     std::vector<std::string> autoStartApps;
210     data.WriteString("disallowModity");
211     data.WriteString("com.test1");
212     ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
213     bool disallowModify = reply.ReadBool();
214     ASSERT_TRUE((ret == EdmReturnErrCode::SYSTEM_ABNORMALLY) || (disallowModify));
215 }
216 
217 /**
218  * @tc.name: TestOnAdminRemoveDoneFail
219  * @tc.desc: Test ManageAutoStartAppsPlugin::OnAdminRemoveDone.
220  * @tc.type: FUNC
221  */
222 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnAdminRemoveDoneFail, TestSize.Level1)
223 {
224     ManageAutoStartAppsPlugin plugin;
225     std::string adminName;
226     std::string currentJsonData;
227     plugin.OnAdminRemoveDone(adminName, currentJsonData, DEFAULT_USER_ID);
228 
229     std::string policyData;
230     MessageParcel data;
231     MessageParcel reply;
232     data.WriteString("bundleInfo");
233     std::vector<std::string> autoStartApps;
234     ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
235     reply.ReadStringVector(&autoStartApps);
236     ASSERT_TRUE((ret == EdmReturnErrCode::SYSTEM_ABNORMALLY) || (autoStartApps.empty()));
237 }
238 
239 /**
240  * @tc.name: TestOnSetPolicySucWithNullData
241  * @tc.desc: Test ManageAutoStartAppsPlugin::OnSetPolicy when data is empty.
242  * @tc.type: FUNC
243  */
244 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnSetPolicySucWithNullData, TestSize.Level1)
245 {
246     ManageAutoStartAppsPlugin plugin;
247     plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
248     std::vector<std::string> data;
249     bool disallowModify = false;
250     std::vector<ManageAutoStartAppInfo> currentData;
251     std::vector<ManageAutoStartAppInfo> mergeData;
252     ErrCode ret = plugin.OnSetPolicy(data, disallowModify, currentData, mergeData, DEFAULT_USER_ID);
253     ASSERT_TRUE(ret == ERR_OK);
254 }
255 
256 /**
257  * @tc.name: TestOnSetPolicyFailWithbundleExceededLimit
258  * @tc.desc: Test ManageAutoStartAppsPlugin::OnSetPolicy when budle is not existed.
259  * @tc.type: FUNC
260  */
261 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnSetPolicyFailWithbundleExceededLimit, TestSize.Level1)
262 {
263     ManageAutoStartAppsPlugin plugin;
264     plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
265     std::vector<std::string> data;
266     for (int i = 0; i < 15; i++) {
267         std::string str = "test/test" + std::to_string(i);
268         data.push_back(str);
269     }
270     bool disallowModify = false;
271     std::vector<ManageAutoStartAppInfo> currentData;
272     std::vector<ManageAutoStartAppInfo> mergeData;
273     ErrCode ret = plugin.OnSetPolicy(data, disallowModify, currentData, mergeData, DEFAULT_USER_ID);
274     ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
275 }
276 
277 /**
278  * @tc.name: TestOnSetPolicyFailWithbundleNotExist
279  * @tc.desc: Test ManageAutoStartAppsPlugin::OnSetPolicy when budle is not existed.
280  * @tc.type: FUNC
281  */
282 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnSetPolicyFailWithbundleNotExist, TestSize.Level1)
283 {
284     ManageAutoStartAppsPlugin plugin;
285     plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
286     std::vector<std::string> data = {RIGHT_TEST_BUNDLE};
287     std::vector<ManageAutoStartAppInfo> currentData;
288     std::vector<ManageAutoStartAppInfo> mergeData;
289     bool disallowModify = false;
290     ErrCode ret = plugin.OnSetPolicy(data, disallowModify, currentData, mergeData, DEFAULT_USER_ID);
291     ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
292 }
293 
294 /**
295  * @tc.name: TestOnSetPolicyFailWithInvalidData
296  * @tc.desc: Test ManageAutoStartAppsPlugin::OnSetPolicy when data is invalid.
297  * @tc.type: FUNC
298  */
299 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnSetPolicyFailWithInvalidData, TestSize.Level1)
300 {
301     ManageAutoStartAppsPlugin plugin;
302     plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
303     std::vector<std::string> data = {INVALID_TEST_BUNDLE};
304     std::vector<ManageAutoStartAppInfo> currentData;
305     std::vector<ManageAutoStartAppInfo> mergeData;
306     bool disallowModify = false;
307     ErrCode ret = plugin.OnSetPolicy(data, disallowModify, currentData, mergeData, DEFAULT_USER_ID);
308     ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
309 }
310 
311 /**
312  * @tc.name: TestOnSetPolicySuc
313  * @tc.desc: Test ManageAutoStartAppsPlugin::OnSetPolicy when budle is existed.
314  * @tc.type: FUNC
315  */
316 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnSetPolicySuc, TestSize.Level1)
317 {
318     std::string developDeviceParam = system::GetParameter(BOOT_OEM_MODE, USER_MODE);
319     if (developDeviceParam == DEVELOP_PARAM) {
320         InstallPlugin installPlugin;
321         InstallParam param = {{HAP_FILE_PATH}, DEFAULT_USER_ID, 0};
322         MessageParcel reply;
323         ErrCode ret = installPlugin.OnSetPolicy(param, reply);
324         EXPECT_TRUE(ret == ERR_OK);
325 
326         ManageAutoStartAppsPlugin plugin;
327         plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
328         std::vector<std::string> data = {RIGHT_TEST_BUNDLE, ERROR_TEST_BUNDLE, INVALID_TEST_BUNDLE};
329         std::vector<ManageAutoStartAppInfo> currentData;
330         std::vector<ManageAutoStartAppInfo> mergeData;
331         bool disallowModify = false;
332         ret = plugin.OnSetPolicy(data, disallowModify, currentData, mergeData, DEFAULT_USER_ID);
333         EXPECT_TRUE(ret == ERR_OK);
334 
335         std::string policyData;
336         ManageAutoStartAppsSerializer::GetInstance()->Serialize(currentData, policyData);
337         MessageParcel parcel;
338         MessageParcel getReply;
339         parcel.WriteString("bundleInfo");
340         ret = plugin.OnGetPolicy(policyData, parcel, getReply, DEFAULT_USER_ID);
341         std::vector<std::string> res;
342         EXPECT_TRUE(ret == ERR_OK);
343         EXPECT_TRUE(getReply.ReadInt32() == ERR_OK);
344         getReply.ReadStringVector(&res);
345         EXPECT_TRUE(res.size() >= 1);
346         EXPECT_TRUE(std::find(res.begin(), res.end(), RIGHT_TEST_BUNDLE) != res.end());
347 
348         std::vector<std::string> removeData = {RIGHT_TEST_BUNDLE, ERROR_TEST_BUNDLE, INVALID_TEST_BUNDLE};
349         mergeData.clear();
350         ret = plugin.OnRemovePolicy(removeData, currentData, mergeData, DEFAULT_USER_ID);
351         EXPECT_TRUE(ret == ERR_OK);
352 
353         MessageParcel removeReply;
354         std::string afterRemovePolicyData;
355         ManageAutoStartAppsSerializer::GetInstance()->Serialize(currentData, afterRemovePolicyData);
356         parcel.WriteString("bundleInfo");
357         ret = plugin.OnGetPolicy(afterRemovePolicyData, parcel, removeReply, DEFAULT_USER_ID);
358         std::vector<std::string> afterRemove;
359         EXPECT_TRUE(ret == ERR_OK);
360         EXPECT_TRUE(removeReply.ReadInt32() == ERR_OK);
361         removeReply.ReadStringVector(&afterRemove);
362         EXPECT_TRUE(afterRemove.size() == 0);
363 
364         UninstallPlugin uninstallPlugin;
365         UninstallParam uninstallParam = {"com.example.l3jsdemo", DEFAULT_USER_ID, false};
366         MessageParcel uninstallReply;
367         ret = uninstallPlugin.OnSetPolicy(uninstallParam, uninstallReply);
368         EXPECT_TRUE(ret == ERR_OK);
369     }
370 }
371 
372 /**
373  * @tc.name: TestOnGetPolicySuc
374  * @tc.desc: Test ManageAutoStartAppsPlugin::OnGetPolicy.
375  * @tc.type: FUNC
376  */
377 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnGetPolicySuc, TestSize.Level1)
378 {
379     ManageAutoStartAppsPlugin plugin;
380     std::string policyData = RIGHT_TEST_BUNDLE;
381     MessageParcel data;
382     MessageParcel reply;
383     data.WriteString("bundleInfo");
384     ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
385     ASSERT_TRUE(ret == ERR_OK);
386     ASSERT_TRUE(reply.ReadInt32() == ERR_OK);
387 }
388 
389 /**
390  * @tc.name: TestOnRemovePolicySucWithNullData
391  * @tc.desc: Test ManageAutoStartAppsPlugin::OnRemovePolicy when data is empty.
392  * @tc.type: FUNC
393  */
394 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnRemovePolicySucWithNullData, TestSize.Level1)
395 {
396     ManageAutoStartAppsPlugin plugin;
397     plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
398     std::vector<std::string> data;
399     std::vector<ManageAutoStartAppInfo> currentData;
400     std::vector<ManageAutoStartAppInfo> mergeData;
401     ErrCode ret = plugin.OnRemovePolicy(data, currentData, mergeData, DEFAULT_USER_ID);
402     ASSERT_TRUE(ret == ERR_OK);
403 }
404 
405 /**
406  * @tc.name: TestOnRemovePolicyFileWithErrBundle
407  * @tc.desc: Test ManageAutoStartAppsPlugin::OnRemovePolicy when budle is not existed.
408  * @tc.type: FUNC
409  */
410 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnRemovePolicyFileWithErrBundle, TestSize.Level1)
411 {
412     ManageAutoStartAppsPlugin plugin;
413     plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
414     std::vector<std::string> data = {ERROR_TEST_BUNDLE};
415     std::vector<ManageAutoStartAppInfo> currentData;
416     std::vector<ManageAutoStartAppInfo> mergeData;
417     ErrCode ret = plugin.OnRemovePolicy(data, currentData, mergeData, DEFAULT_USER_ID);
418     ASSERT_TRUE(ret == ERR_OK);
419 }
420 
421 /**
422  * @tc.name: TestOnRemovePolicySuc
423  * @tc.desc: Test ManageAutoStartAppsPlugin::OnSetPolicy when data is invalid.
424  * @tc.type: FUNC
425  */
426 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnRemovePolicySuc, TestSize.Level1)
427 {
428     std::string developDeviceParam = system::GetParameter(BOOT_OEM_MODE, USER_MODE);
429     if (developDeviceParam == DEVELOP_PARAM) {
430         InstallPlugin installPlugin;
431         InstallParam param = {{HAP_FILE_PATH}, DEFAULT_USER_ID, 0};
432         MessageParcel reply;
433         ErrCode ret = installPlugin.OnSetPolicy(param, reply);
434         EXPECT_TRUE(ret == ERR_OK);
435 
436         ManageAutoStartAppsPlugin plugin;
437         plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
438         std::vector<std::string> data = {RIGHT_TEST_BUNDLE};
439         std::vector<ManageAutoStartAppInfo> currentData;
440         std::vector<ManageAutoStartAppInfo> mergeData;
441         bool disallowModify = false;
442         ret = plugin.OnSetPolicy(data, disallowModify, currentData, mergeData, DEFAULT_USER_ID);
443         EXPECT_TRUE(ret == ERR_OK);
444 
445         data = {INVALID_TEST_BUNDLE};
446         ManageAutoStartAppInfo info;
447         info.SetBundleName(INVALID_TEST_BUNDLE);
448         info.SetAbilityName("");
449         currentData.push_back(info);
450         ret = plugin.OnRemovePolicy(data, currentData, mergeData, DEFAULT_USER_ID);
451         EXPECT_TRUE(ret == ERR_OK);
452 
453         data = {RIGHT_TEST_BUNDLE};
454         ManageAutoStartAppInfo info1;
455         info1.SetUniqueKey(RIGHT_TEST_BUNDLE);
456         currentData = {info1};
457         ret = plugin.OnRemovePolicy(data, currentData, mergeData, DEFAULT_USER_ID);
458         EXPECT_TRUE(ret == ERR_OK);
459 
460         UninstallPlugin uninstallPlugin;
461         UninstallParam uninstallParam = {"com.example.l3jsdemo", DEFAULT_USER_ID, false};
462         MessageParcel uninstallReply;
463         ret = uninstallPlugin.OnSetPolicy(uninstallParam, uninstallReply);
464         EXPECT_TRUE(ret == ERR_OK);
465     }
466 }
467 
468 /**
469  * @tc.name: TestOnRemovePolicySucAlreadyUninstall
470  * @tc.desc: Test ManageAutoStartAppsPlugin::OnSetPolicy when hap already uninstall.
471  * @tc.type: FUNC
472  */
473 HWTEST_F(ManageAutoStartAppsPluginTest, TestOnRemovePolicySucAlreadyUninstall, TestSize.Level1)
474 {
475     std::string developDeviceParam = system::GetParameter(BOOT_OEM_MODE, USER_MODE);
476     if (developDeviceParam == DEVELOP_PARAM) {
477         InstallPlugin installPlugin;
478         InstallParam param = {{HAP_FILE_PATH}, DEFAULT_USER_ID, 0};
479         MessageParcel reply;
480         ErrCode ret = installPlugin.OnSetPolicy(param, reply);
481         EXPECT_TRUE(ret == ERR_OK);
482 
483         ManageAutoStartAppsPlugin plugin;
484         plugin.maxListSize_ = EdmConstants::AUTO_START_APPS_MAX_SIZE;
485         std::vector<std::string> data = {RIGHT_TEST_BUNDLE};
486         std::vector<ManageAutoStartAppInfo> currentData;
487         std::vector<ManageAutoStartAppInfo> mergeData;
488         bool disallowModify = false;
489         ret = plugin.OnSetPolicy(data, disallowModify, currentData, mergeData, DEFAULT_USER_ID);
490         EXPECT_TRUE(ret == ERR_OK);
491 
492         UninstallPlugin uninstallPlugin;
493         UninstallParam uninstallParam = {"com.example.l3jsdemo", DEFAULT_USER_ID, false};
494         MessageParcel uninstallReply;
495         ret = uninstallPlugin.OnSetPolicy(uninstallParam, uninstallReply);
496         EXPECT_TRUE(ret == ERR_OK);
497 
498         data = {RIGHT_TEST_BUNDLE};
499         mergeData.clear();
500         ret = plugin.OnRemovePolicy(data, currentData, mergeData, DEFAULT_USER_ID);
501         EXPECT_TRUE(ret == ERR_OK);
502     }
503 }
504 } // namespace TEST
505 } // namespace EDM
506 } // namespace OHOS