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 #include "window_helper.h"
16 #include "display_manager.h"
17 #include "pointer_event.h"
18 
19 #include <gtest/gtest.h>
20 #include "key_event.h"
21 #include "session/host/include/scene_session.h"
22 #include "session/host/include/sub_session.h"
23 #include "session/host/include/system_session.h"
24 #include "session/host/include/main_session.h"
25 #include "wm_common.h"
26 #include "mock/mock_session_stage.h"
27 #include "input_event.h"
28 #include <pointer_event.h>
29 #include <ui/rs_surface_node.h>
30 
31 using namespace testing;
32 using namespace testing::ext;
33 namespace OHOS {
34 namespace Rosen {
35 class SceneSessionTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp() override;
40     void TearDown() override;
41 };
42 
SetUpTestCase()43 void SceneSessionTest::SetUpTestCase()
44 {
45 }
46 
TearDownTestCase()47 void SceneSessionTest::TearDownTestCase()
48 {
49 }
50 
SetUp()51 void SceneSessionTest::SetUp()
52 {
53 }
54 
TearDown()55 void SceneSessionTest::TearDown()
56 {
57 }
58 
59 namespace {
60 
61 /**
62  * @tc.name: SetGlobalMaximizeMode01
63  * @tc.desc: SetGlobalMaximizeMode
64  * @tc.type: FUNC
65  */
HWTEST_F(SceneSessionTest, SetGlobalMaximizeMode01, Function | SmallTest | Level2)66 HWTEST_F(SceneSessionTest, SetGlobalMaximizeMode01, Function | SmallTest | Level2)
67 {
68     SessionInfo info;
69     info.abilityName_ = "Background01";
70     info.bundleName_ = "Background01";
71     sptr<Rosen::ISession> session_;
72     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
73         new (std::nothrow) SceneSession::SpecificSessionCallback();
74     EXPECT_NE(specificCallback_, nullptr);
75     sptr<SceneSession> scensession;
76     scensession = new (std::nothrow) SceneSession(info, nullptr);
77     EXPECT_NE(scensession, nullptr);
78     scensession->isActive_ = true;
79     auto result = scensession->SetGlobalMaximizeMode(MaximizeMode::MODE_AVOID_SYSTEM_BAR);
80     ASSERT_EQ(result, WSError::WS_OK);
81 }
82 
83 /**
84  * @tc.name: GetGlobalMaximizeMode01
85  * @tc.desc: GetGlobalMaximizeMode
86  * @tc.type: FUNC
87  */
HWTEST_F(SceneSessionTest, GetGlobalMaximizeMode01, Function | SmallTest | Level2)88 HWTEST_F(SceneSessionTest, GetGlobalMaximizeMode01, Function | SmallTest | Level2)
89 {
90     SessionInfo info;
91     info.abilityName_ = "Background01";
92     info.bundleName_ = "Background01";
93     sptr<Rosen::ISession> session_;
94     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
95         new (std::nothrow) SceneSession::SpecificSessionCallback();
96     EXPECT_NE(specificCallback_, nullptr);
97 
98     sptr<SceneSession> scensession;
99     scensession = new (std::nothrow) SceneSession(info, nullptr);
100     EXPECT_NE(scensession, nullptr);
101     scensession->isActive_ = true;
102     MaximizeMode mode;
103     auto result = scensession->GetGlobalMaximizeMode(mode);
104     ASSERT_EQ(result, WSError::WS_OK);
105 }
106 
107 /**
108  * @tc.name: SetAndGetPipTemplateInfo
109  * @tc.desc: SetAndGetPipTemplateInfo Test
110  * @tc.type: FUNC
111  */
HWTEST_F(SceneSessionTest, SetAndGetPipTemplateInfo, Function | SmallTest | Level2)112 HWTEST_F(SceneSessionTest, SetAndGetPipTemplateInfo, Function | SmallTest | Level2)
113 {
114     SessionInfo info;
115     info.abilityName_ = "Background01";
116     info.bundleName_ = "Background01";
117     sptr<Rosen::ISession> session_;
118     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
119         new (std::nothrow) SceneSession::SpecificSessionCallback();
120     EXPECT_NE(specificCallback_, nullptr);
121 
122     sptr<SceneSession> scensession;
123     scensession = new (std::nothrow) SceneSession(info, nullptr);
124     EXPECT_NE(scensession, nullptr);
125     scensession->isActive_ = true;
126     PiPTemplateInfo pipTemplateInfo;
127     pipTemplateInfo.pipTemplateType = static_cast<uint32_t>(PiPTemplateType::VIDEO_CALL);
128     scensession->SetPiPTemplateInfo(pipTemplateInfo);
129     ASSERT_EQ(scensession->GetPiPTemplateInfo().pipTemplateType,
130         static_cast<uint32_t>(PiPTemplateType::VIDEO_CALL));
131 }
132 
133 /**
134  * @tc.name: UpdateWindowSceneAfterCustomAnimation01
135  * @tc.desc: UpdateWindowSceneAfterCustomAnimation
136  * @tc.type: FUNC
137  */
HWTEST_F(SceneSessionTest, UpdateWindowSceneAfterCustomAnimation01, Function | SmallTest | Level2)138 HWTEST_F(SceneSessionTest, UpdateWindowSceneAfterCustomAnimation01, Function | SmallTest | Level2)
139 {
140     SessionInfo info;
141     info.abilityName_ = "Background01";
142     info.bundleName_ = "Background01";
143     sptr<Rosen::ISession> session_;
144     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
145         new (std::nothrow) SceneSession::SpecificSessionCallback();
146     EXPECT_NE(specificCallback_, nullptr);
147     sptr<SceneSession> scensession;
148     scensession = new (std::nothrow) SceneSession(info, nullptr);
149     EXPECT_NE(scensession, nullptr);
150     scensession->isActive_ = true;
151     auto result = scensession->UpdateWindowSceneAfterCustomAnimation(false);
152     ASSERT_EQ(result, WSError::WS_OK);
153     result = scensession->UpdateWindowSceneAfterCustomAnimation(true);
154     ASSERT_EQ(result, WSError::WS_OK);
155 }
156 
157 /**
158  * @tc.name: SetZOrder01
159  * @tc.desc: SetZOrder
160  * @tc.type: FUNC
161  */
HWTEST_F(SceneSessionTest, SetZOrder01, Function | SmallTest | Level2)162 HWTEST_F(SceneSessionTest, SetZOrder01, Function | SmallTest | Level2)
163 {
164     SessionInfo info;
165     info.abilityName_ = "Background01";
166     info.bundleName_ = "Background01";
167     sptr<Rosen::ISession> session_;
168     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
169         new (std::nothrow) SceneSession::SpecificSessionCallback();
170     EXPECT_NE(specificCallback_, nullptr);
171     int resultValue = 0;
172     sptr<SceneSession> scensession;
173     scensession = new (std::nothrow) SceneSession(info, nullptr);
174     EXPECT_NE(scensession, nullptr);
175     scensession->SetZOrder(2);
176     ASSERT_EQ(0, resultValue);
177 }
178 
179 /**
180  * @tc.name: GetTouchHotAreas01
181  * @tc.desc: GetTouchHotAreas
182  * @tc.type: FUNC
183  */
HWTEST_F(SceneSessionTest, GetTouchHotAreas01, Function | SmallTest | Level2)184 HWTEST_F(SceneSessionTest, GetTouchHotAreas01, Function | SmallTest | Level2)
185 {
186     SessionInfo info;
187     info.abilityName_ = "Background01";
188     info.bundleName_ = "GetTouchHotAreas01";
189     sptr<Rosen::ISession> session_;
190     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
191         new (std::nothrow) SceneSession::SpecificSessionCallback();
192     EXPECT_NE(specificCallback_, nullptr);
193     sptr<SceneSession> scensession;
194     scensession = new (std::nothrow) SceneSession(info, nullptr);
195     EXPECT_NE(scensession, nullptr);
196     Rect windowRect = {1, 1, 1, 1};
197     std::vector<Rect> rects;
198     uint32_t hotAreasNum = 10;
199     uint32_t hotAreaWidth = windowRect.width_ / hotAreasNum;
200     uint32_t hotAreaHeight = windowRect.height_ / hotAreasNum;
201     for (uint32_t i = 0; i < hotAreasNum; ++i) {
202         rects.emplace_back(Rect{hotAreaWidth * i, hotAreaHeight * i, hotAreaWidth, hotAreaHeight});
203     }
204     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
205 
206     ASSERT_NE(nullptr, property);
207     property->SetTouchHotAreas(rects);
208     ASSERT_NE(rects, scensession->GetTouchHotAreas());
209 }
210 
211 /**
212  * @tc.name: SetTurnScreenOn01
213  * @tc.desc: SetTurnScreenOn
214  * @tc.type: FUNC
215  */
HWTEST_F(SceneSessionTest, SetTurnScreenOn01, Function | SmallTest | Level2)216 HWTEST_F(SceneSessionTest, SetTurnScreenOn01, Function | SmallTest | Level2)
217 {
218     SessionInfo info;
219     info.abilityName_ = "Background01";
220     info.bundleName_ = "Background01";
221     sptr<Rosen::ISession> session_;
222     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
223         new (std::nothrow) SceneSession::SpecificSessionCallback();
224     EXPECT_NE(specificCallback_, nullptr);
225     sptr<SceneSession> scensession;
226     scensession = new (std::nothrow) SceneSession(info, nullptr);
227     EXPECT_NE(scensession, nullptr);
228     sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
229     ASSERT_NE(mockSessionStage, nullptr);
230     ASSERT_EQ(WSError::WS_OK, scensession->SetTurnScreenOn(false));
231     ASSERT_EQ(false, scensession->IsTurnScreenOn());
232     ASSERT_EQ(WSError::WS_OK, scensession->SetTurnScreenOn(true));
233     ASSERT_EQ(true, scensession->IsTurnScreenOn());
234 }
235 
236 /**
237  * @tc.name: UpdateWindowAnimationFlag01
238  * @tc.desc: UpdateWindowAnimationFlag
239  * @tc.type: FUNC
240  */
HWTEST_F(SceneSessionTest, UpdateWindowAnimationFlag01, Function | SmallTest | Level2)241 HWTEST_F(SceneSessionTest, UpdateWindowAnimationFlag01, Function | SmallTest | Level2)
242 {
243     SessionInfo info;
244     info.abilityName_ = "Background01";
245     info.bundleName_ = "Background01";
246     sptr<Rosen::ISession> session_;
247     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
248         new (std::nothrow) SceneSession::SpecificSessionCallback();
249     EXPECT_NE(specificCallback_, nullptr);
250     sptr<SceneSession> scensession;
251     scensession = new (std::nothrow) SceneSession(info, nullptr);
252     EXPECT_NE(scensession, nullptr);
253     sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
254     ASSERT_NE(mockSessionStage, nullptr);
255     ASSERT_EQ(WSError::WS_OK, scensession->UpdateWindowAnimationFlag(false));
256 }
257 
258 /**
259  * @tc.name: ClearEnterWindow01
260  * @tc.desc: ClearEnterWindow
261  * @tc.type: FUNC
262  */
HWTEST_F(SceneSessionTest, ClearEnterWindow01, Function | SmallTest | Level2)263 HWTEST_F(SceneSessionTest, ClearEnterWindow01, Function | SmallTest | Level2)
264 {
265     SessionInfo info;
266     info.abilityName_ = "Background01";
267     info.bundleName_ = "ClearEnterWindow01";
268     sptr<Rosen::ISession> session_;
269     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
270         new (std::nothrow) SceneSession::SpecificSessionCallback();
271     EXPECT_NE(specificCallback_, nullptr);
272     sptr<SceneSession> scensession;
273     scensession = new (std::nothrow) SceneSession(info, nullptr);
274     EXPECT_NE(scensession, nullptr);
275     int resultValue = 0;
276     SceneSession::ClearEnterWindow();
277     ASSERT_EQ(resultValue, 0);
278 }
279 
280 /**
281  * @tc.name: GetEnterWindow01
282  * @tc.desc: GetEnterWindow
283  * @tc.type: FUNC
284  */
HWTEST_F(SceneSessionTest, GetEnterWindow01, Function | SmallTest | Level2)285 HWTEST_F(SceneSessionTest, GetEnterWindow01, Function | SmallTest | Level2)
286 {
287     SessionInfo info;
288     info.abilityName_ = "Background01";
289     info.bundleName_ = "GetEnterWindow01";
290     sptr<Rosen::ISession> session_;
291     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
292         new (std::nothrow) SceneSession::SpecificSessionCallback();
293     EXPECT_NE(specificCallback_, nullptr);
294     sptr<SceneSession> scensession;
295     scensession = new (std::nothrow) SceneSession(info, nullptr);
296     EXPECT_NE(scensession, nullptr);
297     wptr<SceneSession> scenesession_;
298     ASSERT_EQ(scenesession_, SceneSession::GetEnterWindow());
299 }
300 
301 /**
302  * @tc.name: SetRequestedOrientation
303  * @tc.desc: SetRequestedOrientation
304  * @tc.type: FUNC
305  */
HWTEST_F(SceneSessionTest, SetRequestedOrientation01, Function | SmallTest | Level2)306 HWTEST_F(SceneSessionTest, SetRequestedOrientation01, Function | SmallTest | Level2)
307 {
308     SessionInfo info;
309     info.abilityName_ = "Background01";
310     info.bundleName_ = "SetRequestedOrientation";
311     sptr<SceneSession> scensession;
312     scensession = new (std::nothrow) SceneSession(info, nullptr);
313     EXPECT_NE(scensession, nullptr);
314     Orientation ori = Orientation::UNSPECIFIED;
315     scensession->SetRequestedOrientation(ori);
316     Orientation ret = scensession->GetRequestedOrientation();
317     ASSERT_EQ(ori, ret);
318 
319     scensession->SetRequestedOrientation(Orientation::AUTO_ROTATION_UNSPECIFIED);
320     Orientation ret1 = scensession->GetRequestedOrientation();
321     ASSERT_EQ(ret1, Orientation::AUTO_ROTATION_UNSPECIFIED);
322 
323     scensession->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
324     Orientation ret2 = scensession->GetRequestedOrientation();
325     ASSERT_EQ(ret2, Orientation::USER_ROTATION_PORTRAIT);
326 
327     scensession->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE);
328     Orientation ret3 = scensession->GetRequestedOrientation();
329     ASSERT_EQ(ret3, Orientation::USER_ROTATION_LANDSCAPE);
330 
331     scensession->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED);
332     Orientation ret4 = scensession->GetRequestedOrientation();
333     ASSERT_EQ(ret4, Orientation::USER_ROTATION_PORTRAIT_INVERTED);
334 
335     scensession->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
336     Orientation ret5 = scensession->GetRequestedOrientation();
337     ASSERT_EQ(ret5, Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
338 
339     scensession->SetRequestedOrientation(Orientation::FOLLOW_DESKTOP);
340     Orientation ret6 = scensession->GetRequestedOrientation();
341     ASSERT_EQ(ret6, Orientation::FOLLOW_DESKTOP);
342 }
343 
344 /**
345  * @tc.name: GetRequestedOrientation
346  * @tc.desc: GetRequestedOrientation
347  * @tc.type: FUNC
348  */
HWTEST_F(SceneSessionTest, GetRequestedOrientation, Function | SmallTest | Level2)349 HWTEST_F(SceneSessionTest, GetRequestedOrientation, Function | SmallTest | Level2)
350 {
351     SessionInfo info;
352     info.abilityName_ = "Background01";
353     info.bundleName_ = "GetRequestedOrientation";
354     sptr<SceneSession> scensession;
355     scensession = new (std::nothrow) SceneSession(info, nullptr);
356     EXPECT_NE(scensession, nullptr);
357     Orientation ori = Orientation::HORIZONTAL;
358     scensession->SetRequestedOrientation(ori);
359     Orientation ret = scensession->GetRequestedOrientation();
360     ASSERT_EQ(ori, ret);
361 
362     scensession->SetRequestedOrientation(Orientation::AUTO_ROTATION_UNSPECIFIED);
363     Orientation ret1 = scensession->GetRequestedOrientation();
364     ASSERT_EQ(ret1, Orientation::AUTO_ROTATION_UNSPECIFIED);
365 
366     scensession->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT);
367     Orientation ret2 = scensession->GetRequestedOrientation();
368     ASSERT_EQ(ret2, Orientation::USER_ROTATION_PORTRAIT);
369 
370     scensession->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE);
371     Orientation ret3 = scensession->GetRequestedOrientation();
372     ASSERT_EQ(ret3, Orientation::USER_ROTATION_LANDSCAPE);
373 
374     scensession->SetRequestedOrientation(Orientation::USER_ROTATION_PORTRAIT_INVERTED);
375     Orientation ret4 = scensession->GetRequestedOrientation();
376     ASSERT_EQ(ret4, Orientation::USER_ROTATION_PORTRAIT_INVERTED);
377 
378     scensession->SetRequestedOrientation(Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
379     Orientation ret5 = scensession->GetRequestedOrientation();
380     ASSERT_EQ(ret5, Orientation::USER_ROTATION_LANDSCAPE_INVERTED);
381 
382     scensession->SetRequestedOrientation(Orientation::FOLLOW_DESKTOP);
383     Orientation ret6 = scensession->GetRequestedOrientation();
384     ASSERT_EQ(ret6, Orientation::FOLLOW_DESKTOP);
385 }
386 
387 /**
388  * @tc.name: SetDefaultRequestedOrientation
389  * @tc.desc: SetDefaultRequestedOrientation
390  * @tc.type: FUNC
391  */
HWTEST_F(SceneSessionTest, SetDefaultRequestedOrientation, Function | SmallTest | Level2)392 HWTEST_F(SceneSessionTest, SetDefaultRequestedOrientation, Function | SmallTest | Level2)
393 {
394     SessionInfo info;
395     info.abilityName_ = "Background01";
396     info.bundleName_ = "SetDefaultRequestedOrientation";
397     sptr<SceneSession> scensession;
398     scensession = new (std::nothrow) SceneSession(info, nullptr);
399     EXPECT_NE(scensession, nullptr);
400     Orientation orientation = Orientation::AUTO_ROTATION_UNSPECIFIED;
401     scensession->SetDefaultRequestedOrientation(orientation);
402     Orientation ret = scensession->GetRequestedOrientation();
403     ASSERT_EQ(orientation, ret);
404 }
405 
406 
407 /**
408  * @tc.name: IsKeepScreenOn
409  * @tc.desc: IsKeepScreenOn
410  * @tc.type: FUNC
411  */
HWTEST_F(SceneSessionTest, IsKeepScreenOn, Function | SmallTest | Level2)412 HWTEST_F(SceneSessionTest, IsKeepScreenOn, Function | SmallTest | Level2)
413 {
414     SessionInfo info;
415     info.abilityName_ = "Background01";
416     info.bundleName_ = "IsKeepScreenOn";
417     sptr<Rosen::ISession> session_;
418     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
419         new (std::nothrow) SceneSession::SpecificSessionCallback();
420     ASSERT_NE(specificCallback_, nullptr);
421     sptr<SceneSession> scensession;
422     scensession = new (std::nothrow) SceneSession(info, nullptr);
423     ASSERT_NE(scensession, nullptr);
424     ASSERT_EQ(WSError::WS_OK, scensession->SetKeepScreenOn(true));
425     ASSERT_EQ(true, scensession->IsKeepScreenOn());
426     ASSERT_EQ(WSError::WS_OK, scensession->SetKeepScreenOn(false));
427     ASSERT_EQ(false, scensession->IsKeepScreenOn());
428 }
429 
430 /**
431  * @tc.name: IsAppSession
432  * @tc.desc: IsAppSession true
433  * @tc.type: FUNC
434  */
HWTEST_F(SceneSessionTest, IsAppSession01, Function | SmallTest | Level2)435 HWTEST_F(SceneSessionTest, IsAppSession01, Function | SmallTest | Level2)
436 {
437     SessionInfo info;
438     info.abilityName_ = "Background01";
439     info.bundleName_ = "IsAppSession";
440     info.windowType_ = 1;
441     sptr<Rosen::ISession> session_;
442     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
443         new (std::nothrow) SceneSession::SpecificSessionCallback();
444     EXPECT_NE(specificCallback_, nullptr);
445     sptr<SceneSession> scensession;
446     scensession = new (std::nothrow) SceneSession(info, nullptr);
447     EXPECT_NE(scensession, nullptr);
448     ASSERT_EQ(true, scensession->IsAppSession());
449 }
450 
451 /**
452  * @tc.name: IsAppSession
453  * @tc.desc: IsAppSession false
454  * @tc.type: FUNC
455  */
HWTEST_F(SceneSessionTest, IsAppSession02, Function | SmallTest | Level2)456 HWTEST_F(SceneSessionTest, IsAppSession02, Function | SmallTest | Level2)
457 {
458     SessionInfo info;
459     info.abilityName_ = "Background01";
460     info.bundleName_ = "IsAppSession";
461     info.windowType_ = 2106;
462     sptr<Rosen::ISession> session_;
463     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
464         new (std::nothrow) SceneSession::SpecificSessionCallback();
465     EXPECT_NE(specificCallback_, nullptr);
466     sptr<SceneSession> scensession;
467     scensession = new (std::nothrow) SceneSession(info, nullptr);
468     EXPECT_NE(scensession, nullptr);
469     ASSERT_EQ(false, scensession->IsAppSession());
470 
471     SessionInfo parentInfo;
472     parentInfo.abilityName_ = "testSession1";
473     parentInfo.moduleName_ = "testSession2";
474     parentInfo.bundleName_ = "testSession3";
475     sptr<Session> parentSession = sptr<Session>::MakeSptr(parentInfo);
476     ASSERT_NE(parentSession, nullptr);
477 
478     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
479     EXPECT_NE(property, nullptr);
480     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
481     parentSession->SetSessionProperty(property);
482     scensession->SetParentSession(parentSession);
483     ASSERT_EQ(false, scensession->IsAppSession());
484 
485     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
486     parentSession->SetSessionProperty(property);
487     scensession->SetParentSession(parentSession);
488     ASSERT_EQ(true, scensession->IsAppSession());
489 }
490 
491 /**
492  * @tc.name: IsAppOrLowerSystemSession
493  * @tc.desc: IsAppOrLowerSystemSession true
494  * @tc.type: FUNC
495  */
HWTEST_F(SceneSessionTest, IsAppOrLowerSystemSession01, Function | SmallTest | Level2)496 HWTEST_F(SceneSessionTest, IsAppOrLowerSystemSession01, Function | SmallTest | Level2)
497 {
498     SessionInfo info;
499     info.abilityName_ = "Background01";
500     info.bundleName_ = "IsAppOrLowerSystemSession01";
501     info.windowType_ = 2126;
502 
503     sptr<SceneSession> scensession;
504     scensession = new (std::nothrow) SceneSession(info, nullptr);
505     EXPECT_NE(scensession, nullptr);
506     ASSERT_EQ(true, scensession->IsAppOrLowerSystemSession());
507 }
508 
509 /**
510  * @tc.name: IsAppOrLowerSystemSession
511  * @tc.desc: IsAppOrLowerSystemSession false
512  * @tc.type: FUNC
513  */
HWTEST_F(SceneSessionTest, IsAppOrLowerSystemSession02, Function | SmallTest | Level2)514 HWTEST_F(SceneSessionTest, IsAppOrLowerSystemSession02, Function | SmallTest | Level2)
515 {
516     SessionInfo info;
517     info.abilityName_ = "Background02";
518     info.bundleName_ = "IsAppOrLowerSystemSession02";
519     info.windowType_ = 2106;
520 
521     sptr<SceneSession> scensession;
522     scensession = new (std::nothrow) SceneSession(info, nullptr);
523     EXPECT_NE(scensession, nullptr);
524     ASSERT_EQ(false, scensession->IsAppOrLowerSystemSession());
525 
526     SessionInfo parentInfo;
527     parentInfo.abilityName_ = "testSession1";
528     parentInfo.moduleName_ = "testSession2";
529     parentInfo.bundleName_ = "testSession3";
530     sptr<Session> parentSession = sptr<Session>::MakeSptr(parentInfo);
531     ASSERT_NE(parentSession, nullptr);
532 
533     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
534     EXPECT_NE(property, nullptr);
535     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
536     parentSession->SetSessionProperty(property);
537     scensession->SetParentSession(parentSession);
538     ASSERT_EQ(false, scensession->IsAppOrLowerSystemSession());
539 
540     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
541     parentSession->SetSessionProperty(property);
542     scensession->SetParentSession(parentSession);
543     ASSERT_EQ(true, scensession->IsAppOrLowerSystemSession());
544 }
545 
546 /**
547  * @tc.name: IsSystemSessionAboveApp
548  * @tc.desc: IsSystemSessionAboveApp true
549  * @tc.type: FUNC
550  */
HWTEST_F(SceneSessionTest, IsSystemSessionAboveApp01, Function | SmallTest | Level2)551 HWTEST_F(SceneSessionTest, IsSystemSessionAboveApp01, Function | SmallTest | Level2)
552 {
553     SessionInfo info1;
554     info1.abilityName_ = "HighZOrder01";
555     info1.bundleName_ = "IsSystemSessionAboveApp01";
556     info1.windowType_ = 2122;
557 
558     sptr<SceneSession> scensession1;
559     scensession1 = new (std::nothrow) SceneSession(info1, nullptr);
560     EXPECT_NE(scensession1, nullptr);
561     ASSERT_EQ(true, scensession1->IsSystemSessionAboveApp());
562 
563     SessionInfo info2;
564     info2.abilityName_ = "HighZOrder02";
565     info2.bundleName_ = "IsSystemSessionAboveApp02";
566     info2.windowType_ = 2104;
567 
568     sptr<SceneSession> scensession2;
569     scensession2 = new (std::nothrow) SceneSession(info2, nullptr);
570     EXPECT_NE(scensession2, nullptr);
571     ASSERT_EQ(true, scensession2->IsSystemSessionAboveApp());
572 
573     SessionInfo info3;
574     info3.abilityName_ = "HighZOrder03";
575     info3.bundleName_ = "SCBDropdownPanel13";
576     info3.windowType_ = 2109;
577 
578     sptr<SceneSession> scensession3;
579     scensession3 = new (std::nothrow) SceneSession(info3, nullptr);
580     EXPECT_NE(scensession3, nullptr);
581     ASSERT_EQ(true, scensession3->IsSystemSessionAboveApp());
582 
583     SessionInfo info4;
584     info4.abilityName_ = "HighZOrder04";
585     info4.bundleName_ = "IsSystemSessionAboveApp04";
586     info4.windowType_ = 2109;
587 
588     sptr<SceneSession> scensession4;
589     scensession4 = new (std::nothrow) SceneSession(info4, nullptr);
590     EXPECT_NE(scensession4, nullptr);
591     ASSERT_EQ(false, scensession4->IsSystemSessionAboveApp());
592 }
593 
594 /**
595  * @tc.name: IsSystemSessionAboveApp
596  * @tc.desc: IsSystemSessionAboveApp false
597  * @tc.type: FUNC
598  */
HWTEST_F(SceneSessionTest, IsSystemSessionAboveApp02, Function | SmallTest | Level2)599 HWTEST_F(SceneSessionTest, IsSystemSessionAboveApp02, Function | SmallTest | Level2)
600 {
601     SessionInfo info;
602     info.abilityName_ = "HighZOrder05";
603     info.bundleName_ = "IsSystemSessionAboveApp05";
604     info.windowType_ = 1;
605 
606     sptr<SceneSession> scensession;
607     scensession = new (std::nothrow) SceneSession(info, nullptr);
608     EXPECT_NE(scensession, nullptr);
609     ASSERT_EQ(false, scensession->IsSystemSessionAboveApp());
610 }
611 
612 /**
613  * @tc.name: GetWindowName
614  * @tc.desc: GetWindowName
615  * @tc.type: FUNC
616  */
HWTEST_F(SceneSessionTest, GetWindowName, Function | SmallTest | Level2)617 HWTEST_F(SceneSessionTest, GetWindowName, Function | SmallTest | Level2)
618 {
619     SessionInfo info;
620     info.abilityName_ = "Background01";
621     info.bundleName_ = "GetWindowName";
622     sptr<Rosen::ISession> session_;
623     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
624         new (std::nothrow) SceneSession::SpecificSessionCallback();
625     EXPECT_NE(specificCallback_, nullptr);
626     sptr<SceneSession> scensession;
627     scensession = new (std::nothrow) SceneSession(info, nullptr);
628     EXPECT_NE(scensession, nullptr);
629     ASSERT_NE("ww", scensession->GetWindowName());
630 }
631 
632 /**
633  * @tc.name: IsDecorEnable
634  * @tc.desc: IsDecorEnable
635  * @tc.type: FUNC
636  */
HWTEST_F(SceneSessionTest, IsDecorEnable, Function | SmallTest | Level2)637 HWTEST_F(SceneSessionTest, IsDecorEnable, Function | SmallTest | Level2)
638 {
639     SessionInfo info;
640     info.abilityName_ = "Background01";
641     info.bundleName_ = "IsDecorEnable";
642     info.windowType_ = 1;
643     sptr<Rosen::ISession> session_;
644     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
645         new (std::nothrow) SceneSession::SpecificSessionCallback();
646     EXPECT_NE(specificCallback_, nullptr);
647     sptr<SceneSession> scensession;
648     scensession = new (std::nothrow) SceneSession(info, nullptr);
649     EXPECT_NE(scensession, nullptr);
650     ASSERT_EQ(true, scensession->IsDecorEnable());
651     SessionInfo info_;
652     info_.abilityName_ = "Background01";
653     info_.bundleName_ = "IsDecorEnable";
654     info_.windowType_ = 1000;
655     sptr<SceneSession> scensession_;
656     scensession_ = new (std::nothrow) SceneSession(info_, nullptr);
657     EXPECT_NE(scensession_, nullptr);
658     ASSERT_EQ(false, scensession_->IsDecorEnable());
659 }
660 
661 /**
662  * @tc.name: IsDecorEnable01
663  * @tc.desc: IsDecorEnable
664  * @tc.type: FUNC
665  */
HWTEST_F(SceneSessionTest, IsDecorEnable01, Function | SmallTest | Level2)666 HWTEST_F(SceneSessionTest, IsDecorEnable01, Function | SmallTest | Level2)
667 {
668     SessionInfo info;
669     info.abilityName_ = "Background01";
670     info.bundleName_ = "IsDecorEnable01";
671     info.windowType_ = 1;
672     sptr<Rosen::ISession> session_;
673     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
674         new (std::nothrow) SceneSession::SpecificSessionCallback();
675     EXPECT_NE(specificCallback_, nullptr);
676 
677     sptr<SceneSession> scensession;
678     scensession = new (std::nothrow) SceneSession(info, nullptr);
679     EXPECT_NE(scensession, nullptr);
680     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
681     EXPECT_NE(property, nullptr);
682     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
683     property->SetDecorEnable(true);
684     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
685     scensession->property_ = property;
686     ASSERT_EQ(true, scensession->IsDecorEnable());
687 
688     sptr<SceneSession> scensession_;
689     scensession_ = new (std::nothrow) SceneSession(info, nullptr);
690     EXPECT_NE(scensession_, nullptr);
691     property = new (std::nothrow) WindowSessionProperty();
692     EXPECT_NE(property, nullptr);
693     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
694     property->SetDecorEnable(false);
695     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
696     ASSERT_EQ(true, scensession_->IsDecorEnable());
697 
698     scensession_->SetSessionProperty(nullptr);
699     ASSERT_EQ(false, scensession_->IsDecorEnable());
700 }
701 
702 /**
703  * @tc.name: UpdateNativeVisibility
704  * @tc.desc: UpdateNativeVisibility
705  * @tc.type: FUNC
706  */
HWTEST_F(SceneSessionTest, UpdateNativeVisibility, Function | SmallTest | Level2)707 HWTEST_F(SceneSessionTest, UpdateNativeVisibility, Function | SmallTest | Level2)
708 {
709     SessionInfo info;
710     info.abilityName_ = "Background01";
711     info.bundleName_ = "UpdateNativeVisibility";
712     info.windowType_ = 1;
713     sptr<Rosen::ISession> session_;
714     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
715         new (std::nothrow) SceneSession::SpecificSessionCallback();
716     EXPECT_NE(specificCallback_, nullptr);
717     sptr<SceneSession> scensession;
718     scensession = new (std::nothrow) SceneSession(info, nullptr);
719     EXPECT_NE(scensession, nullptr);
720     scensession->UpdateNativeVisibility(false);
721     ASSERT_EQ(false, scensession->IsVisible());
722     scensession->NotifyWindowVisibility();
723 
724     sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
725     ASSERT_NE(mockSessionStage, nullptr);
726     scensession->sessionStage_ = mockSessionStage;
727     scensession->NotifyWindowVisibility();
728 }
729 
730 /**
731  * @tc.name: SetPrivacyMode01
732  * @tc.desc: Set PrivacyMode as false
733  * @tc.type: FUNC
734  */
HWTEST_F(SceneSessionTest, SetPrivacyMode01, Function | SmallTest | Level2)735 HWTEST_F(SceneSessionTest, SetPrivacyMode01, Function | SmallTest | Level2)
736 {
737     SessionInfo info;
738     info.abilityName_ = "Background01";
739     info.bundleName_ = "SetPrivacyMode";
740     info.windowType_ = 1;
741     sptr<SceneSession> scensession;
742     scensession = new (std::nothrow) SceneSession(info, nullptr);
743     EXPECT_NE(scensession, nullptr);
744     struct RSSurfaceNodeConfig config;
745     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
746     scensession->surfaceNode_ = surfaceNode;
747     scensession->SetPrivacyMode(false);
748     ASSERT_EQ(false, scensession->property_->GetPrivacyMode());
749     ASSERT_EQ(false, scensession->property_->GetSystemPrivacyMode());
750 }
751 
752 /**
753  * @tc.name: SetPrivacyMode02
754  * @tc.desc: Set PrivacyMode as true
755  * @tc.type: FUNC
756  */
HWTEST_F(SceneSessionTest, SetPrivacyMode02, Function | SmallTest | Level2)757 HWTEST_F(SceneSessionTest, SetPrivacyMode02, Function | SmallTest | Level2)
758 {
759     SessionInfo info;
760     info.abilityName_ = "Background02";
761     info.bundleName_ = "SetPrivacyMode";
762     info.windowType_ = 1;
763     sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
764     EXPECT_NE(scensession, nullptr);
765     struct RSSurfaceNodeConfig config;
766     std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
767     scensession->surfaceNode_ = surfaceNode;
768     scensession->SetPrivacyMode(true);
769     ASSERT_EQ(true, scensession->property_->GetPrivacyMode());
770     ASSERT_EQ(true, scensession->property_->GetSystemPrivacyMode());
771 }
772 
773 /**
774  * @tc.name: IsFloatingWindowAppType
775  * @tc.desc: IsFloatingWindowAppType
776  * @tc.type: FUNC
777  */
HWTEST_F(SceneSessionTest, IsFloatingWindowAppType, Function | SmallTest | Level2)778 HWTEST_F(SceneSessionTest, IsFloatingWindowAppType, Function | SmallTest | Level2)
779 {
780     SessionInfo info;
781     info.abilityName_ = "Background01";
782     info.bundleName_ = "IsFloatingWindowAppType";
783     info.windowType_ = 1;
784     sptr<Rosen::ISession> session_;
785     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
786         new (std::nothrow) SceneSession::SpecificSessionCallback();
787     EXPECT_NE(specificCallback_, nullptr);
788     sptr<SceneSession> scensession;
789     scensession = new (std::nothrow) SceneSession(info, nullptr);
790     EXPECT_NE(scensession, nullptr);
791     ASSERT_EQ(false, scensession->IsFloatingWindowAppType());
792 
793     scensession->SetSessionProperty(nullptr);
794     ASSERT_EQ(false, scensession->IsFloatingWindowAppType());
795 }
796 
797 /**
798  * @tc.name: DumpSessionElementInfo01
799  * @tc.desc: DumpSessionElementInfo
800  * @tc.type: FUNC
801  */
HWTEST_F(SceneSessionTest, DumpSessionElementInfo, Function | SmallTest | Level2)802 HWTEST_F(SceneSessionTest, DumpSessionElementInfo, Function | SmallTest | Level2)
803 {
804     SessionInfo info;
805     info.abilityName_ = "Background01";
806     info.bundleName_ = "IsFloatingWindowAppType";
807     info.windowType_ = 1;
808     sptr<Rosen::ISession> session_;
809     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
810         new (std::nothrow) SceneSession::SpecificSessionCallback();
811     EXPECT_NE(specificCallback_, nullptr);
812     sptr<SceneSession> scensession;
813     scensession = new (std::nothrow) SceneSession(info, nullptr);
814     EXPECT_NE(scensession, nullptr);
815     sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
816     ASSERT_NE(mockSessionStage, nullptr);
817     std::vector<std::string> params;
818     scensession->DumpSessionElementInfo(params);
819     int ret = 1;
820     scensession->sessionStage_ = mockSessionStage;
821     scensession->DumpSessionElementInfo(params);
822     ASSERT_EQ(ret, 1);
823 }
824 
825 /**
826  * @tc.name: SaveAspectRatio
827  * @tc.desc: SaveAspectRatio
828  * @tc.type: FUNC
829  */
HWTEST_F(SceneSessionTest, SaveAspectRatio, Function | SmallTest | Level2)830 HWTEST_F(SceneSessionTest, SaveAspectRatio, Function | SmallTest | Level2)
831 {
832     SessionInfo info;
833     info.abilityName_ = "Background01";
834     info.bundleName_ = "IsFloatingWindowAppType";
835     info.windowType_ = 1;
836     sptr<SceneSession> scensession;
837     scensession = new (std::nothrow) SceneSession(info, nullptr);
838     EXPECT_NE(scensession, nullptr);
839     ASSERT_EQ(true, scensession->SaveAspectRatio(0.1));
840 
841     scensession->sessionInfo_.bundleName_ = "";
842     scensession->sessionInfo_.moduleName_ = "";
843     scensession->sessionInfo_.abilityName_ = "";
844     ASSERT_EQ(false, scensession->SaveAspectRatio(0.1));
845 }
846 
847 /**
848  * @tc.name: NotifyIsCustomAnimationPlaying
849  * @tc.desc: NotifyIsCustomAnimationPlaying
850  * @tc.type: FUNC
851  */
HWTEST_F(SceneSessionTest, NotifyIsCustomAnimationPlaying, Function | SmallTest | Level2)852 HWTEST_F(SceneSessionTest, NotifyIsCustomAnimationPlaying, Function | SmallTest | Level2)
853 {
854     SessionInfo info;
855     info.abilityName_ = "Background01";
856     info.bundleName_ = "IsFloatingWindowAppType";
857     info.windowType_ = 1;
858     sptr<Rosen::ISession> session_;
859     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
860         new (std::nothrow) SceneSession::SpecificSessionCallback();
861     EXPECT_NE(specificCallback_, nullptr);
862     sptr<SceneSession> scensession;
863     scensession = new (std::nothrow) SceneSession(info, nullptr);
864     EXPECT_NE(scensession, nullptr);
865     scensession->NotifyIsCustomAnimationPlaying(false);
866 
867     scensession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback();
868     scensession->sessionChangeCallback_->onIsCustomAnimationPlaying_ = [](bool status){};
869     scensession->NotifyIsCustomAnimationPlaying(false);
870 }
871 
872 /**
873  * @tc.name: ModalUIExtension
874  * @tc.desc: ModalUIExtension
875  * @tc.type: FUNC
876  */
HWTEST_F(SceneSessionTest, ModalUIExtension, Function | SmallTest | Level2)877 HWTEST_F(SceneSessionTest, ModalUIExtension, Function | SmallTest | Level2)
878 {
879     SessionInfo info;
880     info.abilityName_ = "ModalUIExtension";
881     info.bundleName_ = "ModalUIExtension";
882     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
883     ASSERT_NE(sceneSession, nullptr);
884 
885     EXPECT_FALSE(sceneSession->HasModalUIExtension());
886     ExtensionWindowEventInfo extensionInfo;
887     extensionInfo.persistentId = 12345;
888     extensionInfo.pid = 1234;
889     extensionInfo.windowRect = { 1, 2, 3, 4 };
890     sceneSession->AddModalUIExtension(extensionInfo);
891     EXPECT_TRUE(sceneSession->HasModalUIExtension());
892 
893     auto getInfo = sceneSession->GetLastModalUIExtensionEventInfo();
894     EXPECT_EQ(getInfo.persistentId, extensionInfo.persistentId);
895     EXPECT_EQ(getInfo.pid, extensionInfo.pid);
896     EXPECT_EQ(getInfo.windowRect, extensionInfo.windowRect);
897 
898     Rect windowRect = { 5, 6, 7, 8 };
899     extensionInfo.windowRect = windowRect;
900     sceneSession->UpdateModalUIExtension(extensionInfo);
901     getInfo = sceneSession->GetLastModalUIExtensionEventInfo();
902     EXPECT_EQ(getInfo.windowRect, windowRect);
903 
904     sceneSession->RemoveModalUIExtension(extensionInfo.persistentId);
905     EXPECT_FALSE(sceneSession->HasModalUIExtension());
906 }
907 
908 /**
909  * @tc.name: NotifySessionRectChange
910  * @tc.desc: NotifySessionRectChange
911  * @tc.type: FUNC
912  */
HWTEST_F(SceneSessionTest, NotifySessionRectChange, Function | SmallTest | Level2)913 HWTEST_F(SceneSessionTest, NotifySessionRectChange, Function | SmallTest | Level2)
914 {
915     SessionInfo info;
916     info.abilityName_ = "Background01";
917     info.bundleName_ = "IsFloatingWindowAppType";
918     info.windowType_ = 1;
919     sptr<Rosen::ISession> session_;
920     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
921         new (std::nothrow) SceneSession::SpecificSessionCallback();
922     EXPECT_NE(specificCallback_, nullptr);
923     sptr<SceneSession> scensession;
924     scensession = new (std::nothrow) SceneSession(info, nullptr);
925     EXPECT_NE(scensession, nullptr);
926     WSRect overlapRect = { 0, 0, 0, 0 };
927     scensession->NotifySessionRectChange(overlapRect, SizeChangeReason::ROTATION, -1);
928     scensession->NotifySessionRectChange(overlapRect, SizeChangeReason::ROTATION, 11);
929     scensession->sessionRectChangeFunc_ = [](const WSRect& rect,
930         const SizeChangeReason reason, DisplayId displayId) {
931         return;
932     };
933     scensession->NotifySessionRectChange(overlapRect, SizeChangeReason::ROTATION, -1);
934     scensession->NotifySessionRectChange(overlapRect, SizeChangeReason::ROTATION, 11);
935 }
936 
937 /**
938  * @tc.name: FixRectByAspectRatio
939  * @tc.desc: FixRectByAspectRatio
940  * @tc.type: FUNC
941  */
HWTEST_F(SceneSessionTest, FixRectByAspectRatio, Function | SmallTest | Level2)942 HWTEST_F(SceneSessionTest, FixRectByAspectRatio, Function | SmallTest | Level2)
943 {
944     SessionInfo info;
945     info.abilityName_ = "Background01";
946     info.bundleName_ = "IsFloatingWindowAppType";
947     info.windowType_ = 1;
948     sptr<Rosen::ISession> session_;
949     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
950         new (std::nothrow) SceneSession::SpecificSessionCallback();
951     EXPECT_NE(specificCallback_, nullptr);
952     sptr<SceneSession> scensession;
953     scensession = new (std::nothrow) SceneSession(info, nullptr);
954     EXPECT_NE(scensession, nullptr);
955     WSRect originalRect_ = { 0, 0, 0, 0 };
956     ASSERT_EQ(false, scensession->FixRectByAspectRatio(originalRect_));
957 }
958 
959 /**
960  * @tc.name: GetKeyboardAvoidArea
961  * @tc.desc: GetKeyboardAvoidArea
962  * @tc.type: FUNC
963  */
HWTEST_F(SceneSessionTest, GetKeyboardAvoidArea, Function | SmallTest | Level2)964 HWTEST_F(SceneSessionTest, GetKeyboardAvoidArea, Function | SmallTest | Level2)
965 {
966     SessionInfo info;
967     info.abilityName_ = "Background01";
968     info.bundleName_ = "IsFloatingWindowAppType";
969     info.windowType_ = 1;
970     sptr<Rosen::ISession> session_;
971     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
972         new (std::nothrow) SceneSession::SpecificSessionCallback();
973     EXPECT_NE(specificCallback_, nullptr);
974     specificCallback_->onGetSceneSessionVectorByType_ = [](WindowType type,
975         uint64_t displayId) -> std::vector<sptr<SceneSession>> {
976         std::vector<sptr<SceneSession>> backgroundSession;
977         return backgroundSession;
978     };
979 
980     sptr<SceneSession> scensession;
981     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
982     EXPECT_NE(scensession, nullptr);
983     WSRect overlapRect = {0, 0, 0, 0};
984     AvoidArea avoidArea;
985     int ret = 1;
986     scensession->GetKeyboardAvoidArea(overlapRect, avoidArea);
987     ASSERT_EQ(ret, 1);
988 
989     scensession->SetSessionProperty(nullptr);
990     scensession->GetKeyboardAvoidArea(overlapRect, avoidArea);
991     ASSERT_EQ(nullptr, scensession->GetSessionProperty());
992 }
993 
994 /**
995  * @tc.name: GetCutoutAvoidArea
996  * @tc.desc: GetCutoutAvoidArea
997  * @tc.type: FUNC
998  */
HWTEST_F(SceneSessionTest, GetCutoutAvoidArea, Function | SmallTest | Level2)999 HWTEST_F(SceneSessionTest, GetCutoutAvoidArea, Function | SmallTest | Level2)
1000 {
1001     SessionInfo info;
1002     info.abilityName_ = "Background01";
1003     info.bundleName_ = "IsFloatingWindowAppType";
1004     info.windowType_ = 1;
1005     sptr<Rosen::ISession> session_;
1006     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1007         new (std::nothrow) SceneSession::SpecificSessionCallback();
1008     EXPECT_NE(specificCallback_, nullptr);
1009     sptr<SceneSession> scensession;
1010     scensession = new (std::nothrow) SceneSession(info, nullptr);
1011     EXPECT_NE(scensession, nullptr);
1012     WSRect overlapRect = { 0, 0, 0, 0 };
1013     AvoidArea avoidArea;
1014     int ret = 1;
1015     scensession->GetCutoutAvoidArea(overlapRect, avoidArea);
1016     ASSERT_EQ(ret, 1);
1017 }
1018 
1019 /**
1020  * @tc.name: SetSystemBarProperty
1021  * @tc.desc: SetSystemBarProperty
1022  * @tc.type: FUNC
1023  */
HWTEST_F(SceneSessionTest, SetSystemBarProperty, Function | SmallTest | Level2)1024 HWTEST_F(SceneSessionTest, SetSystemBarProperty, Function | SmallTest | Level2)
1025 {
1026     SessionInfo info;
1027     info.abilityName_ = "Background01";
1028     info.bundleName_ = "IsFloatingWindowAppType";
1029     info.windowType_ = 1;
1030     sptr<Rosen::ISession> session_;
1031     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1032         new (std::nothrow) SceneSession::SpecificSessionCallback();
1033     EXPECT_NE(specificCallback_, nullptr);
1034 
1035     sptr<SceneSession> scensession;
1036     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1037     EXPECT_NE(scensession, nullptr);
1038     scensession->property_ = nullptr;
1039     SystemBarProperty statusBarProperty;
1040     scensession->SetSystemBarProperty(WindowType::WINDOW_TYPE_FLOAT_CAMERA, statusBarProperty);
1041     ASSERT_EQ(scensession->SetSystemBarProperty(WindowType::WINDOW_TYPE_FLOAT_CAMERA, statusBarProperty),
1042               WSError::WS_ERROR_NULLPTR);
1043     sptr<WindowSessionProperty> property = new WindowSessionProperty();
1044     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1045     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1046     scensession->property_ = property;
1047     ASSERT_EQ(scensession->SetSystemBarProperty(WindowType::WINDOW_TYPE_FLOAT_CAMERA, statusBarProperty),
1048               WSError::WS_OK);
1049 
1050     scensession->onSystemBarPropertyChange_ = [](
1051         const std::unordered_map<WindowType, SystemBarProperty>& propertyMap){};
1052     ASSERT_EQ(scensession->SetSystemBarProperty(WindowType::WINDOW_TYPE_FLOAT_CAMERA, statusBarProperty),
1053         WSError::WS_OK);
1054 }
1055 
1056 /**
1057  * @tc.name: OnShowWhenLocked
1058  * @tc.desc: OnShowWhenLocked
1059  * @tc.type: FUNC ok
1060  */
HWTEST_F(SceneSessionTest, OnShowWhenLocked, Function | SmallTest | Level2)1061 HWTEST_F(SceneSessionTest, OnShowWhenLocked, Function | SmallTest | Level2)
1062 {
1063     SessionInfo info;
1064     info.abilityName_ = "Background01";
1065     info.bundleName_ = "IsFloatingWindowAppType";
1066     info.windowType_ = 1;
1067     sptr<Rosen::ISession> session_;
1068     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1069         new (std::nothrow) SceneSession::SpecificSessionCallback();
1070     EXPECT_NE(specificCallback_, nullptr);
1071     sptr<SceneSession> scensession;
1072     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1073     EXPECT_NE(scensession, nullptr);
1074     int ret = 0;
1075     scensession->OnShowWhenLocked(false);
1076     ASSERT_EQ(ret, 0);
1077 
1078     scensession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback();
1079     EXPECT_NE(scensession->sessionChangeCallback_, nullptr);
1080     scensession->sessionChangeCallback_->OnShowWhenLocked_ = [](bool showWhenLocked){};
1081     ASSERT_EQ(scensession->OnShowWhenLocked(false), WSError::WS_OK);
1082 }
1083 
1084 /**
1085  * @tc.name: IsShowWhenLocked
1086  * @tc.desc: IsShowWhenLocked
1087  * @tc.type: FUNC ok
1088  */
HWTEST_F(SceneSessionTest, IsShowWhenLocked, Function | SmallTest | Level2)1089 HWTEST_F(SceneSessionTest, IsShowWhenLocked, Function | SmallTest | Level2)
1090 {
1091     SessionInfo info;
1092     info.abilityName_ = "Background01";
1093     info.bundleName_ = "IsFloatingWindowAppType";
1094     info.windowType_ = 1;
1095     sptr<Rosen::ISession> session_;
1096     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1097         new (std::nothrow) SceneSession::SpecificSessionCallback();
1098     EXPECT_NE(specificCallback_, nullptr);
1099     sptr<SceneSession> scensession;
1100     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1101     EXPECT_NE(scensession, nullptr);
1102     sptr<WindowSessionProperty> property = new WindowSessionProperty();
1103     EXPECT_NE(property, nullptr);
1104     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1105     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1106     ASSERT_EQ(scensession->IsShowWhenLocked(), false);
1107     scensession->property_ = property;
1108     scensession->SetTemporarilyShowWhenLocked(true);
1109     ASSERT_EQ(scensession->IsShowWhenLocked(), true);
1110     property->SetWindowFlags(4);
1111     scensession->SetTemporarilyShowWhenLocked(false);
1112     ASSERT_EQ(scensession->IsShowWhenLocked(), true);
1113     scensession->SetTemporarilyShowWhenLocked(true);
1114     ASSERT_EQ(scensession->IsShowWhenLocked(), true);
1115 }
1116 
1117 /**
1118  * @tc.name: GetAvoidAreaByType
1119  * @tc.desc: GetAvoidAreaByType
1120  * @tc.type: FUNC ok
1121  */
HWTEST_F(SceneSessionTest, GetAvoidAreaByType, Function | SmallTest | Level2)1122 HWTEST_F(SceneSessionTest, GetAvoidAreaByType, Function | SmallTest | Level2)
1123 {
1124     SessionInfo info;
1125     info.abilityName_ = "Background01";
1126     info.bundleName_ = "IsFloatingWindowAppType";
1127     info.windowType_ = 1;
1128     sptr<Rosen::ISession> session_;
1129     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1130         new (std::nothrow) SceneSession::SpecificSessionCallback();
1131     EXPECT_NE(specificCallback_, nullptr);
1132         specificCallback_->onGetSceneSessionVectorByType_ = [](WindowType type,
1133             uint64_t displayId)-> std::vector<sptr<SceneSession>>
1134     {
1135         SessionInfo info_;
1136         info_.abilityName_ = "Background01";
1137         info_.bundleName_ = "IsFloatingWindowAppType";
1138         std::vector<sptr<SceneSession>> backgroundSession;
1139         sptr<SceneSession> session2=new (std::nothrow) SceneSession(info_, nullptr);
1140         backgroundSession.push_back(session2);
1141         return backgroundSession;
1142     };
1143     sptr<SceneSession> scensession;
1144     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1145     EXPECT_NE(scensession, nullptr);
1146     WSRect rect = { 0, 0, 320, 240}; // width: 320, height: 240
1147     scensession->SetSessionRect(rect);
1148     sptr<WindowSessionProperty> property = new WindowSessionProperty();
1149     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1150     scensession->property_ = property;
1151     AvoidArea avoidArea;
1152     scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT);
1153     scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM);
1154     scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_KEYBOARD);
1155     scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM_GESTURE);
1156     EXPECT_NE(scensession, nullptr);
1157 
1158     property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
1159     scensession->property_ = property;
1160     scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_CUTOUT);
1161     scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM);
1162     scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_KEYBOARD);
1163     scensession->GetAvoidAreaByType(AvoidAreaType::TYPE_SYSTEM_GESTURE);
1164     EXPECT_NE(scensession, nullptr);
1165 }
1166 
1167 /**
1168  * @tc.name: TransferPointerEvent
1169  * @tc.desc: TransferPointerEvent
1170  * @tc.type: FUNC
1171  */
HWTEST_F(SceneSessionTest, TransferPointerEvent, Function | SmallTest | Level2)1172 HWTEST_F(SceneSessionTest, TransferPointerEvent, Function | SmallTest | Level2)
1173 {
1174     SessionInfo info;
1175     info.abilityName_ = "Background01";
1176     info.bundleName_ = "IsFloatingWindowAppType";
1177     info.windowType_ = 1;
1178     sptr<Rosen::ISession> session_;
1179     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1180         new (std::nothrow) SceneSession::SpecificSessionCallback();
1181     EXPECT_NE(specificCallback_, nullptr);
1182     sptr<SceneSession> scensession;
1183     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1184     EXPECT_NE(scensession, nullptr);
1185     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
1186     ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent), WSError::WS_ERROR_NULLPTR);
1187     std::shared_ptr<MMI::PointerEvent> pointerEvent_ =  MMI::PointerEvent::Create();
1188     sptr<WindowSessionProperty> property = new WindowSessionProperty();
1189     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1190     property->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
1191     property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1192     property->SetPersistentId(11);
1193     scensession->property_ = property;
1194     ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent_), WSError::WS_ERROR_INVALID_SESSION);
1195 }
1196 
1197 /**
1198  * @tc.name: TransferPointerEventDecorDialog
1199  * @tc.desc: TransferPointerEventDecorDialog
1200  * @tc.type: FUNC
1201  */
HWTEST_F(SceneSessionTest, TransferPointerEventDecorDialog, Function | SmallTest | Level2)1202 HWTEST_F(SceneSessionTest, TransferPointerEventDecorDialog, Function | SmallTest | Level2)
1203 {
1204     SessionInfo info;
1205     info.abilityName_ = "TransferPointerEventDecorDialog";
1206     info.bundleName_ = "TransferPointerEventDecorDialogBundle";
1207     info.windowType_ = 2122;
1208     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1209         new (std::nothrow) SceneSession::SpecificSessionCallback();
1210     sptr<SceneSession> scensession =
1211         new (std::nothrow) SceneSession(info, specificCallback_);
1212     scensession->moveDragController_ = new MoveDragController(12);
1213     scensession->SetSessionState(SessionState::STATE_ACTIVE);
1214     std::shared_ptr<MMI::PointerEvent> pointerEvent_ =  MMI::PointerEvent::Create();
1215     sptr<WindowSessionProperty> property = new WindowSessionProperty();
1216     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1217     property->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
1218     property->SetWindowType(WindowType::WINDOW_TYPE_DIALOG);
1219     property->SetDecorEnable(true);
1220     property->SetDragEnabled(true);
1221     property->SetPersistentId(12);
1222     scensession->property_ = property;
1223     EXPECT_NE(scensession, nullptr);
1224 }
1225 
1226 /**
1227  * @tc.name: TransferPointerEventSystemDialog
1228  * @tc.desc: TransferPointerEventSystemDialog
1229  * @tc.type: FUNC
1230  */
HWTEST_F(SceneSessionTest, TransferPointerEventSystemDialog, Function | SmallTest | Level2)1231 HWTEST_F(SceneSessionTest, TransferPointerEventSystemDialog, Function | SmallTest | Level2)
1232 {
1233     SessionInfo info;
1234     info.abilityName_ = "TransferPointerEventSystemDialog";
1235     info.bundleName_ = "TransferPointerEventSystemDialogBundle";
1236     info.windowType_ = 2123;
1237     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1238         new (std::nothrow) SceneSession::SpecificSessionCallback();
1239     sptr<SceneSession> scensession =
1240         new (std::nothrow) SceneSession(info, specificCallback_);
1241     scensession->moveDragController_ = new MoveDragController(12);
1242     scensession->SetSessionState(SessionState::STATE_ACTIVE);
1243     std::shared_ptr<MMI::PointerEvent> pointerEvent_ =  MMI::PointerEvent::Create();
1244     sptr<WindowSessionProperty> property = new WindowSessionProperty();
1245     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1246     property->SetMaximizeMode(MaximizeMode::MODE_FULL_FILL);
1247     property->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
1248     property->SetDecorEnable(true);
1249     property->SetDragEnabled(true);
1250     property->SetPersistentId(13);
1251     scensession->property_ = property;
1252     EXPECT_NE(scensession, nullptr);
1253 }
1254 
1255 /**
1256  * @tc.name: CalculateAvoidAreaRect
1257  * @tc.desc: CalculateAvoidAreaRect
1258  * @tc.type: FUNC
1259  */
HWTEST_F(SceneSessionTest, CalculateAvoidAreaRect, Function | SmallTest | Level2)1260 HWTEST_F(SceneSessionTest, CalculateAvoidAreaRect, Function | SmallTest | Level2)
1261 {
1262     SessionInfo info;
1263     info.abilityName_ = "Background01";
1264     info.bundleName_ = "IsFloatingWindowAppType";
1265     info.windowType_ = 1;
1266     sptr<Rosen::ISession> session_;
1267     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1268         new (std::nothrow) SceneSession::SpecificSessionCallback();
1269     EXPECT_NE(specificCallback_, nullptr);
1270     sptr<SceneSession> scensession;
1271     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1272     EXPECT_NE(scensession, nullptr);
1273     int ret = 0;
1274     WSRect overlapRect = { 0, 0, 0, 0 };
1275     WSRect avoidRect = { 0, 0, 0, 0 };
1276     AvoidArea avoidArea;
1277     scensession->CalculateAvoidAreaRect(overlapRect, avoidRect, avoidArea);
1278     WSRect overlapRect_ = { 1, 1, 1, 1 };
1279     WSRect avoidRect_ = { 1, 1, 1, 1 };
1280     scensession->CalculateAvoidAreaRect(overlapRect_, avoidRect_, avoidArea);
1281     ASSERT_EQ(ret, 0);
1282 }
1283 
1284 /**
1285  * @tc.name: OnNeedAvoid
1286  * @tc.desc: OnNeedAvoid
1287  * @tc.type: FUNC
1288  */
HWTEST_F(SceneSessionTest, OnNeedAvoid, Function | SmallTest | Level2)1289 HWTEST_F(SceneSessionTest, OnNeedAvoid, Function | SmallTest | Level2)
1290 {
1291     SessionInfo info;
1292     info.abilityName_ = "Background01";
1293     info.bundleName_ = "IsFloatingWindowAppType";
1294     info.windowType_ = 1;
1295     sptr<Rosen::ISession> session_;
1296     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1297         new (std::nothrow) SceneSession::SpecificSessionCallback();
1298     EXPECT_NE(specificCallback_, nullptr);
1299     sptr<SceneSession> scensession;
1300     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1301     EXPECT_NE(scensession, nullptr);
1302     ASSERT_EQ(scensession->OnNeedAvoid(false), WSError::WS_OK);
1303 
1304     scensession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback();
1305     EXPECT_NE(scensession->sessionChangeCallback_, nullptr);
1306     scensession->sessionChangeCallback_->OnNeedAvoid_ = [](bool state){};
1307     ASSERT_EQ(scensession->OnNeedAvoid(false), WSError::WS_OK);
1308 }
1309 
1310 /**
1311  * @tc.name: SetCollaboratorType
1312  * @tc.desc: SetCollaboratorType
1313  * @tc.type: FUNC
1314  */
HWTEST_F(SceneSessionTest, SetCollaboratorType, Function | SmallTest | Level2)1315 HWTEST_F(SceneSessionTest, SetCollaboratorType, Function | SmallTest | Level2)
1316 {
1317     SessionInfo info;
1318     info.abilityName_ = "Background01";
1319     info.bundleName_ = "IsFloatingWindowAppType";
1320     info.windowType_ = 1;
1321     sptr<Rosen::ISession> session_;
1322     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1323         new (std::nothrow) SceneSession::SpecificSessionCallback();
1324     EXPECT_NE(specificCallback_, nullptr);
1325     sptr<SceneSession> scensession;
1326     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1327     EXPECT_NE(scensession, nullptr);
1328     scensession->SetCollaboratorType(2);
1329     ASSERT_EQ(scensession->GetCollaboratorType(), 2);
1330 }
1331 
1332 /**
1333  * @tc.name: GetAbilityInfo
1334  * @tc.desc: GetAbilityInfo
1335  * @tc.type: FUNC
1336  */
HWTEST_F(SceneSessionTest, GetAbilityInfo, Function | SmallTest | Level2)1337 HWTEST_F(SceneSessionTest, GetAbilityInfo, Function | SmallTest | Level2)
1338 {
1339     SessionInfo info;
1340     info.abilityName_ = "Background01";
1341     info.bundleName_ = "IsFloatingWindowAppType";
1342     info.windowType_ = 1;
1343     sptr<Rosen::ISession> session_;
1344     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1345         new (std::nothrow) SceneSession::SpecificSessionCallback();
1346     EXPECT_NE(specificCallback_, nullptr);
1347     sptr<SceneSession> scensession;
1348     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1349     EXPECT_NE(scensession, nullptr);
1350     std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo;
1351     scensession->SetAbilitySessionInfo(abilityInfo);
1352     ASSERT_EQ(scensession->GetAbilityInfo(), abilityInfo);
1353 }
1354 
1355 /**
1356  * @tc.name: UpdateCameraWindowStatus
1357  * @tc.desc: UpdateCameraWindowStatus
1358  * @tc.type: FUNC
1359  */
HWTEST_F(SceneSessionTest, UpdateCameraWindowStatus, Function | SmallTest | Level2)1360 HWTEST_F(SceneSessionTest, UpdateCameraWindowStatus, Function | SmallTest | Level2)
1361 {
1362     SessionInfo info;
1363     info.abilityName_ = "Background01";
1364     info.bundleName_ = "UpdateCameraWindowStatus";
1365     info.windowType_ = 1;
1366     sptr<Rosen::ISession> session_;
1367     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1368         new (std::nothrow) SceneSession::SpecificSessionCallback();
1369     EXPECT_NE(specificCallback_, nullptr);
1370     sptr<SystemSession> sysSession;
1371     sysSession = new (std::nothrow) SystemSession(info, specificCallback_);
1372     EXPECT_NE(sysSession, nullptr);
1373     int ret = 1;
1374     specificCallback_->onCameraFloatSessionChange_ = [](uint32_t accessTokenId, bool isShowing) {};
1375     specificCallback_->onCameraSessionChange_ = [](uint32_t accessTokenId, bool isShowing) {};
1376 
1377     sysSession->UpdateCameraWindowStatus(false);
1378     sysSession = new (std::nothrow) SystemSession(info, specificCallback_);
1379     sysSession->UpdateCameraWindowStatus(false);
1380     sptr<WindowSessionProperty> property = new WindowSessionProperty();
1381     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1382     sysSession->property_ = property;
1383     sysSession->UpdateCameraWindowStatus(false);
1384     property->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA);
1385     sysSession->property_ = property;
1386     sysSession->UpdateCameraWindowStatus(false);
1387     property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
1388     property->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
1389     PiPTemplateInfo pipType;
1390     pipType.pipTemplateType = static_cast<uint32_t>(PiPTemplateType::VIDEO_CALL);
1391     sysSession->SetPiPTemplateInfo(pipType);
1392     sysSession->property_ = property;
1393     sysSession->UpdateCameraWindowStatus(false);
1394     ASSERT_EQ(ret, 1);
1395 }
1396 
1397 /**
1398  * @tc.name: GetRatioPreferenceKey
1399  * @tc.desc: GetRatioPreferenceKey
1400  * @tc.type: FUNC
1401  */
HWTEST_F(SceneSessionTest, GetRatioPreferenceKey, Function | SmallTest | Level2)1402 HWTEST_F(SceneSessionTest, GetRatioPreferenceKey, Function | SmallTest | Level2)
1403 {
1404     SessionInfo info;
1405     info.abilityName_ = "ability";
1406     info.bundleName_ = "bundle";
1407     info.moduleName_ = "module";
1408     info.windowType_ = 1;
1409     sptr<Rosen::ISession> session_;
1410     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1411         new (std::nothrow) SceneSession::SpecificSessionCallback();
1412     EXPECT_NE(specificCallback_, nullptr);
1413     sptr<SceneSession> scensession;
1414     scensession = new (std::nothrow) SceneSession(info, nullptr);
1415     EXPECT_NE(scensession, nullptr);
1416     std::string key = info.bundleName_ + info.moduleName_ + info.abilityName_;
1417     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1418     ASSERT_EQ(key, scensession->GetRatioPreferenceKey());
1419 
1420     std::string key2(30, 'a');
1421     std::string key3(80, 'a');
1422     scensession->sessionInfo_.bundleName_ = key2;
1423     scensession->sessionInfo_.moduleName_ = key2;
1424     scensession->sessionInfo_.abilityName_ = key2;
1425     ASSERT_EQ(key3, scensession->GetRatioPreferenceKey());
1426 }
1427 
1428 /**
1429  * @tc.name: NotifyPropertyWhenConnect
1430  * @tc.desc: NotifyPropertyWhenConnect
1431  * @tc.type: FUNC
1432  */
HWTEST_F(SceneSessionTest, NotifyPropertyWhenConnect, Function | SmallTest | Level2)1433 HWTEST_F(SceneSessionTest, NotifyPropertyWhenConnect, Function | SmallTest | Level2)
1434 {
1435     SessionInfo info;
1436     info.abilityName_ = "ability";
1437     info.bundleName_ = "bundle";
1438     info.moduleName_ = "module";
1439     info.windowType_ = 1;
1440     sptr<Rosen::ISession> session_;
1441     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1442         new (std::nothrow) SceneSession::SpecificSessionCallback();
1443     EXPECT_NE(specificCallback_, nullptr);
1444     sptr<SceneSession> scensession;
1445     scensession = new (std::nothrow) SceneSession(info, nullptr);
1446     EXPECT_NE(scensession, nullptr);
1447     int ret = 1;
1448     std::string key = info.bundleName_ + info.moduleName_ + info.abilityName_;
1449     scensession = new (std::nothrow) SceneSession(info, specificCallback_);
1450     scensession->NotifyPropertyWhenConnect();
1451     sptr<WindowSessionProperty> property = new WindowSessionProperty();
1452     property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
1453     scensession->property_ = property;
1454     scensession->NotifyPropertyWhenConnect();
1455     ASSERT_EQ(ret, 1);
1456 
1457     scensession->SetSessionProperty(nullptr);
1458     scensession->NotifyPropertyWhenConnect();
1459     ASSERT_EQ(scensession->GetSessionProperty(), nullptr);
1460 }
1461 
1462 /**
1463  * @tc.name: DumpSessionInfo
1464  * @tc.desc: DumpSessionInfo
1465  * @tc.type: FUNC
1466  */
HWTEST_F(SceneSessionTest, DumpSessionInfo, Function | SmallTest | Level2)1467 HWTEST_F(SceneSessionTest, DumpSessionInfo, Function | SmallTest | Level2)
1468 {
1469     SessionInfo info;
1470     info.bundleName_ = "SceneSessionTest";
1471     info.abilityName_ = "DumpSessionInfo";
1472     info.windowType_ = 1;
1473     sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
1474     EXPECT_NE(scensession, nullptr);
1475     std::vector<std::string> infos;
1476     scensession->DumpSessionInfo(infos);
1477     ASSERT_FALSE(infos.empty());
1478 }
1479 
1480 /**
1481  * @tc.name: OnSessionEvent
1482  * @tc.desc: normal function
1483  * @tc.type: FUNC
1484  */
HWTEST_F(SceneSessionTest, OnSessionEvent, Function | SmallTest | Level2)1485 HWTEST_F(SceneSessionTest, OnSessionEvent, Function | SmallTest | Level2)
1486 {
1487     SessionInfo info;
1488     info.abilityName_ = "OnSessionEvent";
1489     info.bundleName_ = "OnSessionEvent";
1490     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1491     EXPECT_NE(sceneSession, nullptr);
1492     sceneSession->moveDragController_ = new MoveDragController(1);
1493     sceneSession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback();
1494     sceneSession->OnSessionEvent(SessionEvent::EVENT_START_MOVE);
1495     sceneSession->moveDragController_->isStartDrag_ = true;
1496     sceneSession->moveDragController_->hasPointDown_ = true;
1497     sceneSession->sessionChangeCallback_ = new SceneSession::SessionChangeCallback();
1498     EXPECT_NE(sceneSession->sessionChangeCallback_, nullptr);
1499     ASSERT_EQ(sceneSession->OnSessionEvent(SessionEvent::EVENT_START_MOVE), WSError::WS_OK);
1500     ASSERT_EQ(sceneSession->OnSessionEvent(SessionEvent::EVENT_END_MOVE), WSError::WS_OK);
1501 }
1502 
1503 /**
1504  * @tc.name: OnSystemSessionEvent
1505  * @tc.desc: normal function
1506  * @tc.type: FUNC
1507  */
HWTEST_F(SceneSessionTest, OnSystemSessionEvent, Function | SmallTest | Level2)1508 HWTEST_F(SceneSessionTest, OnSystemSessionEvent, Function | SmallTest | Level2)
1509 {
1510     SessionInfo info;
1511     info.abilityName_ = "OnSystemSessionEvent";
1512     info.bundleName_ = "OnSystemSessionEvent";
1513     sptr<Rosen::ISession> session_;
1514     sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
1515     ASSERT_NE(scensession, nullptr);
1516 
1517     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
1518     property->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
1519     scensession->SetSessionProperty(property);
1520     scensession->isActive_ = false;
1521 
1522     SessionEvent event = SessionEvent::EVENT_START_MOVE;
1523     auto result = scensession->OnSystemSessionEvent(event);
1524     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
1525 }
1526 
1527 /**
1528  * @tc.name: OnTitleAndDockHoverShowChange
1529  * @tc.desc: normal function
1530  * @tc.type: FUNC
1531  */
HWTEST_F(SceneSessionTest, OnTitleAndDockHoverShowChange, Function | SmallTest | Level2)1532 HWTEST_F(SceneSessionTest, OnTitleAndDockHoverShowChange, Function | SmallTest | Level2)
1533 {
1534     SessionInfo info;
1535     info.abilityName_ = "OnTitleAndDockHoverShowChange";
1536     info.bundleName_ = "OnTitleAndDockHoverShowChange";
1537     sptr<Rosen::ISession> session_;
1538     sptr<SceneSession> scensession = sptr<MainSession>::MakeSptr(info, nullptr);
1539     ASSERT_NE(scensession, nullptr);
1540 
1541     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1542     property->SetWindowType(WindowType::WINDOW_TYPE_GLOBAL_SEARCH);
1543     scensession->SetSessionProperty(property);
1544     auto result = scensession->OnTitleAndDockHoverShowChange(true, true);
1545     EXPECT_EQ(result, WSError::WS_OK);
1546 }
1547 
1548 /**
1549  * @tc.name: SetTopmost
1550  * @tc.desc: normal function
1551  * @tc.type: FUNC
1552  */
HWTEST_F(SceneSessionTest, SetTopmost, Function | SmallTest | Level2)1553 HWTEST_F(SceneSessionTest, SetTopmost, Function | SmallTest | Level2)
1554 {
1555     SessionInfo info;
1556     info.abilityName_ = "SetTopmost";
1557     info.bundleName_ = "SetTopmost";
1558     sptr<Rosen::ISession> session_;
1559     sptr<SceneSession> scenesession = new (std::nothrow) MainSession(info, nullptr);
1560     EXPECT_NE(scenesession, nullptr);
1561 
1562     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
1563     scenesession->SetSessionProperty(property);
1564     auto result = scenesession->SetTopmost(false);
1565     ASSERT_EQ(result, WSError::WS_OK);
1566     ASSERT_FALSE(scenesession->IsTopmost());
1567 }
1568 
1569 /**
1570  * @tc.name: SetMainWindowTopmost
1571  * @tc.desc: normal function
1572  * @tc.type: FUNC
1573  */
HWTEST_F(SceneSessionTest, SetMainWindowTopmost, Function | SmallTest | Level2)1574 HWTEST_F(SceneSessionTest, SetMainWindowTopmost, Function | SmallTest | Level2)
1575 {
1576     SessionInfo info;
1577     info.abilityName_ = "SetMainWindowTopmost";
1578     info.bundleName_ = "SetMainWindowTopmost";
1579     sptr<SceneSession> sceneSession = new (std::nothrow) MainSession(info, nullptr);
1580     EXPECT_NE(sceneSession, nullptr);
1581 
1582     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
1583     sceneSession->SetSessionProperty(property);
1584     auto result = sceneSession->SetMainWindowTopmost(false);
1585     ASSERT_EQ(result, WSError::WS_OK);
1586     ASSERT_FALSE(sceneSession->IsMainWindowTopmost());
1587 }
1588 
1589 /**
1590  * @tc.name: SetAspectRatio2
1591  * @tc.desc: test for aspectRatio NearZero
1592  * @tc.type: FUNC
1593  */
HWTEST_F(SceneSessionTest, SetAspectRatio2, Function | SmallTest | Level2)1594 HWTEST_F(SceneSessionTest, SetAspectRatio2, Function | SmallTest | Level2)
1595 {
1596     SessionInfo info;
1597     info.abilityName_ = "SetAspectRatio2";
1598     info.bundleName_ = "SetAspectRatio2";
1599     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1600     sceneSession->isActive_ = true;
1601 
1602     float ratio = 0.0001;
1603     auto result = sceneSession->SetAspectRatio(ratio);
1604     ASSERT_EQ(result, WSError::WS_OK);
1605 
1606     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1607     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1608     sceneSession->SetSessionProperty(property);
1609     result = sceneSession->SetAspectRatio(ratio);
1610     ASSERT_EQ(result, WSError::WS_OK);
1611     ASSERT_EQ(sceneSession->GetAspectRatio(), ratio);
1612 }
1613 
1614 /**
1615  * @tc.name: SetAspectRatio3
1616  * @tc.desc: test for aspectRatio is smaller than minWidth/maxHeight
1617  * @tc.type: FUNC
1618  */
HWTEST_F(SceneSessionTest, SetAspectRatio3, Function | SmallTest | Level2)1619 HWTEST_F(SceneSessionTest, SetAspectRatio3, Function | SmallTest | Level2)
1620 {
1621     SessionInfo info;
1622     info.abilityName_ = "SetAspectRatio3";
1623     info.bundleName_ = "SetAspectRatio3";
1624     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1625     sceneSession->isActive_ = true;
1626 
1627     float ratio = 2.5;
1628     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1629     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1630     WindowLimits limits;
1631     limits.maxWidth_ = 3000;
1632     limits.maxHeight_ = 3000;
1633     limits.minWidth_ = 2000;
1634     limits.minHeight_ = 2000;
1635     property->SetWindowLimits(limits);
1636     sceneSession->SetSessionProperty(property);
1637     auto result = sceneSession->SetAspectRatio(ratio);
1638     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
1639 }
1640 
1641 /**
1642  * @tc.name: SetAspectRatio4
1643  * @tc.desc: test for aspectRatio is smaller than minWidth/maxHeight
1644  * @tc.type: FUNC
1645  */
HWTEST_F(SceneSessionTest, SetAspectRatio4, Function | SmallTest | Level2)1646 HWTEST_F(SceneSessionTest, SetAspectRatio4, Function | SmallTest | Level2)
1647 {
1648     SessionInfo info;
1649     info.abilityName_ = "SetAspectRatio4";
1650     info.bundleName_ = "SetAspectRatio4";
1651     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1652     sceneSession->isActive_ = true;
1653 
1654     float ratio = 0.1;
1655     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1656     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1657     WindowLimits limits;
1658     limits.maxWidth_ = 3000;
1659     limits.maxHeight_ = 3000;
1660     limits.minWidth_ = 2000;
1661     limits.minHeight_ = 2000;
1662     property->SetWindowLimits(limits);
1663     sceneSession->SetSessionProperty(property);
1664     auto result = sceneSession->SetAspectRatio(ratio);
1665     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
1666 }
1667 
1668 /**
1669  * @tc.name: SetAspectRatio5
1670  * @tc.desc: normal function
1671  * @tc.type: FUNC
1672  */
HWTEST_F(SceneSessionTest, SetAspectRatio5, Function | SmallTest | Level2)1673 HWTEST_F(SceneSessionTest, SetAspectRatio5, Function | SmallTest | Level2)
1674 {
1675     SessionInfo info;
1676     info.abilityName_ = "SetAspectRatio5";
1677     info.bundleName_ = "SetAspectRatio5";
1678     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1679     sceneSession->isActive_ = true;
1680 
1681     float ratio = 0.1;
1682     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1683     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1684     WindowLimits limits;
1685     limits.maxHeight_ = 10;
1686     limits.minWidth_ = 0;
1687     property->SetWindowLimits(limits);
1688     sceneSession->SetSessionProperty(property);
1689     sceneSession->SetAspectRatio(ratio);
1690     auto result = sceneSession->SetAspectRatio(ratio);
1691     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
1692 }
1693 
1694 /**
1695  * @tc.name: SetAspectRatio6
1696  * @tc.desc: test for sessionProperty is nullptr
1697  * @tc.type: FUNC
1698  */
HWTEST_F(SceneSessionTest, SetAspectRatio6, Function | SmallTest | Level2)1699 HWTEST_F(SceneSessionTest, SetAspectRatio6, Function | SmallTest | Level2)
1700 {
1701     SessionInfo info;
1702     info.abilityName_ = "SetAspectRatio6";
1703     info.bundleName_ = "SetAspectRatio6";
1704     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1705     sceneSession->isActive_ = true;
1706     sceneSession->SetSessionProperty(nullptr);
1707 
1708     float ratio = 0.1;
1709     auto result = sceneSession->SetAspectRatio(ratio);
1710     ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
1711 }
1712 
1713 /**
1714  * @tc.name: SetAspectRatio7
1715  * @tc.desc: normal function
1716  * @tc.type: FUNC
1717  */
HWTEST_F(SceneSessionTest, SetAspectRatio7, Function | SmallTest | Level2)1718 HWTEST_F(SceneSessionTest, SetAspectRatio7, Function | SmallTest | Level2)
1719 {
1720     SessionInfo info;
1721     info.abilityName_ = "SetAspectRatio7";
1722     info.bundleName_ = "SetAspectRatio7";
1723     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1724     sceneSession->isActive_ = true;
1725 
1726     float ratio = 0.1;
1727     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1728     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1729     WindowLimits limits;
1730     limits.maxHeight_ = 10;
1731     limits.minWidth_ = 10;
1732     property->SetWindowLimits(limits);
1733     sceneSession->SetSessionProperty(property);
1734     auto result = sceneSession->SetAspectRatio(ratio);
1735     ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
1736 }
1737 
1738 /**
1739  * @tc.name: UpdateRect
1740  * @tc.desc: normal function
1741  * @tc.type: FUNC
1742  */
HWTEST_F(SceneSessionTest, UpdateRect, Function | SmallTest | Level2)1743 HWTEST_F(SceneSessionTest, UpdateRect, Function | SmallTest | Level2)
1744 {
1745     SessionInfo info;
1746     info.abilityName_ = "UpdateRect";
1747     info.bundleName_ = "UpdateRect";
1748     sptr<Rosen::ISession> session_;
1749     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1750         new (std::nothrow) SceneSession::SpecificSessionCallback();
1751     EXPECT_NE(specificCallback_, nullptr);
1752     sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
1753     EXPECT_NE(scensession, nullptr);
1754     scensession->isActive_ = true;
1755 
1756     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
1757     property->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1758 
1759     scensession->SetSessionProperty(property);
1760     WSRect rect({1, 1, 1, 1});
1761     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1762     WSError result = scensession->UpdateRect(rect, reason, "SceneSessionTest");
1763     ASSERT_EQ(result, WSError::WS_OK);
1764 }
1765 
1766 /**
1767  * @tc.name: UpdateInputMethodSessionRect
1768  * @tc.desc: normal function
1769  * @tc.type: FUNC
1770  */
HWTEST_F(SceneSessionTest, UpdateInputMethodSessionRect, Function | SmallTest | Level2)1771 HWTEST_F(SceneSessionTest, UpdateInputMethodSessionRect, Function | SmallTest | Level2)
1772 {
1773     SessionInfo info;
1774     info.abilityName_ = "UpdateInputMethodSessionRect";
1775     info.bundleName_ = "UpdateInputMethodSessionRect";
1776     sptr<Rosen::ISession> session_;
1777     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1778         new (std::nothrow) SceneSession::SpecificSessionCallback();
1779     EXPECT_NE(specificCallback_, nullptr);
1780     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1781     EXPECT_NE(sceneSession, nullptr);
1782     sceneSession->isActive_ = true;
1783 
1784     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
1785     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1786     uint32_t p = 10;
1787     property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p);
1788 
1789     sceneSession->SetSessionProperty(property);
1790     WSRect rect({1, 1, 1, 1});
1791     WSRect newWinRect;
1792     WSRect newRequestRect;
1793     sceneSession->UpdateInputMethodSessionRect(rect, newWinRect, newRequestRect);
1794     EXPECT_NE(sceneSession, nullptr);
1795 
1796     sceneSession->SetSessionProperty(nullptr);
1797     auto res = sceneSession->UpdateInputMethodSessionRect(rect, newWinRect, newRequestRect);
1798     ASSERT_EQ(res, false);
1799 
1800     property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_FLOAT, p);
1801     sceneSession->SetSessionProperty(property);
1802     res = sceneSession->UpdateInputMethodSessionRect(rect, newWinRect, newRequestRect);
1803     ASSERT_EQ(res, false);
1804 }
1805 
1806 /**
1807  * @tc.name: UpdateSessionRect
1808  * @tc.desc: normal function
1809  * @tc.type: FUNC
1810  */
HWTEST_F(SceneSessionTest, UpdateSessionRect, Function | SmallTest | Level2)1811 HWTEST_F(SceneSessionTest, UpdateSessionRect, Function | SmallTest | Level2)
1812 {
1813     SessionInfo info;
1814     info.abilityName_ = "UpdateSessionRect";
1815     info.bundleName_ = "UpdateSessionRect";
1816     sptr<Rosen::ISession> session_;
1817     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1818         new (std::nothrow) SceneSession::SpecificSessionCallback();
1819     EXPECT_NE(specificCallback_, nullptr);
1820     sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
1821     EXPECT_NE(scensession, nullptr);
1822     scensession->isActive_ = true;
1823 
1824     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
1825     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1826     uint32_t p = 10;
1827     property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p);
1828 
1829     scensession->SetSessionProperty(property);
1830     WSRect rect({1, 1, 1, 1});
1831     SizeChangeReason reason = SizeChangeReason::MOVE;
1832     WSError result = scensession->UpdateSessionRect(rect, reason);
1833     ASSERT_EQ(result, WSError::WS_OK);
1834 }
1835 
1836 /**
1837  * @tc.name: UpdateSessionRect1
1838  * @tc.desc: normal function
1839  * @tc.type: FUNC
1840  */
HWTEST_F(SceneSessionTest, UpdateSessionRect1, Function | SmallTest | Level2)1841 HWTEST_F(SceneSessionTest, UpdateSessionRect1, Function | SmallTest | Level2)
1842 {
1843     SessionInfo info;
1844     info.abilityName_ = "UpdateSessionRect";
1845     info.bundleName_ = "UpdateSessionRect";
1846     sptr<Rosen::ISession> session_;
1847     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1848         new (std::nothrow) SceneSession::SpecificSessionCallback();
1849     EXPECT_NE(specificCallback_, nullptr);
1850     sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
1851     EXPECT_NE(scensession, nullptr);
1852     scensession->isActive_ = true;
1853 
1854     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
1855     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1856     uint32_t p = 10;
1857     property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p);
1858 
1859     scensession->SetSessionProperty(property);
1860     WSRect rect({1, 1, 1, 1});
1861     SizeChangeReason reason = SizeChangeReason::RESIZE;
1862     WSError result = scensession->UpdateSessionRect(rect, reason);
1863     ASSERT_EQ(result, WSError::WS_OK);
1864 }
1865 
1866 /**
1867  * @tc.name: UpdateSessionRect2
1868  * @tc.desc: normal function
1869  * @tc.type: FUNC
1870  */
HWTEST_F(SceneSessionTest, UpdateSessionRect2, Function | SmallTest | Level2)1871 HWTEST_F(SceneSessionTest, UpdateSessionRect2, Function | SmallTest | Level2)
1872 {
1873     SessionInfo info;
1874     info.abilityName_ = "UpdateSessionRect";
1875     info.bundleName_ = "UpdateSessionRect";
1876     sptr<Rosen::ISession> session_;
1877     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1878         new (std::nothrow) SceneSession::SpecificSessionCallback();
1879     EXPECT_NE(specificCallback_, nullptr);
1880     sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
1881     EXPECT_NE(scensession, nullptr);
1882     scensession->isActive_ = true;
1883 
1884     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
1885     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
1886     uint32_t p = 10;
1887     property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, p);
1888 
1889     scensession->SetSessionProperty(property);
1890     WSRect rect({1, 1, 1, 1});
1891     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1892     WSError result = scensession->UpdateSessionRect(rect, reason);
1893     ASSERT_EQ(result, WSError::WS_OK);
1894 }
1895 
1896 /**
1897  * @tc.name: UpdateSessionRect3
1898  * @tc.desc: test for isGlobal is true
1899  * @tc.type: FUNC
1900  */
HWTEST_F(SceneSessionTest, UpdateSessionRect3, Function | SmallTest | Level2)1901 HWTEST_F(SceneSessionTest, UpdateSessionRect3, Function | SmallTest | Level2)
1902 {
1903     SessionInfo info;
1904     info.abilityName_ = "UpdateSessionRect";
1905     info.bundleName_ = "UpdateSessionRect";
1906     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1907     sceneSession->isActive_ = true;
1908 
1909     sptr<WindowSessionProperty> property = sptr<WindowSessionProperty>::MakeSptr();
1910     property->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1911     property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 10);
1912 
1913     sceneSession->SetSessionProperty(property);
1914     SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1915     WSRect oldRect({1, 1, 1, 1});
1916     WSRect parentRect({10, 10, 1, 1});
1917 
1918     sptr<SceneSession> parentSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1919     sceneSession->SetParentSession(parentSession);
1920     EXPECT_NE(sceneSession->GetParentSession(), nullptr);
1921     parentSession->SetSessionRect(parentRect);
1922     sceneSession->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1923 
1924     bool isGlobal = true;
1925     WSError result = sceneSession->UpdateSessionRect(oldRect, reason, isGlobal);
1926     ASSERT_EQ(result, WSError::WS_OK);
1927 
1928     WSRect newRect = sceneSession->GetSessionRect();
1929     ASSERT_EQ(newRect.posX_, oldRect.posX_ - parentRect.posX_);
1930     ASSERT_EQ(newRect.posY_, oldRect.posY_ - parentRect.posY_);
1931 }
1932 
1933 /**
1934  * @tc.name: GetStatusBarHeight
1935  * @tc.desc: normal function
1936  * @tc.type: FUNC
1937  */
HWTEST_F(SceneSessionTest, GetStatusBarHeight, Function | SmallTest | Level1)1938 HWTEST_F(SceneSessionTest, GetStatusBarHeight, Function | SmallTest | Level1)
1939 {
1940     SessionInfo info;
1941     info.abilityName_ = "GetStatusBarHeight";
1942     info.bundleName_ = "GetStatusBarHeight";
1943     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
1944     EXPECT_NE(sceneSession, nullptr);
1945     int32_t height = sceneSession->GetStatusBarHeight();
1946     ASSERT_EQ(height, 0);
1947     SystemBarProperty propertyHide;
1948     propertyHide.enable_ = false;
1949     ASSERT_EQ(WSError::WS_OK, sceneSession->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR,
1950         propertyHide));
1951     ASSERT_EQ(height, 0);
1952     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
1953         new (std::nothrow) SceneSession::SpecificSessionCallback();
1954     EXPECT_NE(specificCallback_, nullptr);
1955     sceneSession = new (std::nothrow) SceneSession(info, specificCallback_);
1956     height = sceneSession->GetStatusBarHeight();
1957     ASSERT_EQ(height, 0);
1958     WSRect rect({0, 0, 0, 1});
1959     sceneSession->winRect_ = rect;
1960     specificCallback_->onGetSceneSessionVectorByType_ = [&](WindowType type,
1961         uint64_t displayId)->std::vector<sptr<SceneSession>>
1962     {
1963         std::vector<sptr<SceneSession>> vec;
1964         vec.push_back(sceneSession);
1965         return vec;
1966     };
1967     sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
1968     EXPECT_NE(property, nullptr);
1969     sceneSession->property_ = property;
1970     height = sceneSession->GetStatusBarHeight();
1971     ASSERT_EQ(height, 1);
1972     ASSERT_EQ(WSError::WS_OK, sceneSession->SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR,
1973         propertyHide));
1974     ASSERT_EQ(height, 1);
1975 }
1976 
1977 /**
1978  * @tc.name: GetAppForceLandscapeConfig
1979  * @tc.desc: GetAppForceLandscapeConfig
1980  * @tc.type: FUNC
1981  */
HWTEST_F(SceneSessionTest, GetAppForceLandscapeConfig, Function | SmallTest | Level2)1982 HWTEST_F(SceneSessionTest, GetAppForceLandscapeConfig, Function | SmallTest | Level2)
1983 {
1984     SessionInfo info;
1985     info.abilityName_ = "GetAppForceLandscapeConfig";
1986     info.bundleName_ = "GetAppForceLandscapeConfig";
1987     sptr<SceneSession::SpecificSessionCallback> specificCallback =
1988         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
1989     EXPECT_NE(specificCallback, nullptr);
1990     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
1991     EXPECT_NE(sceneSession, nullptr);
1992     AppForceLandscapeConfig config = {};
1993     auto result = sceneSession->GetAppForceLandscapeConfig(config);
1994     ASSERT_EQ(result, WMError::WM_ERROR_NULLPTR);
1995 }
1996 
1997 /**
1998  * @tc.name: HandleCompatibleModeMoveDrag
1999  * @tc.desc: HandleCompatibleModeMoveDrag
2000  * @tc.type: FUNC
2001  */
HWTEST_F(SceneSessionTest, HandleCompatibleModeMoveDrag, Function | SmallTest | Level2)2002 HWTEST_F(SceneSessionTest, HandleCompatibleModeMoveDrag, Function | SmallTest | Level2)
2003 {
2004     SessionInfo info;
2005     info.abilityName_ = "HandleCompatibleModeMoveDrag";
2006     info.bundleName_ = "HandleCompatibleModeMoveDrag";
2007     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2008     EXPECT_NE(sceneSession, nullptr);
2009 
2010     WSRect rect = {1, 1, 1, 1};
2011     WSRect rect2 = {1, 1, 2, 1};
2012     sceneSession->winRect_ = rect2;
2013     sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
2014     ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
2015 
2016     sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, false);
2017     ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
2018 
2019     rect2 = {1, 1, 1, 2};
2020     sceneSession->winRect_ = rect2;
2021     sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
2022     ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
2023 
2024     rect = {1, 1, 2000, 1};
2025     rect2 = {1, 1, 2, 1};
2026     sceneSession->winRect_ = rect2;
2027     sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
2028     ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
2029 
2030     rect = {1, 1, 2000, 1};
2031     rect2 = {1, 1, 1, 2};
2032     sceneSession->winRect_ = rect2;
2033     sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
2034     ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
2035 
2036     rect = {1, 1, 500, 1};
2037     rect2 = {1, 1, 1, 2};
2038     sceneSession->winRect_ = rect2;
2039     sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
2040     ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
2041 
2042     rect = {1, 1, 500, 1};
2043     rect2 = {1, 1, 1, 2};
2044     sceneSession->winRect_ = rect2;
2045     sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, false);
2046     ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
2047 
2048     sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::MOVE, false);
2049     ASSERT_EQ(sceneSession->reason_, SizeChangeReason::MOVE);
2050 }
2051 
2052 /**
2053  * @tc.name: SetMoveDragCallback
2054  * @tc.desc: SetMoveDragCallback
2055  * @tc.type: FUNC
2056  */
HWTEST_F(SceneSessionTest, SetMoveDragCallback, Function | SmallTest | Level2)2057 HWTEST_F(SceneSessionTest, SetMoveDragCallback, Function | SmallTest | Level2)
2058 {
2059     SessionInfo info;
2060     info.abilityName_ = "SetMoveDragCallback";
2061     info.bundleName_ = "SetMoveDragCallback";
2062     sptr<SceneSession::SpecificSessionCallback> specificCallback =
2063         sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
2064     EXPECT_NE(specificCallback, nullptr);
2065     sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
2066     EXPECT_NE(sceneSession, nullptr);
2067 
2068     sceneSession->moveDragController_ = nullptr;
2069     sceneSession->SetMoveDragCallback();
2070 }
2071 
2072 /**
2073  * @tc.name: GetScreenWidthAndHeightFromServer
2074  * @tc.desc: GetScreenWidthAndHeightFromServer
2075  * @tc.type: FUNC
2076  */
HWTEST_F(SceneSessionTest, GetScreenWidthAndHeightFromServer, Function | SmallTest | Level2)2077 HWTEST_F(SceneSessionTest, GetScreenWidthAndHeightFromServer, Function | SmallTest | Level2)
2078 {
2079     SessionInfo info;
2080     info.abilityName_ = "GetScreenWidthAndHeightFromServer";
2081     info.bundleName_ = "GetScreenWidthAndHeightFromServer";
2082     sptr<Rosen::ISession> session_;
2083     sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
2084         new (std::nothrow) SceneSession::SpecificSessionCallback();
2085     EXPECT_NE(specificCallback_, nullptr);
2086     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
2087     EXPECT_NE(sceneSession, nullptr);
2088     sceneSession->isActive_ = true;
2089 
2090     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
2091     EXPECT_NE(property, nullptr);
2092     property->SetWindowType(WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT);
2093     property->SetKeyboardSessionGravity(SessionGravity::SESSION_GRAVITY_BOTTOM, 0);
2094     sceneSession->SetSessionProperty(property);
2095 
2096     uint32_t screenWidth = 0;
2097     uint32_t screenHeight = 0;
2098     bool result = sceneSession->GetScreenWidthAndHeightFromServer(property, screenWidth, screenHeight);
2099     ASSERT_EQ(result, true);
2100 
2101     sceneSession->SetSessionProperty(nullptr);
2102     result = sceneSession->GetScreenWidthAndHeightFromServer(property, screenWidth, screenHeight);
2103     ASSERT_EQ(result, true);
2104 }
2105 
2106 /**
2107  * @tc.name: SetDefaultDisplayIdIfNeed
2108  * @tc.desc: SetDefaultDisplayIdIfNeed
2109  * @tc.type: FUNC
2110  */
HWTEST_F(SceneSessionTest, SetDefaultDisplayIdIfNeed, Function | SmallTest | Level2)2111 HWTEST_F(SceneSessionTest, SetDefaultDisplayIdIfNeed, Function | SmallTest | Level2)
2112 {
2113     SessionInfo info;
2114     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
2115     EXPECT_NE(sceneSession, nullptr);
2116     sceneSession->SetDefaultDisplayIdIfNeed();
2117 
2118     sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
2119     EXPECT_NE(property, nullptr);
2120     property->SetDisplayId(-99);
2121     sceneSession->SetSessionProperty(property);
2122     sceneSession->SetDefaultDisplayIdIfNeed();
2123     EXPECT_EQ(property->GetDisplayId(), SCREEN_ID_INVALID);
2124 }
2125 
2126 /**
2127  * @tc.name: SetSessionGlobalRect/GetSessionGlobalRect
2128  * @tc.desc: SetSessionGlobalRect
2129  * @tc.type: FUNC
2130  */
HWTEST_F(SceneSessionTest, SetSessionGlobalRect, Function | SmallTest | Level2)2131 HWTEST_F(SceneSessionTest, SetSessionGlobalRect, Function | SmallTest | Level2)
2132 {
2133     SessionInfo info;
2134     sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
2135     EXPECT_NE(sceneSession, nullptr);
2136     WSRect test = { 100, 100, 100, 100 };
2137     sceneSession->SetSessionGlobalRect(test);
2138     sceneSession->SetScbCoreEnabled(true);
2139     EXPECT_EQ(test, sceneSession->GetSessionGlobalRect());
2140 }
2141 } // namespace
2142 } // Rosen
2143 } // OHOS