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 "window_session_property.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 namespace Rosen {
24
25 class WindowSessionPropertyTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 };
30
SetUpTestCase()31 void WindowSessionPropertyTest::SetUpTestCase()
32 {
33 }
34
TearDownTestCase()35 void WindowSessionPropertyTest::TearDownTestCase()
36 {
37 }
38
39 namespace {
40 /**
41 * @tc.name: SetDragEnabled001
42 * @tc.desc: SetDragEnabled and GetDragEnabled to check the value
43 * @tc.type: FUNC
44 */
45 HWTEST_F(WindowSessionPropertyTest, SetDragEnabled001, Function | SmallTest | Level2)
46 {
47 WindowSessionProperty *property = new WindowSessionProperty();
48 ASSERT_EQ(property->GetDragEnabled(), true);
49 property->SetDragEnabled(false);
50 ASSERT_EQ(property->GetDragEnabled(), false);
51 }
52
53 /**
54 * @tc.name: SetRaiseEnabled001
55 * @tc.desc: SetRaiseEnabled and GetRaiseEnabled to check the value
56 * @tc.type: FUNC
57 */
58 HWTEST_F(WindowSessionPropertyTest, SetRaiseEnabled001, Function | SmallTest | Level2)
59 {
60 WindowSessionProperty *property = new WindowSessionProperty();
61 ASSERT_EQ(property->GetRaiseEnabled(), true);
62 property->SetRaiseEnabled(false);
63 ASSERT_EQ(property->GetRaiseEnabled(), false);
64 }
65
66 /**
67 * @tc.name: WindowSessionProperty
68 * @tc.desc: WindowSessionProperty
69 * @tc.type: FUNC
70 */
71 HWTEST_F(WindowSessionPropertyTest, WindowSessionProperty, Function | SmallTest | Level2)
72 {
73 const sptr<WindowSessionProperty> property = new WindowSessionProperty();
74 ASSERT_EQ(property->GetDragEnabled(), true);
75 }
76
77 /**
78 * @tc.name: SetSessionInfo
79 * @tc.desc: SetSessionInfo
80 * @tc.type: FUNC
81 */
82 HWTEST_F(WindowSessionPropertyTest, SetSessionInfo, Function | SmallTest | Level2)
83 {
84 SessionInfo *info = new SessionInfo();
85 WindowSessionProperty *property = new WindowSessionProperty();
86 property->SetSessionInfo(*info);
87 ASSERT_EQ(property->GetRaiseEnabled(), true);
88 }
89 /**
90 * @tc.name: SetRequestedOrientation
91 * @tc.desc: SetRequestedOrientation test
92 * @tc.type: FUNC
93 */
94 HWTEST_F(WindowSessionPropertyTest, SetRequestedOrientation, Function | SmallTest | Level2)
95 {
96 Orientation orientation = Orientation::REVERSE_HORIZONTAL;
97 WindowSessionProperty *property = new WindowSessionProperty();
98 property->SetRequestedOrientation(orientation);
99 Orientation ret = property->GetRequestedOrientation();
100 ASSERT_EQ(ret, orientation);
101
102 property->SetRequestedOrientation(Orientation::AUTO_ROTATION_UNSPECIFIED);
103 Orientation ret1 = property->GetRequestedOrientation();
104 ASSERT_EQ(ret1, Orientation::AUTO_ROTATION_UNSPECIFIED);
105
106 property->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
107 Orientation ret2 = property->GetRequestedOrientation();
108 ASSERT_EQ(ret2, Orientation::USER_ROTATION_PORTRAIT);
109
110 property->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE);
111 Orientation ret3 = property->GetRequestedOrientation();
112 ASSERT_EQ(ret3, Orientation::USER_ROTATION_LANDSCAPE);
113
114 property->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED);
115 Orientation ret4 = property->GetRequestedOrientation();
116 ASSERT_EQ(ret4, Orientation::USER_ROTATION_PORTRAIT_INVERTED);
117
118 property->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
119 Orientation ret5 = property->GetRequestedOrientation();
120 ASSERT_EQ(ret5, Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
121
122 property->SetRequestedOrientation(Orientation::FOLLOW_DESKTOP);
123 Orientation ret6 = property->GetRequestedOrientation();
124 ASSERT_EQ(ret6, Orientation::FOLLOW_DESKTOP);
125 }
126
127 /**
128 * @tc.name: SetPrivacyMode
129 * @tc.desc: SetPrivacyMode test
130 * @tc.type: FUNC
131 */
132 HWTEST_F(WindowSessionPropertyTest, SetPrivacyMode, Function | SmallTest | Level2)
133 {
134 WindowSessionProperty *property = new WindowSessionProperty();
135 ASSERT_EQ(property->GetPrivacyMode(), false);
136 property->SetPrivacyMode(false);
137 ASSERT_EQ(property->GetPrivacyMode(), false);
138 }
139
140 /**
141 * @tc.name: SetSystemPrivacyMode
142 * @tc.desc: SetSystemPrivacyMode test
143 * @tc.type: FUNC
144 */
145 HWTEST_F(WindowSessionPropertyTest, SetSystemPrivacyMode, Function | SmallTest | Level2)
146 {
147 WindowSessionProperty *property = new WindowSessionProperty();
148 ASSERT_EQ(property->GetSystemPrivacyMode(), false);
149 }
150
151 /**
152 * @tc.name: SetBrightness
153 * @tc.desc: SetBrightness test
154 * @tc.type: FUNC
155 */
156 HWTEST_F(WindowSessionPropertyTest, SetBrightness, Function | SmallTest | Level2)
157 {
158 float brightness = 0.02;
159 WindowSessionProperty windowSessionProperty;
160 windowSessionProperty.SetBrightness(brightness);
161 WindowSessionProperty *property = new WindowSessionProperty();
162 ASSERT_NE(property->GetBrightness(), 0);
163 }
164
165 /**
166 * @tc.name: SetTopmost
167 * @tc.desc: SetTopmost test
168 * @tc.type: FUNC
169 */
170 HWTEST_F(WindowSessionPropertyTest, SetTopmost, Function | SmallTest | Level2)
171 {
172 bool topmost = true;
173 WindowSessionProperty windowSessionProperty;
174 windowSessionProperty.SetTopmost(topmost);
175 ASSERT_TRUE(windowSessionProperty.IsTopmost());
176 }
177
178 /**
179 * @tc.name: GetParentId
180 * @tc.desc: GetParentId test
181 * @tc.type: FUNC
182 */
183 HWTEST_F(WindowSessionPropertyTest, GetParentId, Function | SmallTest | Level2)
184 {
185 WindowSessionProperty windowSessionProperty;
186 int32_t result = windowSessionProperty.GetParentId();
187 ASSERT_EQ(0, result);
188 }
189
190 /**
191 * @tc.name: SetWindowFlags
192 * @tc.desc: SetWindowFlags test
193 * @tc.type: FUNC
194 */
195 HWTEST_F(WindowSessionPropertyTest, SetWindowFlags, Function | SmallTest | Level2)
196 {
197 WindowSessionProperty *property = new WindowSessionProperty();
198 ASSERT_EQ(property->GetWindowFlags(), 0);
199 }
200
201 /**
202 * @tc.name: SetAndGetPipTemplateInfo
203 * @tc.desc: SetAndGetPipTemplateInfo test
204 * @tc.type: FUNC
205 */
206 HWTEST_F(WindowSessionPropertyTest, SetAndGetPipTemplateInfo, Function | SmallTest | Level2)
207 {
208 WindowSessionProperty *property = new WindowSessionProperty();
209 PiPTemplateInfo pipTemplateInfo;
210 pipTemplateInfo.pipTemplateType = static_cast<uint32_t>(PiPTemplateType::VIDEO_CALL);
211 property->SetPiPTemplateInfo(pipTemplateInfo);
212 ASSERT_EQ(property->GetPiPTemplateInfo().pipTemplateType,
213 static_cast<uint32_t>(PiPTemplateType::VIDEO_CALL));
214 }
215
216 /**
217 * @tc.name: SetAndGetRealParentId
218 * @tc.desc: SetRealParentId and GetRealParentId test
219 * @tc.type: FUNC
220 */
221 HWTEST_F(WindowSessionPropertyTest, SetAndGetRealParentId, Function | SmallTest | Level2)
222 {
223 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
224 ASSERT_NE(property, nullptr);
225 property->SetRealParentId(1919);
226 EXPECT_EQ(1919, property->GetRealParentId());
227 property->SetRealParentId(810);
228 EXPECT_EQ(810, property->GetRealParentId());
229 }
230
231 /**
232 * @tc.name: SetAndGetUIExtensionUsage
233 * @tc.desc: SetUIExtensionUsage and GetUIExtensionUsage test
234 * @tc.type: FUNC
235 */
236 HWTEST_F(WindowSessionPropertyTest, SetAndGetUIExtensionUsage, Function | SmallTest | Level2)
237 {
238 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
239 ASSERT_NE(property, nullptr);
240 property->SetUIExtensionUsage(UIExtensionUsage::MODAL);
241 EXPECT_EQ(UIExtensionUsage::MODAL, property->GetUIExtensionUsage());
242 property->SetUIExtensionUsage(UIExtensionUsage::EMBEDDED);
243 EXPECT_EQ(UIExtensionUsage::EMBEDDED, property->GetUIExtensionUsage());
244 }
245
246 /**
247 * @tc.name: SetParentWindowType
248 * @tc.desc: SetParentWindowType and GetParentWindowType test
249 * @tc.type: FUNC
250 */
251 HWTEST_F(WindowSessionPropertyTest, SetParentWindowType, Function | SmallTest | Level2)
252 {
253 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
254 ASSERT_NE(property, nullptr);
255 property->SetParentWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
256 EXPECT_EQ(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, property->GetParentWindowType());
257 property->SetParentWindowType(WindowType::WINDOW_TYPE_TOAST);
258 EXPECT_EQ(WindowType::WINDOW_TYPE_TOAST, property->GetParentWindowType());
259 }
260
261 /**
262 * @tc.name: AddWindowFlag
263 * @tc.desc: AddWindowFlag test
264 * @tc.type: FUNC
265 */
266 HWTEST_F(WindowSessionPropertyTest, AddWindowFlag, Function | SmallTest | Level2)
267 {
268 WindowFlag flags=WindowFlag();
269 WindowSessionProperty windowSessionProperty;
270 windowSessionProperty.AddWindowFlag(flags);
271 WindowSessionProperty *property = new WindowSessionProperty();
272 ASSERT_EQ(property->GetWindowFlags(), false);
273 }
274
275 /**
276 * @tc.name: IsTurnScreenOn
277 * @tc.desc: IsTurnScreenOn test
278 * @tc.type: FUNC
279 */
280 HWTEST_F(WindowSessionPropertyTest, IsTurnScreenOn, Function | SmallTest | Level2)
281 {
282 WindowSessionProperty windowSessionProperty;
283 bool result = windowSessionProperty.IsTurnScreenOn();
284 ASSERT_EQ(false, result);
285 }
286
287 /**
288 * @tc.name: IsKeepScreenOn
289 * @tc.desc: IsKeepScreenOn test
290 * @tc.type: FUNC
291 */
292 HWTEST_F(WindowSessionPropertyTest, IsKeepScreenOn, Function | SmallTest | Level2)
293 {
294 WindowSessionProperty windowSessionProperty;
295 bool result = windowSessionProperty.IsKeepScreenOn();
296 ASSERT_EQ(false, result);
297 }
298
299 /**
300 * @tc.name: GetAccessTokenId
301 * @tc.desc: GetAccessTokenId test
302 * @tc.type: FUNC
303 */
304 HWTEST_F(WindowSessionPropertyTest, GetAccessTokenId, Function | SmallTest | Level2)
305 {
306 WindowSessionProperty windowSessionProperty;
307 auto result = windowSessionProperty.GetAccessTokenId();
308 ASSERT_EQ(false, result);
309 }
310
311 /**
312 * @tc.name: SetTokenState
313 * @tc.desc: SetTokenState test
314 * @tc.type: FUNC
315 */
316 HWTEST_F(WindowSessionPropertyTest, SetTokenState, Function | SmallTest | Level2)
317 {
318 WindowSessionProperty *property = new WindowSessionProperty();
319 ASSERT_EQ(property->GetTokenState(), false);
320 }
321
322 /**
323 * @tc.name: SetMaximizeMode
324 * @tc.desc: SetMaximizeMode test
325 * @tc.type: FUNC
326 */
327 HWTEST_F(WindowSessionPropertyTest, SetMaximizeMode, Function | SmallTest | Level2)
328 {
329 WindowSessionProperty windowSessionProperty;
330 MaximizeMode mode = MaximizeMode::MODE_RECOVER;
331 windowSessionProperty.SetMaximizeMode(mode);
332 WindowSessionProperty *property = new WindowSessionProperty();
333 ASSERT_EQ(property->GetMaximizeMode(), mode);
334 }
335
336 /**
337 * @tc.name: SetSystemBarProperty
338 * @tc.desc: SetSystemBarProperty test
339 * @tc.type: FUNC
340 */
341 HWTEST_F(WindowSessionPropertyTest, SetSystemBarProperty, Function | SmallTest | Level2)
342 {
343 SystemBarProperty *systemBarProperty = new SystemBarProperty();
344 WindowType windowtype = WindowType::APP_WINDOW_BASE;
345 WindowSessionProperty windowSessionProperty;
346 windowSessionProperty.SetSystemBarProperty(windowtype, *systemBarProperty);
347 WindowSessionProperty *property = new WindowSessionProperty();
348 ASSERT_EQ(property->GetTokenState(), false);
349 }
350
351 /**
352 * @tc.name: SetKeyboardSessionGravity
353 * @tc.desc: SetKeyboardSessionGravity test
354 * @tc.type: FUNC
355 */
356 HWTEST_F(WindowSessionPropertyTest, SetKeyboardSessionGravity, Function | SmallTest | Level2)
357 {
358 SessionGravity sessionGravity = SessionGravity::SESSION_GRAVITY_FLOAT;
359 uint32_t percent = 1234567890;
360 WindowSessionProperty windowSessionProperty;
361 windowSessionProperty.SetKeyboardSessionGravity(sessionGravity, percent);
362 WindowSessionProperty *property = new WindowSessionProperty();
363 ASSERT_EQ(property->GetTokenState(), false);
364 }
365
366
367 /**
368 * @tc.name: IsDecorEnable
369 * @tc.desc: IsDecorEnable test
370 * @tc.type: FUNC
371 */
372 HWTEST_F(WindowSessionPropertyTest, IsDecorEnable, Function | SmallTest | Level2)
373 {
374 WindowSessionProperty windowSessionProperty;
375 auto result = windowSessionProperty.IsDecorEnable();
376 ASSERT_EQ(false, result);
377 }
378
379 /**
380 * @tc.name: SetModeSupportInfo
381 * @tc.desc: SetModeSupportInfo test
382 * @tc.type: FUNC
383 */
384 HWTEST_F(WindowSessionPropertyTest, SetModeSupportInfo, Function | SmallTest | Level2)
385 {
386 uint32_t modeSupportInfo = 1234567890;
387 WindowSessionProperty windowSessionProperty;
388 windowSessionProperty.SetModeSupportInfo(modeSupportInfo);
389 WindowSessionProperty *property = new WindowSessionProperty();
390 ASSERT_NE(property->GetModeSupportInfo(), 0);
391 }
392 /**
393 * @tc.name: IsFloatingWindowAppType
394 * @tc.desc: IsFloatingWindowAppType test
395 * @tc.type: FUNC
396 */
397 HWTEST_F(WindowSessionPropertyTest, IsFloatingWindowAppType, Function | SmallTest | Level2)
398 {
399 WindowSessionProperty windowSessionProperty;
400 auto result = windowSessionProperty.IsFloatingWindowAppType();
401 ASSERT_EQ(false, result);
402 }
403
404 /**
405 * @tc.name: SetTouchHotAreas
406 * @tc.desc: SetTouchHotAreas test
407 * @tc.type: FUNC
408 */
409 HWTEST_F(WindowSessionPropertyTest, SetTouchHotAreas, Function | SmallTest | Level2)
410 {
411 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
412 EXPECT_NE(nullptr, property);
413 Rect rect { 4, 4, 4, 4 };
414 std::vector<Rect> vRect { rect };
415 property->SetPersistentId(0);
416 property->SetSessionPropertyChangeCallback(nullptr);
417 EXPECT_EQ(nullptr, property->touchHotAreasChangeCallback_);
418 property->SetTouchHotAreas(vRect);
419
__anon62feaa380202()420 auto func = [](){};
421 property->SetPersistentId(1);
422 property->SetSessionPropertyChangeCallback(func);
423 property->SetTouchHotAreas(vRect);
424 EXPECT_NE(nullptr, property->touchHotAreasChangeCallback_);
425
426 Rect rect1 { 5, 5, 5, 5 };
427 vRect.emplace_back(rect1);
428 property->SetTouchHotAreas(vRect);
429 }
430
431 /**
432 * @tc.name: UnmarshallingWindowLimits
433 * @tc.desc: UnmarshallingWindowLimits test
434 * @tc.type: FUNC
435 */
436 HWTEST_F(WindowSessionPropertyTest, UnmarshallingWindowLimits, Function | SmallTest | Level2)
437 {
438 Parcel parcel = Parcel();
439 WindowSessionProperty *property = new WindowSessionProperty();
440 WindowSessionProperty windowSessionProperty;
441 windowSessionProperty.UnmarshallingWindowLimits(parcel, property);
442 ASSERT_EQ(property->GetTokenState(), false);
443 }
444
445 /**
446 * @tc.name: UnMarshallingSystemBarMap
447 * @tc.desc: UnMarshallingSystemBarMap test
448 * @tc.type: FUNC
449 */
450 HWTEST_F(WindowSessionPropertyTest, UnMarshallingSystemBarMap, Function | SmallTest | Level2)
451 {
452 Parcel parcel = Parcel();
453 WindowSessionProperty *property = new WindowSessionProperty();
454 WindowSessionProperty windowSessionProperty;
455 windowSessionProperty.UnMarshallingSystemBarMap(parcel, property);
456 ASSERT_EQ(property->GetTokenState(), false);
457 }
458
459 /**
460 * @tc.name: UnmarshallingTouchHotAreas
461 * @tc.desc: UnmarshallingTouchHotAreas test
462 * @tc.type: FUNC
463 */
464 HWTEST_F(WindowSessionPropertyTest, UnmarshallingTouchHotAreas, Function | SmallTest | Level2)
465 {
466 Parcel parcel = Parcel();
467 WindowSessionProperty *property = new WindowSessionProperty();
468 WindowSessionProperty windowSessionProperty;
469 windowSessionProperty.UnmarshallingTouchHotAreas(parcel, property);
470 ASSERT_EQ(property->GetTokenState(), false);
471 }
472
473 /**
474 * @tc.name: UnmarshallingPiPTemplateInfo
475 * @tc.desc: UnmarshallingPiPTemplateInfo test
476 * @tc.type: FUNC
477 */
478 HWTEST_F(WindowSessionPropertyTest, UnmarshallingPiPTemplateInfo, Function | SmallTest | Level2)
479 {
480 Parcel parcel = Parcel();
481 WindowSessionProperty *property = new WindowSessionProperty();
482 EXPECT_NE(nullptr, property);
483 property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
484 EXPECT_EQ(WindowType::WINDOW_TYPE_PIP, property->GetWindowType());
485 property->UnmarshallingPiPTemplateInfo(parcel, property);
486 delete property;
487 }
488
489 /**
490 * @tc.name: CopyFrom
491 * @tc.desc: CopyFrom test
492 * @tc.type: FUNC
493 */
494 HWTEST_F(WindowSessionPropertyTest, CopyFrom, Function | SmallTest | Level2)
495 {
496 sptr<WindowSessionProperty> property = new WindowSessionProperty();
497 WindowSessionProperty windowSessionProperty;
498 windowSessionProperty.CopyFrom(property);
499 WindowSessionProperty *wproperty = new WindowSessionProperty();
500 ASSERT_EQ(wproperty->GetTokenState(), false);
501 }
502
503 /**
504 * @tc.name: SetFocusable
505 * @tc.desc: SetFocusable and GetFocusable to check the value
506 * @tc.type: FUNC
507 */
508 HWTEST_F(WindowSessionPropertyTest, SetFocusable, Function | SmallTest | Level2)
509 {
510 sptr<WindowSessionProperty> property = new WindowSessionProperty();
511 ASSERT_NE(nullptr, property);
512 ASSERT_EQ(property->GetFocusable(), true);
513 property->SetFocusable(false);
514 ASSERT_EQ(property->GetFocusable(), false);
515 }
516
517 /**
518 * @tc.name: SetTouchable
519 * @tc.desc: SetTouchable and GetTouchable to check the value
520 * @tc.type: FUNC
521 */
522 HWTEST_F(WindowSessionPropertyTest, SetTouchable, Function | SmallTest | Level2)
523 {
524 sptr<WindowSessionProperty> property = new WindowSessionProperty();
525 ASSERT_NE(nullptr, property);
526 ASSERT_EQ(property->GetTouchable(), true);
527 property->SetTouchable(false);
528 ASSERT_EQ(property->GetTouchable(), false);
529 }
530
531 /**
532 * @tc.name: SetForceHide
533 * @tc.desc: SetForceHide and GetForceHide to check the value
534 * @tc.type: FUNC
535 */
536 HWTEST_F(WindowSessionPropertyTest, SetForceHide, Function | SmallTest | Level2)
537 {
538 sptr<WindowSessionProperty> property = new WindowSessionProperty();
539 ASSERT_NE(nullptr, property);
540 ASSERT_EQ(property->GetForceHide(), false);
541 property->SetForceHide(true);
542 ASSERT_EQ(property->GetForceHide(), true);
543 }
544
545 /**
546 * @tc.name: SetSystemCalling
547 * @tc.desc: SetSystemCalling and GetSystemCalling to check the value
548 * @tc.type: FUNC
549 */
550 HWTEST_F(WindowSessionPropertyTest, SetSystemCalling, Function | SmallTest | Level2)
551 {
552 sptr<WindowSessionProperty> property = new WindowSessionProperty();
553 ASSERT_NE(nullptr, property);
554 ASSERT_EQ(property->GetSystemCalling(), false);
555 property->SetSystemCalling(true);
556 ASSERT_EQ(property->GetSystemCalling(), true);
557 }
558
559 /**
560 * @tc.name: SetIsNeedUpdateWindowMode
561 * @tc.desc: SetIsNeedUpdateWindowMode and GetIsNeedUpdateWindowMode to check the value
562 * @tc.type: FUNC
563 */
564 HWTEST_F(WindowSessionPropertyTest, SetIsNeedUpdateWindowMode, Function | SmallTest | Level2)
565 {
566 sptr<WindowSessionProperty> property = new WindowSessionProperty();
567 ASSERT_NE(nullptr, property);
568 ASSERT_EQ(property->GetIsNeedUpdateWindowMode(), false);
569 property->SetIsNeedUpdateWindowMode(true);
570 ASSERT_EQ(property->GetIsNeedUpdateWindowMode(), true);
571 }
572
573 /**
574 * @tc.name: SetIsShaped
575 * @tc.desc: SetIsShaped and GetIsShaped to check the value
576 * @tc.type: FUNC
577 */
578 HWTEST_F(WindowSessionPropertyTest, SetIsShaped, Function | SmallTest | Level2)
579 {
580 sptr<WindowSessionProperty> property = new WindowSessionProperty();
581 ASSERT_NE(nullptr, property);
582 ASSERT_EQ(property->GetIsShaped(), false);
583 property->SetIsShaped(true);
584 ASSERT_EQ(property->GetIsShaped(), true);
585 }
586
587 /**
588 * @tc.name: SetHideNonSystemFloatingWindows
589 * @tc.desc: SetHideNonSystemFloatingWindows and GetHideNonSystemFloatingWindows to check the value
590 * @tc.type: FUNC
591 */
592 HWTEST_F(WindowSessionPropertyTest, SetHideNonSystemFloatingWindows, Function | SmallTest | Level2)
593 {
594 sptr<WindowSessionProperty> property = new WindowSessionProperty();
595 ASSERT_NE(nullptr, property);
596 ASSERT_EQ(property->GetHideNonSystemFloatingWindows(), false);
597 property->SetHideNonSystemFloatingWindows(true);
598 ASSERT_EQ(property->GetHideNonSystemFloatingWindows(), true);
599 }
600
601 /**
602 * @tc.name: KeepKeyboardOnFocus
603 * @tc.desc: KeepKeyboardOnFocus and GetKeepKeyboardFlag to check the value
604 * @tc.type: FUNC
605 */
606 HWTEST_F(WindowSessionPropertyTest, KeepKeyboardOnFocus, Function | SmallTest | Level2)
607 {
608 sptr<WindowSessionProperty> property = new WindowSessionProperty();
609 ASSERT_NE(nullptr, property);
610 ASSERT_EQ(property->GetKeepKeyboardFlag(), false);
611 property->KeepKeyboardOnFocus(true);
612 ASSERT_EQ(property->GetKeepKeyboardFlag(), true);
613 }
614
615 /**
616 * @tc.name: SetTextFieldPositionY
617 * @tc.desc: SetTextFieldPositionY and GetTextFieldPositionY to check the value
618 * @tc.type: FUNC
619 */
620 HWTEST_F(WindowSessionPropertyTest, SetTextFieldPositionY, Function | SmallTest | Level2)
621 {
622 sptr<WindowSessionProperty> property = new WindowSessionProperty();
623 ASSERT_NE(nullptr, property);
624 property->SetTextFieldPositionY(5.5);
625 ASSERT_EQ(property->GetTextFieldPositionY(), 5.5);
626 }
627
628 /**
629 * @tc.name: SetTextFieldHeight
630 * @tc.desc: SetTextFieldHeight and GetTextFieldHeight to check the value
631 * @tc.type: FUNC
632 */
633 HWTEST_F(WindowSessionPropertyTest, SetTextFieldHeight, Function | SmallTest | Level2)
634 {
635 sptr<WindowSessionProperty> property = new WindowSessionProperty();
636 ASSERT_NE(nullptr, property);
637 property->SetTextFieldHeight(5.5);
638 ASSERT_EQ(property->GetTextFieldHeight(), 5.5);
639 }
640
641 /**
642 * @tc.name: SetIsLayoutFullScreen
643 * @tc.desc: SetIsLayoutFullScreen and IsLayoutFullScreen to check the value
644 * @tc.type: FUNC
645 */
646 HWTEST_F(WindowSessionPropertyTest, SetIsLayoutFullScreen, Function | SmallTest | Level2)
647 {
648 sptr<WindowSessionProperty> property = new WindowSessionProperty();
649 ASSERT_NE(nullptr, property);
650 ASSERT_EQ(property->IsLayoutFullScreen(), false);
651 property->SetIsLayoutFullScreen(true);
652 ASSERT_EQ(property->IsLayoutFullScreen(), true);
653 }
654
655 /**
656 * @tc.name: Read
657 * @tc.desc: Read test
658 * @tc.type: FUNC
659 */
660 HWTEST_F(WindowSessionPropertyTest, Read, Function | SmallTest | Level2)
661 {
662 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
663 if (property != nullptr) {
664 Parcel parcel = Parcel();
665 property->Read(parcel, WSPropertyChangeAction::ACTION_UPDATE_MODE);
666 ASSERT_EQ(property->GetPersistentId(), INVALID_SESSION_ID);
667 delete property;
668 }
669 }
670
671 /**
672 * @tc.name: Write
673 * @tc.desc: Write and Read to check the value
674 * @tc.type: FUNC
675 */
676 HWTEST_F(WindowSessionPropertyTest, Write, Function | SmallTest | Level2)
677 {
678 WindowSessionProperty *oldProperty = new (std::nothrow) WindowSessionProperty();
679 WindowSessionProperty *newProperty = new (std::nothrow) WindowSessionProperty();
680 if ((oldProperty != nullptr) && (newProperty != nullptr)) {
681 int32_t persistentId = 2;
682 oldProperty->SetPersistentId(persistentId);
683 oldProperty->SetFocusable(true);
684 Parcel parcel = Parcel();
685 oldProperty->Write(parcel, WSPropertyChangeAction::ACTION_UPDATE_FOCUSABLE);
686
687 newProperty->Read(parcel, WSPropertyChangeAction::ACTION_UPDATE_FOCUSABLE);
688 ASSERT_EQ(newProperty->GetPersistentId(), persistentId);
689 ASSERT_EQ(newProperty->GetFocusable(), true);
690 delete oldProperty;
691 delete newProperty;
692 }
693 }
694
695 /**
696 * @tc.name: GetWindowName
697 * @tc.desc: GetWindowName
698 * @tc.type: FUNC
699 */
700 HWTEST_F(WindowSessionPropertyTest, GetWindowName, Function | SmallTest | Level2)
701 {
702 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
703 if (property == nullptr) {
704 return;
705 }
706 std::string name = "test";
707 property->SetWindowName(name);
708 auto result = property->GetWindowName();
709 ASSERT_EQ(result, name);
710 delete property;
711 }
712
713 /**
714 * @tc.name: GetSessionInfo
715 * @tc.desc: GetSessionInfo
716 * @tc.type: FUNC
717 */
718 HWTEST_F(WindowSessionPropertyTest, GetSessionInfo, Function | SmallTest | Level2)
719 {
720 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
721 if (property == nullptr) {
722 return;
723 }
724 SessionInfo *info = new SessionInfo();
725 if (info == nullptr) {
726 return;
727 }
728 property->SetSessionInfo(*info);
729 auto result = property->GetSessionInfo();
730 ASSERT_EQ(property->GetRaiseEnabled(), true);
731 delete property;
732 }
733
734 /**
735 * @tc.name: EditSessionInfo
736 * @tc.desc: EditSessionInfo
737 * @tc.type: FUNC
738 */
739 HWTEST_F(WindowSessionPropertyTest, EditSessionInfo, Function | SmallTest | Level2)
740 {
741 std::string abilityName = "1234";
742 std::string abilityNameNew = "12345";
743 SessionInfo info;
744 info.abilityName_ = abilityName;
745 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
746 property->SetSessionInfo(info);
747 property->EditSessionInfo().abilityName_ = abilityNameNew;
748 ASSERT_EQ(property->EditSessionInfo().abilityName_, abilityNameNew);
749 }
750
751 /**
752 * @tc.name: GetWindowRect
753 * @tc.desc: GetWindowRect
754 * @tc.type: FUNC
755 */
756 HWTEST_F(WindowSessionPropertyTest, GetWindowRect, Function | SmallTest | Level2)
757 {
758 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
759 if (property == nullptr) {
760 return;
761 }
762 Rect rect = {0, 0, 0, 0};
763 property->SetWindowRect(rect);
764 auto result = property->GetWindowRect();
765 ASSERT_EQ(result, rect);
766 delete property;
767 }
768
769 /**
770 * @tc.name: GetRequestRect
771 * @tc.desc: GetRequestRect
772 * @tc.type: FUNC
773 */
774 HWTEST_F(WindowSessionPropertyTest, GetRequestRect, Function | SmallTest | Level2)
775 {
776 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
777 if (property == nullptr) {
778 return;
779 }
780 Rect requestRect = {0, 0, 0, 0};
781 property->SetWindowRect(requestRect);
782 auto result = property->GetWindowRect();
783 ASSERT_EQ(result, requestRect);
784 delete property;
785 }
786
787 /**
788 * @tc.name: GetWindowType
789 * @tc.desc: GetWindowType
790 * @tc.type: FUNC
791 */
792 HWTEST_F(WindowSessionPropertyTest, GetWindowType, Function | SmallTest | Level2)
793 {
794 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
795 if (property == nullptr) {
796 return;
797 }
798 WindowType type = WindowType::APP_WINDOW_BASE;
799 property->SetWindowType(type);
800 auto result = property->GetWindowType();
801 ASSERT_EQ(result, type);
802 delete property;
803 }
804
805 /**
806 * @tc.name: GetDisplayId
807 * @tc.desc: GetDisplayId
808 * @tc.type: FUNC
809 */
810 HWTEST_F(WindowSessionPropertyTest, GetDisplayId, Function | SmallTest | Level2)
811 {
812 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
813 if (property == nullptr) {
814 return;
815 }
816 DisplayId displayId = 1;
817 property->SetDisplayId(displayId);
818 auto result = property->GetDisplayId();
819 ASSERT_EQ(result, displayId);
820 delete property;
821 }
822
823 /**
824 * @tc.name: GetPersistentId
825 * @tc.desc: GetPersistentId
826 * @tc.type: FUNC
827 */
828 HWTEST_F(WindowSessionPropertyTest, GetPersistentId, Function | SmallTest | Level2)
829 {
830 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
831 if (property == nullptr) {
832 return;
833 }
834 int32_t persistentId = 1;
835 property->SetPersistentId(persistentId);
836 auto result = property->GetPersistentId();
837 ASSERT_EQ(result, persistentId);
838 delete property;
839 }
840
841 /**
842 * @tc.name: GetParentPersistentId
843 * @tc.desc: GetParentPersistentId
844 * @tc.type: FUNC
845 */
846 HWTEST_F(WindowSessionPropertyTest, GetParentPersistentId, Function | SmallTest | Level2)
847 {
848 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
849 if (property == nullptr) {
850 return;
851 }
852 int32_t persistentId = 1;
853 property->SetParentPersistentId(persistentId);
854 auto result = property->GetParentPersistentId();
855 ASSERT_EQ(result, persistentId);
856 delete property;
857 }
858
859 /**
860 * @tc.name: SetTurnScreenOn
861 * @tc.desc: SetTurnScreenOn
862 * @tc.type: FUNC
863 */
864 HWTEST_F(WindowSessionPropertyTest, SetTurnScreenOn, Function | SmallTest | Level2)
865 {
866 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
867 if (property == nullptr) {
868 return;
869 }
870 bool turnScreenOn = false;
871 property->SetTurnScreenOn(turnScreenOn);
872 ASSERT_EQ(property->turnScreenOn_, turnScreenOn);
873 delete property;
874 }
875
876 /**
877 * @tc.name: SetKeepScreenOn
878 * @tc.desc: SetKeepScreenOn
879 * @tc.type: FUNC
880 */
881 HWTEST_F(WindowSessionPropertyTest, SetKeepScreenOn, Function | SmallTest | Level2)
882 {
883 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
884 if (property == nullptr) {
885 return;
886 }
887 bool keepScreenOn = false;
888 property->SetKeepScreenOn(keepScreenOn);
889 ASSERT_EQ(property->keepScreenOn_, keepScreenOn);
890 delete property;
891 }
892
893 /**
894 * @tc.name: MarshallingSessionInfo
895 * @tc.desc: MarshallingSessionInfo test
896 * @tc.type: FUNC
897 */
898 HWTEST_F(WindowSessionPropertyTest, MarshallingSessionInfo, Function | SmallTest | Level2)
899 {
900 Parcel parcel;
901 SessionInfo info = { "testBundleName", "testModuleName", "testAbilityName" };
902 info.want = std::make_shared<AAFwk::Want>();
903 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
904 bool result = property->MarshallingSessionInfo(parcel);
905 ASSERT_EQ(result, true);
906 }
907
908 /**
909 * @tc.name: UnMarshallingSessionInfo
910 * @tc.desc: UnMarshallingSessionInfo test
911 * @tc.type: FUNC
912 */
913 HWTEST_F(WindowSessionPropertyTest, UnMarshallingSessionInfo, Function | SmallTest | Level2)
914 {
915 Parcel parcel;
916 WindowSessionProperty windowSessionProperty;
917 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
918 windowSessionProperty.UnmarshallingWindowLimits(parcel, property);
919 ASSERT_EQ(property->GetTokenState(), false);
920 }
921
922 /**
923 * @tc.name: SetAccessTokenId
924 * @tc.desc: SetAccessTokenId
925 * @tc.type: FUNC
926 */
927 HWTEST_F(WindowSessionPropertyTest, SetAccessTokenId, Function | SmallTest | Level2)
928 {
929 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
930 if (property == nullptr) {
931 return;
932 }
933 uint32_t accessTokenId = 1;
934 property->SetAccessTokenId(accessTokenId);
935 ASSERT_EQ(property->accessTokenId_, accessTokenId);
936 delete property;
937 }
938
939 /**
940 * @tc.name: GetWindowState
941 * @tc.desc: GetWindowState
942 * @tc.type: FUNC
943 */
944 HWTEST_F(WindowSessionPropertyTest, GetWindowState, Function | SmallTest | Level2)
945 {
946 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
947 if (property == nullptr) {
948 return;
949 }
950 WindowState state = WindowState::STATE_INITIAL;
951 property->SetWindowState(state);
952 auto result = property->GetWindowState();
953 ASSERT_EQ(result, state);
954 delete property;
955 }
956
957 /**
958 * @tc.name: SetSystemPrivacyMode02
959 * @tc.desc: SetSystemPrivacyMode
960 * @tc.type: FUNC
961 */
962 HWTEST_F(WindowSessionPropertyTest, SetSystemPrivacyMode02, Function | SmallTest | Level2)
963 {
964 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
965 if (property == nullptr) {
966 return;
967 }
968 bool isSystemPrivate = false;
969 property->SetSystemPrivacyMode(isSystemPrivate);
970 ASSERT_EQ(property->isSystemPrivacyMode_, isSystemPrivate);
971 delete property;
972 }
973
974 /**
975 * @tc.name: SetTokenState02
976 * @tc.desc: SetTokenState
977 * @tc.type: FUNC
978 */
979 HWTEST_F(WindowSessionPropertyTest, SetTokenState02, Function | SmallTest | Level2)
980 {
981 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
982 if (property == nullptr) {
983 return;
984 }
985 bool hasToken = false;
986 property->SetTokenState(hasToken);
987 ASSERT_EQ(property->tokenState_, hasToken);
988 delete property;
989 }
990
991 /**
992 * @tc.name: MarshallingTouchHotAreas
993 * @tc.desc: MarshallingTouchHotAreas test
994 * @tc.type: FUNC
995 */
996 HWTEST_F(WindowSessionPropertyTest, MarshallingTouchHotAreas, Function | SmallTest | Level2)
997 {
998 Parcel parcel = Parcel();
999 WindowSessionProperty *property = new WindowSessionProperty();
1000 if (property == nullptr) {
1001 return;
1002 }
1003 for (int i = 0; i < 55; i++) {
1004 struct Rect rect[i];
1005 property->touchHotAreas_.push_back(rect[i]);
1006 }
1007 bool result = property->MarshallingTouchHotAreas(parcel);
1008 ASSERT_EQ(result, false);
1009 delete property;
1010 }
1011
1012 /**
1013 * @tc.name: UnmarshallingPiPTemplateInfo02
1014 * @tc.desc: UnmarshallingPiPTemplateInfo test
1015 * @tc.type: FUNC
1016 */
1017 HWTEST_F(WindowSessionPropertyTest, UnmarshallingPiPTemplateInfo02, Function | SmallTest | Level2)
1018 {
1019 Parcel parcel = Parcel();
1020 WindowSessionProperty *property = new WindowSessionProperty();
1021 if (property == nullptr) {
1022 return;
1023 }
1024 property->type_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
1025 WindowSessionProperty windowSessionProperty;
1026 windowSessionProperty.UnmarshallingPiPTemplateInfo(parcel, property);
1027 ASSERT_EQ(property->GetTokenState(), false);
1028 delete property;
1029 }
1030
1031 /**
1032 * @tc.name: MarshallingPiPTemplateInfo
1033 * @tc.desc: MarshallingPiPTemplateInfo test
1034 * @tc.type: FUNC
1035 */
1036 HWTEST_F(WindowSessionPropertyTest, MarshallingPiPTemplateInfo, Function | SmallTest | Level2)
1037 {
1038 Parcel parcel = Parcel();
1039 WindowSessionProperty *property = new WindowSessionProperty();
1040 if (property == nullptr) {
1041 return;
1042 }
1043 property->type_ = WindowType::WINDOW_TYPE_PIP;
1044 for (int i = 0; i < 10; i++) {
1045 property->pipTemplateInfo_.controlGroup.push_back(i);
1046 }
1047 bool result = property->MarshallingPiPTemplateInfo(parcel);
1048 ASSERT_EQ(result, false);
1049 delete property;
1050 }
1051
1052 /**
1053 * @tc.name: SetIsPcAppInPad/GetIsPcAppInPad
1054 * @tc.desc: SetIsPcAppInPad/GetIsPcAppInPad
1055 * @tc.type: FUNC
1056 */
1057 HWTEST_F(WindowSessionPropertyTest, SetIsPcAppInPad, Function | SmallTest | Level2)
1058 {
1059 WindowSessionProperty *property = new (std::nothrow) WindowSessionProperty();
1060 if (property == nullptr) {
1061 return;
1062 }
1063 bool isPcAppInPad = true;
1064 property->SetIsPcAppInPad(isPcAppInPad);
1065 auto result = property->GetIsPcAppInPad();
1066 ASSERT_EQ(result, isPcAppInPad);
1067 delete property;
1068 }
1069
1070 /**
1071 * @tc.name: SetSubWindowLevel
1072 * @tc.desc: SetSubWindowLevel Test
1073 * @tc.type: FUNC
1074 */
1075 HWTEST_F(WindowSessionPropertyTest, SetSubWindowLevel, Function | SmallTest | Level2)
1076 {
1077 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1078 EXPECT_NE(property, nullptr);
1079 uint32_t level = 4;
1080 property->SetSubWindowLevel(level);
1081 ASSERT_EQ(level, property->GetSubWindowLevel());
1082 }
1083
1084 /**
1085 * @tc.name: GetSubWindowLevel
1086 * @tc.desc: GetSubWindowLevel Test
1087 * @tc.type: FUNC
1088 */
1089 HWTEST_F(WindowSessionPropertyTest, GetSubWindowLevel, Function | SmallTest | Level2)
1090 {
1091 sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1092 EXPECT_NE(property, nullptr);;
1093 ASSERT_EQ(1, property->GetSubWindowLevel());
1094 }
1095 } // namespace
1096 } // namespace Rosen
1097 } // namespace OHOS
1098