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 "set_allowed_kiosk_apps_plugin.h"
18 #include "system_ability_definition.h"
19 #include "edm_constants.h"
20 #include "edm_ipc_interface_code.h"
21 #include "iplugin_manager.h"
22 #include "plugin_singleton.h"
23 #include "utils.h"
24
25 using namespace testing::ext;
26 using namespace testing;
27
28 namespace OHOS {
29 namespace EDM {
30 namespace TEST {
31 const std::string TEST_BUNDLE_NAME = "testBundleName";
32 class SetAllowedKioskAppsPluginTest : public testing::Test {
33 protected:
34 static void SetUpTestSuite(void);
35
36 static void TearDownTestSuite(void);
37 };
38
SetUpTestSuite(void)39 void SetAllowedKioskAppsPluginTest::SetUpTestSuite(void)
40 {
41 Utils::SetEdmInitialEnv();
42 }
43
TearDownTestSuite(void)44 void SetAllowedKioskAppsPluginTest::TearDownTestSuite(void)
45 {
46 Utils::ResetTokenTypeAndUid();
47 ASSERT_TRUE(Utils::IsOriginalUTEnv());
48 std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
49 }
50
51 /**
52 * @tc.name: SetAllowedKioskAppsPluginDataEmpty
53 * @tc.desc: Test SetAllowedKioskAppsPlugin::OnSetPolicy when data is empty.
54 * @tc.type: FUNC
55 */
56 HWTEST_F(SetAllowedKioskAppsPluginTest, SetAllowedKioskAppsPluginDataEmpty, TestSize.Level1)
57 {
58 SetAllowedKioskAppsPlugin plugin;
59 std::vector<std::string> data;
60 std::vector<std::string> currentData;
61 std::vector<std::string> mergeData;
62 plugin.OnSetPolicy(data, currentData, mergeData, DEFAULT_USER_ID);
63 ASSERT_TRUE(data.empty());
64 }
65
66 /**
67 * @tc.name: SetAllowedKioskAppsPluginDataOverLimit
68 * @tc.desc: Test SetAllowedKioskAppsPlugin::OnSetPolicy when data is over limit.
69 * @tc.type: FUNC
70 */
71 HWTEST_F(SetAllowedKioskAppsPluginTest, SetAllowedKioskAppsPluginDataOverLimit, TestSize.Level1)
72 {
73 SetAllowedKioskAppsPlugin plugin;
74 std::vector<std::string> data(EdmConstants::POLICIES_MAX_SIZE + 1, TEST_BUNDLE_NAME);
75 std::vector<std::string> currentData;
76 std::vector<std::string> mergeData;
77 ErrCode ret = plugin.OnSetPolicy(data, currentData, mergeData, DEFAULT_USER_ID);
78 ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
79 }
80
81 /**
82 * @tc.name: SetAllowedKioskAppsPluginSuc
83 * @tc.desc: Test SetAllowedKioskAppsPlugin::OnGetPolicy function.
84 * @tc.type: FUNC
85 */
86 HWTEST_F(SetAllowedKioskAppsPluginTest, SetAllowedKioskAppsPluginSuc, TestSize.Level1)
87 {
88 SetAllowedKioskAppsPlugin plugin;
89 std::vector<std::string> data;
90 data.push_back(TEST_BUNDLE_NAME);
91 std::vector<std::string> currentData;
92 std::vector<std::string> mergeData;
93 plugin.OnSetPolicy(data, currentData, mergeData, DEFAULT_USER_ID);
94 plugin.OnOtherServiceStart(ABILITY_MGR_SERVICE_ID);
95 plugin.OnOtherServiceStart(WINDOW_MANAGER_SERVICE_ID);
96 ASSERT_TRUE(!data.empty());
97 }
98
99 /**
100 * @tc.name: SetAllowedKioskAppsPluginGetTest
101 * @tc.desc: Test SetAllowedKioskAppsPlugin::OnGetPolicy function.
102 * @tc.type: FUNC
103 */
104 HWTEST_F(SetAllowedKioskAppsPluginTest, SetAllowedKioskAppsPluginGetTest, TestSize.Level1)
105 {
106 SetAllowedKioskAppsPlugin plugin;
107 std::string policyData = "[\"com.example.edmtest\"]";
108 MessageParcel data;
109 MessageParcel reply;
110 ErrCode ret = plugin.OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
111 ASSERT_TRUE(ret == ERR_OK);
112 }
113
114 /**
115 * @tc.name: SetAllowedKioskAppsPluginOnAdminRemove
116 * @tc.desc: Test SetAllowedKioskAppsPlugin::OnAdminRemove function.
117 * @tc.type: FUNC
118 */
119 HWTEST_F(SetAllowedKioskAppsPluginTest, SetAllowedKioskAppsPluginOnAdminRemove, TestSize.Level1)
120 {
121 SetAllowedKioskAppsPlugin plugin;
122 std::vector<std::string> data;
123 std::vector<std::string> mergeData;
124 ErrCode ret = plugin.OnAdminRemove(TEST_BUNDLE_NAME, data, mergeData, DEFAULT_USER_ID);
125 ASSERT_TRUE(ret == ERR_OK);
126 }
127 } // namespace TEST
128 } // namespace EDM
129 } // namespace OHOS