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
18 #include "app_utils.h"
19 #include "hilog_tag_wrapper.h"
20 #include "parameters.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace AbilityRuntime {
27 class AppUtilsTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase(void)35 void AppUtilsTest::SetUpTestCase(void)
36 {}
37
TearDownTestCase(void)38 void AppUtilsTest::TearDownTestCase(void)
39 {}
40
SetUp()41 void AppUtilsTest::SetUp()
42 {}
43
TearDown()44 void AppUtilsTest::TearDown()
45 {}
46
47 /**
48 * @tc.number: AppUtilsTest_0100
49 * @tc.desc: Test IsInheritWindowSplitScreenMode works
50 * @tc.type: FUNC
51 */
52 HWTEST_F(AppUtilsTest, AppUtilsTest_0100, TestSize.Level0)
53 {
54 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0100 called.");
55 bool isInheritWindowSplitScreenMode = AAFwk::AppUtils::GetInstance().IsInheritWindowSplitScreenMode();
56 std::string deviceType = OHOS::system::GetDeviceType();
57 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
58 if (deviceType == "default") {
59 EXPECT_TRUE(isInheritWindowSplitScreenMode == true);
60 } else if (deviceType == "phone") {
61 EXPECT_TRUE(isInheritWindowSplitScreenMode == true);
62 } else if (deviceType == "2in1") {
63 EXPECT_TRUE(isInheritWindowSplitScreenMode == false);
64 }
65 }
66
67 /**
68 * @tc.number: AppUtilsTest_0200
69 * @tc.desc: Test IsSupportAncoApp works
70 * @tc.type: FUNC
71 */
72 HWTEST_F(AppUtilsTest, AppUtilsTest_0200, TestSize.Level0)
73 {
74 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0200 called.");
75 bool isSupportAncoApp = AAFwk::AppUtils::GetInstance().IsSupportAncoApp();
76 std::string deviceType = OHOS::system::GetDeviceType();
77 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
78 if (deviceType == "default") {
79 EXPECT_TRUE(isSupportAncoApp == false);
80 } else if (deviceType == "phone") {
81 EXPECT_TRUE(isSupportAncoApp == true);
82 } else if (deviceType == "2in1") {
83 EXPECT_TRUE(isSupportAncoApp == false);
84 }
85 }
86
87 /**
88 * @tc.number: AppUtilsTest_0300
89 * @tc.desc: Test GetTimeoutUnitTimeRatio works
90 * @tc.type: FUNC
91 */
92 HWTEST_F(AppUtilsTest, AppUtilsTest_0300, TestSize.Level0)
93 {
94 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0300 called.");
95 int32_t timeoutUnitTimeRatio = AAFwk::AppUtils::GetInstance().GetTimeoutUnitTimeRatio();
96 std::string deviceType = OHOS::system::GetDeviceType();
97 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
98 if (deviceType == "default") {
99 EXPECT_TRUE(timeoutUnitTimeRatio == 1);
100 } else if (deviceType == "phone") {
101 EXPECT_TRUE(timeoutUnitTimeRatio == 1);
102 } else if (deviceType == "2in1") {
103 EXPECT_TRUE(timeoutUnitTimeRatio == 10);
104 }
105 }
106
107 /**
108 * @tc.number: AppUtilsTest_0400
109 * @tc.desc: Test IsSelectorDialogDefaultPossion works
110 * @tc.type: FUNC
111 */
112 HWTEST_F(AppUtilsTest, AppUtilsTest_0400, TestSize.Level0)
113 {
114 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0400 called.");
115 bool isSelectorDialogDefaultPossion = AAFwk::AppUtils::GetInstance().IsSelectorDialogDefaultPossion();
116 std::string deviceType = OHOS::system::GetDeviceType();
117 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
118 if (deviceType == "default") {
119 EXPECT_TRUE(isSelectorDialogDefaultPossion == true);
120 } else if (deviceType == "phone") {
121 EXPECT_TRUE(isSelectorDialogDefaultPossion == true);
122 } else if (deviceType == "2in1") {
123 EXPECT_TRUE(isSelectorDialogDefaultPossion == false);
124 }
125 }
126
127 /**
128 * @tc.number: AppUtilsTest_0500
129 * @tc.desc: Test IsStartSpecifiedProcess works
130 * @tc.type: FUNC
131 */
132 HWTEST_F(AppUtilsTest, AppUtilsTest_0500, TestSize.Level0)
133 {
134 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0500 called.");
135 bool isStartSpecifiedProcess = AAFwk::AppUtils::GetInstance().IsStartSpecifiedProcess();
136 std::string deviceType = OHOS::system::GetDeviceType();
137 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
138 if (deviceType == "default") {
139 EXPECT_TRUE(isStartSpecifiedProcess == false);
140 } else if (deviceType == "phone") {
141 EXPECT_TRUE(isStartSpecifiedProcess == false);
142 } else if (deviceType == "2in1") {
143 EXPECT_TRUE(isStartSpecifiedProcess == true);
144 }
145 }
146
147 /**
148 * @tc.number: AppUtilsTest_0600
149 * @tc.desc: Test IsUseMultiRenderProcess works
150 * @tc.type: FUNC
151 */
152 HWTEST_F(AppUtilsTest, AppUtilsTest_0600, TestSize.Level0)
153 {
154 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0600 called.");
155 bool isUseMultiRenderProcess = AAFwk::AppUtils::GetInstance().IsUseMultiRenderProcess();
156 std::string deviceType = OHOS::system::GetDeviceType();
157 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
158 if (deviceType == "default") {
159 EXPECT_TRUE(isUseMultiRenderProcess == true);
160 } else if (deviceType == "phone") {
161 EXPECT_TRUE(isUseMultiRenderProcess == true);
162 } else if (deviceType == "2in1") {
163 EXPECT_TRUE(isUseMultiRenderProcess == true);
164 }
165 }
166
167 /**
168 * @tc.number: AppUtilsTest_0700
169 * @tc.desc: Test IsLimitMaximumOfRenderProcess works
170 * @tc.type: FUNC
171 */
172 HWTEST_F(AppUtilsTest, AppUtilsTest_0700, TestSize.Level0)
173 {
174 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0700 called.");
175 bool isLimitMaximumOfRenderProcess = AAFwk::AppUtils::GetInstance().IsLimitMaximumOfRenderProcess();
176 std::string deviceType = OHOS::system::GetDeviceType();
177 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
178 if (deviceType == "default") {
179 EXPECT_TRUE(isLimitMaximumOfRenderProcess == true);
180 } else if (deviceType == "phone") {
181 EXPECT_TRUE(isLimitMaximumOfRenderProcess == true);
182 } else if (deviceType == "2in1") {
183 EXPECT_TRUE(isLimitMaximumOfRenderProcess == false);
184 }
185 }
186
187 /**
188 * @tc.number: AppUtilsTest_0800
189 * @tc.desc: Test IsGrantPersistUriPermission works
190 * @tc.type: FUNC
191 */
192 HWTEST_F(AppUtilsTest, AppUtilsTest_0800, TestSize.Level0)
193 {
194 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0800 called.");
195 bool isGrantPersistUriPermission = AAFwk::AppUtils::GetInstance().IsGrantPersistUriPermission();
196 std::string deviceType = OHOS::system::GetDeviceType();
197 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
198 if (deviceType == "default") {
199 EXPECT_TRUE(isGrantPersistUriPermission == false);
200 } else if (deviceType == "phone") {
201 EXPECT_TRUE(isGrantPersistUriPermission == false);
202 } else if (deviceType == "2in1") {
203 EXPECT_TRUE(isGrantPersistUriPermission == true);
204 }
205 }
206
207 /**
208 * @tc.number: AppUtilsTest_0900
209 * @tc.desc: Test IsStartOptionsWithAnimation works
210 * @tc.type: FUNC
211 */
212 HWTEST_F(AppUtilsTest, AppUtilsTest_0900, TestSize.Level0)
213 {
214 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_0900 called.");
215 bool isStartOptionsWithAnimation = AAFwk::AppUtils::GetInstance().IsStartOptionsWithAnimation();
216 std::string deviceType = OHOS::system::GetDeviceType();
217 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
218 if (deviceType == "default") {
219 EXPECT_TRUE(isStartOptionsWithAnimation == false);
220 } else if (deviceType == "phone") {
221 EXPECT_TRUE(isStartOptionsWithAnimation == false);
222 } else if (deviceType == "2in1") {
223 EXPECT_TRUE(isStartOptionsWithAnimation == true);
224 }
225 }
226
227 /**
228 * @tc.number: AppUtilsTest_1000
229 * @tc.desc: Test IsMultiProcessModel works
230 * @tc.type: FUNC
231 */
232 HWTEST_F(AppUtilsTest, AppUtilsTest_1000, TestSize.Level0)
233 {
234 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_1000 called.");
235 bool isMultiProcessModel = AAFwk::AppUtils::GetInstance().IsMultiProcessModel();
236 std::string deviceType = OHOS::system::GetDeviceType();
237 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
238 if (deviceType == "default") {
239 EXPECT_TRUE(isMultiProcessModel == false);
240 } else if (deviceType == "phone") {
241 EXPECT_TRUE(isMultiProcessModel == false);
242 } else if (deviceType == "2in1") {
243 EXPECT_TRUE(isMultiProcessModel == true);
244 }
245 }
246
247 /**
248 * @tc.number: AppUtilsTest_1100
249 * @tc.desc: Test IsStartOptionsWithProcessOptions works
250 * @tc.type: FUNC
251 */
252 HWTEST_F(AppUtilsTest, AppUtilsTest_1100, TestSize.Level0)
253 {
254 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_1100 called.");
255 bool isStartOptionsWithProcessOptions = AAFwk::AppUtils::GetInstance().IsStartOptionsWithProcessOptions();
256 std::string deviceType = OHOS::system::GetDeviceType();
257 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
258 if (deviceType == "default") {
259 EXPECT_TRUE(isStartOptionsWithProcessOptions == false);
260 } else if (deviceType == "phone") {
261 EXPECT_TRUE(isStartOptionsWithProcessOptions == false);
262 } else if (deviceType == "2in1") {
263 EXPECT_TRUE(isStartOptionsWithProcessOptions == true);
264 }
265 }
266
267 /**
268 * @tc.number: AppUtilsTest_1200
269 * @tc.desc: Test EnableMoveUIAbilityToBackgroundApi works
270 * @tc.type: FUNC
271 */
272 HWTEST_F(AppUtilsTest, AppUtilsTest_1200, TestSize.Level0)
273 {
274 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_1200 called.");
275 bool enableMoveUIAbilityToBackgroundApi = AAFwk::AppUtils::GetInstance().EnableMoveUIAbilityToBackgroundApi();
276 std::string deviceType = OHOS::system::GetDeviceType();
277 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
278 if (deviceType == "default") {
279 EXPECT_TRUE(enableMoveUIAbilityToBackgroundApi == true);
280 } else if (deviceType == "phone") {
281 EXPECT_TRUE(enableMoveUIAbilityToBackgroundApi == true);
282 } else if (deviceType == "2in1") {
283 EXPECT_TRUE(enableMoveUIAbilityToBackgroundApi == false);
284 }
285 }
286
287 /**
288 * @tc.number: AppUtilsTest_1300
289 * @tc.desc: Test MaxChildProcess works
290 * @tc.type: FUNC
291 */
292 HWTEST_F(AppUtilsTest, AppUtilsTest_1300, TestSize.Level0)
293 {
294 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_1300 called.");
295 auto maxChildProcess = AAFwk::AppUtils::GetInstance().MaxChildProcess();
296 std::string deviceType = OHOS::system::GetDeviceType();
297 TAG_LOGI(AAFwkTag::TEST, "current deviceType is %{public}s", deviceType.c_str());
298 if (deviceType == "phone" || deviceType == "2in1") {
299 EXPECT_TRUE(maxChildProcess != 0);
300 }
301 }
302
303 /**
304 * @tc.number: AppUtilsTest_1400
305 * @tc.desc: Test IsAllowNativeChildProcess works
306 * @tc.type: FUNC
307 */
308 HWTEST_F(AppUtilsTest, AppUtilsTest_1400, TestSize.Level0)
309 {
310 TAG_LOGI(AAFwkTag::TEST, "AppUtilsTest_1400 called.");
311 auto allow = AAFwk::AppUtils::GetInstance().IsAllowNativeChildProcess("com.test.demo");
312 EXPECT_FALSE(allow);
313 }
314 } // namespace AbilityRuntime
315 } // namespace OHOS
316