1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17 #include <pointer_event.h>
18 #include <ui/rs_surface_node.h>
19
20 #include "mock/mock_session_stage.h"
21 #include "mock/mock_window_event_channel.h"
22 #include "session/host/include/extension_session.h"
23 #include "session/host/include/move_drag_controller.h"
24 #include "session/host/include/scene_session.h"
25 #include "session/host/include/session.h"
26 #include "session_info.h"
27
28 using namespace testing;
29 using namespace testing::ext;
30
31 namespace OHOS {
32 namespace Rosen {
33 namespace {
34 const std::string UNDEFINED = "undefined";
35 }
36
37 class TestWindowEventChannel : public IWindowEventChannel {
38 public:
39 WSError TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override;
40 WSError TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
41 WSError TransferFocusActiveEvent(bool isFocusActive) override;
42 WSError TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed) override;
43 WSError TransferFocusState(bool focusState) override;
44
AsObject()45 sptr<IRemoteObject> AsObject() override
46 {
47 return nullptr;
48 };
49 };
50
TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent> & keyEvent)51 WSError TestWindowEventChannel::TransferKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
52 {
53 return WSError::WS_OK;
54 }
55
TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)56 WSError TestWindowEventChannel::TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
57 {
58 return WSError::WS_OK;
59 }
60
TransferFocusActiveEvent(bool isFocusActive)61 WSError TestWindowEventChannel::TransferFocusActiveEvent(bool isFocusActive)
62 {
63 return WSError::WS_OK;
64 }
65
TransferKeyEventForConsumed(const std::shared_ptr<MMI::KeyEvent> & keyEvent,bool & isConsumed)66 WSError TestWindowEventChannel::TransferKeyEventForConsumed(
67 const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed)
68 {
69 return WSError::WS_OK;
70 }
71
TransferFocusState(bool foucsState)72 WSError TestWindowEventChannel::TransferFocusState(bool foucsState)
73 {
74 return WSError::WS_OK;
75 }
76
77 class WindowSessionTest : public testing::Test {
78 public:
79 static void SetUpTestCase();
80 static void TearDownTestCase();
81 void SetUp() override;
82 void TearDown() override;
83 private:
84 RSSurfaceNode::SharedPtr CreateRSSurfaceNode();
85 sptr<Session> session_ = nullptr;
86 };
87
SetUpTestCase()88 void WindowSessionTest::SetUpTestCase()
89 {
90 }
91
TearDownTestCase()92 void WindowSessionTest::TearDownTestCase()
93 {
94 }
95
SetUp()96 void WindowSessionTest::SetUp()
97 {
98 SessionInfo info;
99 info.abilityName_ = "testSession1";
100 info.moduleName_ = "testSession2";
101 info.bundleName_ = "testSession3";
102 session_ = new (std::nothrow) Session(info);
103 session_->surfaceNode_ = CreateRSSurfaceNode();
104 EXPECT_NE(nullptr, session_);
105 }
106
TearDown()107 void WindowSessionTest::TearDown()
108 {
109 session_ = nullptr;
110 }
111
CreateRSSurfaceNode()112 RSSurfaceNode::SharedPtr WindowSessionTest::CreateRSSurfaceNode()
113 {
114 struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
115 rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode";
116 auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig);
117 return surfaceNode;
118 }
119
120 namespace {
121 /**
122 * @tc.name: SetActive01
123 * @tc.desc: set session active
124 * @tc.type: FUNC
125 * @tc.require: #I6JLSI
126 */
127 HWTEST_F(WindowSessionTest, SetActive01, Function | SmallTest | Level2)
128 {
129 sptr<ISession> sessionToken = nullptr;
130 sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
131 EXPECT_NE(nullptr, mockSessionStage);
132 EXPECT_CALL(*(mockSessionStage), SetActive(_)).WillOnce(Return(WSError::WS_OK));
133 EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _)).Times(1).WillOnce(Return(WSError::WS_OK));
134 session_->sessionStage_ = mockSessionStage;
135 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetActive(true));
136
137 sptr<WindowEventChannelMocker> mockEventChannel = new(std::nothrow) WindowEventChannelMocker(mockSessionStage);
138 EXPECT_NE(nullptr, mockEventChannel);
139 auto surfaceNode = CreateRSSurfaceNode();
140 SystemSessionConfig sessionConfig;
141 ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, surfaceNode, sessionConfig));
142 ASSERT_EQ(WSError::WS_OK, session_->SetActive(true));
143 ASSERT_EQ(false, session_->isActive_);
144
145 session_->UpdateSessionState(SessionState::STATE_FOREGROUND);
146 ASSERT_EQ(WSError::WS_OK, session_->SetActive(true));
147 ASSERT_EQ(true, session_->isActive_);
148 }
149
150 /**
151 * @tc.name: UpdateRect01
152 * @tc.desc: update rect
153 * @tc.type: FUNC
154 * @tc.require: #I6JLSI
155 */
156 HWTEST_F(WindowSessionTest, UpdateRect01, Function | SmallTest | Level2)
157 {
158 sptr<ISession> sessionToken = nullptr;
159 sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
160 EXPECT_NE(nullptr, mockSessionStage);
161 session_->sessionStage_ = mockSessionStage;
162 EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _)).Times(1).WillOnce(Return(WSError::WS_OK));
163
164 WSRect rect = {0, 0, 0, 0};
165 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED));
166 sptr<WindowEventChannelMocker> mockEventChannel = new(std::nothrow) WindowEventChannelMocker(mockSessionStage);
167 EXPECT_NE(nullptr, mockEventChannel);
168 SystemSessionConfig sessionConfig;
169 ASSERT_EQ(WSError::WS_OK, session_->Connect(mockSessionStage, mockEventChannel, nullptr, sessionConfig));
170
171 rect = {0, 0, 100, 100};
172 EXPECT_CALL(*(mockSessionStage), UpdateRect(_, _)).Times(1).WillOnce(Return(WSError::WS_OK));
173 ASSERT_EQ(WSError::WS_OK, session_->UpdateRect(rect, SizeChangeReason::UNDEFINED));
174 ASSERT_EQ(rect, session_->winRect_);
175 }
176
177 /**
178 * @tc.name: IsSessionValid01
179 * @tc.desc: check func IsSessionValid
180 * @tc.type: FUNC
181 */
182 HWTEST_F(WindowSessionTest, IsSessionValid01, Function | SmallTest | Level2)
183 {
184 session_->state_ = SessionState::STATE_DISCONNECT;
185 ASSERT_FALSE(session_->IsSessionValid());
186 session_->state_ = SessionState::STATE_CONNECT;
187 ASSERT_TRUE(session_->IsSessionValid());
188 }
189
190 /**
191 * @tc.name: UpdateWindowSessionProperty01
192 * @tc.desc: UpdateWindowSessionProperty
193 * @tc.type: FUNC
194 */
195 HWTEST_F(WindowSessionTest, UpdateWindowSessionProperty01, Function | SmallTest | Level2)
196 {
197 session_->state_ = SessionState::STATE_DISCONNECT;
198 ASSERT_EQ(session_->UpdateWindowSessionProperty(nullptr), WSError::WS_OK);
199 }
200
201 /**
202 * @tc.name: Connect01
203 * @tc.desc: check func Connect
204 * @tc.type: FUNC
205 */
206 HWTEST_F(WindowSessionTest, Connect01, Function | SmallTest | Level2)
207 {
208 auto surfaceNode = CreateRSSurfaceNode();
209 session_->state_ = SessionState::STATE_CONNECT;
210 SystemSessionConfig systemConfig;
211 auto result = session_->Connect(nullptr, nullptr, nullptr, systemConfig);
212 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
213
214 session_->state_ = SessionState::STATE_DISCONNECT;
215 result = session_->Connect(nullptr, nullptr, nullptr, systemConfig);
216 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
217
218 sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
219 EXPECT_NE(nullptr, mockSessionStage);
220 result = session_->Connect(mockSessionStage, nullptr, surfaceNode, systemConfig);
221 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
222
223 sptr<TestWindowEventChannel> testWindowEventChannel = new(std::nothrow) TestWindowEventChannel();
224 EXPECT_NE(nullptr, testWindowEventChannel);
225 result = session_->Connect(mockSessionStage, testWindowEventChannel, surfaceNode, systemConfig);
226 ASSERT_EQ(result, WSError::WS_OK);
227 }
228
229 /**
230 * @tc.name: Foreground01
231 * @tc.desc: check func Foreground
232 * @tc.type: FUNC
233 */
234 HWTEST_F(WindowSessionTest, Foreground01, Function | SmallTest | Level2)
235 {
236 session_->state_ = SessionState::STATE_DISCONNECT;
237 sptr<WindowSessionProperty> property = new(std::nothrow) WindowSessionProperty();
238 ASSERT_NE(nullptr, property);
239 auto result = session_->Foreground(property);
240 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
241
242 session_->state_ = SessionState::STATE_CONNECT;
243 session_->isActive_ = true;
244 result = session_->Foreground(property);
245 ASSERT_EQ(result, WSError::WS_OK);
246
247 session_->isActive_ = false;
248 ASSERT_EQ(result, WSError::WS_OK);
249 }
250
251 /**
252 * @tc.name: Background01
253 * @tc.desc: check func Background
254 * @tc.type: FUNC
255 */
256 HWTEST_F(WindowSessionTest, Background01, Function | SmallTest | Level2)
257 {
258 session_->state_ = SessionState::STATE_CONNECT;
259 auto result = session_->Background();
260 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION);
261
262 session_->state_ = SessionState::STATE_INACTIVE;
263 result = session_->Background();
264 ASSERT_EQ(result, WSError::WS_OK);
265 ASSERT_EQ(session_->state_, SessionState::STATE_BACKGROUND);
266 }
267
268 /**
269 * @tc.name: Disconnect01
270 * @tc.desc: check func Disconnect
271 * @tc.type: FUNC
272 */
273 HWTEST_F(WindowSessionTest, Disconnect01, Function | SmallTest | Level2)
274 {
275 session_->state_ = SessionState::STATE_CONNECT;
276 auto result = session_->Disconnect();
277 ASSERT_EQ(result, WSError::WS_OK);
278 ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
279
280 session_->state_ = SessionState::STATE_BACKGROUND;
281 result = session_->Disconnect();
282 ASSERT_EQ(result, WSError::WS_OK);
283 ASSERT_EQ(session_->state_, SessionState::STATE_DISCONNECT);
284 }
285
286 /**
287 * @tc.name: PendingSessionActivation01
288 * @tc.desc: check func PendingSessionActivation
289 * @tc.type: FUNC
290 */
291 HWTEST_F(WindowSessionTest, PendingSessionActivation01, Function | SmallTest | Level2)
292 {
293 int resultValue = 0;
__anon409d9c1d0302(const SessionInfo& info) 294 NotifyPendingSessionActivationFunc callback = [&resultValue](const SessionInfo& info) {
295 resultValue = 1;
296 };
297
298 sptr<AAFwk::SessionInfo> info = new (std::nothrow)AAFwk::SessionInfo();
299 session_->pendingSessionActivationFunc_ = nullptr;
300 session_->PendingSessionActivation(info);
301 ASSERT_EQ(resultValue, 0);
302
303 session_->SetPendingSessionActivationEventListener(callback);
304 session_->PendingSessionActivation(info);
305 ASSERT_EQ(resultValue, 1);
306
307 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->PendingSessionActivation(nullptr));
308 }
309
310 /**
311 * @tc.name: TerminateSessionNew01
312 * @tc.desc: check func TerminateSessionNew
313 * @tc.type: FUNC
314 */
315 HWTEST_F(WindowSessionTest, TerminateSessionNew01, Function | SmallTest | Level2)
316 {
317 int resultValue = 0;
__anon409d9c1d0402(const SessionInfo& info, bool needStartCaller) 318 NotifyTerminateSessionFuncNew callback = [&resultValue](const SessionInfo& info, bool needStartCaller) {
319 resultValue = 1;
320 };
321
322 bool needStartCaller = false;
323 sptr<AAFwk::SessionInfo> info = new (std::nothrow)AAFwk::SessionInfo();
324 session_->terminateSessionFuncNew_ = nullptr;
325 session_->TerminateSessionNew(info, needStartCaller);
326 ASSERT_EQ(resultValue, 0);
327
328 needStartCaller = true;
329 session_->SetTerminateSessionListenerNew(callback);
330 session_->TerminateSessionNew(info, needStartCaller);
331 ASSERT_EQ(resultValue, 1);
332
333 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->TerminateSessionNew(nullptr, needStartCaller));
334 }
335
336 /**
337 * @tc.name: NotifySessionException01
338 * @tc.desc: check func NotifySessionException
339 * @tc.type: FUNC
340 */
341 HWTEST_F(WindowSessionTest, NotifySessionException01, Function | SmallTest | Level2)
342 {
343 int resultValue = 0;
__anon409d9c1d0502(const SessionInfo& info) 344 NotifySessionExceptionFunc callback = [&resultValue](const SessionInfo& info) {
345 resultValue = 1;
346 };
347
348 sptr<AAFwk::SessionInfo> info = new (std::nothrow)AAFwk::SessionInfo();
349 session_->sessionExceptionFuncs_.clear();
350 session_->NotifySessionException(info);
351 ASSERT_EQ(resultValue, 0);
352
353 session_->SetSessionExceptionListener(callback);
354 session_->NotifySessionException(info);
355 ASSERT_EQ(resultValue, 1);
356
357 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->NotifySessionException(nullptr));
358 }
359
360 /**
361 * @tc.name: UpdateActiveStatus01
362 * @tc.desc: check func UpdateActiveStatus01
363 * @tc.type: FUNC
364 */
365 HWTEST_F(WindowSessionTest, UpdateActiveStatus01, Function | SmallTest | Level2)
366 {
367 ASSERT_NE(session_, nullptr);
368 session_->isActive_ = false;
369 session_->UpdateSessionState(SessionState::STATE_FOREGROUND);
370 auto result = session_->UpdateActiveStatus(false);
371 ASSERT_EQ(result, WSError::WS_DO_NOTHING);
372
373 result = session_->UpdateActiveStatus(true);
374 ASSERT_EQ(result, WSError::WS_OK);
375 ASSERT_EQ(SessionState::STATE_ACTIVE, session_->state_);
376 }
377
378 /**
379 * @tc.name: UpdateActiveStatus02
380 * @tc.desc: check func UpdateActiveStatus02
381 * @tc.type: FUNC
382 */
383 HWTEST_F(WindowSessionTest, UpdateActiveStatus02, Function | SmallTest | Level2)
384 {
385 ASSERT_NE(session_, nullptr);
386 session_->isActive_ = false;
387 session_->UpdateSessionState(SessionState::STATE_INACTIVE);
388 auto result = session_->UpdateActiveStatus(true);
389 ASSERT_EQ(result, WSError::WS_DO_NOTHING);
390 ASSERT_EQ(SessionState::STATE_INACTIVE, session_->state_);
391 ASSERT_EQ(false, session_->isActive_);
392
393 session_->UpdateSessionState(SessionState::STATE_FOREGROUND);
394 result = session_->UpdateActiveStatus(true);
395 ASSERT_EQ(result, WSError::WS_OK);
396 ASSERT_EQ(SessionState::STATE_ACTIVE, session_->state_);
397
398 result = session_->UpdateActiveStatus(false);
399 ASSERT_EQ(result, WSError::WS_OK);
400 ASSERT_EQ(SessionState::STATE_INACTIVE, session_->state_);
401 }
402
403 /**
404 * @tc.name: SetSessionRect
405 * @tc.desc: check func SetSessionRect
406 * @tc.type: FUNC
407 */
408 HWTEST_F(WindowSessionTest, SetSessionRect, Function | SmallTest | Level2)
409 {
410 ASSERT_NE(session_, nullptr);
411 WSRect rect = { 0, 0, 320, 240}; // width: 320, height: 240
412 session_->SetSessionRect(rect);
413 ASSERT_EQ(rect, session_->winRect_);
414 }
415
416 /**
417 * @tc.name: GetSessionRect
418 * @tc.desc: check func GetSessionRect
419 * @tc.type: FUNC
420 */
421 HWTEST_F(WindowSessionTest, GetSessionRect, Function | SmallTest | Level2)
422 {
423 ASSERT_NE(session_, nullptr);
424 WSRect rect = { 0, 0, 320, 240}; // width: 320, height: 240
425 session_->SetSessionRect(rect);
426 ASSERT_EQ(rect, session_->GetSessionRect());
427 }
428
429 /**
430 * @tc.name: CheckDialogOnForeground
431 * @tc.desc: check func CheckDialogOnForeground
432 * @tc.type: FUNC
433 */
434 HWTEST_F(WindowSessionTest, CheckDialogOnForeground, Function | SmallTest | Level2)
435 {
436 ASSERT_NE(session_, nullptr);
437 session_->dialogVec_.clear();
438 ASSERT_EQ(false, session_->CheckDialogOnForeground());
439 SessionInfo info;
440 info.abilityName_ = "dialogAbilityName";
441 info.moduleName_ = "dialogModuleName";
442 info.bundleName_ = "dialogBundleName";
443 sptr<Session> dialogSession = new (std::nothrow) Session(info);
444 ASSERT_NE(dialogSession, nullptr);
445 dialogSession->state_ = SessionState::STATE_INACTIVE;
446 session_->dialogVec_.push_back(dialogSession);
447 ASSERT_EQ(false, session_->CheckDialogOnForeground());
448 session_->dialogVec_.clear();
449 }
450
451 /**
452 * @tc.name: NotifyDestroy
453 * @tc.desc: check func NotifyDestroy
454 * @tc.type: FUNC
455 */
456 HWTEST_F(WindowSessionTest, NotifyDestroy, Function | SmallTest | Level2)
457 {
458 sptr<SessionStageMocker> mockSessionStage = new(std::nothrow) SessionStageMocker();
459 ASSERT_NE(mockSessionStage, nullptr);
460 session_->sessionStage_ = mockSessionStage;
461 EXPECT_CALL(*(mockSessionStage), NotifyDestroy()).Times(1).WillOnce(Return(WSError::WS_OK));
462 ASSERT_EQ(WSError::WS_OK, session_->NotifyDestroy());
463 session_->sessionStage_ = nullptr;
464 ASSERT_EQ(WSError::WS_ERROR_NULLPTR, session_->NotifyDestroy());
465 }
466
467 /**
468 * @tc.name: RequestSessionBack
469 * @tc.desc: request session back
470 * @tc.type: FUNC
471 */
472 HWTEST_F(WindowSessionTest, RequestSessionBack, Function | SmallTest | Level2)
473 {
474 ASSERT_NE(session_, nullptr);
475
476 ASSERT_EQ(WSError::WS_DO_NOTHING, session_->RequestSessionBack());
477
__anon409d9c1d0602() 478 NotifyBackPressedFunc callback = []() {};
479
480 session_->SetBackPressedListenser(callback);
481 ASSERT_EQ(WSError::WS_OK, session_->RequestSessionBack());
482 }
483
484 /**
485 * @tc.name: RaiseToAppTop01
486 * @tc.desc: RaiseToAppTop
487 * @tc.type: FUNC
488 */
489 HWTEST_F(WindowSessionTest, RaiseToAppTop01, Function | SmallTest | Level2)
490 {
491 SessionInfo info;
492 info.abilityName_ = "testSession1";
493 info.bundleName_ = "testSession3";
494 sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
495 EXPECT_NE(scensession, nullptr);
496 auto result = scensession->RaiseToAppTop();
497 ASSERT_EQ(result, WSError::WS_OK);
498
499 sptr<SceneSession::SessionChangeCallback> scensessionchangeCallBack =
500 new (std::nothrow) SceneSession::SessionChangeCallback();
501 EXPECT_NE(scensessionchangeCallBack, nullptr);
502 scensession->RegisterSessionChangeCallback(scensessionchangeCallBack);
503 result = scensession->RaiseToAppTop();
504 ASSERT_EQ(result, WSError::WS_OK);
505
__anon409d9c1d0702() 506 NotifyRaiseToTopFunc onRaiseToTop_ = []() {};
507 scensessionchangeCallBack->onRaiseToTop_ = onRaiseToTop_;
508 result = scensession->RaiseToAppTop();
509 ASSERT_EQ(result, WSError::WS_OK);
510 }
511
512 /**
513 * @tc.name: UpdateSessionRect01
514 * @tc.desc: UpdateSessionRect
515 * @tc.type: FUNC
516 */
517 HWTEST_F(WindowSessionTest, UpdateSessionRect01, Function | SmallTest | Level2)
518 {
519 SessionInfo info;
520 info.abilityName_ = "testSession1";
521 info.bundleName_ = "testSession3";
522 sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
523 EXPECT_NE(scensession, nullptr);
524 WSRect rect = {0, 0, 320, 240}; // width: 320, height: 240
525 auto result = scensession->UpdateSessionRect(rect, SizeChangeReason::RESIZE);
526 ASSERT_EQ(result, WSError::WS_OK);
527
528 sptr<SceneSession::SessionChangeCallback> scensessionchangeCallBack =
529 new (std::nothrow) SceneSession::SessionChangeCallback();
530 EXPECT_NE(scensessionchangeCallBack, nullptr);
531 scensession->RegisterSessionChangeCallback(scensessionchangeCallBack);
532 result = scensession->UpdateSessionRect(rect, SizeChangeReason::RESIZE);
533 ASSERT_EQ(result, WSError::WS_OK);
534
535 int resultValue = 0;
536 NotifySessionRectChangeFunc onRectChange_ = [&resultValue](const WSRect &rect, const SizeChangeReason& reason)
__anon409d9c1d0802(const WSRect &rect, const SizeChangeReason& reason) 537 { resultValue = 1; };
538 scensessionchangeCallBack->onRectChange_ = onRectChange_;
539 result = scensession->UpdateSessionRect(rect, SizeChangeReason::RESIZE);
540 ASSERT_EQ(result, WSError::WS_OK);
541 }
542
543 /**
544 * @tc.name: DestroyAndDisconnectSpecificSession01
545 * @tc.desc: DestroyAndDisconnectSpecificSession
546 * @tc.type: FUNC
547 */
548 HWTEST_F(WindowSessionTest, DestroyAndDisconnectSpecificSession01, Function | SmallTest | Level2)
549 {
550 SessionInfo info;
551 info.abilityName_ = "testSession1";
552 info.bundleName_ = "testSession3";
553 int32_t persistentId = 0;
554 sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
555 EXPECT_NE(scensession, nullptr);
556 auto result = scensession->DestroyAndDisconnectSpecificSession(persistentId);
557 ASSERT_EQ(result, WSError::WS_OK);
558
559 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
560 new (std::nothrow) SceneSession::SpecificSessionCallback();
561 EXPECT_NE(specificCallback_, nullptr);
562 int resultValue = 0;
563 specificCallback_->onDestroy_ = [&resultValue](const int32_t &persistentId) -> WSError
__anon409d9c1d0902(const int32_t &persistentId) 564 {
565 resultValue = 1;
566 return WSError::WS_OK;
567 };
568 scensession = new (std::nothrow) SceneSession(info, specificCallback_);
569 EXPECT_NE(scensession, nullptr);
570 result = scensession->DestroyAndDisconnectSpecificSession(persistentId);
571 ASSERT_EQ(result, WSError::WS_OK);
572 }
573
574 /**
575 * @tc.name: CreateAndConnectSpecificSession02
576 * @tc.desc: CreateAndConnectSpecificSession
577 * @tc.type: FUNC
578 */
579 HWTEST_F(WindowSessionTest, CreateAndConnectSpecificSession2, Function | SmallTest | Level2)
580 {
581 SessionInfo info;
582 info.abilityName_ = "testSession1";
583 info.bundleName_ = "testSession3";
584 sptr<Rosen::ISession> session_;
585 auto surfaceNode_ = CreateRSSurfaceNode();
586 sptr<WindowSessionProperty> property_ = nullptr;
587 int32_t persistentId = 0;
588 sptr<SessionStageMocker> mockSessionStage = new (std::nothrow) SessionStageMocker();
589 EXPECT_NE(mockSessionStage, nullptr);
590 sptr<SceneSession::SpecificSessionCallback> specificCallback_ =
591 new (std::nothrow) SceneSession::SpecificSessionCallback();
592 EXPECT_NE(specificCallback_, nullptr);
593 int resultValue = 0;
594 sptr<SceneSession> scensession;
595 sptr<TestWindowEventChannel> testWindowEventChannel = new (std::nothrow) TestWindowEventChannel();
596 EXPECT_NE(testWindowEventChannel, nullptr);
597
598 scensession = new (std::nothrow) SceneSession(info, nullptr);
599 EXPECT_NE(scensession, nullptr);
600 auto result = scensession->CreateAndConnectSpecificSession(mockSessionStage, testWindowEventChannel, surfaceNode_,
601 property_, persistentId, session_);
602 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
603 specificCallback_->onCreate_ = [&resultValue, specificCallback_](const SessionInfo &info,
604 sptr<WindowSessionProperty> property) -> sptr<SceneSession>
__anon409d9c1d0a02(const SessionInfo &info, sptr<WindowSessionProperty> property) 605 {
606 sptr<SceneSession> scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback_);
607 EXPECT_NE(scensessionreturn, nullptr);
608 resultValue = 1;
609 return scensessionreturn;
610 };
611 scensession = new (std::nothrow) SceneSession(info, specificCallback_);
612 EXPECT_NE(scensession, nullptr);
613 }
614
615 /**
616 * @tc.name: OnSessionEvent01
617 * @tc.desc: OnSessionEvent
618 * @tc.type: FUNC
619 */
620 HWTEST_F(WindowSessionTest, OnSessionEvent01, Function | SmallTest | Level2)
621 {
622 SessionInfo info;
623 info.abilityName_ = "testSession1";
624 info.bundleName_ = "testSession3";
625 sptr<SceneSession> scensession = new (std::nothrow) SceneSession(info, nullptr);
626 EXPECT_NE(scensession, nullptr);
627 auto result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
628 ASSERT_EQ(result, WSError::WS_OK);
629
630 sptr<SceneSession::SessionChangeCallback> scensessionchangeCallBack =
631 new (std::nothrow) SceneSession::SessionChangeCallback();
632 EXPECT_NE(scensessionchangeCallBack, nullptr);
633 scensession->RegisterSessionChangeCallback(scensessionchangeCallBack);
634 result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
635 ASSERT_EQ(result, WSError::WS_OK);
636
637 int resultValue = 0;
638 NotifySessionEventFunc onSessionEvent_ = [&resultValue](int32_t eventId)
__anon409d9c1d0b02(int32_t eventId) 639 { resultValue = 1; };
640 scensessionchangeCallBack->OnSessionEvent_ = onSessionEvent_;
641 result = scensession->OnSessionEvent(SessionEvent::EVENT_MINIMIZE);
642 ASSERT_EQ(result, WSError::WS_OK);
643 }
644
645 /**
646 * @tc.name: ConsumeMoveEvent01
647 * @tc.desc: ConsumeMoveEvent, abnormal scene
648 * @tc.type: FUNC
649 */
650 HWTEST_F(WindowSessionTest, ConsumeMoveEvent01, Function | SmallTest | Level2)
651 {
652 SessionInfo info;
653 info.abilityName_ = "testSession1";
654 info.bundleName_ = "testSession3";
655 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
656 EXPECT_NE(sceneSession, nullptr);
657 ASSERT_TRUE(sceneSession->moveDragController_);
658 sceneSession->moveDragController_->InitMoveDragProperty();
659 WSRect originalRect = { 100, 100, 1000, 1000 };
660
661 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
662 auto result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
663 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
664
665 pointerEvent = MMI::PointerEvent::Create();
666 ASSERT_TRUE(pointerEvent);
667 pointerEvent->SetPointerId(1);
668 sceneSession->moveDragController_->moveDragProperty_.pointerId_ = 0;
669 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
670 ASSERT_EQ(result, WSError::WS_DO_NOTHING);
671
672 pointerEvent->SetPointerId(0);
673 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_MOUSE);
674 pointerEvent->SetButtonId(MMI::PointerEvent::MOUSE_BUTTON_RIGHT);
675 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
676 ASSERT_EQ(result, WSError::WS_ERROR_NULLPTR);
677 }
678
679 /**
680 * @tc.name: ConsumeMoveEvent02
681 * @tc.desc: ConsumeMoveEvent, normal secne
682 * @tc.type: FUNC
683 */
684 HWTEST_F(WindowSessionTest, ConsumeMoveEvent02, Function | SmallTest | Level2)
685 {
686 SessionInfo info;
687 info.abilityName_ = "testSession1";
688 info.bundleName_ = "testSession3";
689 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
690 EXPECT_NE(sceneSession, nullptr);
691 ASSERT_TRUE(sceneSession->moveDragController_);
692 sceneSession->moveDragController_->InitMoveDragProperty();
693 WSRect originalRect = { 100, 100, 1000, 1000 };
694 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
695 ASSERT_TRUE(pointerEvent);
696 pointerEvent->SetAgentWindowId(1);
697 pointerEvent->SetPointerId(0);
698 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
699 MMI::PointerEvent::PointerItem pointerItem;
700 pointerItem.SetPointerId(0);
701 pointerEvent->AddPointerItem(pointerItem);
702
703 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
704 pointerItem.SetDisplayX(115);
705 pointerItem.SetDisplayY(500);
706 pointerItem.SetWindowX(15);
707 pointerItem.SetWindowY(400);
708 auto result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
709 ASSERT_EQ(result, WSError::WS_OK);
710
711 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
712 pointerItem.SetDisplayX(145);
713 pointerItem.SetDisplayY(550);
714 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
715 ASSERT_EQ(result, WSError::WS_OK);
716
717 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
718 pointerItem.SetDisplayX(175);
719 pointerItem.SetDisplayY(600);
720 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
721 ASSERT_EQ(result, WSError::WS_OK);
722
723 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
724 pointerItem.SetDisplayX(205);
725 pointerItem.SetDisplayY(650);
726 result = sceneSession->moveDragController_->ConsumeMoveEvent(pointerEvent, originalRect);
727 ASSERT_EQ(result, WSError::WS_OK);
728 }
729
730 /**
731 * @tc.name: ConsumeDragEvent01
732 * @tc.desc: ConsumeDragEvent, abnormal scene
733 * @tc.type: FUNC
734 */
735 HWTEST_F(WindowSessionTest, ConsumeDragEvent01, Function | SmallTest | Level2)
736 {
737 SessionInfo info;
738 info.abilityName_ = "testSession1";
739 info.bundleName_ = "testSession3";
740 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
741 EXPECT_NE(sceneSession, nullptr);
742 ASSERT_TRUE(sceneSession->moveDragController_);
743 sceneSession->moveDragController_->InitMoveDragProperty();
744 WSRect originalRect = { 100, 100, 1000, 1000 };
745 SystemSessionConfig sessionConfig;
746
747 std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
748 sptr<WindowSessionProperty> property = nullptr;
749 auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property,
750 sessionConfig);
751 ASSERT_EQ(result, false);
752
753 pointerEvent = MMI::PointerEvent::Create();
754 ASSERT_TRUE(pointerEvent);
755 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
756 property = new WindowSessionProperty();
757 sceneSession->moveDragController_->isStartDrag_ = false;
758 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
759 ASSERT_EQ(result, false);
760
761 pointerEvent->SetPointerId(1);
762 sceneSession->moveDragController_->moveDragProperty_.pointerId_ = 0;
763 sceneSession->moveDragController_->isStartDrag_ = true;
764 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
765 ASSERT_EQ(result, false);
766
767 pointerEvent->SetPointerId(0);
768 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
769 ASSERT_EQ(result, false);
770 }
771
772 /**
773 * @tc.name: ConsumeDragEvent02
774 * @tc.desc: ConsumeDragEvent, normal scene
775 * @tc.type: FUNC
776 */
777 HWTEST_F(WindowSessionTest, ConsumeDragEvent02, Function | SmallTest | Level2)
778 {
779 SessionInfo info;
780 info.abilityName_ = "testSession1";
781 info.bundleName_ = "testSession3";
782 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
783 EXPECT_NE(sceneSession, nullptr);
784 ASSERT_TRUE(sceneSession->moveDragController_);
785 sceneSession->moveDragController_->InitMoveDragProperty();
786 WSRect originalRect = { 100, 100, 1000, 1000 };
787 sptr<WindowSessionProperty> property = new WindowSessionProperty();
788 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
789 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
790 SystemSessionConfig sessionConfig;
791 sessionConfig.isSystemDecorEnable_ = true;
792 sessionConfig.decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
793 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
794 ASSERT_TRUE(pointerEvent);
795 pointerEvent->SetAgentWindowId(1);
796 pointerEvent->SetPointerId(0);
797 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
798 MMI::PointerEvent::PointerItem pointerItem;
799 pointerItem.SetPointerId(0);
800 pointerEvent->AddPointerItem(pointerItem);
801
802 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
803 pointerItem.SetDisplayX(100);
804 pointerItem.SetDisplayY(100);
805 pointerItem.SetWindowX(0);
806 pointerItem.SetWindowY(0);
807 auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property,
808 sessionConfig);
809 ASSERT_EQ(result, true);
810
811 sceneSession->moveDragController_->aspectRatio_ = 0.0f;
812 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
813 pointerItem.SetDisplayX(150);
814 pointerItem.SetDisplayY(150);
815 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
816 ASSERT_EQ(result, true);
817
818 sceneSession->moveDragController_->aspectRatio_ = 1.0f;
819 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_MOVE);
820 pointerItem.SetDisplayX(200);
821 pointerItem.SetDisplayY(200);
822 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
823 ASSERT_EQ(result, true);
824
825 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_UP);
826 pointerItem.SetDisplayX(250);
827 pointerItem.SetDisplayY(250);
828 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
829 ASSERT_EQ(result, true);
830 }
831
832 /**
833 * @tc.name: ConsumeDragEvent03
834 * @tc.desc: ConsumeDragEvent, normal scene
835 * @tc.type: FUNC
836 */
837 HWTEST_F(WindowSessionTest, ConsumeDragEvent03, Function | SmallTest | Level2)
838 {
839 SessionInfo info;
840 info.abilityName_ = "testSession1";
841 info.bundleName_ = "testSession3";
842 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
843 EXPECT_NE(sceneSession, nullptr);
844 ASSERT_TRUE(sceneSession->moveDragController_);
845 sceneSession->moveDragController_->InitMoveDragProperty();
846 WSRect originalRect = { 100, 100, 1000, 1000 };
847 sptr<WindowSessionProperty> property = new WindowSessionProperty();
848 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
849 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
850 SystemSessionConfig sessionConfig;
851 sessionConfig.isSystemDecorEnable_ = true;
852 sessionConfig.decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
853 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
854 ASSERT_TRUE(pointerEvent);
855 pointerEvent->SetAgentWindowId(1);
856 pointerEvent->SetPointerId(0);
857 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
858 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
859 MMI::PointerEvent::PointerItem pointerItem;
860 pointerItem.SetPointerId(0);
861 pointerEvent->AddPointerItem(pointerItem);
862
863 // LEFT_TOP
864 pointerItem.SetWindowX(0);
865 pointerItem.SetWindowY(0);
866 auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property,
867 sessionConfig);
868 ASSERT_EQ(result, true);
869
870 // RIGHT_TOP
871 pointerItem.SetWindowX(1000);
872 pointerItem.SetWindowY(0);
873 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
874 ASSERT_EQ(result, true);
875
876 // RIGHT_BOTTOM
877 pointerItem.SetWindowX(1000);
878 pointerItem.SetWindowY(1000);
879 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
880 ASSERT_EQ(result, true);
881
882 // LEFT_BOTTOM
883 pointerItem.SetWindowX(0);
884 pointerItem.SetWindowY(1000);
885 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
886 ASSERT_EQ(result, true);
887 }
888
889 /**
890 * @tc.name: ConsumeDragEvent04
891 * @tc.desc: ConsumeDragEvent, normal scene
892 * @tc.type: FUNC
893 */
894 HWTEST_F(WindowSessionTest, ConsumeDragEvent04, Function | SmallTest | Level2)
895 {
896 SessionInfo info;
897 info.abilityName_ = "testSession1";
898 info.bundleName_ = "testSession3";
899 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
900 EXPECT_NE(sceneSession, nullptr);
901 ASSERT_TRUE(sceneSession->moveDragController_);
902 sceneSession->moveDragController_->InitMoveDragProperty();
903 WSRect originalRect = { 100, 100, 1000, 1000 };
904 sptr<WindowSessionProperty> property = new WindowSessionProperty();
905 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
906 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
907 SystemSessionConfig sessionConfig;
908 sessionConfig.isSystemDecorEnable_ = true;
909 sessionConfig.decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
910 std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
911 ASSERT_TRUE(pointerEvent);
912 pointerEvent->SetAgentWindowId(1);
913 pointerEvent->SetPointerId(0);
914 pointerEvent->SetSourceType(MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN);
915 pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
916 MMI::PointerEvent::PointerItem pointerItem;
917 pointerItem.SetPointerId(0);
918 pointerEvent->AddPointerItem(pointerItem);
919
920 // LEFT
921 pointerItem.SetWindowX(0);
922 pointerItem.SetWindowY(500);
923 auto result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property,
924 sessionConfig);
925 ASSERT_EQ(result, true);
926
927 // TOP
928 pointerItem.SetWindowX(500);
929 pointerItem.SetWindowY(0);
930 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
931 ASSERT_EQ(result, true);
932
933 // RIGHT
934 pointerItem.SetWindowX(1000);
935 pointerItem.SetWindowY(500);
936 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
937 ASSERT_EQ(result, true);
938
939 // BOTTOM
940 pointerItem.SetWindowX(500);
941 pointerItem.SetWindowY(1000);
942 result = sceneSession->moveDragController_->ConsumeDragEvent(pointerEvent, originalRect, property, sessionConfig);
943 ASSERT_EQ(result, true);
944 }
945
946 /**
947 * @tc.name: SetAspectRatio01
948 * @tc.desc: SetAspectRatio
949 * @tc.type: FUNC
950 */
951 HWTEST_F(WindowSessionTest, SetAspectRatio01, Function | SmallTest | Level2)
952 {
953 SessionInfo info;
954 info.abilityName_ = "testSession1";
955 info.bundleName_ = "testSession3";
956 sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
957 EXPECT_NE(sceneSession, nullptr);
958 ASSERT_TRUE(sceneSession->moveDragController_);
959
960 SystemSessionConfig sessionConfig;
961 sessionConfig.isSystemDecorEnable_ = true;
962 sessionConfig.decorModeSupportInfo_ = WindowModeSupport::WINDOW_MODE_SUPPORT_ALL;
963 sceneSession->systemConfig_ = sessionConfig;
964 sptr<WindowSessionProperty> property = new WindowSessionProperty();
965 property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
966 property->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
967 WindowLimits windowLimits = WindowLimits(1500, 1500, 500, 500, 3.0f, 0.3333f);
968 property->SetWindowLimits(windowLimits);
969 sceneSession->property_ = property;
970 float ratio = 4.0f;
971 auto result = sceneSession->SetAspectRatio(ratio);
972 if (result == WSError::WS_ERROR_INVALID_PARAM) {
973 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
974 }
975 ratio = 0.2f;
976 result = sceneSession->SetAspectRatio(ratio);
977 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
978 ratio = 1.5f;
979 result = sceneSession->SetAspectRatio(ratio);
980 ASSERT_EQ(result, WSError::WS_OK);
981
982 sessionConfig.isSystemDecorEnable_ = false;
983 sceneSession->systemConfig_ = sessionConfig;
984 ratio = 4.0f;
985 result = sceneSession->SetAspectRatio(ratio);
986 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
987 ratio = 0.2f;
988 result = sceneSession->SetAspectRatio(ratio);
989 ASSERT_EQ(result, WSError::WS_ERROR_INVALID_PARAM);
990 ratio = 1.5f;
991 result = sceneSession->SetAspectRatio(ratio);
992 ASSERT_EQ(result, WSError::WS_OK);
993 }
994
995 /**
996 * @tc.name: GetWindowId01
997 * @tc.desc: GetWindowId, normal scene
998 * @tc.type: FUNC
999 */
1000 HWTEST_F(WindowSessionTest, GetWindowId, Function | SmallTest | Level2)
1001 {
1002 ASSERT_NE(session_, nullptr);
1003 ASSERT_EQ(0, session_->GetWindowId());
1004 }
1005
1006 /**
1007 * @tc.name: GetVisible01
1008 * @tc.desc: GetVisible, normal scene
1009 * @tc.type: FUNC
1010 */
1011 HWTEST_F(WindowSessionTest, GetVisible, Function | SmallTest | Level2)
1012 {
1013 ASSERT_NE(session_, nullptr);
1014 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetVisible(false));
1015 session_->state_ = SessionState::STATE_CONNECT;
1016 if (!session_->GetVisible()) {
1017 ASSERT_EQ(false, session_->GetVisible());
1018 }
1019 }
1020
1021 /**
1022 * @tc.name: IsActive01
1023 * @tc.desc: IsActive, normal scene
1024 * @tc.type: FUNC
1025 */
1026 HWTEST_F(WindowSessionTest, IsActive, Function | SmallTest | Level2)
1027 {
1028 ASSERT_NE(session_, nullptr);
1029 session_->isActive_ = false;
1030 if (!session_->IsActive()) {
1031 ASSERT_EQ(false, session_->IsActive());
1032 }
1033 }
1034
1035 /**
1036 * @tc.name: SetFocusable01
1037 * @tc.desc: SetFocusable, normal scene
1038 * @tc.type: FUNC
1039 */
1040 HWTEST_F(WindowSessionTest, SetFocusable, Function | SmallTest | Level2)
1041 {
1042 ASSERT_NE(session_, nullptr);
1043 session_->state_ = SessionState::STATE_DISCONNECT;
1044 ASSERT_EQ(WSError::WS_ERROR_INVALID_SESSION, session_->SetFocusable(false));
1045 }
1046 }
1047 } // namespace Rosen
1048 } // namespace OHOS
1049