1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include <gtest/gtest.h>
17#include <regex>
18#include <pointer_event.h>
19#include <ui/rs_surface_node.h>
20
21#include "mock/mock_session_stage.h"
22#include "mock/mock_window_event_channel.h"
23#include "mock/mock_pattern_detach_callback.h"
24#include "session/host/include/extension_session.h"
25#include "session/host/include/move_drag_controller.h"
26#include "session/host/include/scene_session.h"
27#include "session_manager/include/scene_session_manager.h"
28#include "session/host/include/session.h"
29#include "session_info.h"
30#include "process_options.h"
31#include "key_event.h"
32#include "wm_common.h"
33#include "window_manager_hilog.h"
34#include "accessibility_event_info.h"
35
36using namespace testing;
37using namespace testing::ext;
38
39namespace OHOS {
40namespace Rosen {
41namespace {
42const std::string UNDEFINED = "undefined";
43}
44
45class WindowSessionTest2 : public testing::Test {
46public:
47    static void SetUpTestCase();
48    static void TearDownTestCase();
49    void SetUp() override;
50    void TearDown() override;
51
52    int32_t GetTaskCount();
53    sptr<SceneSessionManager> ssm_;
54
55private:
56    RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
57    sptr<Session> session_ = nullptr;
58    static constexpr uint32_t WAIT_SYNC_IN_NS = 500000;
59
60    class TLifecycleListener : public ILifecycleListener {
61    public:
62        virtual ~TLifecycleListener() {}
63        void OnActivation() override {}
64        void OnConnect() override {}
65        void OnForeground() override {}
66        void OnBackground() override {}
67        void OnDisconnect() override {}
68        void OnExtensionDied() override {}
69        void OnExtensionTimeout(int32_t errorCode) override {}
70        void OnAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info,
71            int64_t uiExtensionIdLevel) override {}
72        void OnDrawingCompleted() override {}
73    };
74    std::shared_ptr<TLifecycleListener> lifecycleListener_ = std::make_shared<TLifecycleListener>();
75
76    sptr<SessionStageMocker> mockSessionStage_ = nullptr;
77    sptr<WindowEventChannelMocker> mockEventChannel_ = nullptr;
78};
79
80void WindowSessionTest2::SetUpTestCase()
81{
82}
83
84void WindowSessionTest2::TearDownTestCase()
85{
86}
87
88void WindowSessionTest2::SetUp()
89{
90    SessionInfo info;
91    info.abilityName_ = "testSession1";
92    info.moduleName_ = "testSession2";
93    info.bundleName_ = "testSession3";
94    session_ = new (std::nothrow) Session(info);
95    session_->surfaceNode_ = CreateRSSurfaceNode();
96    EXPECT_NE(nullptr, session_);
97    ssm_ = new SceneSessionManager();
98    session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_);
99    auto isScreenLockedCallback = [this]() {
100        return ssm_->IsScreenLocked();
101    };
102    session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
103
104    mockSessionStage_ = new (std::nothrow) SessionStageMocker();
105    ASSERT_NE(mockSessionStage_, nullptr);
106
107    mockEventChannel_ = new (std::nothrow) WindowEventChannelMocker(mockSessionStage_);
108    ASSERT_NE(mockEventChannel_, nullptr);
109}
110
111void WindowSessionTest2::TearDown()
112{
113    session_ = nullptr;
114    usleep(WAIT_SYNC_IN_NS);
115}
116
117RSSurfaceNode::SharedPtr WindowSessionTest2::CreateRSSurfaceNode()
118{
119    struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
120    rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTest2SurfaceNode";
121    auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
122    if (surfaceNode == nullptr) {
123        GTEST_LOG_(INFO) << "WindowSessionTest2::CreateRSSurfaceNode surfaceNode is nullptr";
124    }
125    return surfaceNode;
126}
127
128int32_t WindowSessionTest2::GetTaskCount()
129{
130    std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize();
131    std::regex pattern("\\d+");
132    std::smatch matches;
133    int32_t taskNum = 0;
134    while (std::regex_search(dumpInfo, matches, pattern)) {
135        taskNum += std::stoi(matches.str());
136        dumpInfo = matches.suffix();
137    }
138    return taskNum;
139}
140
141namespace {
142/**
143 * @tc.name: SetParentSession
144 * @tc.desc: SetParentSession Test
145 * @tc.type: FUNC
146 */
147HWTEST_F(WindowSessionTest2, SetParentSession, Function | SmallTest | Level2)
148{
149    ASSERT_NE(session_, nullptr);
150    SessionInfo info;
151    info.abilityName_ = "testSession1";
152    info.moduleName_ = "testSession2";
153    info.bundleName_ = "testSession3";
154    sptr<Session> session = new (std::nothrow) Session(info);
155    session_->SetParentSession(session);
156
157    session_->property_ = new WindowSessionProperty();
158    ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
159}
160
161/**
162 * @tc.name: BindDialogToParentSession
163 * @tc.desc: BindDialogToParentSession Test
164 * @tc.type: FUNC
165 */
166HWTEST_F(WindowSessionTest2, BindDialogToParentSession, Function | SmallTest | Level2)
167{
168    ASSERT_NE(session_, nullptr);
169    SessionInfo info;
170    info.abilityName_ = "testSession1";
171    info.moduleName_ = "testSession2";
172    info.bundleName_ = "testSession3";
173    sptr<Session> session = new (std::nothrow) Session(info);
174    session_->BindDialogToParentSession(session);
175
176    sptr<Session> session1 = new (std::nothrow) Session(info);
177    ASSERT_NE(session1, nullptr);
178    session1->persistentId_ = 33;
179    session1->SetParentSession(session_);
180    session1->state_ = SessionState::STATE_ACTIVE;
181    session_->dialogVec_.push_back(session1);
182
183    sptr<Session> session2 = new (std::nothrow) Session(info);
184    ASSERT_NE(session2, nullptr);
185    session2->persistentId_ = 34;
186    session2->SetParentSession(session_);
187    session2->state_ = SessionState::STATE_ACTIVE;
188    session_->dialogVec_.push_back(session2);
189    session_->BindDialogToParentSession(session1);
190
191    session_->property_ = new WindowSessionProperty();
192    ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
193}
194
195/**
196 * @tc.name: RemoveDialogToParentSession
197 * @tc.desc: RemoveDialogToParentSession Test
198 * @tc.type: FUNC
199 */
200HWTEST_F(WindowSessionTest2, RemoveDialogToParentSession, Function | SmallTest | Level2)
201{
202    ASSERT_NE(session_, nullptr);
203    SessionInfo info;
204    info.abilityName_ = "testSession1";
205    info.moduleName_ = "testSession2";
206    info.bundleName_ = "testSession3";
207    sptr<Session> session = new (std::nothrow) Session(info);
208    session_->RemoveDialogToParentSession(session);
209
210    sptr<Session> session1 = new (std::nothrow) Session(info);
211    ASSERT_NE(session1, nullptr);
212    session1->persistentId_ = 33;
213    session1->SetParentSession(session_);
214    session1->state_ = SessionState::STATE_ACTIVE;
215    session_->dialogVec_.push_back(session1);
216
217    sptr<Session> session2 = new (std::nothrow) Session(info);
218    ASSERT_NE(session2, nullptr);
219    session2->persistentId_ = 34;
220    session2->SetParentSession(session_);
221    session2->state_ = SessionState::STATE_ACTIVE;
222    session_->dialogVec_.push_back(session2);
223    session_->RemoveDialogToParentSession(session1);
224
225    session_->property_ = new WindowSessionProperty();
226    ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
227}
228
229/**
230 * @tc.name: TransferPointerEvent01
231 * @tc.desc: !IsSystemSession() && !IsSessionValid() is true
232 * @tc.type: FUNC
233 */
234HWTEST_F(WindowSessionTest2, TransferPointerEvent01, Function | SmallTest | Level2)
235{
236    ASSERT_NE(session_, nullptr);
237
238    session_->sessionInfo_.isSystem_ = false;
239    session_->state_ = SessionState::STATE_DISCONNECT;
240
241    std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
242    ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->TransferPointerEvent(pointerEvent));
243}
244
245/**
246 * @tc.name: TransferPointerEvent02
247 * @tc.desc: pointerEvent is nullptr
248 * @tc.type: FUNC
249 */
250HWTEST_F(WindowSessionTest2, TransferPointerEvent02, Function | SmallTest | Level2)
251{
252    ASSERT_NE(session_, nullptr);
253    session_->sessionInfo_.isSystem_ = true;
254
255    std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
256    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
257}
258
259/**
260 * @tc.name: TransferPointerEvent03
261 * @tc.desc: WindowType is WINDOW_TYPE_APP_MAIN_WINDOW, CheckDialogOnForeground() is true
262 * @tc.type: FUNC
263 */
264HWTEST_F(WindowSessionTest2, TransferPointerEvent03, Function | SmallTest | Level2)
265{
266    ASSERT_NE(session_, nullptr);
267
268    session_->sessionInfo_.isSystem_ = true;
269
270    std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
271    ASSERT_NE(pointerEvent, nullptr);
272
273    session_->property_ = new WindowSessionProperty();
274    session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
275
276    SessionInfo info;
277    info.abilityName_ = "dialogAbilityName";
278    info.moduleName_ = "dialogModuleName";
279    info.bundleName_ = "dialogBundleName";
280    sptr<Session> dialogSession = new (std::nothrow) Session(info);
281    ASSERT_NE(dialogSession, nullptr);
282    dialogSession->state_ = SessionState::STATE_ACTIVE;
283    session_->dialogVec_.push_back(dialogSession);
284
285    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
286}
287
288/**
289 * @tc.name: TransferPointerEvent04
290 * @tc.desc: parentSession_ && parentSession_->CheckDialogOnForeground() is true
291 * @tc.type: FUNC
292 */
293HWTEST_F(WindowSessionTest2, TransferPointerEvent04, Function | SmallTest | Level2)
294{
295    ASSERT_NE(session_, nullptr);
296
297    session_->sessionInfo_.isSystem_ = true;
298
299    std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
300    ASSERT_NE(pointerEvent, nullptr);
301
302    session_->property_ = new WindowSessionProperty();
303    session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
304
305    SessionInfo info;
306    info.abilityName_ = "dialogAbilityName";
307    info.moduleName_ = "dialogModuleName";
308    info.bundleName_ = "dialogBundleName";
309    sptr<Session> dialogSession = new (std::nothrow) Session(info);
310    ASSERT_NE(dialogSession, nullptr);
311    dialogSession->state_ = SessionState::STATE_ACTIVE;
312    session_->dialogVec_.push_back(dialogSession);
313    session_->parentSession_ = session_;
314
315    ASSERT_EQ(WSError::WS_ERROR_INVALID_PERMISSION, session_->TransferPointerEvent(pointerEvent));
316}
317
318/**
319 * @tc.name: TransferPointerEvent05
320 * @tc.desc: windowEventChannel_ is nullptr
321 * @tc.type: FUNC
322 */
323HWTEST_F(WindowSessionTest2, TransferPointerEvent05, Function | SmallTest | Level2)
324{
325    ASSERT_NE(session_, nullptr);
326
327    session_->sessionInfo_.isSystem_ = true;
328
329    std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
330
331    session_->property_ = new WindowSessionProperty();
332    session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
333
334    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferPointerEvent(pointerEvent));
335}
336
337/**
338 * @tc.name: TransferPointerEvent06
339 * @tc.desc: windowEventChannel_ is not nullptr
340 * @tc.type: FUNC
341 */
342HWTEST_F(WindowSessionTest2, TransferPointerEvent06, Function | SmallTest | Level2)
343{
344    ASSERT_NE(session_, nullptr);
345
346    session_->sessionInfo_.isSystem_ = true;
347
348    std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
349    ASSERT_NE(pointerEvent, nullptr);
350
351    session_->property_ = new WindowSessionProperty();
352    session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
353    session_->windowEventChannel_ = mockEventChannel_;
354
355    auto needNotifyClient = true;
356    session_->TransferPointerEvent(pointerEvent, needNotifyClient);
357
358    needNotifyClient = false;
359    pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
360    ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
361
362    pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_MOVE);
363    ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
364
365    pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
366    ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
367
368    pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
369    ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
370
371    pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_IN_WINDOW);
372    ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
373
374    pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_PULL_OUT_WINDOW);
375    ASSERT_EQ(WSError::WS_OK, session_->TransferPointerEvent(pointerEvent, needNotifyClient));
376}
377
378/**
379 * @tc.name: TransferKeyEvent01
380 * @tc.desc: !IsSystemSession() && !IsSessionVaild() is true
381 * @tc.type: FUNC
382 */
383HWTEST_F(WindowSessionTest2, TransferKeyEvent01, Function | SmallTest | Level2)
384{
385    ASSERT_NE(session_, nullptr);
386
387    session_->sessionInfo_.isSystem_ = false;
388    session_->state_ = SessionState::STATE_DISCONNECT;
389
390    std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
391    ASSERT_NE(keyEvent, nullptr);
392    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
393
394    session_->windowEventChannel_ = mockEventChannel_;
395    ASSERT_EQ(WSError::WS_OK, session_->TransferKeyEvent(keyEvent));
396}
397
398/**
399 * @tc.name: TransferKeyEvent02
400 * @tc.desc: keyEvent is nullptr
401 * @tc.type: FUNC
402 */
403HWTEST_F(WindowSessionTest2, TransferKeyEvent02, Function | SmallTest | Level2)
404{
405    ASSERT_NE(session_, nullptr);
406
407    session_->sessionInfo_.isSystem_ = true;
408
409    std::shared_ptr<MMI::KeyEvent> keyEvent = MMI::KeyEvent::Create();
410    ASSERT_NE(keyEvent, nullptr);
411    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
412}
413
414/**
415 * @tc.name: TransferKeyEvent03
416 * @tc.desc: WindowType is WINDOW_TYPE_APP_MAIN_WINDOW, CheckDialogOnForeground() is true
417 * @tc.type: FUNC
418 */
419HWTEST_F(WindowSessionTest2, TransferKeyEvent03, Function | SmallTest | Level2)
420{
421    ASSERT_NE(session_, nullptr);
422
423    session_->sessionInfo_.isSystem_ = true;
424
425    auto keyEvent = MMI::KeyEvent::Create();
426    ASSERT_NE(keyEvent, nullptr);
427
428    session_->property_ = new WindowSessionProperty();
429    session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
430
431    SessionInfo info;
432    info.abilityName_ = "dialogAbilityName";
433    info.moduleName_ = "dialogModuleName";
434    info.bundleName_ = "dialogBundleName";
435    sptr<Session> dialogSession = new (std::nothrow) Session(info);
436    ASSERT_NE(dialogSession, nullptr);
437    dialogSession->state_ = SessionState::STATE_ACTIVE;
438    session_->dialogVec_.push_back(dialogSession);
439
440    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
441}
442
443/**
444 * @tc.name: TransferKeyEvent04
445 * @tc.desc: parentSession_ && parentSession_->CheckDialogOnForeground() is true
446 * @tc.type: FUNC
447 */
448HWTEST_F(WindowSessionTest2, TransferKeyEvent04, Function | SmallTest | Level2)
449{
450    ASSERT_NE(session_, nullptr);
451
452    session_->sessionInfo_.isSystem_ = true;
453
454    auto keyEvent = MMI::KeyEvent::Create();
455    ASSERT_NE(keyEvent, nullptr);
456
457    session_->property_ = new WindowSessionProperty();
458    session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
459
460    SessionInfo info;
461    info.abilityName_ = "dialogAbilityName";
462    info.moduleName_ = "dialogModuleName";
463    info.bundleName_ = "dialogBundleName";
464    sptr<Session> dialogSession = new (std::nothrow) Session(info);
465    ASSERT_NE(dialogSession, nullptr);
466    dialogSession->state_ = SessionState::STATE_ACTIVE;
467    session_->dialogVec_.push_back(dialogSession);
468    session_->parentSession_ = session_;
469
470    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
471}
472
473/**
474 * @tc.name: TransferKeyEvent05
475 * @tc.desc: windowEventChannel_ is nullptr
476 * @tc.type: FUNC
477 */
478HWTEST_F(WindowSessionTest2, TransferKeyEvent05, Function | SmallTest | Level2)
479{
480    ASSERT_NE(session_, nullptr);
481
482    session_->sessionInfo_.isSystem_ = true;
483
484    auto keyEvent = MMI::KeyEvent::Create();
485    ASSERT_NE(keyEvent, nullptr);
486
487    session_->property_ = new WindowSessionProperty();
488    session_->property_->SetWindowType(WindowType::WINDOW_TYPE_SCENE_BOARD);
489
490    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEvent(keyEvent));
491}
492
493/**
494 * @tc.name: TransferBackPressedEventForConsumed01
495 * @tc.desc: windowEventChannel_ is nullptr
496 * @tc.type: FUNC
497 */
498HWTEST_F(WindowSessionTest2, TransferBackPressedEventForConsumed01, Function | SmallTest | Level2)
499{
500    ASSERT_NE(session_, nullptr);
501
502    session_->windowEventChannel_ = nullptr;
503
504    bool isConsumed = false;
505    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferBackPressedEventForConsumed(isConsumed));
506}
507
508/**
509 * @tc.name: TransferFocusActiveEvent01
510 * @tc.desc: windowEventChannel_ is nullptr
511 * @tc.type: FUNC
512 */
513HWTEST_F(WindowSessionTest2, TransferFocusActiveEvent01, Function | SmallTest | Level2)
514{
515    ASSERT_NE(session_, nullptr);
516
517    session_->windowEventChannel_ = nullptr;
518
519    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferFocusActiveEvent(false));
520}
521
522/**
523 * @tc.name: TransferFocusStateEvent01
524 * @tc.desc: windowEventChannel_ is nullptr
525 * @tc.type: FUNC
526 */
527HWTEST_F(WindowSessionTest2, TransferFocusStateEvent01, Function | SmallTest | Level2)
528{
529    ASSERT_NE(session_, nullptr);
530
531    session_->windowEventChannel_ = nullptr;
532
533    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferFocusStateEvent(false));
534}
535
536/**
537 * @tc.name: Snapshot01
538 * @tc.desc: ret is false
539 * @tc.type: FUNC
540 */
541HWTEST_F(WindowSessionTest2, Snapshot01, Function | SmallTest | Level2)
542{
543    ASSERT_NE(session_, nullptr);
544
545    session_->surfaceNode_ = nullptr;
546
547    ASSERT_EQ(nullptr, session_->Snapshot());
548}
549
550/**
551 * @tc.name: SaveSnapshot
552 * @tc.desc: SaveSnapshot Test
553 * @tc.type: FUNC
554 */
555HWTEST_F(WindowSessionTest2, SaveSnapshot, Function | SmallTest | Level2)
556{
557    ASSERT_NE(session_, nullptr);
558
559    session_->scenePersistence_ = nullptr;
560    session_->snapshot_ = nullptr;
561    session_->SaveSnapshot(true);
562    EXPECT_EQ(session_->snapshot_, nullptr);
563
564    session_->scenePersistence_ = new ScenePersistence(session_->sessionInfo_.bundleName_, session_->persistentId_);
565
566    session_->SaveSnapshot(false);
567    ASSERT_EQ(session_->snapshot_, nullptr);
568
569    session_->SaveSnapshot(true);
570    ASSERT_EQ(session_->snapshot_, nullptr);
571}
572
573/**
574 * @tc.name: SetSessionStateChangeListenser
575 * @tc.desc: SetSessionStateChangeListenser Test
576 * @tc.type: FUNC
577 */
578HWTEST_F(WindowSessionTest2, SetSessionStateChangeListenser, Function | SmallTest | Level2)
579{
580    ASSERT_NE(session_, nullptr);
581
582    NotifySessionStateChangeFunc func = nullptr;
583    session_->SetSessionStateChangeListenser(func);
584
585    session_->state_ = SessionState::STATE_DISCONNECT;
586    ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
587}
588
589/**
590 * @tc.name: SetSessionFocusableChangeListener
591 * @tc.desc: SetSessionFocusableChangeListener Test
592 * @tc.type: FUNC
593 */
594HWTEST_F(WindowSessionTest2, SetSessionFocusableChangeListener, Function | SmallTest | Level2)
595{
596    ASSERT_NE(session_, nullptr);
597
598    NotifySessionFocusableChangeFunc func = [](const bool isFocusable)
599    {
600    };
601    session_->SetSessionFocusableChangeListener(func);
602
603    session_->state_ = SessionState::STATE_DISCONNECT;
604    ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
605}
606
607/**
608 * @tc.name: SetSessionTouchableChangeListener
609 * @tc.desc: SetSessionTouchableChangeListener Test
610 * @tc.type: FUNC
611 */
612HWTEST_F(WindowSessionTest2, SetSessionTouchableChangeListener, Function | SmallTest | Level2)
613{
614    ASSERT_NE(session_, nullptr);
615
616    NotifySessionTouchableChangeFunc func = [](const bool touchable)
617    {
618    };
619    session_->SetSessionTouchableChangeListener(func);
620
621    session_->state_ = SessionState::STATE_DISCONNECT;
622    ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
623}
624
625/**
626 * @tc.name: SetSessionInfoLockedStateChangeListener
627 * @tc.desc: SetSessionInfoLockedStateChangeListener Test
628 * @tc.type: FUNC
629 */
630HWTEST_F(WindowSessionTest2, SetSessionInfoLockedStateChangeListener, Function | SmallTest | Level2)
631{
632    ASSERT_NE(session_, nullptr);
633
634    NotifySessionTouchableChangeFunc func = [](const bool lockedState)
635    {
636    };
637    session_->SetSessionInfoLockedStateChangeListener(func);
638
639    session_->SetSessionInfoLockedState(true);
640    ASSERT_EQ(true, session_->sessionInfo_.lockedState);
641}
642
643/**
644 * @tc.name: SetClickListener
645 * @tc.desc: SetClickListener Test
646 * @tc.type: FUNC
647 */
648HWTEST_F(WindowSessionTest2, SetClickListener, Function | SmallTest | Level2)
649{
650    ASSERT_NE(session_, nullptr);
651
652    NotifyClickFunc func = nullptr;
653    session_->SetClickListener(func);
654
655    session_->state_ = SessionState::STATE_DISCONNECT;
656    ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
657}
658
659/**
660 * @tc.name: UpdateFocus01
661 * @tc.desc: isFocused_ equal isFocused
662 * @tc.type: FUNC
663 */
664HWTEST_F(WindowSessionTest2, UpdateFocus01, Function | SmallTest | Level2)
665{
666    ASSERT_NE(session_, nullptr);
667
668    bool isFocused = session_->isFocused_;
669    ASSERT_EQ(WSError::WS_DO_NOTHING, session_->UpdateFocus(isFocused));
670}
671
672/**
673 * @tc.name: UpdateFocus02
674 * @tc.desc: isFocused_ not equal isFocused, IsSessionValid() return false
675 * @tc.type: FUNC
676 */
677HWTEST_F(WindowSessionTest2, UpdateFocus02, Function | SmallTest | Level2)
678{
679    ASSERT_NE(session_, nullptr);
680
681    session_->sessionInfo_.isSystem_ = true;
682
683    bool isFocused = session_->isFocused_;
684    ASSERT_EQ(WSError::WS_OK, session_->UpdateFocus(!isFocused));
685}
686
687/**
688 * @tc.name: UpdateWindowMode01
689 * @tc.desc: IsSessionValid() return false
690 * @tc.type: FUNC
691 */
692HWTEST_F(WindowSessionTest2, UpdateWindowMode01, Function | SmallTest | Level2)
693{
694    ASSERT_NE(session_, nullptr);
695
696    session_->property_ = nullptr;
697
698    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->UpdateWindowMode(WindowMode::WINDOW_MODE_UNDEFINED));
699}
700
701/**
702 * @tc.name: NotifyForegroundInteractiveStatus
703 * @tc.desc: NotifyForegroundInteractiveStatus Test
704 * @tc.type: FUNC
705 */
706HWTEST_F(WindowSessionTest2, NotifyForegroundInteractiveStatus, Function | SmallTest | Level2)
707{
708    ASSERT_NE(session_, nullptr);
709
710    session_->sessionStage_ = nullptr;
711    bool interactive = true;
712    session_->NotifyForegroundInteractiveStatus(interactive);
713
714    sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
715    ASSERT_NE(mockSessionStage, nullptr);
716    session_->sessionStage_ = mockSessionStage;
717    session_->state_ = SessionState::STATE_FOREGROUND;
718    interactive = false;
719    session_->NotifyForegroundInteractiveStatus(interactive);
720
721    session_->state_ = SessionState::STATE_DISCONNECT;
722    ASSERT_EQ(WSError::WS_OK, session_->SetFocusable(false));
723}
724
725/**
726 * @tc.name: SetEventHandler001
727 * @tc.desc: SetEventHandler Test
728 * @tc.type: FUNC
729 */
730HWTEST_F(WindowSessionTest2, SetEventHandler001, Function | SmallTest | Level2)
731{
732    ASSERT_NE(session_, nullptr);
733    int res = 0;
734    std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr;
735    session_->SetEventHandler(handler);
736    ASSERT_EQ(res, 0);
737}
738
739/**
740 * @tc.name: PostTask002
741 * @tc.desc: PostTask Test
742 * @tc.type: FUNC
743 */
744HWTEST_F(WindowSessionTest2, PostTask002, Function | SmallTest | Level2)
745{
746    ASSERT_NE(session_, nullptr);
747    int32_t persistentId = 0;
748    sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
749    if (property == nullptr) {
750        return;
751    }
752    property->SetPersistentId(persistentId);
753    int32_t res = session_->GetPersistentId();
754    ASSERT_EQ(res, 0);
755}
756
757/**
758 * @tc.name: GetSurfaceNode003
759 * @tc.desc: GetSurfaceNode Test
760 * @tc.type: FUNC
761 */
762HWTEST_F(WindowSessionTest2, GetSurfaceNode003, Function | SmallTest | Level2)
763{
764    ASSERT_NE(session_, nullptr);
765    session_->surfaceNode_ = nullptr;
766    std::shared_ptr<RSSurfaceNode> res = session_->GetSurfaceNode();
767    ASSERT_EQ(res, nullptr);
768}
769
770/**
771 * @tc.name: GetLeashWinSurfaceNode004
772 * @tc.desc: GetLeashWinSurfaceNode Test
773 * @tc.type: FUNC
774 */
775HWTEST_F(WindowSessionTest2, GetLeashWinSurfaceNode004, Function | SmallTest | Level2)
776{
777    ASSERT_NE(session_, nullptr);
778    session_->leashWinSurfaceNode_ = nullptr;
779    std::shared_ptr<RSSurfaceNode> res = session_->GetLeashWinSurfaceNode();
780    ASSERT_EQ(res, nullptr);
781}
782
783/**
784 * @tc.name: SetSessionInfoAncoSceneState005
785 * @tc.desc: SetSessionInfoAncoSceneState Test
786 * @tc.type: FUNC
787 */
788HWTEST_F(WindowSessionTest2, SetSessionInfoAncoSceneState005, Function | SmallTest | Level2)
789{
790    ASSERT_NE(session_, nullptr);
791    int res = 0;
792    int32_t ancoSceneState = 0;
793    session_->SetSessionInfoAncoSceneState(ancoSceneState);
794    ASSERT_EQ(res, 0);
795}
796
797/**
798 * @tc.name: SetSessionInfoTime006
799 * @tc.desc: SetSessionInfoTime Test
800 * @tc.type: FUNC
801 */
802HWTEST_F(WindowSessionTest2, SetSessionInfoTime006, Function | SmallTest | Level2)
803{
804    ASSERT_NE(session_, nullptr);
805    int res = 0;
806    std::string time = "";
807    session_->SetSessionInfoTime(time);
808    ASSERT_EQ(res, 0);
809}
810
811/**
812 * @tc.name: SetSessionInfoAbilityInfo007
813 * @tc.desc: SetSessionInfoAbilityInfo Test
814 * @tc.type: FUNC
815 */
816HWTEST_F(WindowSessionTest2, SetSessionInfoAbilityInfo007, Function | SmallTest | Level2)
817{
818    ASSERT_NE(session_, nullptr);
819    int res = 0;
820    std::shared_ptr<AppExecFwk::AbilityInfo> abilityInfo = nullptr;
821    session_->SetSessionInfoAbilityInfo(abilityInfo);
822    ASSERT_EQ(res, 0);
823}
824
825/**
826 * @tc.name: SetSessionInfoWant008
827 * @tc.desc: SetSessionInfoWant Test
828 * @tc.type: FUNC
829 */
830HWTEST_F(WindowSessionTest2, SetSessionInfoWant008, Function | SmallTest | Level2)
831{
832    ASSERT_NE(session_, nullptr);
833    int res = 0;
834    std::shared_ptr<AAFwk::Want> want = nullptr;
835    session_->SetSessionInfoWant(want);
836    ASSERT_EQ(res, 0);
837}
838
839/**
840 * @tc.name: SetSessionInfoProcessOptions
841 * @tc.desc: SetSessionInfoProcessOptions Test
842 * @tc.type: FUNC
843 */
844HWTEST_F(WindowSessionTest2, SetSessionInfoProcessOptions, Function | SmallTest | Level2)
845{
846    ASSERT_NE(session_, nullptr);
847    std::shared_ptr<AAFwk::ProcessOptions> processOptions = std::make_shared<AAFwk::ProcessOptions>();
848    session_->SetSessionInfoProcessOptions(processOptions);
849    ASSERT_EQ(processOptions, session_->sessionInfo_.processOptions);
850}
851
852/**
853 * @tc.name: SetSessionInfoPersistentId009
854 * @tc.desc: SetSessionInfoPersistentId Test
855 * @tc.type: FUNC
856 */
857HWTEST_F(WindowSessionTest2, SetSessionInfoPersistentId009, Function | SmallTest | Level2)
858{
859    ASSERT_NE(session_, nullptr);
860    int res = 0;
861    int32_t persistentId = 0;
862    session_->SetSessionInfoPersistentId(persistentId);
863    ASSERT_EQ(res, 0);
864}
865
866/**
867 * @tc.name: SetSessionInfoCallerPersistentId010
868 * @tc.desc: SetSessionInfoCallerPersistentId Test
869 * @tc.type: FUNC
870 */
871HWTEST_F(WindowSessionTest2, SetSessionInfoCallerPersistentId010, Function | SmallTest | Level2)
872{
873    ASSERT_NE(session_, nullptr);
874    int res = 0;
875    int32_t callerPersistentId = 0;
876    session_->SetSessionInfoCallerPersistentId(callerPersistentId);
877    ASSERT_EQ(res, 0);
878}
879
880/**
881 * @tc.name: PostExportTask011
882 * @tc.desc: PostExportTask Test
883 * @tc.type: FUNC
884 */
885HWTEST_F(WindowSessionTest2, PostExportTask011, Function | SmallTest | Level2)
886{
887    ASSERT_NE(session_, nullptr);
888    int32_t persistentId = 0;
889    sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
890    if (property == nullptr) {
891        return;
892    }
893    property->SetPersistentId(persistentId);
894    int32_t ret = session_->GetPersistentId();
895    ASSERT_EQ(ret, 0);
896}
897
898/**
899 * @tc.name: GetPersistentId012
900 * @tc.desc: GetPersistentId Test
901 * @tc.type: FUNC
902 */
903HWTEST_F(WindowSessionTest2, GetPersistentId012, Function | SmallTest | Level2)
904{
905    ASSERT_NE(session_, nullptr);
906    int32_t persistentId = 0;
907    sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
908    if (property == nullptr) {
909        return;
910    }
911    property->SetPersistentId(persistentId);
912    int32_t ret = session_->GetPersistentId();
913    ASSERT_EQ(ret, 0);
914}
915
916/**
917 * @tc.name: SetLeashWinSurfaceNode013
918 * @tc.desc: SetLeashWinSurfaceNode Test
919 * @tc.type: FUNC
920 */
921HWTEST_F(WindowSessionTest2, SetLeashWinSurfaceNode013, Function | SmallTest | Level2)
922{
923    ASSERT_NE(session_, nullptr);
924    auto leashWinSurfaceNode = WindowSessionTest2::CreateRSSurfaceNode();
925    session_->SetLeashWinSurfaceNode(leashWinSurfaceNode);
926    ASSERT_EQ(session_->leashWinSurfaceNode_, leashWinSurfaceNode);
927}
928
929/**
930 * @tc.name: SetSessionInfoContinueState014
931 * @tc.desc: SetSessionInfoContinueState Test
932 * @tc.type: FUNC
933 */
934HWTEST_F(WindowSessionTest2, SetSessionInfoContinueState014, Function | SmallTest | Level2)
935{
936    ASSERT_NE(session_, nullptr);
937    enum ContinueState state;
938    state = CONTINUESTATE_UNKNOWN;
939    session_->SetSessionInfoContinueState(state);
940    ASSERT_EQ(session_->sessionInfo_.continueState, state);
941}
942
943/**
944 * @tc.name: SetSessionInfoIsClearSession015
945 * @tc.desc: SetSessionInfoIsClearSession return false
946 * @tc.type: FUNC
947 */
948HWTEST_F(WindowSessionTest2, SetSessionInfoIsClearSession015, Function | SmallTest | Level2)
949{
950    ASSERT_NE(session_, nullptr);
951    session_->SetSessionInfoIsClearSession(false);
952    ASSERT_EQ(false, session_->sessionInfo_.isClearSession);
953}
954
955/**
956 * @tc.name: SetSessionInfoIsClearSession016
957 * @tc.desc: SetSessionInfoIsClearSession return true
958 * @tc.type: FUNC
959 */
960HWTEST_F(WindowSessionTest2, SetSessionInfoIsClearSession016, Function | SmallTest | Level2)
961{
962    ASSERT_NE(session_, nullptr);
963    session_->SetSessionInfoIsClearSession(true);
964    ASSERT_EQ(true, session_->sessionInfo_.isClearSession);
965}
966
967/**
968 * @tc.name: SetSessionInfoAffinity017
969 * @tc.desc: SetSessionInfoAffinity
970 * @tc.type: FUNC
971 */
972HWTEST_F(WindowSessionTest2, SetSessionInfoAffinity017, Function | SmallTest | Level2)
973{
974    ASSERT_NE(session_, nullptr);
975    std::string affinity = "setSessionIofoAffinity";
976    session_->SetSessionInfoAffinity(affinity);
977    ASSERT_EQ(affinity, session_->sessionInfo_.sessionAffinity);
978}
979
980/**
981 * @tc.name: SetSessionInfo018
982 * @tc.desc: SetSessionInfo
983 * @tc.type: FUNC
984 */
985HWTEST_F(WindowSessionTest2, SetSessionInfo018, Function | SmallTest | Level2)
986{
987    ASSERT_NE(session_, nullptr);
988    SessionInfo info;
989    info.want = nullptr;
990    info.callerToken_ = nullptr;
991    info.requestCode = 1;
992    info.callerPersistentId_ = 1;
993    info.callingTokenId_ = 1;
994    info.uiAbilityId_ = 1;
995    info.startSetting = nullptr;
996    info.continueSessionId_ = "";
997    session_->SetSessionInfo(info);
998    ASSERT_EQ(nullptr, session_->sessionInfo_.want);
999    ASSERT_EQ(nullptr, session_->sessionInfo_.callerToken_);
1000    ASSERT_EQ(1, session_->sessionInfo_.requestCode);
1001    ASSERT_EQ(1, session_->sessionInfo_.callerPersistentId_);
1002    ASSERT_EQ(1, session_->sessionInfo_.callingTokenId_);
1003    ASSERT_EQ(1, session_->sessionInfo_.uiAbilityId_);
1004    ASSERT_EQ("", session_->sessionInfo_.continueSessionId_);
1005    ASSERT_EQ(nullptr, session_->sessionInfo_.startSetting);
1006}
1007
1008/**
1009 * @tc.name: SetScreenId019
1010 * @tc.desc: SetScreenId
1011 * @tc.type: FUNC
1012 */
1013HWTEST_F(WindowSessionTest2, SetScreenId019, Function | SmallTest | Level2)
1014{
1015    ASSERT_NE(session_, nullptr);
1016    uint64_t screenId = 0;
1017    session_->SetScreenId(screenId);
1018    ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1019}
1020
1021/**
1022 * @tc.name: RegisterLifecycleListener020
1023 * @tc.desc: RegisterLifecycleListener
1024 * @tc.type: FUNC
1025 */
1026HWTEST_F(WindowSessionTest2, RegisterLifecycleListener020, Function | SmallTest | Level2)
1027{
1028    ASSERT_NE(session_, nullptr);
1029    const std::shared_ptr<ILifecycleListener>& listener = nullptr;
1030    bool ret = session_->RegisterLifecycleListener(listener);
1031    ASSERT_EQ(false, ret);
1032}
1033
1034/**
1035 * @tc.name: UnregisterLifecycleListener021
1036 * @tc.desc: UnregisterLifecycleListener
1037 * @tc.type: FUNC
1038 */
1039HWTEST_F(WindowSessionTest2, UnregisterLifecycleListener021, Function | SmallTest | Level2)
1040{
1041    ASSERT_NE(session_, nullptr);
1042    const std::shared_ptr<ILifecycleListener>& listener = nullptr;
1043    bool ret = session_->UnregisterLifecycleListener(listener);
1044    ASSERT_EQ(false, ret);
1045}
1046
1047/**
1048 * @tc.name: NotifyExtensionDied027
1049 * @tc.desc: NotifyExtensionDied
1050 * @tc.type: FUNC
1051 */
1052HWTEST_F(WindowSessionTest2, NotifyExtensionDied027, Function | SmallTest | Level2)
1053{
1054    ASSERT_NE(session_, nullptr);
1055    session_->NotifyExtensionDied();
1056
1057    session_->RegisterLifecycleListener(lifecycleListener_);
1058    session_->NotifyExtensionDied();
1059    uint64_t screenId = 0;
1060    session_->SetScreenId(screenId);
1061    session_->UnregisterLifecycleListener(lifecycleListener_);
1062    ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1063}
1064
1065/**
1066 * @tc.name: NotifyTransferAccessibilityEvent
1067 * @tc.desc: NotifyTransferAccessibilityEvent
1068 * @tc.type: FUNC
1069 */
1070HWTEST_F(WindowSessionTest2, NotifyTransferAccessibilityEvent, Function | SmallTest | Level2)
1071{
1072    ASSERT_NE(session_, nullptr);
1073    OHOS::Accessibility::AccessibilityEventInfo info1;
1074    int64_t uiExtensionIdLevel = 6;
1075    session_->NotifyTransferAccessibilityEvent(info1, uiExtensionIdLevel);
1076
1077    session_->RegisterLifecycleListener(lifecycleListener_);
1078    session_->NotifyTransferAccessibilityEvent(info1, uiExtensionIdLevel);
1079    uint64_t screenId = 0;
1080    session_->SetScreenId(screenId);
1081    session_->UnregisterLifecycleListener(lifecycleListener_);
1082    ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1083}
1084
1085/**
1086 * @tc.name: GetAspectRatio028
1087 * @tc.desc: GetAspectRatio
1088 * @tc.type: FUNC
1089 */
1090HWTEST_F(WindowSessionTest2, GetAspectRatio028, Function | SmallTest | Level2)
1091{
1092    ASSERT_NE(session_, nullptr);
1093    float ret = session_->aspectRatio_;
1094    float res = 0.0f;
1095    ASSERT_EQ(ret, res);
1096}
1097
1098/**
1099 * @tc.name: SetAspectRatio029
1100 * @tc.desc: SetAspectRatio
1101 * @tc.type: FUNC
1102 */
1103HWTEST_F(WindowSessionTest2, SetAspectRatio029, Function | SmallTest | Level2)
1104{
1105    ASSERT_NE(session_, nullptr);
1106    float radio = 2.0f;
1107    WSError ERR = session_->SetAspectRatio(radio);
1108    float ret = session_->aspectRatio_;
1109    ASSERT_EQ(ret, radio);
1110    ASSERT_EQ(ERR, WSError::WS_OK);
1111}
1112
1113/**
1114 * @tc.name: GetSessionState030
1115 * @tc.desc: GetSessionState
1116 * @tc.type: FUNC
1117 */
1118HWTEST_F(WindowSessionTest2, GetSessionState030, Function | SmallTest | Level2)
1119{
1120    ASSERT_NE(session_, nullptr);
1121    SessionState state = session_->GetSessionState();
1122    ASSERT_EQ(state, session_->state_);
1123}
1124
1125/**
1126 * @tc.name: SetSessionState031
1127 * @tc.desc: SetSessionState
1128 * @tc.type: FUNC
1129 */
1130HWTEST_F(WindowSessionTest2, SetSessionState031, Function | SmallTest | Level2)
1131{
1132    ASSERT_NE(session_, nullptr);
1133    SessionState state = SessionState::STATE_CONNECT;
1134    session_->SetSessionState(state);
1135    ASSERT_EQ(state, session_->state_);
1136}
1137
1138/**
1139 * @tc.name: GetTouchable33
1140 * @tc.desc: GetTouchable
1141 * @tc.type: FUNC
1142 */
1143HWTEST_F(WindowSessionTest2, GetTouchable33, Function | SmallTest | Level2)
1144{
1145    ASSERT_NE(session_, nullptr);
1146    bool res = session_->GetTouchable();
1147    ASSERT_EQ(true, res);
1148}
1149
1150/**
1151 * @tc.name: SetSystemTouchable34
1152 * @tc.desc: SetSystemTouchable
1153 * @tc.type: FUNC
1154 */
1155HWTEST_F(WindowSessionTest2, SetSystemTouchable34, Function | SmallTest | Level2)
1156{
1157    ASSERT_NE(session_, nullptr);
1158    bool touchable = false;
1159    session_->SetSystemTouchable(touchable);
1160    ASSERT_EQ(session_->systemTouchable_, touchable);
1161}
1162
1163/**
1164 * @tc.name: GetSystemTouchable35
1165 * @tc.desc: GetSystemTouchable
1166 * @tc.type: FUNC
1167 */
1168HWTEST_F(WindowSessionTest2, GetSystemTouchable35, Function | SmallTest | Level2)
1169{
1170    ASSERT_NE(session_, nullptr);
1171    bool res = session_->GetSystemTouchable();
1172    ASSERT_EQ(res, true);
1173}
1174
1175/**
1176 * @tc.name: SetRSVisible36
1177 * @tc.desc: SetRSVisible
1178 * @tc.type: FUNC
1179 */
1180HWTEST_F(WindowSessionTest2, SetVisible36, Function | SmallTest | Level2)
1181{
1182    ASSERT_NE(session_, nullptr);
1183    bool isVisible = false;
1184    ASSERT_EQ(WSError::WS_OK, session_->SetRSVisible(isVisible));
1185}
1186
1187/**
1188 * @tc.name: GetRSVisible37
1189 * @tc.desc: GetRSVisible
1190 * @tc.type: FUNC
1191 */
1192HWTEST_F(WindowSessionTest2, GetVisible37, Function | SmallTest | Level2)
1193{
1194    ASSERT_NE(session_, nullptr);
1195    if (!session_->GetRSVisible()) {
1196        ASSERT_EQ(false, session_->GetRSVisible());
1197    }
1198}
1199
1200/**
1201 * @tc.name: SetVisibilityState38
1202 * @tc.desc: SetVisibilityState
1203 * @tc.type: FUNC
1204 */
1205HWTEST_F(WindowSessionTest2, SetVisibilityState38, Function | SmallTest | Level2)
1206{
1207    ASSERT_NE(session_, nullptr);
1208    WindowVisibilityState state { WINDOW_VISIBILITY_STATE_NO_OCCLUSION};
1209    ASSERT_EQ(WSError::WS_OK, session_->SetVisibilityState(state));
1210    ASSERT_EQ(state, session_->visibilityState_);
1211}
1212
1213/**
1214 * @tc.name: GetVisibilityState39
1215 * @tc.desc: GetVisibilityState
1216 * @tc.type: FUNC
1217 */
1218HWTEST_F(WindowSessionTest2, GetVisibilityState39, Function | SmallTest | Level2)
1219{
1220    ASSERT_NE(session_, nullptr);
1221    WindowVisibilityState state { WINDOW_LAYER_STATE_MAX};
1222    ASSERT_EQ(state, session_->GetVisibilityState());
1223}
1224
1225/**
1226 * @tc.name: SetDrawingContentState40
1227 * @tc.desc: SetDrawingContentState
1228 * @tc.type: FUNC
1229 */
1230HWTEST_F(WindowSessionTest2, SetDrawingContentState40, Function | SmallTest | Level2)
1231{
1232    ASSERT_NE(session_, nullptr);
1233    bool isRSDrawing = false;
1234    ASSERT_EQ(WSError::WS_OK, session_->SetDrawingContentState(isRSDrawing));
1235    ASSERT_EQ(false, session_->isRSDrawing_);
1236}
1237
1238/**
1239 * @tc.name: GetDrawingContentState41
1240 * @tc.desc: GetDrawingContentState
1241 * @tc.type: FUNC
1242 */
1243HWTEST_F(WindowSessionTest2, GetDrawingContentState41, Function | SmallTest | Level2)
1244{
1245    ASSERT_NE(session_, nullptr);
1246    bool res = session_->GetDrawingContentState();
1247    ASSERT_EQ(res, false);
1248}
1249
1250/**
1251 * @tc.name: GetBrightness42
1252 * @tc.desc: GetBrightness
1253 * @tc.type: FUNC
1254 */
1255HWTEST_F(WindowSessionTest2, GetBrightness42, Function | SmallTest | Level2)
1256{
1257    ASSERT_NE(session_, nullptr);
1258    session_->state_ = SessionState::STATE_DISCONNECT;
1259    session_->property_ = nullptr;
1260    ASSERT_EQ(UNDEFINED_BRIGHTNESS, session_->GetBrightness());
1261}
1262
1263/**
1264 * @tc.name: DrawingCompleted
1265 * @tc.desc: DrawingCompleled
1266 * @tc.type: FUNC
1267 */
1268HWTEST_F(WindowSessionTest2, DrawingCompleted, Function | SmallTest | Level2)
1269{
1270    ASSERT_NE(session_, nullptr);
1271    auto result = session_->DrawingCompleted();
1272    ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PERMISSION);
1273}
1274
1275/**
1276 * @tc.name: SetSystemActive48
1277 * @tc.desc: SetSystemActive
1278 * @tc.type: FUNC
1279 */
1280HWTEST_F(WindowSessionTest2, SetSystemActive48, Function | SmallTest | Level2)
1281{
1282    ASSERT_NE(session_, nullptr);
1283    bool systemActive = false;
1284    session_->SetSystemActive(systemActive);
1285    ASSERT_EQ(systemActive, session_->isSystemActive_);
1286}
1287
1288/**
1289 * @tc.name: SetSystemActive48
1290 * @tc.desc: SetSystemActive
1291 * @tc.type: FUNC
1292 */
1293HWTEST_F(WindowSessionTest2, SetChangeSessionVisibilityWithStatusBarEventListener, Function | SmallTest | Level2)
1294{
1295    int resultValue = 0;
1296    NotifyChangeSessionVisibilityWithStatusBarFunc func1 = [&resultValue](SessionInfo& info, const bool visible) {
1297        resultValue = 1;
1298    };
1299    NotifyChangeSessionVisibilityWithStatusBarFunc func2 = [&resultValue](SessionInfo& info, const bool visible) {
1300        resultValue = 2;
1301    };
1302
1303    session_->SetChangeSessionVisibilityWithStatusBarEventListener(func1);
1304    ASSERT_NE(session_->changeSessionVisibilityWithStatusBarFunc_, nullptr);
1305
1306    SessionInfo info;
1307    session_->changeSessionVisibilityWithStatusBarFunc_(info, true);
1308    ASSERT_EQ(resultValue, 1);
1309
1310    session_->SetChangeSessionVisibilityWithStatusBarEventListener(func2);
1311    ASSERT_NE(session_->changeSessionVisibilityWithStatusBarFunc_, nullptr);
1312    session_->changeSessionVisibilityWithStatusBarFunc_(info, true);
1313    ASSERT_EQ(resultValue, 2);
1314}
1315
1316/**
1317 * @tc.name: SetAttachState01
1318 * @tc.desc: SetAttachState Test
1319 * @tc.type: FUNC
1320 */
1321HWTEST_F(WindowSessionTest2, SetAttachState01, Function | SmallTest | Level2)
1322{
1323    ASSERT_NE(session_, nullptr);
1324    session_->SetAttachState(false);
1325    ASSERT_EQ(session_->isAttach_, false);
1326}
1327
1328/**
1329 * @tc.name: SetAttachState02
1330 * @tc.desc: SetAttachState Test
1331 * @tc.type: FUNC
1332 */
1333HWTEST_F(WindowSessionTest2, SetAttachState02, Function | SmallTest | Level2)
1334{
1335    ASSERT_NE(session_, nullptr);
1336    int32_t persistentId = 123;
1337    sptr<PatternDetachCallbackMocker> detachCallback = new PatternDetachCallbackMocker();
1338    session_->persistentId_ = persistentId;
1339    session_->SetAttachState(true);
1340    session_->RegisterDetachCallback(detachCallback);
1341    session_->SetAttachState(false);
1342    usleep(WAIT_SYNC_IN_NS);
1343    Mock::VerifyAndClearExpectations(&detachCallback);
1344    ASSERT_EQ(session_->isAttach_, false);
1345}
1346
1347/**
1348 * @tc.name: RegisterDetachCallback01
1349 * @tc.desc: RegisterDetachCallback Test
1350 * @tc.type: FUNC
1351 */
1352HWTEST_F(WindowSessionTest2, RegisterDetachCallback01, Function | SmallTest | Level2)
1353{
1354    ASSERT_NE(session_, nullptr);
1355    sptr<IPatternDetachCallback> detachCallback;
1356    session_->RegisterDetachCallback(detachCallback);
1357    ASSERT_EQ(session_->detachCallback_, detachCallback);
1358}
1359
1360/**
1361 * @tc.name: RegisterDetachCallback02
1362 * @tc.desc: RegisterDetachCallback Test
1363 * @tc.type: FUNC
1364 */
1365HWTEST_F(WindowSessionTest2, RegisterDetachCallback02, Function | SmallTest | Level2)
1366{
1367    ASSERT_NE(session_, nullptr);
1368    sptr<IPatternDetachCallback> detachCallback;
1369    session_->RegisterDetachCallback(detachCallback);
1370    ASSERT_EQ(session_->detachCallback_, detachCallback);
1371    sptr<IPatternDetachCallback> detachCallback2;
1372    session_->RegisterDetachCallback(detachCallback2);
1373    ASSERT_EQ(session_->detachCallback_, detachCallback2);
1374}
1375
1376/**
1377 * @tc.name: RegisterDetachCallback03
1378 * @tc.desc: RegisterDetachCallback Test
1379 * @tc.type: FUNC
1380 */
1381HWTEST_F(WindowSessionTest2, RegisterDetachCallback03, Function | SmallTest | Level2)
1382{
1383    ASSERT_NE(session_, nullptr);
1384    int32_t persistentId = 123;
1385    sptr<PatternDetachCallbackMocker> detachCallback = new PatternDetachCallbackMocker();
1386    EXPECT_CALL(*detachCallback, OnPatternDetach(persistentId)).Times(::testing::AtLeast(1));
1387    session_->persistentId_ = persistentId;
1388    session_->SetAttachState(true);
1389    session_->SetAttachState(false);
1390    session_->RegisterDetachCallback(detachCallback);
1391    Mock::VerifyAndClearExpectations(&detachCallback);
1392}
1393
1394/**
1395 * @tc.name: SetContextTransparentFunc
1396 * @tc.desc: SetContextTransparentFunc Test
1397 * @tc.type: FUNC
1398 */
1399HWTEST_F(WindowSessionTest2, SetContextTransparentFunc, Function | SmallTest | Level2)
1400{
1401    ASSERT_NE(session_, nullptr);
1402    session_->SetContextTransparentFunc(nullptr);
1403    ASSERT_EQ(session_->contextTransparentFunc_, nullptr);
1404    NotifyContextTransparentFunc func = [](){};
1405    session_->SetContextTransparentFunc(func);
1406    ASSERT_NE(session_->contextTransparentFunc_, nullptr);
1407}
1408
1409/**
1410 * @tc.name: NeedCheckContextTransparent
1411 * @tc.desc: NeedCheckContextTransparent Test
1412 * @tc.type: FUNC
1413 */
1414HWTEST_F(WindowSessionTest2, NeedCheckContextTransparent, Function | SmallTest | Level2)
1415{
1416    ASSERT_NE(session_, nullptr);
1417    session_->SetContextTransparentFunc(nullptr);
1418    ASSERT_EQ(session_->NeedCheckContextTransparent(), false);
1419    NotifyContextTransparentFunc func = [](){};
1420    session_->SetContextTransparentFunc(func);
1421    ASSERT_EQ(session_->NeedCheckContextTransparent(), true);
1422}
1423
1424/**
1425 * @tc.name: SetShowRecent001
1426 * @tc.desc: Exist detect task when in recent.
1427 * @tc.type: FUNC
1428 */
1429HWTEST_F(WindowSessionTest2, SetShowRecent001, Function | SmallTest | Level2)
1430{
1431    std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1432    auto task = [](){};
1433    int64_t delayTime = 3000;
1434    session_->handler_->PostTask(task, taskName, delayTime);
1435    int32_t beforeTaskNum = GetTaskCount();
1436
1437    session_->SetShowRecent(true);
1438    ASSERT_EQ(beforeTaskNum, GetTaskCount());
1439    session_->handler_->RemoveTask(taskName);
1440}
1441
1442/**
1443 * @tc.name: SetShowRecent002
1444 * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is false.
1445 * @tc.type: FUNC
1446 */
1447HWTEST_F(WindowSessionTest2, SetShowRecent002, Function | SmallTest | Level2)
1448{
1449    std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1450    auto task = [](){};
1451    int64_t delayTime = 3000;
1452    session_->handler_->PostTask(task, taskName, delayTime);
1453    session_->showRecent_ = false;
1454    int32_t beforeTaskNum = GetTaskCount();
1455
1456    session_->SetShowRecent(false);
1457    ASSERT_EQ(beforeTaskNum, GetTaskCount());
1458    session_->handler_->RemoveTask(taskName);
1459}
1460
1461/**
1462 * @tc.name: SetShowRecent003
1463 * @tc.desc: SetShowRecent:showRecent is false, showRecent_ is true, detach task.
1464 * @tc.type: FUNC
1465 */
1466HWTEST_F(WindowSessionTest2, SetShowRecent003, Function | SmallTest | Level2)
1467{
1468    std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1469    auto task = [](){};
1470    int64_t delayTime = 3000;
1471    session_->handler_->PostTask(task, taskName, delayTime);
1472    session_->showRecent_ = true;
1473    session_->isAttach_ = false;
1474    int32_t beforeTaskNum = GetTaskCount();
1475
1476    session_->SetShowRecent(false);
1477    ASSERT_EQ(beforeTaskNum, GetTaskCount());
1478    session_->handler_->RemoveTask(taskName);
1479}
1480
1481/**
1482 * @tc.name: SetShowRecent004
1483 * @tc.desc: SetShowRecent
1484 * @tc.type: FUNC
1485 */
1486HWTEST_F(WindowSessionTest2, SetShowRecent004, Function | SmallTest | Level2)
1487{
1488    session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1489    ssm_->SetScreenLocked(false);
1490
1491    session_->property_ = new WindowSessionProperty();
1492    session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1493
1494    bool showRecent = false;
1495    session_->showRecent_ = true;
1496    session_->SetAttachState(true);
1497    session_->SetShowRecent(showRecent);
1498    ASSERT_EQ(session_->GetShowRecent(), showRecent);
1499}
1500
1501/**
1502 * @tc.name: GetAttachState001
1503 * @tc.desc: GetAttachState001
1504 * @tc.type: FUNC
1505 */
1506HWTEST_F(WindowSessionTest2, GetAttachState001, Function | SmallTest | Level2)
1507{
1508    std::string taskName = "wms:WindowStateDetect" + std::to_string(session_->persistentId_);
1509    session_->SetAttachState(false);
1510    bool isAttach = session_->GetAttachState();
1511    ASSERT_EQ(false, isAttach);
1512    session_->handler_->RemoveTask(taskName);
1513}
1514
1515/**
1516 * @tc.name: UpdateSizeChangeReason
1517 * @tc.desc: UpdateSizeChangeReason UpdateDensity
1518 * @tc.type: FUNC
1519 */
1520HWTEST_F(WindowSessionTest2, UpdateSizeChangeReason, Function | SmallTest | Level2)
1521{
1522    SizeChangeReason reason = SizeChangeReason{1};
1523    ASSERT_EQ(session_->UpdateSizeChangeReason(reason), WSError::WS_OK);
1524}
1525
1526/**
1527 * @tc.name: SetPendingSessionActivationEventListener
1528 * @tc.desc: SetPendingSessionActivationEventListener
1529 * @tc.type: FUNC
1530 */
1531HWTEST_F(WindowSessionTest2, SetPendingSessionActivationEventListener, Function | SmallTest | Level2)
1532{
1533    int resultValue = 0;
1534    NotifyPendingSessionActivationFunc callback = [&resultValue](const SessionInfo& info) {
1535        resultValue = 1;
1536    };
1537
1538    sptr<AAFwk::SessionInfo> info = new (std::nothrow)AAFwk::SessionInfo();
1539    session_->SetPendingSessionActivationEventListener(callback);
1540    NotifyTerminateSessionFunc callback1 = [&resultValue](const SessionInfo& info) {
1541        resultValue = 2;
1542    };
1543    session_->SetTerminateSessionListener(callback1);
1544    LifeCycleTaskType taskType = LifeCycleTaskType{0};
1545    session_->RemoveLifeCycleTask(taskType);
1546    ASSERT_EQ(resultValue, 0);
1547}
1548
1549/**
1550 * @tc.name: SetSessionIcon
1551 * @tc.desc: SetSessionIcon UpdateDensity
1552 * @tc.type: FUNC
1553 */
1554HWTEST_F(WindowSessionTest2, SetSessionIcon, Function | SmallTest | Level2)
1555{
1556    std::shared_ptr<Media::PixelMap> icon;
1557    session_->SetSessionIcon(icon);
1558    ASSERT_EQ(session_->Clear(), WSError::WS_OK);
1559    session_->SetSessionSnapshotListener(nullptr);
1560    NotifyPendingSessionActivationFunc func = [](const SessionInfo& info) {};
1561    session_->pendingSessionActivationFunc_ = func;
1562    ASSERT_EQ(session_->PendingSessionToForeground(), WSError::WS_OK);
1563
1564    session_->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("SetSessionIcon", 1);
1565    session_->updateSessionIconFunc_ = nullptr;
1566    ASSERT_EQ(WSError::WS_OK, session_->SetSessionIcon(icon));
1567
1568    NofitySessionIconUpdatedFunc func2 = [](const std::string& iconPath) {};
1569    session_->updateSessionIconFunc_ = func2;
1570    ASSERT_EQ(WSError::WS_OK, session_->SetSessionIcon(icon));
1571
1572    NotifyTerminateSessionFuncNew func3 = [](const SessionInfo& info, bool needStartCaller, bool isFromBroker) {};
1573    session_->terminateSessionFuncNew_ = func3;
1574    ASSERT_EQ(WSError::WS_OK, session_->Clear());
1575}
1576
1577/**
1578 * @tc.name: SetSessionExceptionListener
1579 * @tc.desc: SetSessionExceptionListener
1580 * @tc.type: FUNC
1581 */
1582HWTEST_F(WindowSessionTest2, SetSessionExceptionListener, Function | SmallTest | Level2)
1583{
1584    session_->SetSessionExceptionListener(nullptr, true);
1585
1586    NotifySessionExceptionFunc func = [](const SessionInfo& info, bool needRemoveSession) {};
1587    session_->SetSessionExceptionListener(func, true);
1588
1589    ASSERT_NE(nullptr, session_->jsSceneSessionExceptionFunc_);
1590}
1591
1592/**
1593 * @tc.name: SetRaiseToAppTopForPointDownFunc
1594 * @tc.desc: SetRaiseToAppTopForPointDownFunc Test
1595 * @tc.type: FUNC
1596 */
1597HWTEST_F(WindowSessionTest2, SetRaiseToAppTopForPointDownFunc, Function | SmallTest | Level2)
1598{
1599    ASSERT_NE(session_, nullptr);
1600    session_->SetRaiseToAppTopForPointDownFunc(nullptr);
1601
1602    NotifyRaiseToTopForPointDownFunc func = []() {};
1603    session_->raiseToTopForPointDownFunc_ = func;
1604    session_->RaiseToAppTopForPointDown();
1605    session_->HandlePointDownDialog();
1606    session_->ClearDialogVector();
1607
1608    session_->SetBufferAvailableChangeListener(nullptr);
1609    session_->UnregisterSessionChangeListeners();
1610    session_->SetSessionStateChangeNotifyManagerListener(nullptr);
1611    session_->SetSessionInfoChangeNotifyManagerListener(nullptr);
1612    session_->NotifyFocusStatus(true);
1613
1614    session_->SetRequestFocusStatusNotifyManagerListener(nullptr);
1615    session_->SetNotifyUIRequestFocusFunc(nullptr);
1616    session_->SetNotifyUILostFocusFunc(nullptr);
1617    session_->UnregisterSessionChangeListeners();
1618
1619    NotifyPendingSessionToBackgroundForDelegatorFunc func2 = [](const SessionInfo& info, bool shouldBackToCaller) {};
1620    session_->pendingSessionToBackgroundForDelegatorFunc_ = func2;
1621    ASSERT_EQ(WSError::WS_OK, session_->PendingSessionToBackgroundForDelegator(true));
1622}
1623
1624/**
1625 * @tc.name: NotifyCloseExistPipWindow
1626 * @tc.desc: check func NotifyCloseExistPipWindow
1627 * @tc.type: FUNC
1628 */
1629HWTEST_F(WindowSessionTest2, NotifyCloseExistPipWindow, Function | SmallTest | Level2)
1630{
1631    sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
1632    ASSERT_NE(mockSessionStage, nullptr);
1633    ManagerState key = ManagerState{0};
1634    session_->GetStateFromManager(key);
1635    session_->NotifyUILostFocus();
1636
1637    session_->lostFocusFunc_ = []() {};
1638    session_->NotifyUILostFocus();
1639
1640    session_->SetSystemSceneBlockingFocus(true);
1641    session_->GetBlockingFocus();
1642    session_->sessionStage_ = mockSessionStage;
1643    EXPECT_CALL(*(mockSessionStage), NotifyCloseExistPipWindow()).Times(1).WillOnce(Return(WSError::WS_OK));
1644    ASSERT_EQ(WSError::WS_OK, session_->NotifyCloseExistPipWindow());
1645    session_->sessionStage_ = nullptr;
1646    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyCloseExistPipWindow());
1647}
1648
1649/**
1650 * @tc.name: SetSystemConfig
1651 * @tc.desc: SetSystemConfig Test
1652 * @tc.type: FUNC
1653 */
1654HWTEST_F(WindowSessionTest2, SetSystemConfig, Function | SmallTest | Level2)
1655{
1656    ASSERT_NE(session_, nullptr);
1657    SystemSessionConfig systemConfig;
1658    session_->SetSystemConfig(systemConfig);
1659    float snapshotScale = 0.5;
1660    session_->SetSnapshotScale(snapshotScale);
1661    session_->ProcessBackEvent();
1662    session_->NotifyOccupiedAreaChangeInfo(nullptr);
1663    session_->UpdateMaximizeMode(true);
1664    ASSERT_EQ(session_->GetZOrder(), 0);
1665
1666    session_->SetUINodeId(0);
1667    session_->GetUINodeId();
1668    session_->SetShowRecent(true);
1669    session_->GetShowRecent();
1670    session_->SetBufferAvailable(true);
1671
1672    session_->SetNeedSnapshot(true);
1673    session_->SetFloatingScale(0.5);
1674    ASSERT_EQ(session_->GetFloatingScale(), 0.5f);
1675    session_->SetScale(50, 100, 50, 100);
1676    session_->GetScaleX();
1677    session_->GetScaleY();
1678    session_->GetPivotX();
1679    session_->GetPivotY();
1680    session_->SetSCBKeepKeyboard(true);
1681    session_->GetSCBKeepKeyboardFlag();
1682    ASSERT_EQ(WSError::WS_OK, session_->MarkProcessed(11));
1683}
1684
1685/**
1686 * @tc.name: SetOffset
1687 * @tc.desc: SetOffset Test
1688 * @tc.type: FUNC
1689 */
1690HWTEST_F(WindowSessionTest2, SetOffset, Function | SmallTest | Level2)
1691{
1692    ASSERT_NE(session_, nullptr);
1693    session_->SetOffset(50, 100);
1694    session_->GetOffsetX();
1695    session_->GetOffsetY();
1696    WSRectF bounds;
1697    session_->SetBounds(bounds);
1698    session_->GetBounds();
1699    session_->UpdateTitleInTargetPos(true, 100);
1700    session_->SetNotifySystemSessionPointerEventFunc(nullptr);
1701    session_->SetNotifySystemSessionKeyEventFunc(nullptr);
1702    ASSERT_EQ(session_->GetBufferAvailable(), false);
1703}
1704
1705/**
1706 * @tc.name: ResetSessionConnectState
1707 * @tc.desc: ResetSessionConnectState
1708 * @tc.type: FUNC
1709 */
1710HWTEST_F(WindowSessionTest2, ResetSessionConnectState, Function | SmallTest | Level2)
1711{
1712    ASSERT_NE(session_, nullptr);
1713    session_->ResetSessionConnectState();
1714    ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
1715    ASSERT_EQ(session_->GetCallingPid(), -1);
1716}
1717
1718/**
1719 * @tc.name: ResetIsActive
1720 * @tc.desc: ResetIsActive
1721 * @tc.type: FUNC
1722 */
1723HWTEST_F(WindowSessionTest2, ResetIsActive, Function | SmallTest | Level2)
1724{
1725    ASSERT_NE(session_, nullptr);
1726    session_->ResetIsActive();
1727    ASSERT_EQ(session_->isActive_, false);
1728}
1729
1730/**
1731 * @tc.name: PostExportTask02
1732 * @tc.desc: PostExportTask
1733 * @tc.type: FUNC
1734 */
1735HWTEST_F(WindowSessionTest2, PostExportTask02, Function | SmallTest | Level2)
1736{
1737    ASSERT_NE(session_, nullptr);
1738    std::string name = "sessionExportTask";
1739    auto task = [](){};
1740    int64_t delayTime = 0;
1741
1742    session_->PostExportTask(task, name, delayTime);
1743    auto result = session_->GetBufferAvailable();
1744    ASSERT_EQ(result, false);
1745
1746    sptr<SceneSessionManager> sceneSessionManager = new SceneSessionManager();
1747    session_->SetEventHandler(sceneSessionManager->taskScheduler_->GetEventHandler(),
1748        sceneSessionManager->eventHandler_);
1749    session_->PostExportTask(task, name, delayTime);
1750    auto result2 = session_->GetBufferAvailable();
1751    ASSERT_EQ(result2, false);
1752}
1753
1754/**
1755 * @tc.name: SetLeashWinSurfaceNode02
1756 * @tc.desc: SetLeashWinSurfaceNode
1757 * @tc.type: FUNC
1758 */
1759HWTEST_F(WindowSessionTest2, SetLeashWinSurfaceNode02, Function | SmallTest | Level2)
1760{
1761    ASSERT_NE(session_, nullptr);
1762    session_->leashWinSurfaceNode_ = WindowSessionTest2::CreateRSSurfaceNode();
1763    session_->SetLeashWinSurfaceNode(nullptr);
1764
1765    session_->leashWinSurfaceNode_ = nullptr;
1766    session_->SetLeashWinSurfaceNode(nullptr);
1767    auto result = session_->GetBufferAvailable();
1768    ASSERT_EQ(result, false);
1769}
1770
1771/**
1772 * @tc.name: GetCloseAbilityWantAndClean
1773 * @tc.desc: GetCloseAbilityWantAndClean
1774 * @tc.type: FUNC
1775 */
1776HWTEST_F(WindowSessionTest2, GetCloseAbilityWantAndClean, Function | SmallTest | Level2)
1777{
1778    ASSERT_NE(session_, nullptr);
1779    AAFwk::Want outWant;
1780    session_->sessionInfo_.closeAbilityWant = std::make_shared<AAFwk::Want>();
1781    session_->GetCloseAbilityWantAndClean(outWant);
1782
1783    session_->sessionInfo_.closeAbilityWant = nullptr;
1784    session_->GetCloseAbilityWantAndClean(outWant);
1785    auto result = session_->GetBufferAvailable();
1786    ASSERT_EQ(result, false);
1787}
1788
1789/**
1790 * @tc.name: SetScreenId02
1791 * @tc.desc: SetScreenId Test
1792 * @tc.type: FUNC
1793 */
1794HWTEST_F(WindowSessionTest2, SetScreenId02, Function | SmallTest | Level2)
1795{
1796    ASSERT_NE(session_, nullptr);
1797    uint64_t screenId = 0;
1798    session_->sessionStage_ = new (std::nothrow) SessionStageMocker();
1799    session_->SetScreenId(screenId);
1800    ASSERT_EQ(0, session_->sessionInfo_.screenId_);
1801}
1802
1803/**
1804 * @tc.name: SetFocusable03
1805 * @tc.desc: SetFocusable
1806 * @tc.type: FUNC
1807 */
1808HWTEST_F(WindowSessionTest2, SetFocusable03, Function | SmallTest | Level2)
1809{
1810    ASSERT_NE(session_, nullptr);
1811    session_->isFocused_ = true;
1812    session_->property_ = new (std::nothrow) WindowSessionProperty();
1813    session_->property_->focusable_ = false;
1814    bool isFocusable = true;
1815
1816    auto result = session_->SetFocusable(isFocusable);
1817    ASSERT_EQ(result, WSError::WS_OK);
1818    ASSERT_EQ(session_->GetFocusable(), true);
1819}
1820
1821/**
1822 * @tc.name: GetFocused
1823 * @tc.desc: GetFocused Test
1824 * @tc.type: FUNC
1825 */
1826HWTEST_F(WindowSessionTest2, GetFocused, Function | SmallTest | Level2)
1827{
1828    ASSERT_NE(session_, nullptr);
1829    bool result = session_->GetFocused();
1830    ASSERT_EQ(result, false);
1831
1832    session_->isFocused_ = true;
1833    bool result2 = session_->GetFocused();
1834    ASSERT_EQ(result2, true);
1835}
1836
1837/**
1838 * @tc.name: UpdatePointerArea
1839 * @tc.desc: UpdatePointerArea Test
1840 * @tc.type: FUNC
1841 */
1842HWTEST_F(WindowSessionTest2, UpdatePointerArea, Function | SmallTest | Level2)
1843{
1844    ASSERT_NE(session_, nullptr);
1845    WSRect rect = { 0, 0, 0, 0 };
1846    session_->preRect_ = rect;
1847    session_->UpdatePointerArea(rect);
1848    ASSERT_EQ(session_->GetFocused(), false);
1849}
1850
1851/**
1852 * @tc.name: UpdateSizeChangeReason02
1853 * @tc.desc: UpdateSizeChangeReason Test
1854 * @tc.type: FUNC
1855 */
1856HWTEST_F(WindowSessionTest2, UpdateSizeChangeReason02, Function | SmallTest | Level2)
1857{
1858    ASSERT_NE(session_, nullptr);
1859    SizeChangeReason reason = SizeChangeReason::UNDEFINED;
1860    WSError result = session_->UpdateSizeChangeReason(reason);
1861    ASSERT_EQ(result, WSError::WS_DO_NOTHING);
1862}
1863
1864/**
1865 * @tc.name: UpdateDensity
1866 * @tc.desc: UpdateDensity Test
1867 * @tc.type: FUNC
1868 */
1869HWTEST_F(WindowSessionTest2, UpdateDensity, Function | SmallTest | Level2)
1870{
1871    ASSERT_NE(session_, nullptr);
1872
1873    session_->state_ = SessionState::STATE_DISCONNECT;
1874    ASSERT_FALSE(session_->IsSessionValid());
1875    WSError result = session_->UpdateDensity();
1876    ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
1877
1878    session_->state_ = SessionState::STATE_CONNECT;
1879    ASSERT_TRUE(session_->IsSessionValid());
1880    session_->sessionStage_ = nullptr;
1881    WSError result02 = session_->UpdateDensity();
1882    ASSERT_EQ(result02, WSError::WS_ERROR_NULLPTR);
1883}
1884
1885/**
1886 * @tc.name: TransferKeyEventForConsumed01
1887 * @tc.desc: windowEventChannel_ is nullptr
1888 * @tc.type: FUNC
1889 */
1890HWTEST_F(WindowSessionTest2, TransferKeyEventForConsumed01, Function | SmallTest | Level2)
1891{
1892    ASSERT_NE(session_, nullptr);
1893
1894    session_->windowEventChannel_ = nullptr;
1895
1896    auto keyEvent = MMI::KeyEvent::Create();
1897    bool isConsumed = false;
1898    ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->TransferKeyEventForConsumed(keyEvent, isConsumed));
1899}
1900
1901/**
1902 * @tc.name: GetMainSession
1903 * @tc.desc: GetMainSession Test
1904 * @tc.type: FUNC
1905 */
1906HWTEST_F(WindowSessionTest2, GetMainSession, Function | SmallTest | Level2)
1907{
1908    ASSERT_NE(session_, nullptr);
1909    SessionInfo info;
1910    info.abilityName_ = "getMainSession";
1911    info.moduleName_ = "getMainSession";
1912    info.bundleName_ = "getMainSession";
1913    sptr<Session> session = sptr<Session>::MakeSptr(info);
1914    ASSERT_NE(session, nullptr);
1915    session->property_ = sptr<WindowSessionProperty>::MakeSptr();
1916    ASSERT_NE(session->property_, nullptr);
1917    session_->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
1918    EXPECT_EQ(session, session->GetMainSession());
1919
1920    sptr<Session> subSession = sptr<Session>::MakeSptr(info);
1921    ASSERT_NE(subSession, nullptr);
1922    subSession->SetParentSession(session);
1923    subSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1924    ASSERT_NE(subSession->property_, nullptr);
1925    subSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1926    EXPECT_EQ(session, subSession->GetMainSession());
1927
1928    sptr<Session> subSubSession = sptr<Session>::MakeSptr(info);
1929    ASSERT_NE(subSubSession, nullptr);
1930    subSubSession->SetParentSession(subSession);
1931    subSubSession->property_ = sptr<WindowSessionProperty>::MakeSptr();
1932    ASSERT_NE(subSubSession->property_, nullptr);
1933    subSubSession->property_->SetWindowType(WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
1934    EXPECT_EQ(session, subSubSession->GetMainSession());
1935}
1936
1937/**
1938 * @tc.name: IsSupportDetectWindow
1939 * @tc.desc: IsSupportDetectWindow Test
1940 * @tc.type: FUNC
1941 */
1942HWTEST_F(WindowSessionTest2, IsSupportDetectWindow, Function | SmallTest | Level2)
1943{
1944    session_->systemConfig_.windowUIType_ = WindowUIType::PHONE_WINDOW;
1945    ssm_->SetScreenLocked(true);
1946    bool ret = session_->IsSupportDetectWindow(true);
1947    ASSERT_EQ(ret, false);
1948
1949    ssm_->SetScreenLocked(false);
1950    session_->property_ = new WindowSessionProperty();
1951    session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_END);
1952    ret = session_->IsSupportDetectWindow(true);
1953    ASSERT_EQ(ret, false);
1954
1955    ssm_->SetScreenLocked(false);
1956    session_->property_->SetWindowType(WindowType::APP_MAIN_WINDOW_BASE);
1957    session_->systemConfig_.windowUIType_ = WindowUIType::PC_WINDOW;
1958    ret = session_->IsSupportDetectWindow(false);
1959    ASSERT_EQ(ret, false);
1960}
1961
1962/**
1963 * @tc.name: ShouldCreateDetectTask
1964 * @tc.desc: ShouldCreateDetectTask Test
1965 * @tc.type: FUNC
1966 */
1967HWTEST_F(WindowSessionTest2, ShouldCreateDetectTask, Function | SmallTest | Level2)
1968{
1969    DetectTaskInfo detectTaskInfo;
1970    detectTaskInfo.taskState = DetectTaskState::ATTACH_TASK;
1971    detectTaskInfo.taskWindowMode = WindowMode::WINDOW_MODE_FULLSCREEN;
1972    session_->SetDetectTaskInfo(detectTaskInfo);
1973    bool ret = session_->ShouldCreateDetectTask(true, WindowMode::WINDOW_MODE_UNDEFINED);
1974    ASSERT_EQ(ret, true);
1975    detectTaskInfo.taskState = DetectTaskState::DETACH_TASK;
1976    session_->SetDetectTaskInfo(detectTaskInfo);
1977    ret = session_->ShouldCreateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED);
1978    ASSERT_EQ(ret, true);
1979    ret = session_->ShouldCreateDetectTask(true, WindowMode::WINDOW_MODE_UNDEFINED);
1980    ASSERT_EQ(ret, false);
1981}
1982
1983/**
1984 * @tc.name: ShouldCreateDetectTaskInRecent
1985 * @tc.desc: ShouldCreateDetectTaskInRecent Test
1986 * @tc.type: FUNC
1987 */
1988HWTEST_F(WindowSessionTest2, ShouldCreateDetectTaskInRecent, Function | SmallTest | Level2)
1989{
1990    bool ret = session_->ShouldCreateDetectTaskInRecent(true, true, true);
1991    ASSERT_EQ(ret, false);
1992    ret = session_->ShouldCreateDetectTaskInRecent(false, true, true);
1993    ASSERT_EQ(ret, true);
1994    ret = session_->ShouldCreateDetectTaskInRecent(false, true, false);
1995    ASSERT_EQ(ret, false);
1996    ret = session_->ShouldCreateDetectTaskInRecent(false, false, false);
1997    ASSERT_EQ(ret, false);
1998}
1999
2000/**
2001 * @tc.name: CreateWindowStateDetectTask
2002 * @tc.desc: CreateWindowStateDetectTask Test
2003 * @tc.type: FUNC
2004 */
2005HWTEST_F(WindowSessionTest2, CreateWindowStateDetectTask, Function | SmallTest | Level2)
2006{
2007    auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); };
2008    session_->RegisterIsScreenLockedCallback(isScreenLockedCallback);
2009    session_->SetSessionState(SessionState::STATE_CONNECT);
2010    bool isAttach = true;
2011    session_->CreateWindowStateDetectTask(isAttach, WindowMode::WINDOW_MODE_UNDEFINED);
2012    ASSERT_EQ(isAttach, true);
2013
2014    session_->handler_ = nullptr;
2015    session_->CreateWindowStateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED);
2016    ASSERT_EQ(session_->handler_, nullptr);
2017}
2018
2019/**
2020 * @tc.name: SetOffset01
2021 * @tc.desc: SetOffset Test
2022 * @tc.type: FUNC
2023 */
2024HWTEST_F(WindowSessionTest2, SetOffset01, Function | SmallTest | Level2)
2025{
2026    ASSERT_NE(session_, nullptr);
2027    session_->SetOffset(0, 0);
2028    ASSERT_EQ(session_->GetOffsetX(), 0);
2029}
2030}
2031} // namespace Rosen
2032} // namespace OHOS
2033