1 /*
2 * Copyright (c) 2022 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 "window_property.h"
19 #include "wm_common_inner.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 class WindowPropertyTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 virtual void SetUp() override;
31 virtual void TearDown() override;
32 };
33
SetUpTestCase()34 void WindowPropertyTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void WindowPropertyTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void WindowPropertyTest::SetUp()
43 {
44 }
45
TearDown()46 void WindowPropertyTest::TearDown()
47 {
48 }
49
50 namespace {
51 /**
52 * @tc.name: MarshallingUnmarshalling
53 * @tc.desc: Marshalling Unmarshalling test
54 * @tc.type: FUNC
55 */
56 HWTEST_F(WindowPropertyTest, MarshallingUnmarshalling, Function | SmallTest | Level2)
57 {
58 WindowProperty winPropSrc;
59 winPropSrc.SetPrivacyMode(true);
60 winPropSrc.SetTransparent(true);
61 winPropSrc.SetTransform(Transform::Identity());
62
63 Parcel parcel;
64 winPropSrc.Marshalling(parcel);
65 WindowProperty* winPropDst = winPropSrc.Unmarshalling(parcel);
66
67 ASSERT_EQ(winPropDst->GetPrivacyMode(), true);
68 ASSERT_EQ(winPropDst->GetTransparent(), true);
69 ASSERT_EQ(winPropDst->GetTransform(), Transform::Identity());
70 delete winPropDst;
71 }
72
73 /**
74 * @tc.name: CopyFrom
75 * @tc.desc: CopyFrom test
76 * @tc.type: FUNC
77 */
78 HWTEST_F(WindowPropertyTest, CopyFrom, Function | SmallTest | Level2)
79 {
80 const sptr<WindowProperty> winPropSrc = new(std::nothrow) WindowProperty();
81 winPropSrc->SetPrivacyMode(true);
82 winPropSrc->SetTransparent(true);
83 winPropSrc->SetTransform(Transform::Identity());
84
85 WindowProperty winPropDst(winPropSrc); // winPropDst.CopyFrom(winPropSrc);
86
87 ASSERT_EQ(winPropSrc->GetPrivacyMode(), winPropDst.GetPrivacyMode());
88 ASSERT_EQ(winPropSrc->GetTransparent(), winPropDst.GetTransparent());
89 ASSERT_EQ(winPropSrc->GetTransform(), winPropDst.GetTransform());
90 }
91
92 /**
93 * @tc.name: Read
94 * @tc.desc: Read test
95 * @tc.type: FUNC
96 */
97 HWTEST_F(WindowPropertyTest, Read, Function | SmallTest | Level2)
98 {
99 WindowProperty winPropSrc;
100 winPropSrc.SetPrivacyMode(true);
101 winPropSrc.SetTransparent(true);
102
103 Parcel parcel;
104 winPropSrc.Marshalling(parcel);
105
106 WindowProperty winPropDst;
107 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_RECT);
108 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_MODE);
109 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_FLAGS);
110 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS);
111 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_FOCUSABLE);
112 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_TOUCHABLE);
113 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW);
114 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_ORIENTATION);
115 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
116 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
117 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
118 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO);
119 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA);
120 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY);
121 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
122 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE);
123 winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE);
124
125 ASSERT_EQ(false, winPropDst.GetPrivacyMode());
126 ASSERT_EQ(false, winPropDst.GetTransparent());
127 }
128
129 /**
130 * @tc.name: Write
131 * @tc.desc: Write test
132 * @tc.type: FUNC
133 */
134 HWTEST_F(WindowPropertyTest, Write, Function | SmallTest | Level2)
135 {
136 Parcel parcel;
137 WindowProperty winPropDst;
138 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_RECT));
139 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_MODE));
140 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_FLAGS));
141 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS));
142 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_FOCUSABLE));
143 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_TOUCHABLE));
144 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW));
145 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_ORIENTATION));
146 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON));
147 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
148 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS));
149 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO));
150 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA));
151 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY));
152 ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG));
153 }
154
155 /**
156 * @tc.name: SetAbilityInfo
157 * @tc.desc: Test SetAbilityInfo and GetAbilityInfo
158 * @tc.type: FUNC
159 */
160 HWTEST_F(WindowPropertyTest, SetAbilityInfo, Function | SmallTest | Level2)
161 {
162 WindowProperty winPropDst;
163 AbilityInfo info;
164 info.bundleName_ = "testBundleName";
165 info.abilityName_ = "testAbilityName";
166 winPropDst.SetAbilityInfo(info);
167 ASSERT_EQ("testBundleName", winPropDst.GetAbilityInfo().bundleName_);
168 ASSERT_EQ("testAbilityName", winPropDst.GetAbilityInfo().abilityName_);
169 }
170
171 /**
172 * @tc.name: ResumeLastWindowMode
173 * @tc.desc: Test ResumeLastWindowMode
174 * @tc.type: FUNC
175 */
176 HWTEST_F(WindowPropertyTest, ResumeLastWindowMode, Function | SmallTest | Level2)
177 {
178 WindowProperty winPropDst;
179 winPropDst.modeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_PIP;
180 winPropDst.lastMode_ = WindowMode::WINDOW_MODE_PIP;
181 winPropDst.mode_ = WindowMode::WINDOW_MODE_UNDEFINED;
182 winPropDst.ResumeLastWindowMode();
183 ASSERT_EQ(WindowMode::WINDOW_MODE_PIP, winPropDst.mode_);
184
185 winPropDst.modeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_SECONDARY;
186 winPropDst.lastMode_ = WindowMode::WINDOW_MODE_PIP;
187 winPropDst.mode_ = WindowMode::WINDOW_MODE_UNDEFINED;
188 winPropDst.ResumeLastWindowMode();
189 ASSERT_EQ(WindowMode::WINDOW_MODE_UNDEFINED, winPropDst.mode_);
190
191 winPropDst.modeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_FLOATING;
192 winPropDst.lastMode_ = WindowMode::WINDOW_MODE_PIP;
193 winPropDst.mode_ = WindowMode::WINDOW_MODE_UNDEFINED;
194 winPropDst.ResumeLastWindowMode();
195 ASSERT_EQ(WindowMode::WINDOW_MODE_FLOATING, winPropDst.mode_);
196 }
197
198 /**
199 * @tc.name: HandleComputeTransform
200 * @tc.desc: HandleComputeTransform test
201 * @tc.type: FUNC
202 */
203 HWTEST_F(WindowPropertyTest, HandleComputeTransform, Function | SmallTest | Level2)
204 {
205 WindowProperty winPropSrc;
206 winPropSrc.SetPrivacyMode(true);
207 winPropSrc.SetTransparent(true);
208 int resultValue = 0;
__anone8ca6a420202() 209 std::function<void()> func = [&]() {
210 winPropSrc.HandleComputeTransform(Transform::Identity());
211 resultValue = 1;
212 };
213 func();
214 ASSERT_EQ(resultValue, 1);
215 }
216
217 /**
218 * @tc.name: ComputeTransform
219 * @tc.desc: ComputeTransform test
220 * @tc.type: FUNC
221 */
222 HWTEST_F(WindowPropertyTest, ComputeTransform, Function | SmallTest | Level2)
223 {
224 WindowProperty winPropSrc;
225 winPropSrc.SetPrivacyMode(true);
226 winPropSrc.SetTransparent(true);
227 int resultValue = 0;
__anone8ca6a420302() 228 std::function<void()> func = [&]() {
229 winPropSrc.ComputeTransform();
230 resultValue = 1;
231 };
232 func();
233 ASSERT_EQ(resultValue, 1);
234 }
235
236 /**
237 * @tc.name: SetZoomTransform
238 * @tc.desc: SetZoomTransform test
239 * @tc.type: FUNC
240 */
241 HWTEST_F(WindowPropertyTest, SetZoomTransform, Function | SmallTest | Level2)
242 {
243 WindowProperty winPropSrc;
244 winPropSrc.SetPrivacyMode(true);
245 winPropSrc.SetTransparent(true);
246 int resultValue = 0;
__anone8ca6a420402() 247 std::function<void()> func = [&]() {
248 winPropSrc.SetZoomTransform(Transform::Identity());
249 resultValue = 1;
250 };
251 func();
252 ASSERT_EQ(resultValue, 1);
253 }
254
255 /**
256 * @tc.name: ClearTransformZAxisOffset
257 * @tc.desc: ClearTransformZAxisOffset test
258 * @tc.type: FUNC
259 */
260 HWTEST_F(WindowPropertyTest, ClearTransformZAxisOffset, Function | SmallTest | Level2)
261 {
262 WindowProperty winPropSrc;
263 winPropSrc.SetPrivacyMode(true);
264 winPropSrc.SetTransparent(true);
265 Transform trans;
266 int resultValue = 0;
__anone8ca6a420502() 267 std::function<void()> func = [&]() {
268 winPropSrc.ClearTransformZAxisOffset(trans);
269 resultValue = 1;
270 };
271 func();
272 ASSERT_EQ(resultValue, 1);
273 }
274
275 /**
276 * @tc.name: UpdatePointerEvent
277 * @tc.desc: UpdatePointerEvent test
278 * @tc.type: FUNC
279 */
280 HWTEST_F(WindowPropertyTest, UpdatePointerEvent, Function | SmallTest | Level2)
281 {
282 WindowProperty winPropSrc;
283 winPropSrc.SetPrivacyMode(true);
284 winPropSrc.SetTransparent(true);
285 std::shared_ptr<MMI::PointerEvent> pointerEvent;
286 int resultValue = 0;
__anone8ca6a420602() 287 std::function<void()> func = [&]() {
288 winPropSrc.UpdatePointerEvent(pointerEvent);
289 resultValue = 1;
290 };
291 func();
292 ASSERT_EQ(resultValue, 1);
293 }
294
295 /**
296 * @tc.name: isNeedComputerTransform
297 * @tc.desc: isNeedComputerTransform test
298 * @tc.type: FUNC
299 */
300 HWTEST_F(WindowPropertyTest, isNeedComputerTransform, Function | SmallTest | Level2)
301 {
302 WindowProperty winPropSrc;
303 winPropSrc.SetPrivacyMode(true);
304 winPropSrc.SetTransparent(true);
305 bool ret = winPropSrc.isNeedComputerTransform();
306 ASSERT_EQ(false, ret);
307 }
308
309 /**
310 * @tc.name: SetAnimateWindowFlag
311 * @tc.desc: SetAnimateWindowFlag test
312 * @tc.type: FUNC
313 */
314 HWTEST_F(WindowPropertyTest, SetAnimateWindowFlag, Function | SmallTest | Level2)
315 {
316 WindowProperty winPropSrc;
317 winPropSrc.SetPrivacyMode(true);
318 winPropSrc.SetTransparent(true);
319 bool isAnimateWindow = false;
320 int resultValue = 0;
__anone8ca6a420702() 321 std::function<void()> func = [&]() {
322 winPropSrc.SetAnimateWindowFlag(isAnimateWindow);
323 resultValue = 1;
324 };
325 func();
326 ASSERT_EQ(resultValue, 1);
327 }
328
329 /**
330 * @tc.name: IsDisplayZoomOn
331 * @tc.desc: IsDisplayZoomOn test
332 * @tc.type: FUNC
333 */
334 HWTEST_F(WindowPropertyTest, IsDisplayZoomOn, Function | SmallTest | Level2)
335 {
336 WindowProperty winPropSrc;
337 winPropSrc.SetPrivacyMode(true);
338 winPropSrc.SetTransparent(true);
339 bool ret = winPropSrc.IsDisplayZoomOn();
340 ASSERT_EQ(false, ret);
341 }
342
343 /**
344 * @tc.name: IsAnimateWindow
345 * @tc.desc: IsAnimateWindow test
346 * @tc.type: FUNC
347 */
348 HWTEST_F(WindowPropertyTest, IsAnimateWindow, Function | SmallTest | Level2)
349 {
350 WindowProperty winPropSrc;
351 winPropSrc.SetPrivacyMode(true);
352 winPropSrc.SetTransparent(true);
353 bool ret = winPropSrc.IsAnimateWindow();
354 ASSERT_EQ(false, ret);
355 }
356
357 /**
358 * @tc.name: SetSizeLimits
359 * @tc.desc: SetSizeLimits test
360 * @tc.type: FUNC
361 */
362 HWTEST_F(WindowPropertyTest, SetSizeLimits, Function | SmallTest | Level2)
363 {
364 WindowProperty winPropSrc;
365 winPropSrc.SetPrivacyMode(true);
366 winPropSrc.SetTransparent(true);
367 WindowSizeLimits sizeLimits;
368 int resultValue = 0;
__anone8ca6a420802() 369 std::function<void()> func = [&]() {
370 winPropSrc.SetSizeLimits(sizeLimits);
371 resultValue = 1;
372 };
373 func();
374 ASSERT_EQ(resultValue, 1);
375 }
376
377 /**
378 * @tc.name: SetUpdatedSizeLimits
379 * @tc.desc: SetUpdatedSizeLimits test
380 * @tc.type: FUNC
381 */
382 HWTEST_F(WindowPropertyTest, SetUpdatedSizeLimits, Function | SmallTest | Level2)
383 {
384 WindowProperty winPropSrc;
385 winPropSrc.SetPrivacyMode(true);
386 winPropSrc.SetTransparent(true);
387 WindowSizeLimits sizeLimits;
388 int resultValue = 0;
__anone8ca6a420902() 389 std::function<void()> func = [&]() {
390 winPropSrc.SetUpdatedSizeLimits(sizeLimits);
391 resultValue = 1;
392 };
393 func();
394 ASSERT_EQ(resultValue, 1);
395 }
396
397 /**
398 * @tc.name: SetDecorEnable
399 * @tc.desc: SetDecorEnable test
400 * @tc.type: FUNC
401 */
402 HWTEST_F(WindowPropertyTest, SetDecorEnable, Function | SmallTest | Level2)
403 {
404 WindowProperty winPropSrc;
405 winPropSrc.SetPrivacyMode(true);
406 winPropSrc.SetTransparent(true);
407 bool decorEnable = false;
408 int resultValue = 0;
__anone8ca6a420a02() 409 std::function<void()> func = [&]() {
410 winPropSrc.SetDecorEnable(decorEnable);
411 resultValue = 1;
412 };
413 func();
414 ASSERT_EQ(resultValue, 1);
415 }
416 }
417 } // namespace Rosen
418 } // namespace OHOS